colorbtn.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/colorbtn.h
00003  * \brief MGUI CTRL_COLORBUTTON and FORM_COLORBUTTON class definitions
00004  *
00005  * \if NODOC
00006  * $Id: colorbtn.h_v 1.7 2003/10/03 19:58:19 linux32build!build Exp $
00007  *
00008  * $Log: colorbtn.h_v $
00009  * Revision 1.7  2003/10/03 19:58:19  linux32build!build
00010  * Doxygen
00011  *
00012  * Revision 1.6  2003/09/15 13:49:32  fileserver!dwilliss
00013  * Doxygen
00014  *
00015  * Revision 1.5  2003/04/09 20:46:42  dwilliss
00016  * Don't use _T in templates. Mac ctypes.h defines a global _T
00017  *
00018  * Revision 1.4  2002/10/09 16:31:00  mju
00019  * Moved to 'mgui' folder.
00020  *
00021  * Revision 1.2  2001/12/13 20:15:32  mju
00022  * Add CTRL version without label.
00023  *
00024  * Revision 1.1  2001/12/13 16:58:26  mju
00025  * Initial revision
00026  * \endif
00027 **/
00028 
00029 #ifndef  INC_MGUI_COLORBTN_H
00030 #define  INC_MGUI_COLORBTN_H
00031 
00032 #ifndef  INC_MGUI_CTRL_H
00033 #include <mgui/ctrl.h>
00034 #endif
00035 
00036 namespace MGUI {
00037 
00038 //===================================================================================================================
00039 //! PushButton control for showing and selecting a "color".
00040 //! The button will be shown in the selected color and contains no visible text.
00041 class CTRL_COLORBUTTON : public MGUI::CTRL {
00042    public:
00043 
00044       enum STYLE {
00045          STYLE_Default =            0x0000,
00046          STYLE_OutputOnly =         0x0001,     //!< User cannot change value
00047          STYLE_AllowTransparent =   0x0002      //!< Allow transparent/transparency settings
00048          };
00049 
00050       //! Constructor.
00051       CTRL_COLORBUTTON (
00052          );
00053 
00054       //! Destructor.
00055       virtual ~CTRL_COLORBUTTON (
00056          );
00057 
00058       //! Create control.
00059       void Create (
00060          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00061          const COLOR& dftcolor,                 //!< Default color
00062          STYLE style = STYLE_Default,           //!< Control style
00063          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00064          );
00065 
00066       //! Get current color.
00067       const COLOR& GetColor (
00068          ) const { return (m_color); }
00069 
00070       //! Get current color.
00071       COLORREF GetColorRef (
00072          ) const { return (m_color.GetColorRef()); }
00073 
00074       //! Set color.
00075       void SetColor (
00076          const COLOR& color,                 //!< New color value to set
00077          bool notify = true                  //!< Call OnChangeColor() if 'true'
00078          );
00079 
00080       //! Set color.
00081       void SetColor (
00082          const COLORREF color,               //!< New color value to set
00083          bool notify = true                  //!< Call OnChangeColor() if 'true'
00084          ) { COLOR c; c.SetColorRef(color); SetColor(c, notify); }
00085 
00086    protected:
00087 
00088       //! Called when color is changed.
00089       //! Derived class must call corresponding superclass method BEFORE performing its own processing.
00090       virtual void OnChangeColor (
00091          );
00092 
00093    private:
00094    #ifndef GENERATING_DOXYGEN_OUTPUT
00095 
00096    #ifdef WIN32_MFC
00097       class MyButton : public CButton {
00098          public:
00099             MyButton (
00100                CTRL_COLORBUTTON& guiform
00101                ): m_guiform(guiform)
00102                { }
00103          protected:
00104             afx_msg void OnClicked ();
00105             DECLARE_MESSAGE_MAP()
00106          private:
00107             CTRL_COLORBUTTON& m_guiform;
00108             virtual void DrawItem (DRAWITEMSTRUCT*);
00109          };
00110       MyButton m_ctrl;
00111    #endif
00112 
00113    #ifdef X_NATIVE
00114       Pixel m_pixel;
00115    #endif
00116 
00117       COLOR m_color;
00118       STYLE m_style;
00119 
00120    #ifdef X_NATIVE
00121       static void CCB_ChangeColorMap (void*, UINT8*);
00122       static void CB_PushButton (Widget, CTRL_COLORBUTTON*, void*);
00123       void UpdateButtonColor ();
00124    #endif
00125 
00126       CTRL_COLORBUTTON (const CTRL_COLORBUTTON&);
00127       CTRL_COLORBUTTON& operator= (const CTRL_COLORBUTTON&);
00128    #endif // GENERATING_DOXYGEN_OUTPUT
00129    };
00130 DEFINE_ENUM_OPERATORS(CTRL_COLORBUTTON::STYLE);
00131 
00132 
00133 //-------------------------------------------------------------------------------------------------------------------
00134 //! Template form containing label and button for showing and selecting a "color".
00135 template <class _CT> class CTRL_COLORBUTTON_T : public MGUI::CTRL_COLORBUTTON {
00136    public:
00137 
00138       //! Constructor.
00139       CTRL_COLORBUTTON_T (
00140          ): m_pContainer(0), m_pfOnChangeColor(0) { }
00141 
00142       //! Create control.
00143       void Create (
00144          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00145          _CT *pContainer,                       //!< Pointer to callback container class
00146          void (_CT::*pfOnChangeColor)(),        //! Container method to call for color change notification
00147          const COLOR& dftcolor,                 //!< Default color
00148          STYLE style = STYLE_Default,           //!< Control style
00149          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00150          ) {
00151          m_pContainer = pContainer;
00152          m_pfOnChangeColor = pfOnChangeColor;
00153          CTRL_COLORBUTTON::Create(ParentPane,dftcolor,style,sizealign);
00154          }
00155 
00156    private:
00157       #ifndef GENERATING_DOXYGEN_OUTPUT
00158       _CT *m_pContainer;
00159       void (_CT::*m_pfOnChangeColor)();
00160 
00161       virtual void OnChangeColor (
00162          ) { (m_pContainer->*m_pfOnChangeColor)(); }
00163       #endif // GENERATING_DOXYGEN_OUTPUT
00164    };
00165 
00166 
00167 //===================================================================================================================
00168 //! Form containing label and color pushbutton for showing and selecting a "color".
00169 //! The button will be shown in the selected color and contains no visible text.
00170 class FORM_COLORBUTTON : public MGUI::FORM_COMPOSITE {
00171    public:
00172 
00173       //! Constructor.
00174       FORM_COLORBUTTON (
00175          );
00176 
00177       //! Destructor.
00178       virtual ~FORM_COLORBUTTON (
00179          );
00180 
00181       //! Create form with label from resource lookup.
00182       void Create (
00183          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00184          const char* label,                     //!< Label string for resource lookup
00185          const COLOR& dftcolor,                 //!< Default color
00186          MGUI::CTRL_COLORBUTTON::STYLE buttonstyle = MGUI::CTRL_COLORBUTTON::STYLE_Default,
00187          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00188          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00189          );
00190 
00191       //! Create form with Unicode label.
00192       void Create (
00193          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00194          const UNICODE *label,                  //!< Label string
00195          const COLOR& dftcolor,                 //!< Default color
00196          MGUI::CTRL_COLORBUTTON::STYLE buttonstyle = MGUI::CTRL_COLORBUTTON::STYLE_Default,
00197          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00198          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00199          );
00200 
00201       //! Get current color.
00202       const COLOR& GetColor (
00203          ) const { return (m_button.GetColor()); }
00204 
00205       //! Get current color.
00206       COLORREF GetColorRef (
00207          ) const { return (m_button.GetColorRef()); }
00208 
00209       //! Retrieve label control for form.
00210       //! Usually the label control is only retrieved for alignment purposes.
00211       MGUI::CTRL_LABEL& GetLabel (
00212          ) { return (m_label); }
00213 
00214       //! Set color.
00215       void SetColor (
00216          const COLOR& color,                 //!< New color value to set
00217          bool notify = true                  //!< Call OnChangeColor() if 'true'
00218          ) { m_button.SetColor(color,notify); }
00219 
00220       //! Set color.
00221       void SetColor (
00222          const COLORREF color,               //!< New color value to set
00223          bool notify = true                  //!< Call OnChangeColor() if 'true'
00224          ) { m_button.SetColor(color,notify); }
00225 
00226       //! Set label text using string from resource lookup.
00227       void SetLabel (
00228          const char* label                   //!< New label text
00229          ) { m_label.SetLabel(label); }
00230 
00231       //! Set label text from Unicode string.
00232       void SetLabel (
00233          const UNICODE* label                //!< New label text
00234          ) { m_label.SetLabel(label); }
00235 
00236    protected:
00237 
00238       //! Called when value is changed.
00239       //! Derived class must call corresponding superclass method BEFORE performing its own processing.
00240       virtual void OnChangeColor (
00241          );
00242 
00243    private:
00244       #ifndef GENERATING_DOXYGEN_OUTPUT
00245 
00246       CTRL_COLORBUTTON_T<FORM_COLORBUTTON> m_button;
00247       MGUI::CTRL_LABEL m_label;
00248 
00249       FORM_COLORBUTTON (const FORM_COLORBUTTON&);
00250       FORM_COLORBUTTON& operator= (const FORM_COLORBUTTON&);
00251       #endif // GENERATING_DOXYGEN_OUTPUT
00252    };
00253 
00254 
00255 //-------------------------------------------------------------------------------------------------------------------
00256 //! Template form containing label and button for showing and selecting a "color".
00257 template <class _CT> class FORM_COLORBUTTON_T : public MGUI::FORM_COLORBUTTON {
00258    public:
00259 
00260       //! Constructor.
00261       FORM_COLORBUTTON_T (
00262          ): m_pContainer(0), m_pfOnChangeColor(0) { }
00263 
00264       //! Create with label from resource lookup.
00265       void Create (
00266          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00267          const char* label,                     //!< Label string for resource lookup
00268          _CT *pContainer,                       //!< Pointer to callback container class
00269          void (_CT::*pfOnChangeColor)(),        //! Container method to call for color change notification
00270          const COLOR& dftcolor,                 //!< Default color
00271          MGUI::CTRL_COLORBUTTON::STYLE buttonstyle = MGUI::CTRL_COLORBUTTON::STYLE_Default,
00272          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00273          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00274          ) {
00275          m_pContainer = pContainer;
00276          m_pfOnChangeColor = pfOnChangeColor;
00277          FORM_COLORBUTTON::Create(ParentPane,label,dftcolor,buttonstyle,sizealign,labelstyle);
00278          }
00279 
00280       //! Create with Unicode label.
00281       void Create (
00282          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00283          const UNICODE *label,                  //!< Label string
00284          _CT *pContainer,                       //!< Pointer to callback container class
00285          void (_CT::*pfOnChangeColor)(),        //! Container method to call for color change notification
00286          const COLOR& dftcolor,                 //!< Default color
00287          MGUI::CTRL_COLORBUTTON::STYLE buttonstyle = MGUI::CTRL_COLORBUTTON::STYLE_Default,
00288          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00289          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00290          ) {
00291          m_pContainer = pContainer;
00292          m_pfOnChangeColor = pfOnChangeColor;
00293          FORM_COLORBUTTON::Create(ParentPane,label,dftcolor,buttonstyle,sizealign,labelstyle);
00294          }
00295 
00296    private:
00297       #ifndef GENERATING_DOXYGEN_OUTPUT
00298       _CT *m_pContainer;
00299       void (_CT::*m_pfOnChangeColor)();
00300 
00301       virtual void OnChangeColor (
00302          ) { (m_pContainer->*m_pfOnChangeColor)(); }
00303       #endif // GENERATING_DOXYGEN_OUTPUT
00304    };
00305 
00306 //===================================================================================================================
00307 
00308 }  // End of MGUI namespace
00309 
00310 #endif   // INC_MGUI_COLORBTN_H

Generated on Tue Dec 14 13:18:15 2004 for TNTsdk by  doxygen 1.3.8-20040913