ctrl.h

Go to the documentation of this file.
00001 /** 
00002  * \file mgui/ctrl.h
00003  * \brief Definitions for MGUI::CTRL classes.
00004  *
00005  * \if NODOC
00006  * $Id: ctrl.h_v 1.58 2004/10/13 22:18:04 mju Exp $
00007  *
00008  * $Log: ctrl.h_v $
00009  * Revision 1.58  2004/10/13 22:18:04  mju
00010  * Use mistring for labels instead of unicode*.
00011  *
00012  * Revision 1.57  2004/10/06 23:43:12  dfriberg
00013  * Fixed ordered list comment (doxygen)
00014  *
00015  * Revision 1.56  2004/10/04 15:26:23  mju
00016  * Use mistring in togglebutton_t.
00017  *
00018  * Revision 1.55  2004/08/19 13:46:08  mju
00019  * Change tooltipctrl to match base create fn to avoid annoying warnings.
00020  *
00021  * Revision 1.54  2004/07/27 13:42:09  mju
00022  * Add groupbox.setlabeltext.
00023  *
00024  * Revision 1.53  2004/07/26 15:10:45  mju
00025  * Add ability to specify width in pixels for text fields.
00026  *
00027  * Revision 1.52  2004/06/23 20:51:37  dwilliss
00028  * Added activate members to edit templates
00029  *
00030  * Revision 1.51  2004/05/28 21:43:47  mju
00031  * Change separator to take length and add create method using text.
00032  *
00033  * Revision 1.50  2004/04/08 21:23:19  mju
00034  * Change setfocus to v_setfocus.
00035  *
00036  * Revision 1.49  2004/03/30 17:26:10  vdronov
00037  * CTRL_SEPARATOR class added
00038  *
00039  * Revision 1.48  2004/03/15 17:45:57  dwilliss
00040  * Added a SetMaxLength() method to edit controls
00041  *
00042  * Revision 1.47  2003/12/18 13:43:44  mju
00043  * Simplify 'edit' templates by making ctor take pContainer and using SetFunc...
00044  *   methods to set functions.  This allows use of base Create() methods.
00045  * Add OnUserEdit for edit_number.
00046  *
00047  * Revision 1.46  2003/12/12 18:49:36  mju
00048  * Move 'selection' methods to edit_base.
00049  * Add set/clear selection methods to ctrl_text.
00050  *
00051  * Revision 1.45  2003/12/12 15:30:23  mju
00052  * Change CB_valuechanged parm.
00053  *
00054  * Revision 1.44  2003/12/11 20:57:27  mju
00055  * Need OnUserEdit in FORM_EDIT_STRING.
00056  *
00057  * Revision 1.43  2003/12/11 18:38:58  mju
00058  * Add OnUserEdit for form_edit_string too.
00059  *
00060  * Revision 1.42  2003/12/11 18:27:10  mju
00061  * Don't call pfOnUserEdit if null.
00062  *
00063  * Revision 1.41  2003/12/11 15:40:06  mju
00064  * For edit controls make base overridables private as don't need to call from derived.
00065  *
00066  * Revision 1.40  2003/11/14 16:14:21  dwilliss
00067  * Added MISTRING versions of label create and set methods to allow TEXTIDs
00068  * Should deprecate the plain UNICODE versions?  Not sure, leave `em for now.
00069  *
00070  * Revision 1.39  2003/11/03 18:47:53  mju
00071  * Make edit::getValue methods non-inline and non-const so can update to lateset edits.
00072  *
00073  * Revision 1.38  2003/10/27 16:16:06  mju
00074  * For 'edit' controls, move Get/SetModify to base and implement for X also.
00075  *
00076  * Revision 1.37  2003/10/02 16:19:23  linux32build!build
00077  * Doxygen fix
00078  *
00079  * Revision 1.36  2003/10/01 22:32:38  dwilliss
00080  * doxygen
00081  *
00082  * Revision 1.35  2003/09/15 13:49:32  fileserver!dwilliss
00083  * Doxygen
00084  *
00085  * Revision 1.34  2003/08/19 22:39:21  msmith
00086  * CTRL_LABEL for MFC now does multiline text and icons.
00087  *
00088  * Revision 1.33  2003/08/01 16:54:03  scowan
00089  * Added ctrl label create icon methods.
00090  *
00091  * Revision 1.32  2003/06/30 15:01:52  scowan
00092  * Moved ctrl text clear method from an inline.
00093  *
00094  * Revision 1.31  2003/04/15 16:42:32  mju
00095  * Include rect.h.
00096  *
00097  * Revision 1.30  2003/04/09 20:48:09  dwilliss
00098  * Don't use _T in templates.  Mac's ctype.h defines a global _T
00099  *
00100  * Revision 1.29  2003/01/27 18:54:19  mju
00101  * Move POINT defn to layout.h.
00102  *
00103  * Revision 1.28  2003/01/16 21:35:11  mju
00104  * Move listbox/combobox hdrs to end as need ctrl first.
00105  *
00106  * Revision 1.27  2003/01/16 21:13:10  mju
00107  * Move listbox/combobox defns to own headers.
00108  *
00109  * Revision 1.24  2002/12/02 17:13:19  mju
00110  * Add GetBackgroundColor.
00111  *
00112  * Revision 1.23  2002/11/18 21:54:05  mju
00113  * Add listbox X callbacks.
00114  *
00115  * Revision 1.22  2002/10/14 19:16:31  mju
00116  * Only define togglebutton::style_RadioFirst for MFC.
00117  *
00118  * Revision 1.21  2002/10/11 19:40:34  dwilliss
00119  * Get rid of KEYSTATE_Alt
00120  *
00121  * Revision 1.20  2002/10/11 16:14:51  mju
00122  * Change CTRL to have pointer instead of reference to actual control for MFC.
00123  * This allows the definition of the MFC control to be in the implementation module.
00124  *
00125  * Revision 1.19  2002/10/11 14:49:18  dwilliss
00126  * Moved the KEYSTATE enum to here
00127  *
00128  * Revision 1.18  2002/10/09 16:51:18  mju
00129  * Forward declare TEXTSTYLE.
00130  *
00131  * Revision 1.17  2002/10/09 15:33:21  mju
00132  * Moved to 'mgui' folder.
00133  *
00134  * Revision 1.16  2002/10/09 15:26:17  dwilliss
00135  * Added some methods and a flag to CTRL_TEXT
00136  *
00137  * Revision 1.15  2002/09/17 17:13:03  scowan
00138  * Removed mgui namespace qualifier on a ctor declaration.
00139  *
00140  * Revision 1.13  2002/08/09 13:29:57  mju
00141  * Add const getcombobox method.
00142  *
00143  * Revision 1.12  2002/07/09 15:39:58  dwilliss
00144  * Added an InvalidateRect method to match the MFC one
00145  *
00146  * Revision 1.11  2002/06/06 20:56:44  mju
00147  * Don't inline combo/listbox methods.
00148  *
00149  * Revision 1.9  2002/01/03 15:10:16  mju
00150  * Allow GROUPBOX cast to PANE in X too.
00151  *
00152  * Revision 1.8  2001/12/19 21:01:05  mju
00153  * Change comments for OnPressed regarding base class method.
00154  *
00155  * Revision 1.7  2001/12/18 23:07:58  mju
00156  * Add listheight for X ComboBox so will remember preferred size.
00157  *
00158  * Revision 1.6  2001/12/18 18:25:01  mju
00159  * Add FORM_EDIT_STRING::ClearValue().
00160  *
00161  * Revision 1.4  2001/12/14 18:52:11  mju
00162  * ICONID is now an enum.
00163  *
00164  * Revision 1.3  2001/12/13 17:00:05  mju
00165  * MGUI unification with X.
00166  *
00167  * Revision 1.2  2001/12/05 21:55:27  mju
00168  * Include MFC header when building for such.
00169  *
00170  * Revision 1.1  2001/12/03 17:38:38  mju
00171  * Initial revision
00172  * \endif
00173 **/
00174 
00175 #ifndef  INC_MGUI_CTRL_H
00176 #define  INC_MGUI_CTRL_H
00177 
00178 #ifndef INC_MGUI_FORM_H
00179 #include <mgui/form.h>
00180 #endif
00181 
00182 #ifndef  INC_MI32_RANGE_H
00183 #include <mi32/range.h>
00184 #endif
00185 
00186 #ifndef  INC_MI32_RECT_H
00187 #include <mi32/rect.h>
00188 #endif
00189 
00190 #ifndef  INC_MI32_LATLONFM_H
00191 #include <mi32/latlonfm.h>
00192 #endif
00193 
00194 #ifndef  INC_MI32_UNITCONV_H
00195 #include <mi32/unitconv.h>
00196 #endif
00197 
00198 #ifndef  INC_MI32_SIMPLEAR_H
00199 #include <mi32/simplear.h>
00200 #endif
00201 
00202 #ifndef  INC_MI32_ICONID_H
00203 #include <mi32/iconid.h>
00204 #endif
00205 
00206 struct TEXTSTYLE;
00207 
00208 namespace MGUI {
00209 
00210 
00211 //===================================================================================================================
00212 //! Enum used to specify which keys are pressed during a message handler.
00213 //! NOTE:  These are exactly equivilant to some Windows constants.
00214 //! The Alt KEYSTATE is not here because there is no mask for it in X
00215 enum KEYSTATE {
00216    KEYSTATE_None     = 0x0000,
00217    KEYSTATE_Ctrl     = 0x0002,
00218    KEYSTATE_Control  = 0x0002,
00219    KEYSTATE_Shift    = 0x0004
00220    };
00221 
00222 DEFINE_ENUM_OP_BITWISE(MGUI::KEYSTATE);
00223 
00224 //===================================================================================================================
00225 //! Base class for "single" graphical user interface controls.
00226 //!
00227 //! There are two basic types of 'controls' which can be used in user interface implementation,
00228 //! controls which the user can interact with and 'static' controls which the user cannot change
00229 //! directly.
00230 //!
00231 //! All controls which the user can manipulate also encapsulate information about the current
00232 //! 'state' of the control (except for MGUI::CTRL_PUSHBUTTON as explained below).  There are three ways
00233 //! to use each of these controls in a program (in order of convenience):
00234 //!
00235 //!      -# If changing the state of a control has no other immediate effect then the control class
00236 //!         may be used directly and the state information retrieved when needed, such as when the
00237 //!         user presses 'OK' on the dialog.  This option is not available for MGUI::CTRL_PUSHBUTTON as
00238 //!         pressing a button must always have some other affect and MGUI::CTRL_PUSHBUTTON contains no
00239 //!         'state' information.
00240 //!      -# Use the template version of the control and specify a callback 'container' and callback
00241 //!         method pointer for the control.  This allows the callback to be a method of the 'container'
00242 //!         class (usually the dialog, page or main window) thus allowing access to other controls in
00243 //!         the container.  This is similar to MFC message maps and avoids the common need to include
00244 //!         a reference or pointer to the container in a subclass.  Templates for controls with a
00245 //!         single On... virtual method will generally include the container and method pointer as
00246 //!         parameters to the Create() methods.  Templates for controls with multiple On... virtual
00247 //!         methods will generally have a SetFunc... method for each corresponding On... virtual
00248 //!         method in their base class and will not override the Create() methods.
00249 //!      -# Inherit from the control class and override the On... virtual method to perform task
00250 //!         specific processing.  This is simplest if no reference to the containing dialog or
00251 //!         window is necessary.  Also for some control types, the template version itself may be
00252 //!         inherited from to override other virtual methods, such as MGUI::CTRL_EDIT_... validation
00253 //!         methods.
00254 //!
00255 class CTRL : public MGUI::FORM {
00256    public:
00257 
00258       //! Destructor.
00259       virtual ~CTRL (
00260          ) = 0;
00261 
00262       //! Get interface 'background' color.
00263       static const COLOR& GetBackgroundColor (
00264          );
00265 
00266    #ifdef WIN32_MFC
00267       //! Get "client rectangle" for the primary control window (MFC only).
00268       void GetClientRect (
00269          LPRECT lpRect
00270          ) const { m_pWnd->GetClientRect(lpRect); }
00271    #endif
00272 
00273    #ifdef WIN32_MFC
00274       //! Get the CWnd of the primary control (MFC only).
00275       CWnd* GetCWnd (
00276          ) { return (m_pWnd); }
00277    #endif
00278 
00279    #ifdef X_NATIVE
00280       //! Get the Widget for the control or container if multiple controls (X only).
00281       //! The widget should only be used for attachment, do not assume the
00282       //! widget is of a particular type.
00283       Widget GetWidget (
00284          ) { return (m_widget); }
00285    #endif
00286 
00287    #ifdef WIN32_MFC
00288       //! Invalidate the entire client area (MFC only).
00289       //! This will force it to redraw the next WM_PAINT message occurs.
00290       void Invalidate (
00291          bool erase = true
00292          ) { m_pWnd->Invalidate(erase); }
00293    #endif
00294 
00295    #ifdef WIN32_MFC
00296       //! Invalidate a rectangle in the client area (MFC only).
00297       //! This will force it to redraw the next WM_PAINT message occurs.
00298       void InvalidateRect (
00299          const LRECT2D& lrect,
00300          bool erase = true
00301          ) { 
00302          CRect rect(lrect.xinit, lrect.yinit, lrect.xlast, lrect.ylast);
00303          m_pWnd->InvalidateRect(rect, erase); 
00304          }
00305    #endif
00306 
00307       //! Determine if control has been created.
00308       //! @return true if created, false if not.
00309       virtual bool IsCreated (
00310          ) const;
00311 
00312       //! Determine if control is enabled for keyboard or mouse input.
00313       //! @return true if enabled, false if not, or if not yet created.
00314       virtual bool IsEnabled (
00315          ) const;
00316 
00317    #ifdef WIN32_MFC
00318       //! Called to process messages before translation (MFC only).
00319       //! Allows a control to trap messages before they get passed.  Should return
00320       //! 'true' if the message was translated and should not be dispatched or
00321       //! 'false' if the message was not handled and should be dispatched.
00322       //! The control must also be added to the root layout's pretranslation list via
00323       //! MGUI::LAYOUT_PANE_BASE::PreTransListAddCtrl().  This should be done in the
00324       //! control's Create() method.
00325       virtual bool PreTranslateMessageHook (
00326          MSG *pMsg
00327          ) { return (false); }
00328    #endif
00329 
00330       //! Set whether mouse or keyboard input to control is allowed.
00331       virtual void SetEnabled (
00332          bool enabled = true
00333          );
00334 
00335    #ifdef WIN32_MFC
00336       //! Allow the window to be redrawn (MFC only).
00337       void SetRedraw (
00338          bool redraw = true
00339          ) { m_pWnd->SetRedraw(redraw); }
00340    #endif
00341 
00342       //! Set whether control is visible or not.
00343       virtual void SetVisible (
00344          bool visible = true
00345          );
00346 
00347    #ifdef WIN32_MFC
00348       //! Generate a WM_PAINT message if the window needs to be updated
00349       void UpdateWindow (
00350          ) { m_pWnd->UpdateWindow(); }
00351    #endif
00352 
00353    protected:
00354 
00355    #ifdef WIN32_MFC
00356       CWnd *m_pWnd;           //!< Pointer to actual control in derived class
00357 
00358       //! Constructor (MFC version).
00359       CTRL (
00360          CWnd& wnd
00361          ): m_pWnd(&wnd) { }
00362 
00363       CTRL (
00364          CWnd *pWnd
00365          ): m_pWnd(pWnd) { }
00366 
00367    #endif
00368 
00369    #ifdef X_NATIVE
00370       Widget m_widget;
00371 
00372       //! Constructor (X version).
00373       CTRL (
00374          ): m_widget(0) { }
00375 
00376       //! Add 'Destroy' callback for widget.
00377       void AddDestroyCallback (
00378          );
00379 
00380       //! Called if widgets are destroyed before CTRL class instance.
00381       //! Will not be called if CTRL class instance is destroyed before widgets.
00382       //! Usually just sets widgets to NULL so won't be referenced in destructor.
00383       //! Derived class must call corresponding base class method AFTER performing its own processing.
00384       virtual void OnDestroy (
00385          );
00386    #endif
00387 
00388    private:
00389       #ifndef GENERATING_DOXYGEN_OUTPUT
00390 
00391    #ifdef X_NATIVE
00392       static void CB_Destroy (Widget, CTRL*, void*);
00393    #endif
00394 
00395       // MGUI::FORM overrides.
00396       virtual void v_SetFocus () const;
00397 
00398       CTRL (const CTRL&);
00399       CTRL& operator= (const CTRL&);
00400       #endif // GENERATING_DOXYGEN_OUTPUT
00401    };
00402 
00403 
00404 //===================================================================================================================
00405 //! Non-editable label control.
00406 class CTRL_LABEL : public MGUI::CTRL {
00407    public:
00408 
00409       enum STYLE {
00410          STYLE_LeftNoWrap,                      //!< Left-justify text without word wrapping
00411          STYLE_Left,                            //!< Left-justify, MFC may word-wrap if too long
00412          STYLE_Center,                          //!< Center, MFC may word-wrap if too long
00413          STYLE_Right                            //!< Right-justify, MFC may word-wrap if too long
00414          };
00415 
00416       //! Constructor.
00417       CTRL_LABEL (
00418          )
00419       #ifdef WIN32_MFC
00420          :
00421          m_icon(0),
00422          CTRL(m_ctrl)
00423       #endif
00424          { }
00425 
00426       ~CTRL_LABEL (
00427          );
00428 
00429       //! Create control with label from resource lookup.
00430       void Create (
00431          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00432          const char* label,                     //!< Label string for resource lookup
00433          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00434          STYLE style = STYLE_LeftNoWrap
00435          );
00436 
00437       //! Create control with MISTRING or TEXTID label.
00438       void Create (
00439          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00440          const MISTRING& label,                 //!< Label string (allows TEXTID)
00441          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00442          STYLE style = STYLE_LeftNoWrap
00443          );
00444 
00445       //! Create control with ICONID
00446       void Create (
00447          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00448          ICONID iconid,                         //!< ICON to use as the label
00449          const char *tooltip,
00450          int iconsize = 0
00451          );
00452 
00453       //! Create control with ICONID with MISTRING or TEXTID tooltip
00454       void Create (
00455          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00456          ICONID iconid,                         //!< ICON to use as the label
00457          const MISTRING& tooltip,               //!< tooltip string (allows TEXTID)
00458          int iconsize = 0
00459          );
00460 
00461    #ifdef WIN32_MFC
00462       //! Get reference to MFC control (MFC only).
00463       CStatic& GetCtrl (
00464          ) { return (m_ctrl); }
00465    #endif
00466 
00467       //! Set new label from resource lookup.
00468       void SetLabel (
00469          const char *string
00470          );
00471 
00472       //! Set new label from Unicode string.
00473       void SetLabel (
00474          const MISTRING& string
00475          );
00476 
00477    private:
00478       #ifndef GENERATING_DOXYGEN_OUTPUT
00479 
00480    #ifdef WIN32_MFC
00481       CStatic m_ctrl;
00482       HICON m_icon;
00483 
00484       void CreateIconWin (
00485          MGUI::LAYOUT_PANE_BASE& ParentPane,
00486          ICONID iconid,
00487          const CString& label,
00488          int iconsize
00489          );
00490 
00491       void CreateWin (
00492          MGUI::LAYOUT_PANE_BASE& ParentPane,
00493          const CString& label,
00494          MGUI::LAYOUT_SIZEALIGN sizealign,
00495          STYLE style
00496          );
00497    #endif
00498 
00499    #ifdef X_NATIVE
00500       bool CreateIcon (
00501          MGUI::LAYOUT_PANE_BASE& ParentPane,
00502          ICONID iconid,
00503          const char *name,
00504          int iconsize
00505          );
00506 
00507       void CreateX (
00508          MGUI::LAYOUT_PANE_BASE& ParentPane,
00509          XTARGS& args,
00510          const char *name,
00511          MGUI::LAYOUT_SIZEALIGN sizealign,
00512          STYLE style
00513          );
00514    #endif
00515 
00516       CTRL_LABEL (const CTRL_LABEL&);
00517       CTRL_LABEL& operator= (const CTRL_LABEL&);
00518       #endif // GENERATING_DOXYGEN_OUTPUT
00519    };
00520 
00521 
00522 //===================================================================================================================
00523 //!   Group Box control, equivalent to XmFrame.
00524 class CTRL_GROUPBOX : public MGUI::CTRL {
00525    public:
00526 
00527       //! Constructor.
00528       CTRL_GROUPBOX (
00529          );
00530 
00531       //! Destructor.
00532       virtual ~CTRL_GROUPBOX (
00533          );
00534 
00535       //! Cast to MGUI::LAYOUT_PANE_BASE& for use as parent to other controls.
00536       operator MGUI::LAYOUT_PANE_BASE& (
00537          ) { return (m_GroupBoxPane); }
00538 
00539       //! Create control with no label.
00540       void Create (
00541          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00542          MGUI::LAYOUT_ORIENTATION orientation = MGUI::LAYOUT_ORIENTATION_Vertical,
00543          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00544          int ChildSpacing = 4,               //!< Spacing between children of group box
00545          int ExtraBorder = 0                 //!< Extra border around inside of group box, in addition to ChildSpacing
00546          );
00547 
00548       //! Create control with label from resource lookup.
00549       void Create (
00550          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00551          const char* string,                 //!< Label string for resource lookup
00552          MGUI::LAYOUT_ORIENTATION orientation = MGUI::LAYOUT_ORIENTATION_Vertical,
00553          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00554          int ChildSpacing = 4,               //!< Spacing between children of group box
00555          int ExtraBorder = 0                 //!< Extra border around inside of group box, in addition to ChildSpacing
00556          );
00557 
00558       //! Create control with Unicode label.
00559       void Create (
00560          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00561          const MISTRING& string,             //!< Label string
00562          MGUI::LAYOUT_ORIENTATION orientation = MGUI::LAYOUT_ORIENTATION_Vertical,
00563          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00564          int ChildSpacing = 4,               //!< Spacing between children of group box
00565          int ExtraBorder = 0                 //!< Extra border around inside of group box, in addition to ChildSpacing
00566          );
00567 
00568    #ifdef WIN32_MFC
00569       //! Get reference to MFC control (MFC only).
00570       CButton& GetCtrl (
00571          ) { return (m_ctrl); }
00572    #endif
00573 
00574       //! Get layout pane to invoke options on it.
00575       MGUI::LAYOUT_PANE_BASE& GetPane (
00576          ) { return (m_GroupBoxPane); }
00577 
00578       void SetLabelText (
00579          const MISTRING& label
00580          );
00581 
00582    private:
00583 
00584       #ifndef GENERATING_DOXYGEN_OUTPUT
00585       class LAYOUT_PANE : public MGUI::LAYOUT_PANE_BASE {
00586          public:
00587             LAYOUT_PANE (
00588                ) { }
00589             virtual ~LAYOUT_PANE (
00590                ) { }
00591             void Create (
00592                #ifdef WIN32_MFC
00593                MGUI::LAYOUT_PANE_BASE& ParentPane,
00594                CButton& ctrl,
00595                #else
00596                Widget FrameWidget,
00597                #endif
00598                MGUI::LAYOUT_ORIENTATION orientation,
00599                MGUI::LAYOUT_SIZEALIGN sizealign,
00600                int ChildSpacing,
00601                int ExtraBorder,
00602                int TopExtra
00603                );
00604          private:
00605             LAYOUT_PANE (const LAYOUT_PANE&);
00606             LAYOUT_PANE& operator= (const LAYOUT_PANE&);
00607          };
00608 
00609       LAYOUT_PANE m_GroupBoxPane;
00610 
00611    #ifdef WIN32_MFC
00612       CButton m_ctrl;
00613 
00614       void CreateWin (
00615          MGUI::LAYOUT_PANE_BASE& ParentPane,
00616          const CString& label,
00617          MGUI::LAYOUT_ORIENTATION orientation,
00618          MGUI::LAYOUT_SIZEALIGN sizealign,
00619          int ChildSpacing,
00620          int ExtraBorder
00621          );
00622    #endif   // WIN32_MFC
00623 
00624    #ifdef X_NATIVE
00625       Widget m_label;
00626       void CreateX (
00627          MGUI::LAYOUT_PANE_BASE& ParentPane,
00628          MGUI::LAYOUT_ORIENTATION orientation,
00629          MGUI::LAYOUT_SIZEALIGN sizealign,
00630          int ChildSpacing,
00631          int ExtraBorder
00632          );
00633    #endif
00634 
00635       CTRL_GROUPBOX (const CTRL_GROUPBOX&);
00636       CTRL_GROUPBOX& operator= (const CTRL_GROUPBOX&);
00637       #endif // GENERATING_DOXYGEN_OUTPUT
00638    };
00639 
00640 
00641 //===================================================================================================================
00642 //! PushButton control supporting both text and icon buttons.
00643 class CTRL_PUSHBUTTON : public MGUI::CTRL {
00644    public:
00645 
00646       //! Constructor.
00647       CTRL_PUSHBUTTON (
00648          )
00649       #ifdef WIN32_MFC
00650          : CTRL(m_ctrl), m_ctrl(*this), m_hIcon(0)
00651       #endif
00652          { }
00653 
00654       //! Destructor.
00655       virtual ~CTRL_PUSHBUTTON (
00656          );
00657 
00658       //! Create control with label from resource lookup.
00659       void Create (
00660          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00661          const char* label,                     //!< Label string for resource lookup
00662          bool large = false,                    //!< Create large buttons (for dialogs)
00663          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00664          );
00665 
00666       //! Create control with Unicode label.
00667       void Create (
00668          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00669          const MISTRING& label,                 //!< Label string
00670          bool large = false,                    //!< Create large buttons (for dialogs)
00671          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00672          );
00673 
00674       //! Create control with icon and ToolTip from resource lookup.
00675       void Create (
00676          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00677          ICONID iconid,                         //!< Icon ID
00678          const char* tooltip,                   //!< ToolTip string for resource lookup
00679          int iconsize = 0                       //!< Icon size, 0 for default
00680          );
00681 
00682       //! Create control with icon and ToolTip from resource lookup.
00683       void Create (
00684          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00685          ICONID iconid,                         //!< Icon ID
00686          const MISTRING& tooltip,               //!< ToolTip string
00687          int iconsize = 0                       //!< Icon size, 0 for default
00688          );
00689 
00690    #ifdef WIN32_MFC
00691       //! Get reference to MFC control (MFC only).
00692       CButton& GetCtrl (
00693          ) { return (m_ctrl); }
00694    #endif
00695 
00696    protected:
00697 
00698       //! Called when button is pushed.
00699       virtual void OnPressed (
00700          ) = 0;
00701 
00702    private:
00703       #ifndef GENERATING_DOXYGEN_OUTPUT
00704 
00705    #ifdef WIN32_MFC
00706       class MyButton : public CButton {
00707          public:
00708             MyButton (
00709                CTRL_PUSHBUTTON& guictrl
00710                ): m_guictrl(guictrl)
00711                { }
00712          protected:
00713             afx_msg void OnClicked ();
00714             DECLARE_MESSAGE_MAP()
00715          private:
00716             CTRL_PUSHBUTTON& m_guictrl;
00717          friend class MGUI::CTRL_PUSHBUTTON;
00718          };
00719       friend class MyButton;
00720 
00721       MyButton m_ctrl;
00722       HICON m_hIcon;
00723    #endif   // WIN32_MFC
00724 
00725    #ifdef X_NATIVE
00726       static void CB_PushButton (Widget, CTRL_PUSHBUTTON*, void*);
00727 
00728       bool CreateIcon (
00729          LAYOUT_PANE_BASE& ParentPane,
00730          ICONID iconid,
00731          const char *name,
00732          int iconsize
00733          );
00734 
00735       void CreateWidget (
00736          LAYOUT_PANE_BASE& ParentPane,
00737          XTARGS& args,
00738          const char *name,
00739          bool large = false
00740          );
00741    #endif   // X_NATIVE
00742 
00743       CTRL_PUSHBUTTON (const CTRL_PUSHBUTTON&);
00744       CTRL_PUSHBUTTON& operator= (const CTRL_PUSHBUTTON&);
00745    #endif // GENERATING_DOXYGEN_OUTPUT
00746    };
00747 
00748 
00749 //-------------------------------------------------------------------------------------------------------------------
00750 //! Convenience template for PushButton control to allow method in container class to be called.
00751 //! This template allows a method in a 'container' class to be called when the button is pressed,
00752 //! rather than requiring that a subclass be defined with the OnPressed() virtual method overridden.
00753 template <class _CT> class CTRL_PUSHBUTTON_T : public MGUI::CTRL_PUSHBUTTON {
00754    public:
00755 
00756       //! Constructor.
00757       explicit CTRL_PUSHBUTTON_T (
00758          ): m_pContainer(0), m_pfOnPressed(0) { }
00759 
00760       //! Create control with label from resource lookup.
00761       void Create (
00762          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00763          const char* label,                     //!< Label string for resource lookup
00764          _CT *pContainer,                       //!< Pointer to callback container class
00765          void (_CT::*pfOnPressed)(),            //! Callback function pointer
00766          bool large = false,                    //!< Create large buttons (for dialogs)
00767          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00768          ) {
00769          m_pContainer = pContainer;
00770          m_pfOnPressed = pfOnPressed;
00771          CTRL_PUSHBUTTON::Create(ParentPane,label,large,sizealign);
00772          }
00773 
00774       //! Create control with Unicode label.
00775       void Create (
00776          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00777          const MISTRING& label,                 //!< Label string
00778          _CT *pContainer,                       //!< Pointer to callback container class
00779          void (_CT::*pfOnPressed)(),            //! Callback function pointer
00780          bool large = false,                    //!< Create large buttons (for dialogs)
00781          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00782          ) {
00783          m_pContainer = pContainer;
00784          m_pfOnPressed = pfOnPressed;
00785          CTRL_PUSHBUTTON::Create(ParentPane,label,large,sizealign);
00786          }
00787 
00788       //! Create control with icon and ToolTip from resource lookup.
00789       void Create (
00790          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00791          ICONID iconid,                         //!< Icon ID
00792          const char* tooltip,                   //!< ToolTip string for resource lookup
00793          _CT *pContainer,                       //!< Pointer to callback container class
00794          void (_CT::*pfOnPressed)(),               //! Callback function pointer
00795          int iconsize = 0                       //!< Icon size, 0 for default
00796          ) {
00797          m_pContainer = pContainer;
00798          m_pfOnPressed = pfOnPressed;
00799          CTRL_PUSHBUTTON::Create(ParentPane,iconid,tooltip,iconsize);
00800          }
00801 
00802       //! Create control with icon and ToolTip from resource lookup.
00803       void Create (
00804          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00805          ICONID iconid,                         //!< Icon ID
00806          const MISTRING& tooltip,               //!< ToolTip string
00807          _CT *pContainer,                       //!< Pointer to callback container class
00808          void (_CT::*pfOnPressed)(),            //! Callback function pointer
00809          int iconsize = 0                       //!< Icon size, 0 for default
00810          ) {
00811          m_pContainer = pContainer;
00812          m_pfOnPressed = pfOnPressed;
00813          CTRL_PUSHBUTTON::Create(ParentPane,iconid,tooltip,iconsize);
00814          }
00815 
00816    private:
00817       #ifndef GENERATING_DOXYGEN_OUTPUT
00818       _CT *m_pContainer;
00819       void (_CT::*m_pfOnPressed)();
00820 
00821       virtual void OnPressed (
00822          ) { (m_pContainer->*m_pfOnPressed)(); }
00823       #endif // GENERATING_DOXYGEN_OUTPUT
00824    };
00825 
00826 
00827 //===================================================================================================================
00828 //! Toggle button control supporting both "checkbox" and "radio" behavior with text and icon buttons.
00829 //! Note that in the X version radio behavior between buttons is NOT enforced by this control.  For
00830 //! portability it is recommended that the MGUI::FORM_RADIOBUTTONS class be used to manage a set of
00831 //! radio buttons or that the code enforce radio behavior itself for more complex cases.
00832 class CTRL_TOGGLEBUTTON : public MGUI::CTRL {
00833    public:
00834 
00835       enum STYLE {
00836          STYLE_Check,                           //!< Checkbox style
00837          STYLE_Radio,                           //!< Radiobutton style
00838    #ifdef WIN32_MFC
00839          STYLE_RadioFirst                       //!< Radiobutton style, first in radio group (MFC only)
00840    #endif
00841          };
00842 
00843       //! Constructor.
00844       CTRL_TOGGLEBUTTON (
00845          )
00846       #ifdef WIN32_MFC
00847          : CTRL(m_ctrl), m_ctrl(*this), m_hIcon(0)
00848       #endif
00849          { }
00850 
00851       //! Destructor.
00852       virtual ~CTRL_TOGGLEBUTTON (
00853          );
00854 
00855       //! Create with label from resource lookup.
00856       void Create (
00857          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00858          const char* label,                     //!< Label string for resource lookup
00859          STYLE style = STYLE_Check,             //!< Toggle style
00860          bool dftvalue = false,                 //!< Default value
00861          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00862          );
00863 
00864       //! Create with Unicode label.
00865       void Create (
00866          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00867          const MISTRING& label,                 //!< Label string
00868          STYLE style = STYLE_Check,             //!< Toggle style
00869          bool dftvalue = false,                 //!< Default value
00870          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00871          );
00872 
00873       //! Create icon togglebutton with ToolTip from resource lookup.
00874       void Create (
00875          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00876          ICONID iconid,                         //!< Icon ID
00877          const char* tooltip,                   //!< ToolTip string
00878          STYLE style = STYLE_Check,             //!< Toggle style
00879          bool dftvalue = false,                 //!< Default value
00880          int iconsize = 0                       //!< Icon size, 0 for default
00881          );
00882 
00883       //! Create icon togglebutton with Unicode ToolTip.
00884       void Create (
00885          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00886          ICONID iconid,                         //!< Icon ID
00887          const MISTRING& tooltip,                  //!< ToolTip string
00888          STYLE style = STYLE_Check,             //!< Toggle style
00889          bool dftvalue = false,                 //!< Default value
00890          int iconsize = 0                       //!< Icon size, 0 for default
00891          );
00892 
00893    #ifdef WIN32_MFC
00894       //! Get reference to MFC control (MFC only).
00895       CButton& GetCtrl (
00896          ) { return (m_ctrl); }
00897    #endif
00898 
00899       //! Get current toggle setting.
00900       //! Returns 'false' if control not yet created.
00901       bool GetValue (
00902          ) const;
00903 
00904       //! Set control value.
00905       //! Method has no effect if control has not yet been created.
00906       void SetValue (
00907          bool value,                            //!< Value to set
00908          bool notify = true                     //!< If true call OnChangeValue() if value changed
00909          );
00910 
00911    protected:
00912 
00913       //! Called when button is pushed.
00914       virtual void OnPressed (
00915          );
00916 
00917    private:
00918       #ifndef GENERATING_DOXYGEN_OUTPUT
00919 
00920    #ifdef WIN32_MFC
00921       class MyButton : public CButton {
00922          public:
00923             MyButton (
00924                CTRL_TOGGLEBUTTON& guictrl
00925                ): m_guictrl(guictrl)
00926                { }
00927          protected:
00928             afx_msg void OnClicked ();
00929             DECLARE_MESSAGE_MAP()
00930          private:
00931             CTRL_TOGGLEBUTTON& m_guictrl;
00932          friend class MGUI::CTRL_TOGGLEBUTTON;
00933          };
00934       friend class MyButton;
00935 
00936       MyButton m_ctrl;
00937       HICON m_hIcon;
00938    #endif   // WIN32_MFC
00939 
00940    #ifdef X_NATIVE
00941       static void CB_ToggleButton (Widget, CTRL_TOGGLEBUTTON*, void*);
00942 
00943       bool CreateIcon (
00944          MGUI::LAYOUT_PANE_BASE& ParentPane,
00945          ICONID iconid,
00946          const char *name,
00947          STYLE style,
00948          bool dftvalue,
00949          int iconsize
00950          );
00951 
00952       void CreateWidget (
00953          MGUI::LAYOUT_PANE_BASE& ParentPane,
00954          XTARGS& args,
00955          const char* label,
00956          STYLE style,
00957          bool dftvalue
00958          );
00959    #endif   // X_NATIVE
00960 
00961       CTRL_TOGGLEBUTTON (const CTRL_TOGGLEBUTTON&);
00962       CTRL_TOGGLEBUTTON& operator= (const CTRL_TOGGLEBUTTON&);
00963       #endif // GENERATING_DOXYGEN_OUTPUT
00964    };
00965 
00966 
00967 //-------------------------------------------------------------------------------------------------------------------
00968 //! Convenience template for Toggle button to allow method in container class to be called.
00969 template <class _CT> class CTRL_TOGGLEBUTTON_T : public MGUI::CTRL_TOGGLEBUTTON {
00970    public:
00971 
00972       //! Constructor.
00973       explicit CTRL_TOGGLEBUTTON_T (
00974          ): m_pContainer(0), m_pfOnPressed(0) { }
00975 
00976       //! Create with label from resource lookup.
00977       void Create (
00978          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00979          const char* label,                     //!< Label string for resource lookup
00980          _CT *pContainer,                       //!< Pointer to callback container class
00981          void (_CT::*pfOnPressed)(),               //! Callback function pointer
00982          STYLE style = STYLE_Check,             //!< Toggle style
00983          bool dftvalue = false,                 //!< Default value
00984          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
00985          ) {
00986          m_pContainer = pContainer;
00987          m_pfOnPressed = pfOnPressed;
00988          CTRL_TOGGLEBUTTON::Create(ParentPane,label,style,dftvalue,sizealign);
00989          }
00990 
00991       //! Create with Unicode label.
00992       void Create (
00993          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00994          const MISTRING& label,                 //!< Label string
00995          _CT *pContainer,                       //!< Pointer to callback container class
00996          void (_CT::*pfOnPressed)(),               //! Callback function pointer
00997          STYLE style = STYLE_Check,             //!< Toggle style
00998          bool dftvalue = false,                 //!< Default value
00999          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize
01000          ) {
01001          m_pContainer = pContainer;
01002          m_pfOnPressed = pfOnPressed;
01003          CTRL_TOGGLEBUTTON::Create(ParentPane,label,style,dftvalue,sizealign);
01004          }
01005 
01006       //! Create icon with ToolTip from resource lookup.
01007       void Create (
01008          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
01009          ICONID iconid,                         //!< Icon ID
01010          const char* tooltip,                   //!< ToolTip string
01011          _CT *pContainer,                       //!< Pointer to callback container class
01012          void (_CT::*pfOnPressed)(),               //! Callback function pointer
01013          STYLE style = STYLE_Check,             //!< Toggle style
01014          bool dftvalue = false,                 //!< Default value
01015          int iconsize = 0                       //!< Icon size, 0 for default
01016          ) {
01017          m_pContainer = pContainer;
01018          m_pfOnPressed = pfOnPressed;
01019          CTRL_TOGGLEBUTTON::Create(ParentPane,iconid,tooltip,style,dftvalue,iconsize);
01020          }
01021 
01022       //! Create icon with Unicode ToolTip.
01023       void Create (
01024          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
01025          ICONID iconid,                         //!< Icon ID
01026          const MISTRING& tooltip,                  //!< ToolTip string
01027          _CT *pContainer,                       //!< Pointer to callback container class
01028          void (_CT::*pfOnPressed)(),               //! Callback function pointer
01029          STYLE style = STYLE_Check,             //!< Toggle style
01030          bool dftvalue = false,                 //!< Default value
01031          int iconsize = 0                       //!< Icon size, 0 for default
01032          ) {
01033          m_pContainer = pContainer;
01034          m_pfOnPressed = pfOnPressed;
01035          CTRL_TOGGLEBUTTON::Create(ParentPane,iconid,tooltip,style,dftvalue,iconsize);
01036          }
01037 
01038    private:
01039       #ifndef GENERATING_DOXYGEN_OUTPUT
01040       _CT *m_pContainer;
01041       void (_CT::*m_pfOnPressed)();
01042 
01043       virtual void OnPressed (
01044          ) { (m_pContainer->*m_pfOnPressed)(); }
01045       #endif // GENERATING_DOXYGEN_OUTPUT
01046    };
01047 
01048 
01049 //===================================================================================================================
01050 //! Base class for 'edit' controls.
01051 class CTRL_EDIT_BASE : public MGUI::CTRL {
01052    public:
01053 
01054       //! Constructor.
01055       CTRL_EDIT_BASE (
01056          );
01057 
01058       //! Destructor.
01059       ~CTRL_EDIT_BASE (
01060          );
01061 
01062       //! Clear the current selection
01063       void ClearSelection (
01064          )
01065       #ifdef WIN32_MFC
01066          { m_ctrl.Clear(); }
01067       #endif
01068          ;
01069 
01070       //! Copy the current selection to the clipboard
01071       void CopySelection (
01072          )
01073       #ifdef WIN32_MFC
01074          { m_ctrl.Copy(); }
01075       #endif
01076          ;
01077 
01078       //! Cut the current selection to the clipboard
01079       void CutSelection (
01080          )
01081       #ifdef WIN32_MFC
01082          { m_ctrl.Cut(); }
01083       #endif
01084          ;
01085 
01086    #ifdef WIN32_MFC
01087       //! Get reference to MFC control (MFC only).
01088       CEdit& GetCtrl (
01089          ) { return (m_ctrl); }
01090    #endif
01091 
01092       //! Returns true if contents of the edit-control have been modified by user, false if not.
01093       //! Use SetModify() to reset.
01094       const bool GetModify (
01095          ) const {
01096       #ifdef WIN32_MFC
01097          return (m_ctrl.GetModify() != FALSE);
01098       #else
01099          return (m_UserEdited);
01100       #endif
01101          }
01102 
01103       //! Get the current selection of the edit control.
01104       //!   If nStartChar == nEndChar, nothing is selected.
01105       void GetSelection (
01106          int& nStartChar,     //!< Receives the first character in the current selection
01107          int& nEndChar        //!< Receives the first non-selected character past the end of the current selection
01108          ) const
01109       #ifdef WIN32_MFC
01110          { m_ctrl.GetSel(nStartChar,nEndChar); }
01111       #endif
01112          ;
01113 
01114       //! Set the maximim text length in characters
01115       void SetMaxLength (
01116          int length
01117          );
01118 
01119       //! Set or clear the "modified" state of the edit control.
01120       void SetModify (
01121          bool modified = true
01122          ) {
01123       #ifdef WIN32_MFC
01124          m_ctrl.SetModify(modified);
01125       #else
01126          m_UserEdited = modified;
01127       #endif
01128          }
01129 
01130       //! Set whether value is read-only or not.
01131       void SetReadOnly (
01132          bool ReadOnly = true                //!< True if read only, false if not
01133          ) {
01134       #ifdef WIN32_MFC
01135          m_ctrl.SetReadOnly(ReadOnly);
01136       #else
01137          MxSetTextEditable(m_widget,!ReadOnly);
01138       #endif
01139          }
01140 
01141       //! Select range of characters in string.
01142       void SetSelection (
01143          int StartChar = 0,                  //!< Starting character position in string, 0 for beginning
01144          int EndChar = -1,                   //!< Ending character position, -1 for end of string
01145          bool NoScroll = true                //!< Indicates whether to scroll caret into view
01146          )
01147       #ifdef WIN32_MFC
01148          { m_ctrl.SetSel(StartChar,EndChar,NoScroll); }
01149       #endif
01150          ;
01151 
01152       //! Set set of 'valid' or 'invalid' characters.
01153       //! This does not alter the current contents, if any.
01154       void SetValidChars (
01155          const UNICODE* string,              //!< Characters valid or invalid to enter
01156          bool invert = false                 //!< Allow all but specified characters
01157          );
01158 
01159    protected:
01160 
01161    #ifdef WIN32_MFC
01162       class MyEdit : public CEdit {
01163          public:
01164             MyEdit (
01165                CTRL_EDIT_BASE& guictrl
01166                ): m_guictrl(guictrl)
01167                { }
01168             virtual ~MyEdit (
01169                ) { }
01170             virtual BOOL PreCreateWindow (CREATESTRUCT& cs);
01171          protected:
01172             afx_msg void OnChange ();
01173             afx_msg void OnKillFocus ();
01174             DECLARE_MESSAGE_MAP()
01175          private:
01176             #ifndef GENERATING_DOXYGEN_OUTPUT
01177             CTRL_EDIT_BASE& m_guictrl;
01178             #endif // GENERATING_DOXYGEN_OUTPUT
01179          };
01180       friend class MyEdit;
01181       MyEdit m_ctrl;
01182    #endif
01183 
01184    #ifdef X_NATIVE
01185       bool m_UserEdited;
01186    #endif
01187       bool m_HasValue;
01188 
01189       //! Check that all characters in string are in valid set.
01190       //!   @return 'true' if valid, 'false' if not
01191       bool CheckValidChars (
01192          MISTRING& string                       //!< String to be checked
01193          ) const;
01194 
01195       void CreateCtrl (
01196          LAYOUT_PANE_BASE& ParentPane,
01197          int width,                             //!< Width in 'typical' characters
01198          int height,                            //!< Height in text lines, 0 for single-line edit
01199          bool RightJustify,
01200          bool ReadOnly,
01201          bool Opaque,
01202          bool WidthInPixels,
01203          LAYOUT_SIZEALIGN sizealign
01204          );
01205 
01206       bool GetEditStr (
01207          MISTRING& str
01208          ) const;
01209 
01210       // Send value change notification via OnChangeValue.
01211       void NotifyChanged (
01212          ) { OnChangeValue(); }
01213 
01214       //! Called internally to update text control from specified string.
01215       void UpdateCtrl (
01216          const MISTRING& string
01217          );
01218 
01219       //! Called internally to update control-specific data from edit control.
01220       //! Derived class must call corresponding base class method AFTER performing its own processing.
01221       virtual void UpdateValue (bool notify = true);
01222 
01223    private:
01224    #ifndef GENERATING_DOXYGEN_OUTPUT
01225 
01226    #ifdef X_NATIVE
01227       Widget m_TraversalWidget;
01228       XmTraversalDirection m_TraversalDir;
01229       bool m_InternalModify;
01230       int m_MaxLength;
01231    #endif
01232 
01233       bool m_ValidInvert;
01234       MISTRING m_ValidChars;
01235 
01236    #ifdef X_NATIVE
01237       static void CB_Activate (Widget, CTRL_EDIT_BASE*, void*);
01238       static void CB_Focus (Widget, CTRL_EDIT_BASE*, void*);
01239       static void CB_LosingFocus (Widget, CTRL_EDIT_BASE*, void*);
01240       static void CB_ModifyVerify (Widget, CTRL_EDIT_BASE*, void*);
01241       static void CB_ValueChanged (Widget, CTRL_EDIT_BASE*, XmAnyCallbackStruct*);
01242    #endif
01243 
01244       CTRL_EDIT_BASE (const CTRL_EDIT_BASE&);
01245       CTRL_EDIT_BASE& operator= (const CTRL_EDIT_BASE&);
01246    #endif // GENERATING_DOXYGEN_OUTPUT
01247 
01248       // CTRL_EDIT_BASE Overridables
01249 
01250       //! Called when user presses <Enter> in edit control.
01251       virtual void OnActivate ();
01252 
01253       //! Called when value is changed after validation.
01254       //! If the user modifies the text in the edit control this will not be called until the control loses "focus".
01255       virtual void OnChangeValue ();
01256 
01257       //! Called when user modifies the text in the edit control.
01258       //! The actual value does not get updated until the control loses focus or GetValue() is called.
01259       virtual void OnUserEdit ();
01260 
01261    };
01262 
01263 
01264 //===================================================================================================================
01265 //! String 'edit' control.
01266 class CTRL_EDIT_STRING : public MGUI::CTRL_EDIT_BASE {
01267    public:
01268 
01269       enum FLAGS {
01270          FLAG_Default =       0x0000,
01271          FLAG_RightJustify =  0x0001,     //!< Right-justify value, default is to left-justify
01272          FLAG_ReadOnly =      0x0002,     //!< User cannot change value
01273          FLAG_Opaque =        0x0004,     //!< Show '*'s for password input
01274          FLAG_WidthInPixels = 0x0008,     //!< Width specified in pixels
01275          };
01276 
01277       //! Constructor.
01278       CTRL_EDIT_STRING (
01279          );
01280 
01281       //! Destructor.
01282       virtual ~CTRL_EDIT_STRING (
01283          );
01284 
01285       //! Clear to empty string.
01286       void ClearValue (
01287          bool notify = true                     //!< Call OnChangeValue() if control has already been created
01288          );
01289 
01290       //! Create control.
01291       void Create (
01292          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
01293          int maxlen,                            //!< Maximum number of characters allowed in string, not including termination
01294          int width = 0,                         //!< Width in 'typical' characters, minimum if can expand based on sizealign
01295          FLAGS flags = FLAG_Default,
01296          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedHeight
01297          );
01298 
01299       //! Get current string value.
01300       const MISTRING& GetValue (
01301          );
01302 
01303       //! Read value from INI file.
01304       //! If Create() has already been performed the control's state will be updated.
01305       void IniRead (
01306          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
01307          const char *IniGroup,               //!< INI group to read from
01308          const char *IniField,               //!< INI field to read from
01309          bool notify = true                  //!< Call OnChangeValue() if control has already been created
01310          );
01311 
01312       //! Write current value to INI file.
01313       void IniWrite (
01314          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
01315          const char *IniGroup,               //!< INI group to read from
01316          const char *IniField                //!< INI field to read from
01317          ) const { ::IniWrite(IniHandle,IniGroup,IniField,m_value); }
01318 
01319       //! Set current string value with validation.
01320       //! OnValidate() will be called and if valid, the string will be updated.
01321       //! No comparison is made with the current string value.
01322       void SetValue (
01323          const UNICODE* string,              //!< New string to set
01324          bool notify = true                  //!< Call OnChangeValue() if string actually updated
01325          );
01326 
01327    protected:
01328 
01329       //! Validate the string and alter if possible/necessary.
01330       //! Derived class must call corresponding base class method BEFORE performing its own processing.
01331       //!   @return 'true' if string could be validated, 'false' if not
01332       virtual bool OnValidate (
01333          MISTRING& string                    //!< String to be validated
01334          );
01335 
01336    private:
01337       #ifndef GENERATING_DOXYGEN_OUTPUT
01338 
01339       MISTRING m_value;
01340 
01341       //! Called internally to update control-specific data from edit control.
01342       virtual void UpdateValue (bool notify = true);
01343 
01344       CTRL_EDIT_STRING (const CTRL_EDIT_STRING&);
01345       CTRL_EDIT_STRING& operator= (const CTRL_EDIT_STRING&);
01346       #endif // GENERATING_DOXYGEN_OUTPUT
01347    };
01348 
01349 DEFINE_ENUM_OPERATORS(MGUI::CTRL_EDIT_STRING::FLAGS);
01350 
01351 
01352 //-------------------------------------------------------------------------------------------------------------------
01353 //! Convenience template for String 'edit' control to allow method in container class to be called.
01354 template <class _CT> class CTRL_EDIT_STRING_T : public MGUI::CTRL_EDIT_STRING {
01355    public:
01356 
01357       //! Constructor.
01358       explicit CTRL_EDIT_STRING_T (
01359          _CT *pContainer
01360          ): m_pContainer(pContainer), m_pfOnChangeValue(0), m_pfOnUserEdit(0), m_pfOnValidate(0), m_pfOnActivate(0)
01361          { }
01362 
01363       //! Set container pointer.
01364       //! Container may also be specified in constructor.
01365       void SetContainer (
01366          _CT *pContainer
01367          ) { m_pContainer = pContainer; }
01368 
01369       //! Set container method to call for OnActivate().
01370       void SetFuncActivate (
01371          void (_CT::*pfOnActivate)()
01372          ) { m_pfOnActivate = pfOnActivate; };
01373 
01374       //! Set container method to call for OnChangeValue().
01375       void SetFuncChangeValue (
01376          void (_CT::*pfOnChangeValue)()
01377          ) { m_pfOnChangeValue = pfOnChangeValue; };
01378 
01379       //! Set container method to call for OnUserEdit().
01380       void SetFuncUserEdit (
01381          void (_CT::*pfOnUserEdit)()
01382          ) { m_pfOnUserEdit = pfOnUserEdit; };
01383 
01384       //! Set container method to call for OnValidate().
01385       void SetFuncValidate (
01386          bool (_CT::*pfOnValidate)(MISTRING& string)
01387          ) { m_pfOnValidate = pfOnValidate; };
01388 
01389    private:
01390       #ifndef GENERATING_DOXYGEN_OUTPUT
01391       _CT *m_pContainer;
01392       void (_CT::*m_pfOnChangeValue)();
01393       void (_CT::*m_pfOnUserEdit)();
01394       bool (_CT::*m_pfOnValidate)(MISTRING&);
01395       void (_CT::*m_pfOnActivate)();
01396 
01397       virtual void OnChangeValue (
01398          ) { if (m_pfOnChangeValue != 0) (m_pContainer->*m_pfOnChangeValue)(); }
01399 
01400       virtual void OnActivate (
01401          ) { if (m_pfOnActivate != 0) (m_pContainer->*m_pfOnActivate)(); }
01402 
01403       virtual void OnUserEdit (
01404          ) { if (m_pfOnUserEdit != 0) (m_pContainer->*m_pfOnUserEdit)(); }
01405 
01406       virtual bool OnValidate (
01407          MISTRING& str
01408          ) {
01409          if (m_pfOnValidate != 0) return((m_pContainer->*m_pfOnValidate)(str));
01410          return (CTRL_EDIT_STRING::OnValidate(str));
01411          }
01412       #endif // GENERATING_DOXYGEN_OUTPUT
01413    };
01414 
01415 
01416 //===================================================================================================================
01417 //! Form consisting of label and string edit field.
01418 class FORM_EDIT_STRING : public MGUI::FORM_COMPOSITE {
01419    public:
01420       //! Constructor.
01421       FORM_EDIT_STRING (
01422          );
01423 
01424       //! Destructor.
01425       virtual ~FORM_EDIT_STRING (
01426          );
01427 
01428       //! Clear to empty string.
01429       void ClearValue (
01430          bool notify = true                     //!< Call OnChangeValue() if control has already been created
01431          ) { m_editctrl.ClearValue(notify); }
01432 
01433       //! Create form with label from resource lookup.
01434       void Create (
01435          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
01436          const char *label,                     //!< Label
01437          int maxlen,                            //!< Maximum number of characters allowed in string, not including termination
01438          int width = 0,                         //!< Width in 'typical' characters, minimum if can expand based on sizing
01439          MGUI::CTRL_EDIT_STRING::FLAGS flags = MGUI::CTRL_EDIT_STRING::FLAG_Default,
01440          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedHeight,
01441          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
01442          );
01443 
01444       //! Create form with Unicode label.
01445       void Create (
01446          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
01447          const MISTRING& label,                 //!< Label
01448          int maxlen,                            //!< Maximum number of characters allowed in string, not including termination
01449          int width = 0,                         //!< Width in 'typical' characters, minimum if can expand based on sizing
01450          MGUI::CTRL_EDIT_STRING::FLAGS flags = MGUI::CTRL_EDIT_STRING::FLAG_Default,
01451          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedHeight,
01452          MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
01453          );
01454 
01455       //! Retrieve string "edit" control for form.
01456       MGUI::CTRL_EDIT_STRING& GetEditCtrl (
01457          ) { return (m_editctrl); }
01458 
01459       //! Retrieve label control for form.
01460       //! Usually the label control is only retrieved for alignment purposes.
01461       MGUI::CTRL_LABEL& GetLabel (
01462          ) { return (m_label); }
01463 
01464       //! Get current string value.
01465       const MISTRING& GetValue (
01466          ) { return (m_editctrl.GetValue()); }
01467 
01468       //! Read value from INI file.
01469       //! If Create() has already been performed the control's state will be updated.
01470       void IniRead (
01471          INIHANDLE IniHandle,                //!< Handle to INI file to read from, 0 for default
01472          const char *IniGroup,               //!< INI group to read from
01473          const char *IniField,               //!< INI field to read from
01474          bool notify = true                  //!< Call OnChangeValue() if control has already been created
01475          ) { m_editctrl.IniRead(IniHandle,IniGroup,IniField,notify); }
01476 
01477       //! Write current value to INI file.
01478       void IniWrite (
01479          INIHANDLE IniHandle,                //!< Handle to INI file to write to, 0 for default
01480          const char *IniGroup,               //!< INI group to write to
01481          const char *IniField                //!< INI field to write to
01482          ) const { m_editctrl.IniWrite(IniHandle,IniGroup,IniField); }
01483 
01484       //! Set label text using string from resource lookup.
01485       void SetLabel (
01486          const char *label                   //!< New label text
01487          ) { m_label.SetLabel(label); }
01488 
01489       //! Set label text from Unicode string.
01490       void SetLabel (
01491          const MISTRING& label                  //!< New label text
01492          ) { m_label.SetLabel(label); }
01493 
01494       //! Select range of characters in string.
01495       void SetSelection (
01496          int StartChar = 0,                  //!< Starting character position in string, 0 for beginning
01497          int EndChar = -1,                   //!< Ending character position, -1 for end of string
01498          bool NoScroll = true                //!< Indicates whether to scroll caret into view
01499          ) { m_editctrl.SetSelection(StartChar,EndChar,NoScroll); }
01500 
01501       //! Set set of 'valid' or 'invalid' characters.
01502       //! This does not alter the current contents, if any.