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

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