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

Generated on Wed May 31 15:26:43 2006 for TNTsdk by  doxygen 1.3.8-20040913