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.6 2004/07/27 13:33:34 mju Exp $
00007  *
00008  * $Log: formbtxt.h_v $
00009  * Revision 1.6  2004/07/27 13:33:34  mju
00010  * Un-deprecate template methods.
00011  *
00012  * Revision 1.5  2004/07/22 14:55:19  mju
00013  * Use MISTRING so can use textid.
00014  *
00015  * Revision 1.4  2003/10/03 19:58:19  linux32build!build
00016  * Doxygen
00017  *
00018  * Revision 1.3  2003/09/15 13:49:32  fileserver!dwilliss
00019  * Doxygen
00020  *
00021  * Revision 1.2  2003/04/09 20:49:59  dwilliss
00022  * Don't use _T in templates. Mac's ctype.h defines a global _T
00023  *
00024  * Revision 1.1  2002/10/09 16:20:16  mju
00025  * Initial revision
00026  *
00027  * \endif
00028 **/
00029 
00030 #ifndef  INC_MGUI_FORMBTXT_H
00031 #define  INC_MGUI_FORMBTXT_H
00032 
00033 #ifndef  INC_MGUI_CTRL_H
00034 #include <mgui/ctrl.h>
00035 #endif
00036 
00037 
00038 namespace MGUI {
00039 
00040 //===================================================================================================================
00041 //! Form containing PUSHBUTTON and non-editable text field.
00042 class FORM_BUTTONTEXT : public MGUI::FORM_COMPOSITE {
00043    public:
00044 
00045       //! Constructor.
00046       FORM_BUTTONTEXT (
00047          );
00048 
00049       //! Clear the text field.
00050       void ClearText (
00051          ) {
00052          #ifdef WIN32_MFC
00053             m_Text.SetWindowText("");
00054          #else
00055             m_Text.ClearValue(false);
00056          #endif
00057          }
00058 
00059       //! Create with label from resource lookup.
00060       void Create (
00061          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00062          const char *label,                  //!< Button label string for resource lookup
00063          int width = 0,                      //!< Width in 'em' characters
00064          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00065          );
00066 
00067       //! Create with MISTRING label.
00068       void Create (
00069          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00070          const MISTRING& label,              //!< Button label string
00071          int width = 0,                      //!< Width in 'em' characters
00072          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00073          );
00074 
00075       //! Get reference to button control.
00076       CTRL_PUSHBUTTON& GetButton (
00077          ) { return (m_Button); }
00078 
00079       //! Set text to show in field.
00080       void SetText (
00081          const MISTRING& string
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 MISTRING& 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 Tue Dec 14 13:18:16 2004 for TNTsdk by  doxygen 1.3.8-20040913