formeditobjname.h

Go to the documentation of this file.
00001 /** 
00002  * \file mgui/formeditobjname.h 
00003  * \brief Definitions for MGUI::FORM_EDIT_OBJECTNAME classes.
00004  *
00005  * \if NODOC
00006  * $Id: formeditobjname.h_v 1.3 2003/12/11 15:07:06 mju Exp $
00007  *
00008  * $Log: formeditobjname.h_v $
00009  * Revision 1.3  2003/12/11 15:07:06  mju
00010  * Remove unnecessary base virtual call for onchangevalue.
00011  *
00012  * Revision 1.2  2003/10/01 22:32:25  dwilliss
00013  * doxygen
00014  *
00015  * Revision 1.1  2003/09/29 22:59:26  scowan
00016  * Initial revision
00017  * \endif
00018 **/
00019 
00020 #ifndef  INC_MGUI_FORM_EDIT_OBJNAME_H
00021 #define  INC_MGUI_FORM_EDIT_OBJNAME_H
00022 
00023 #ifndef INC_MGUI_FORM_H
00024 #include <mgui/form.h>
00025 #endif
00026 
00027 #ifndef  INC_MGUI_CTRL_H
00028 #include <mgui/ctrl.h>
00029 #endif
00030 
00031 #ifndef  INC_RVCDEFNS_H
00032 #include <mi32/rvcdefns.h>
00033 #endif
00034 
00035 namespace MGUI {
00036 
00037 //! String 'edit' control.
00038 class CTRL_EDIT_OBJECTNAME : public MGUI::CTRL_EDIT_BASE {
00039    public:
00040 
00041       //! Constructor.
00042       CTRL_EDIT_OBJECTNAME (
00043          );
00044 
00045       //! Destructor.
00046       virtual ~CTRL_EDIT_OBJECTNAME (
00047          );
00048 
00049       //! Clear to empty string.
00050       void ClearValue (
00051          bool notify = true                     //!< Call OnChangeValue() if control has already been created
00052          );
00053 
00054       //! Create control.
00055       void Create (
00056          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00057          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00058          );
00059 
00060       //! Get current string value.
00061       const RVC::OBJECTNAME& GetValue (
00062          ) const { return (m_value); }
00063 
00064       //! Read value from INI file.
00065       //! If Create() has already been performed the control's state will be updated.
00066       void IniRead (
00067          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
00068          const char *IniGroup,               //!< INI group to read from
00069          const char *IniField,               //!< INI field to read from
00070          bool notify = true                  //!< Call OnChangeValue() if control has already been created
00071          );
00072 
00073       //! Write current value to INI file.
00074       void IniWrite (
00075          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
00076          const char *IniGroup,               //!< INI group to read from
00077          const char *IniField                //!< INI field to read from
00078          ) const { ::IniWrite(IniHandle,IniGroup,IniField,m_value); }
00079 
00080       //! Select range of characters in string.
00081       void SetSelection (
00082          int StartChar = 0,                  //!< Starting character position in string, 0 for beginning
00083          int EndChar = -1,                   //!< Ending character position, -1 for end of string
00084          bool NoScroll = true                //!< Indicates whether to scroll caret into view
00085          )
00086       #ifdef WIN32_MFC
00087          { m_ctrl.SetSel(StartChar,EndChar,NoScroll); }
00088       #endif
00089          ;
00090 
00091       //! Set current string value with validation.
00092       //! OnValidate() will be called and if valid, the string will be updated.
00093       //! No comparison is made with the current string value.
00094       void SetValue (
00095          const RVC::OBJECTNAME& name,        //!< New string to set
00096          bool notify = true                  //!< Call OnChangeValue() if string actually updated
00097          );
00098 
00099    protected:
00100 
00101       //! Validate the string and alter if possible/necessary.
00102       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00103       //!   @return 'true' if string could be validated, 'false' if not
00104       virtual bool OnValidate (
00105          MISTRING& string                    //!< String to be validated
00106          );
00107 
00108    private:
00109 
00110       RVC::OBJECTNAME m_value;
00111 
00112       //! Called internally to update control-specific data from edit control.
00113       virtual void OnUserEdit ();
00114       virtual void UpdateValue (bool notify = true);
00115 
00116       CTRL_EDIT_OBJECTNAME (const CTRL_EDIT_OBJECTNAME&);
00117       CTRL_EDIT_OBJECTNAME& operator= (const CTRL_EDIT_OBJECTNAME&);
00118    };
00119 
00120 
00121 
00122 //-------------------------------------------------------------------------------------------------------------------
00123 //! Convenience template for String 'edit' control to allow method in container class to be called.
00124 template <class _CT> class CTRL_EDIT_OBJECTNAME_T : public MGUI::CTRL_EDIT_OBJECTNAME {
00125    public:
00126 
00127       //! Constructor.
00128       explicit CTRL_EDIT_OBJECTNAME_T (
00129          ): m_pContainer(0), m_pfOnChangeValue(0), m_pfOnValidate(0)
00130          { }
00131 
00132       //! Create control.
00133       void Create (
00134          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00135          _CT *pContainer,                       //!< Pointer to container
00136          void (_CT::*pfOnChangeValue)(),              //!< Function to call when value changed, NULL for none
00137          bool (_CT::*pfOnValidate)(MISTRING& string), //!< Function to call for validation, NULL for none
00138          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00139          ) {
00140          m_pContainer = pContainer;
00141          m_pfOnChangeValue = pfOnChangeValue;
00142          m_pfOnValidate = pfOnValidate;
00143          CTRL_EDIT_OBJECTNAME::Create(ParentPane, sizealign);
00144          }
00145 
00146    private:
00147       _CT *m_pContainer;
00148       void (_CT::*m_pfOnChangeValue)();
00149       bool (_CT::*m_pfOnValidate)(MISTRING&);
00150 
00151       virtual void OnChangeValue (
00152          ) {
00153          if (m_pContainer != 0) (m_pContainer->*m_pfOnChangeValue)();
00154          }
00155 
00156       virtual bool OnValidate (
00157          MISTRING& str
00158          ) {
00159          if (m_pContainer != 0 && m_pfOnValidate != 0) return((m_pContainer->*m_pfOnValidate)(str));
00160          return (CTRL_EDIT_OBJECTNAME::OnValidate(str));
00161          }
00162    };
00163 
00164 
00165 //===================================================================================================================
00166 //! Form consisting of label and string edit field.
00167 class FORM_EDIT_OBJECTNAME : public MGUI::FORM_COMPOSITE {
00168    public:
00169       //! Constructor.
00170       FORM_EDIT_OBJECTNAME (
00171          );
00172 
00173       //! Destructor.
00174       virtual ~FORM_EDIT_OBJECTNAME (
00175          );
00176 
00177       //! Clear to empty string.
00178       void ClearValue (
00179          bool notify = true                     //!< Call OnChangeValue() if control has already been created
00180          ) { m_editctrl.ClearValue(notify); }
00181 
00182       //! Create form with label from resource lookup.
00183       void Create (
00184          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00185          const MISTRING& label,                 //!< Label
00186          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00187          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00188          );
00189 
00190       //! Retrieve string "edit" control for form.
00191       MGUI::CTRL_EDIT_OBJECTNAME& GetEditCtrl (
00192          ) { return (m_editctrl); }
00193 
00194       //! Retrieve label control for form.
00195       //! Usually the label control is only retrieved for alignment purposes.
00196       MGUI::CTRL_LABEL& GetLabel (
00197          ) { return (m_label); }
00198 
00199       //! Get current string value.
00200       const RVC::OBJECTNAME& GetValue (
00201          ) const { return (m_editctrl.GetValue()); }
00202 
00203       //! Read value from INI file.
00204       //! If Create() has already been performed the control's state will be updated.
00205       void IniRead (
00206          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
00207          const char *IniGroup,               //!< INI group to read from
00208          const char *IniField,               //!< INI field to read from
00209          bool notify = true                  //!< Call OnChangeValue() if control has already been created
00210          ) { m_editctrl.IniRead(IniHandle,IniGroup,IniField,notify); }
00211 
00212       //! Write current value to INI file.
00213       void IniWrite (
00214          INIHANDLE IniHandle,                //!< Handle to INI file to write to, 0 for default
00215          const char *IniGroup,               //!< INI group to write to
00216          const char *IniField                //!< INI field to write to
00217          ) const { m_editctrl.IniWrite(IniHandle,IniGroup,IniField); }
00218 
00219       //! Set label text using string from resource lookup.
00220       void SetLabel (
00221          const MISTRING& label               //!< New label text
00222          ) { m_label.SetLabel(label); }
00223 
00224       //! Select range of characters in string.
00225       void SetSelection (
00226          int StartChar = 0,                  //!< Starting character position in string, 0 for beginning
00227          int EndChar = -1,                   //!< Ending character position, -1 for end of string
00228          bool NoScroll = true                //!< Indicates whether to scroll caret into view
00229          ) { m_editctrl.SetSelection(StartChar,EndChar,NoScroll); }
00230 
00231       //! Set set of 'valid' or 'invalid' characters.
00232       //! This does not alter the current contents, if any.
00233       void SetValidChars (
00234          const UNICODE* string,              //!< Characters valid or invalid to enter
00235          bool invert = false                 //!< Allow all but specified characters
00236          ) { m_editctrl.SetValidChars(string,invert); }
00237 
00238       //! Set current string value with validation.
00239       //! OnValidate() will be called and if valid, the string will be updated.
00240       //! No comparison is made with the current string value.
00241       void SetValue (
00242          const RVC::OBJECTNAME& name,        //!< New string to set
00243          bool notify = true                  //!< Call OnChangeValue() if string actually updated
00244          ) { m_editctrl.SetValue(name, notify); }
00245 
00246    protected:
00247 
00248       //! Called when value is changed after validation.
00249       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00250       //! If the user modifies the text in the edit control this will not be called until the control loses "focus".
00251       virtual void OnChangeValue ();
00252 
00253       //! Validate the string and alter if possible/necessary.
00254       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00255       //!   @return 'true' if string could be validated, 'false' if not
00256       virtual bool OnValidate (
00257          MISTRING& string                    //!< String to be validated
00258          );
00259 
00260    private:
00261       CTRL_LABEL m_label;
00262       CTRL_EDIT_OBJECTNAME_T<FORM_EDIT_OBJECTNAME> m_editctrl;
00263    };
00264 
00265 
00266 //:>-------------------------------------------------------------------------------------------------------------------
00267 //!   Convenience template for FORM_EDIT_OBJECTNAME to allow method in container class to be called.
00268 template <class _CT> class FORM_EDIT_OBJECTNAME_T : public MGUI::FORM_EDIT_OBJECTNAME {
00269    public:
00270 
00271       //! Constructor.
00272       explicit FORM_EDIT_OBJECTNAME_T (
00273          ): m_pContainer(0), m_pfOnChangeValue(0), m_pfOnValidate(0)
00274          { }
00275 
00276       //! Create form with label from resource lookup.
00277       void Create (
00278          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00279          const MISTRING& label,                 //!< Label
00280          _CT *pContainer,                       //!< Pointer to container
00281          void (_CT::*pfOnChangeValue)(),              //!< Function to call when value changed, NULL for none
00282          bool (_CT::*pfOnValidate)(MISTRING& string), //!< Function to call for validation, NULL for none
00283          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00284          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00285          ) {
00286          m_pContainer = pContainer;
00287          m_pfOnChangeValue = pfOnChangeValue;
00288          m_pfOnValidate = pfOnValidate;
00289          FORM_EDIT_OBJECTNAME::Create(ParentPane,label,sizealign,labelstyle);
00290          }
00291 
00292    private:
00293 
00294       _CT *m_pContainer;
00295       void (_CT::*m_pfOnChangeValue)();
00296       bool (_CT::*m_pfOnValidate)(MISTRING&);
00297 
00298       virtual void OnChangeValue (
00299          ) { if (m_pfOnChangeValue != 0) (m_pContainer->*m_pfOnChangeValue)(); }
00300       virtual bool OnValidate (
00301          MISTRING& string
00302          ) { return ((m_pfOnValidate != 0) ? (m_pContainer->*m_pfOnValidate)(string) : true); }
00303    };
00304 
00305 }  // End of MGUI namespace
00306 
00307 #endif      // INC_MGUI_FORM_EDIT_OBJNAME_H
00308 

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