wg_range_control.h

00001 // wg_range_control.h
00002 //
00003 // CRangeControl interface
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #ifndef _WG_RANGE_CONTROL_H_
00026 #define _WG_RANGE_CONTROL_H_
00027 
00028 #include "wg_window.h"
00029 #include "wg_message_server.h"
00030 
00031 
00032 namespace wGui
00033 {
00034 
00037 
00038 template<typename T>
00039 class CRangeControl : public CWindow
00040 {
00041 public:
00049      CRangeControl(const CRect& WindowRect, CWindow* pParent, T minLimit, T maxLimit, T stepSize, T defaultValue) :
00050           CWindow(WindowRect, pParent), m_MinLimit(minLimit), m_MaxLimit(maxLimit), m_StepSize(stepSize), m_Value(defaultValue) { }
00051 
00054      virtual void SetMinLimit(T minLimit) { m_MinLimit = minLimit; }
00055 
00058      virtual T GetMinLimit(void) const { return m_MinLimit; }
00059 
00062      virtual void SetMaxLimit(T maxLimit) { m_MaxLimit = maxLimit; }
00063 
00066      virtual T GetMaxLimit(void) const { return m_MaxLimit; }
00067 
00070      virtual void SetStepSize(T stepSize) { m_StepSize = stepSize; }
00071 
00074      virtual T GetStepSize(void) const { return m_StepSize; }
00075 
00079      virtual void SetValue(T value, bool bRedraw = true)
00080      {
00081           m_Value = ConstrainValue(value);
00082           CMessageServer::Instance().QueueMessage(new CValueMessage<T>(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, m_Value));
00083 
00084           if (bRedraw)
00085           {
00086                Draw();
00087           }
00088      }
00089 
00092      virtual T GetValue(void) const { return m_Value; }
00093 
00096      virtual void Increment(bool bRedraw = true) { SetValue(m_Value + m_StepSize, bRedraw); }
00097 
00100      virtual void Decrement(bool bRedraw = true) { SetValue(m_Value - m_StepSize, bRedraw); }
00101 
00105      virtual T ConstrainValue(T value) const
00106      {
00107           if (value < m_MinLimit)
00108           {
00109                value = m_MinLimit;
00110           }
00111           if (value > m_MaxLimit)
00112           {
00113                value = m_MaxLimit;
00114           }
00115           return value;
00116      }
00117 
00118 
00119 protected:
00120      T m_MinLimit;  
00121      T m_MaxLimit;  
00122      T m_StepSize;  
00123      T m_Value;  
00124 
00125 
00126 private:
00127      void operator=(CRangeControl) { }  
00128 };
00129 
00130 }
00131 
00132 
00133 #endif  // _WG_RANGE_CONTROL_H_
00134 

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1