mgui/formbtxt.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/formbtxt.h
00003  * \brief MGUI::FORM_BUTTONTEXT class definitions
00004  *
00005  * \if NODOC
00006  * $Id: formbtxt.h_v 1.4 2003/10/03 19:58:19 linux32build!build Exp $
00007  *
00008  * $Log: formbtxt.h_v $
00009  * Revision 1.4  2003/10/03 19:58:19  linux32build!build
00010  * Doxygen
00011  *
00012  * Revision 1.3  2003/09/15 13:49:32  fileserver!dwilliss
00013  * Doxygen
00014  *
00015  * Revision 1.2  2003/04/09 20:49:59  dwilliss
00016  * Don't use _T in templates. Mac's ctype.h defines a global _T
00017  *
00018  * Revision 1.1  2002/10/09 16:20:16  mju
00019  * Initial revision
00020  *
00021  * \endif
00022 **/
00023 
00024 #ifndef  INC_MGUI_FORMBTXT_H
00025 #define  INC_MGUI_FORMBTXT_H
00026 
00027 #ifndef  INC_MGUI_CTRL_H
00028 #include <mgui/ctrl.h>
00029 #endif
00030 
00031 
00032 namespace MGUI {
00033 
00034 //===================================================================================================================
00035 //! Form containing PUSHBUTTON and non-editable text field.
00036 class FORM_BUTTONTEXT : public MGUI::FORM_COMPOSITE {
00037    public:
00038 
00039       //! Constructor.
00040       FORM_BUTTONTEXT (
00041          );
00042 
00043       //! Clear the text field.
00044       void ClearText (
00045          ) {
00046          #ifdef WIN32_MFC
00047             m_Text.SetWindowText("");
00048          #else
00049             m_Text.ClearValue(false);
00050          #endif
00051          }
00052 
00053       //! Create with label from resource lookup.
00054       void Create (
00055          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00056          const char *label,                  //!< Button label string for resource lookup
00057          int width = 0,                      //!< Width in 'em' characters
00058          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00059          );
00060 
00061       //! Create with Unicode label.
00062       void Create (
00063          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00064          const UNICODE *label,               //!< Button label string
00065          int width = 0,                      //!< Width in 'em' characters
00066          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00067          );
00068 
00069       //! Get reference to button control.
00070       CTRL_PUSHBUTTON& GetButton (
00071          ) { return (m_Button); }
00072 
00073       //! Set text to show in field.
00074       void SetText (
00075          const UNICODE* string
00076          ) {
00077          #ifdef WIN32_MFC
00078             m_Text.SetWindowText(CString(string));
00079          #else
00080             m_Text.SetValue(string,false);
00081          #endif
00082          }
00083 
00084    protected:
00085 
00086       virtual void OnPressed (
00087          ) = 0;
00088 
00089    private:
00090       #ifndef GENERATING_DOXYGEN_OUTPUT
00091    #ifdef WIN32_MFC
00092       class MyEdit : public CEdit {
00093          public:
00094             virtual BOOL PreCreateWindow (CREATESTRUCT& cs);
00095          };
00096       MyEdit m_Text;
00097    #else
00098       CTRL_EDIT_STRING m_Text;
00099    #endif
00100 
00101       CTRL_PUSHBUTTON_T<FORM_BUTTONTEXT> m_Button;
00102 
00103       void CreateText (int width, LAYOUT_SIZEALIGN sizealign);
00104 
00105       FORM_BUTTONTEXT (const FORM_BUTTONTEXT&);
00106       FORM_BUTTONTEXT& operator= (const FORM_BUTTONTEXT&);
00107       #endif // GENERATING_DOXYGEN_OUTPUT
00108    };
00109 
00110 
00111 //===================================================================================================================
00112 //! Convenience template for FORM_BUTTONTEXT to allow container method to be called.
00113 template <class _CT> class FORM_BUTTONTEXT_T : public MGUI::FORM_BUTTONTEXT {
00114    public:
00115 
00116       //! Constructor.
00117       FORM_BUTTONTEXT_T (
00118          ): m_pContainer(0), m_pfOnPressed(0) { }
00119 
00120       //! Create the control with label from resource lookup.
00121       void Create (
00122          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00123          const char* label,                     //!< Label string for resource lookup
00124          _CT *pContainer,                       //!< Pointer to callback container class
00125          void (_CT::*pfOnPressed)(),               //! Callback function pointer
00126          int width = 0,                         //!< Width in 'em' characters
00127          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00128          ) {
00129          m_pContainer = pContainer;
00130          m_pfOnPressed = pfOnPressed;
00131          FORM_BUTTONTEXT::Create(ParentPane,label,width,sizealign);
00132          return;
00133          }
00134 
00135       //! Create the control with Unicode label.
00136       void Create (
00137          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00138          const UNICODE* label,                  //!< Label string
00139          _CT *pContainer,                       //!< Pointer to callback container class
00140          void (_CT::*pfOnPressed)(),               //! Callback function pointer
00141          int width = 0,                         //!< Width in 'em' characters
00142          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00143          ) {
00144          m_pContainer = pContainer;
00145          m_pfOnPressed = pfOnPressed;
00146          FORM_BUTTONTEXT::Create(ParentPane,label,width,sizealign);
00147          return;
00148          }
00149 
00150    private:
00151       #ifndef GENERATING_DOXYGEN_OUTPUT
00152       _CT *m_pContainer;
00153       void (_CT::*m_pfOnPressed)();
00154 
00155       //! Called when button is pushed.
00156       virtual void OnPressed (
00157          ) { (m_pContainer->*m_pfOnPressed)(); }
00158       #endif // GENERATING_DOXYGEN_OUTPUT
00159    };
00160 
00161 
00162 //===================================================================================================================
00163 
00164 }  // End namespace MGUI
00165 
00166 #endif   // INC_MGUI_FORMBTXT_H

Generated on Thu Aug 12 06:18:28 2004 for TNTsdk by doxygen 1.3.4-20031026