dlgbase.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/dlgbase.h
00003  * \brief MGUI::DLG_BASE class definition
00004  *
00005  * \if NODOC
00006  * $Id: dlgbase.h_v 1.21 2004/03/01 17:01:34 mju Exp $
00007  *
00008  * $Log: dlgbase.h_v $
00009  * Revision 1.21  2004/03/01 17:01:34  mju
00010  * Deprecate entire dlg_base class.
00011  *
00012  * Revision 1.20  2003/11/12 16:59:19  mju
00013  * Add doxygen deprecated tag.
00014  *
00015  * Revision 1.19  2003/10/27 17:22:25  scowan
00016  * Added deprecate groupkey defines.
00017  *
00018  * Revision 1.18  2003/10/03 19:58:19  linux32build!build
00019  * Doxygen
00020  *
00021  * Revision 1.17  2003/09/15 13:49:32  fileserver!dwilliss
00022  * Doxygen
00023  *
00024  * Revision 1.16  2003/03/05 16:00:42  mju
00025  * Use mainpane's widget instead of keeping own copy.
00026  *
00027  * Revision 1.15  2003/01/31 17:54:34  mju
00028  * Add SetReturnValue.
00029  *
00030  * Revision 1.14  2003/01/22 15:34:47  mju
00031  * GetHelpID no longer pure.
00032  *
00033  * Revision 1.13  2002/10/23 22:03:36  mju
00034  * Add m_Title so can set title before creating dialog.
00035  *
00036  * Revision 1.12  2002/10/23 15:40:04  mju
00037  * Add SetTitle from textid.
00038  *
00039  * Revision 1.11  2002/10/09 15:47:18  mju
00040  * Move to 'mgui' folder.
00041  *
00042  * Revision 1.10  2002/07/15 21:04:27  mju
00043  * Add ability to set root border.
00044  *
00045  * Revision 1.9  2002/05/30 15:25:13  mju
00046  * Remove deprecated typedef.
00047  *
00048  * Revision 1.7  2001/12/18 15:28:23  mju
00049  * Rename as DLG_BASE.
00050  *
00051  * Revision 1.6  2001/12/17 18:49:52  mju
00052  * Add implementations of UpdateLayout and GetCmdTarget for X.
00053  * Add protected SetStyle() method.
00054  *
00055  * Revision 1.5  2001/12/13 22:19:09  mju
00056  * Unify X and MFC interface.
00057  *
00058  * Revision 1.4  2001/12/13 17:00:13  mju
00059  * Don't use deprecated miwin header.
00060  *
00061  * Revision 1.3  2001/11/30 18:54:22  mju
00062  * Make On... methods public.
00063  *
00064  * Revision 1.2  2001/11/29 18:28:52  mju
00065  * Fix to compile for MFC.
00066  *
00067  * Revision 1.1  2001/11/28 22:11:45  mju
00068  * Initial revision
00069  * \endif
00070 **/
00071 
00072 #ifndef  INC_MGUI_DLGBASE_H
00073 #define  INC_MGUI_DLGBASE_H
00074 
00075 #if defined(DEPRECATE_ALL)
00076 #error <mgui/dlgbase.h> is deprecated, use <mgui/dlgshell.h> instead
00077 #endif
00078 
00079 #if !defined(DEPRECATE_GROUPKEY)
00080 
00081 #ifndef  INC_MI32_STDDEFNS_H
00082 #include <mi32/stddefns.h>
00083 #endif
00084 
00085 #ifndef  INC_MGUI_COMMAND_H
00086 #include <mgui/command.h>
00087 #endif
00088 
00089 #ifndef  INC_MGUI_CONTROL_H
00090 #include <mgui/ctrl.h>
00091 #endif
00092 
00093 #ifdef WIN32
00094 #pragma warning (disable:4996)   // Disable warning about deprecated declaration within header
00095 #endif
00096 
00097 namespace MGUI {
00098 
00099 //! \deprecated Replaced with MGUI::DLGSHELL
00100 //! Base class for general dialog support for both modeless and modal behavior.
00101 //!
00102 //! This class is available for both X and MFC with a nearly identical public
00103 //! and protected interfaces.  There are a few platform-specific methods for
00104 //! use by the actual dialog implementation.  The derived dialog implementation
00105 //! class must override the GetDialogName() and OnInitDialog()
00106 //! methods.  Most derived classes will also override the OnApply to perform the
00107 //! desired update of the external data when the user presses 'OK' or 'Apply'.
00108 //! When overriding the On...() virtual methods pay close attention to when (or
00109 //! whether) the corresponding base method is to be called to ensure correct behavior.
00110 class DEPRECATED DLG_BASE {
00111    public:
00112 
00113       //! Style settings, may be combined.
00114       enum STYLE {
00115          STYLE_Default =         0x00,    //!< Default style
00116          STYLE_Resizable =       0x01,    //!< Dialog is resizable
00117          STYLE_ContextHelp =     0x02,    //!< (Non-X) Include '?' icon in titlebar, cannot combine with AllowMinimize or AllowMaximize
00118          STYLE_AllowMinimize =   0x04,    //!< (Non-X) Include minimize box in titlebar, cannot combine with STYLE_ContextHelp
00119          STYLE_AllowMaximize =   0x08,    //!< (Non-X) Include maximize box in titlebar, cannot combine with STYLE_ContextHelp
00120          STYLE_CenterOnScreen =  0x10,    //!< Initially center dialog on monitor containing parent window
00121          STYLE_CenterOnMouse =   0x20,    //!< Initially center dialog on mouse cursor
00122          STYLE_DeleteOnClose =   0x40     //!< Delete (destroy) dialog on closing, only used for modeless dialogs
00123          };
00124 
00125       //! Standard dialog button selections, may be combined for some methods.
00126       enum BUTTONS {
00127          BUTTONS_Default =    0x00,       //!< Default buttons per dialog style
00128          BUTTON_OK =          0x01,
00129          BUTTON_Cancel =      0x02,
00130          BUTTON_Apply =       0x04,
00131          BUTTON_Close =       0x08,
00132          BUTTON_Help =        0x10
00133          };
00134 
00135       //! Destructor.
00136       virtual ~DLG_BASE (
00137          ) = 0;
00138 
00139       //! Cast to MDLGPARENT for use as parent for other dialogs.
00140       operator MDLGPARENT (
00141          ) const { return (GetDlgParent()); }
00142 
00143       //! Close the dialog if modeless.
00144       void Close (
00145          bool notify = true                     //!< Notify via OnClose()
00146          );
00147 
00148       //! Create 'modeless' dialog (without opening it).
00149       ERRVALUE CreateModeless (
00150          MDLGPARENT dlgparent,                  //!< Parent for dialog
00151          bool AllowMinimize = false             //!< (Non-X) Allow dialog to be "minimized"
00152          );
00153 
00154       //! Open dialog in modal state and wait for user to dismiss via OK/Cancel.
00155       //! @return 0 if OK, EUserCancel if Cancel, < 0 if error
00156       ERRVALUE DoModal (
00157          MDLGPARENT dlgparent                   //!< Parent for modal dialog
00158          );
00159 
00160       //! Get MDLGPARENT for use as parent for child dialogs.
00161       MDLGPARENT GetDlgParent (
00162          ) const;
00163 
00164    #ifdef WIN32_MFC
00165       //! Get current window placement (MFC only).
00166       void GetWindowPlacement (
00167          WINDOWPLACEMENT& placement
00168          ) const;
00169    #endif
00170 
00171       //! Determine if dialog window has been created.
00172       bool IsCreated (
00173          ) const {
00174          #ifdef WIN32_MFC
00175             return (m_pmfcdlg != 0);
00176          #else
00177             return (m_MainPane.IsCreated());
00178          #endif
00179          }
00180 
00181       //! Determine if dialog is currently open.
00182       bool IsOpen (
00183          ) const;
00184 
00185       //! Called when user presses 'Apply' button.
00186       //! Will also be called when 'OK' button is pressed UNLESS 'Apply' button exists AND is disabled.
00187       //! Derived class must call base class OnApply() method BEFORE performing its own processing.
00188       virtual void OnApply (
00189          );
00190 
00191       //! Called when 'Cancel' button is pressed.
00192       //! Derived class must call base class OnCancel() method AFTER performing its own processing
00193       //! to properly close the dialog.  In some cases the user may be given an opportunity to 
00194       //! verify that they intended to press the Cancel button.  If they elect not to cancel then
00195       //! the base class OnCancel() method should not be called.  This will cause the dialog to
00196       //! remain open and allow the user to retain the settings.
00197       virtual void OnCancel (
00198          );
00199 
00200       //! Called when dialog is closed.
00201       //! Derived class must call base class OnClose() method AFTER performing its own processing
00202       //! to properly close the dialog.  
00203       virtual void OnClose (
00204          );
00205 
00206       //! Called when dialog is destroyed.
00207       virtual void OnDestroy (
00208          );
00209 
00210       //! Called when 'OK' button is pressed.
00211       //! Derived class must call base class OnOK() method AFTER performing its own processing
00212       //! to properly close the dialog.  If the dialog settings do not pass their associated
00213       //! validation test then an appropriate message should be displayed for the user and
00214       //! the base class OnOK() method should not be called.  This will cause the dialog to
00215       //! remain open and allow the user to correct the settings.
00216       virtual void OnOK (
00217          );
00218 
00219       //! Called when dialog is opened after the dialog is actually "managed" and displayed.
00220       //! Derived class must call base class OnOpen() method BEFORE performing its own processing.
00221       virtual void OnOpen (
00222          );
00223 
00224       //! Open dialog if created in modeless state.
00225       ERRVALUE Open (
00226          );
00227 
00228       //! Set whether 'Apply' (if exists) button is enabled.
00229       void SetApplyEnabled (
00230          bool enabled = true
00231          ) { m_ApplyPB.SetEnabled(enabled); }
00232 
00233       //! Set whether 'OK' button (if exists) is enabled.
00234       void SetOkEnabled (
00235          bool enabled = true
00236          ) { m_OkPB.SetEnabled(enabled); }
00237 
00238       //! Set dialog title from UNICODE string.
00239       void SetTitle (
00240          const UNICODE *title
00241          );
00242 
00243       //! Set dialog title from TEXTID.
00244       void SetTitle (
00245          TEXTID textid
00246          );
00247 
00248    #ifdef WIN32_MFC
00249       //! Set window placement (MFC only).
00250       bool SetWindowPlacement (
00251          const WINDOWPLACEMENT& placement
00252          );
00253    #endif
00254 
00255    protected:
00256 
00257       //! Default constructor, initializes only.
00258       DLG_BASE (
00259          STYLE style = STYLE_Default      //!< Dialog style settings
00260          );
00261 
00262       //! Create standard button.
00263       //! @return Reference to button created (usually for alignment only).
00264       MGUI::CTRL_PUSHBUTTON& CreateButton (
00265          BUTTONS button,                        //!< Button to create
00266          const char *label = 0                  //!< Override for label, used for resource lookup
00267          );
00268 
00269       //! Create standard buttons at bottom of dialog.
00270       //! Default button labels will depend on the dialog style.
00271       //! Modal dialog buttons will be 'OK', 'Cancel' and 'Help'.
00272       //! Modeless dialog buttons will be 'OK', 'Cancel', 'Apply' and 'Help'.
00273       //! For modeless dialogs, pressing 'OK' has the same effect as pressing
00274       //! 'Apply' followed by 'Close'.
00275       void CreateButtons (
00276          BUTTONS buttons = BUTTONS_Default      //!< Buttons to create
00277          );
00278 
00279       //! Get pane to create buttons at bottom of dialog.
00280       //! This allows additional 'non-standard' buttons to be added to the dialog.
00281       //! This will create the pane if it has not been created already.
00282       MGUI::LAYOUT_PANE& GetButtonPane (
00283          );
00284 
00285       //! Get "command router" for dialog.
00286       MGUI::COMMAND_ROUTER* GetCmdRouter (
00287          ) const
00288       #ifdef X_NATIVE
00289          { return (0); }
00290       #endif
00291          ;
00292 
00293       //! Get dialog HelpID.
00294       //! @return String for HelpID.
00295       virtual const char* GetDialogHelpID (
00296          ) const;
00297 
00298       //! Get dialog name for title resource.
00299       //! @return String for title resource lookup.
00300       virtual const char* GetDialogName (
00301          ) const = 0;
00302 
00303       //! Get main layout pane.
00304       MGUI::LAYOUT_PANE_MAIN& GetMainPane (
00305          );
00306 
00307       //! Create dialog contents.
00308       //! Derived class MUST implement this.  Function must return 0 for success or an error code.
00309       //! This will be called by the dialog creation code and thus should not be called
00310       //! directly.  This is normally overridden only by the specific dialog implementation and
00311       //! not by the code that actually uses that dialog implementation.
00312       //! The implementation should call GetMainForm() or GetMainPane() to determine the form
00313       //! widget or pane to create the controls in.
00314       virtual ERRVALUE OnInitDialog (
00315          ) = 0;
00316 
00317       //! Set to ignore nonvisible items when doing layout.
00318       //! This must be called before CreateModeless() or DoModal() and is usually done in
00319       //! the subclass constructor.
00320       void SetIgnoreNonVisible (
00321          bool IgnoreNonVisible = true
00322          ) { m_IgnoreNonVisible = IgnoreNonVisible; return; }
00323 
00324       //! Set value to return from dialog.
00325       void SetReturnValue (
00326          int RetValue
00327          ) { m_RetValue = RetValue; }
00328 
00329       //! Set spacing for root pane.
00330       //! This must be called before CreateModeless() or DoModal() and is usually done in
00331       //! the subclass constructor.
00332       void SetRootSpacing (
00333          int RootSpacing
00334          ) { m_RootSpacing = RootSpacing; }
00335 
00336    #ifdef WIN32_MFC
00337       //! Set status bar so dialog allows for in layout (MFC only).
00338       //! StatusBar must be created before OnInitDialog() returns.
00339       void SetStatusBar (
00340          CStatusBar *StatusBar                  //!< Pointer to status bar
00341          ) { m_pStatusBar = StatusBar; }
00342    #endif
00343 
00344    #ifdef WIN32_MFC
00345       //! Set status bar so dialog allows for in layout (MFC only).
00346       //! StatusBar must be created before OnInitDialog() returns.
00347       void SetStatusBar (
00348          MGUI::CTRL_STATUSBAR& StatusBar
00349          ) { m_pStatusBar = &StatusBar.GetStatusBar(); }
00350    #endif
00351 
00352       //! Set dialog style.
00353       //! This must be called before CreateModeless() or DoModal() and not in
00354       //!   OnInitDialog() for proper behavior.
00355       void SetStyle (
00356          STYLE style
00357          ) { m_Style = style; }
00358 
00359       //! Force update of dialog layout.
00360       void UpdateLayout (
00361          )
00362       #ifdef X_NATIVE
00363          { }
00364       #endif
00365          ;
00366 
00367    private:
00368    #ifndef GENERATING_DOXYGEN_OUTPUT
00369 
00370    #ifdef WIN32_MFC
00371       public:
00372       class MFCDLG;
00373       private:
00374       friend class MFCDLG;
00375       MFCDLG *m_pmfcdlg;
00376       CStatusBar *m_pStatusBar;
00377       UINT8 *m_TemplateBuf;
00378    #endif
00379 
00380    #ifdef X_NATIVE
00381       Widget XXXdelete;
00382       LAYOUT_PANE_MAIN m_MainPane;
00383    #endif
00384 
00385       STYLE m_Style;
00386       bool m_IsModal;
00387       bool m_IgnoreNonVisible;
00388       ERRVALUE m_RetValue;
00389       int m_RootSpacing;
00390       MISTRING m_Title;
00391 
00392       LAYOUT_PANE m_ButtonPane;
00393       CTRL_PUSHBUTTON_T<DLG_BASE> m_OkPB;
00394       CTRL_PUSHBUTTON_T<DLG_BASE> m_CancelPB;
00395       CTRL_PUSHBUTTON_T<DLG_BASE> m_ApplyPB;
00396       CTRL_PUSHBUTTON_T<DLG_BASE> m_HelpPB;
00397 
00398       //! Create actual dialog and root pane.
00399       ERRVALUE CreateDlg (
00400          MDLGPARENT dlgparent,                  //!< Parent for dialog, NULL for default
00401          bool modal = false,                    //!< Create as modal
00402          bool AllowMinimize = false
00403          );
00404 
00405       void OnHelp ();
00406 
00407    #ifdef X_NATIVE
00408       static void CB_Close (Widget, DLG_BASE*, void*);
00409    #endif
00410 
00411       DLG_BASE (const DLG_BASE&);
00412       DLG_BASE& operator= (const DLG_BASE&);
00413    #endif // GENERATING_DOXYGEN_OUTPUT
00414    };
00415 
00416 DEFINE_ENUM_OPERATORS(DLG_BASE::BUTTONS);
00417 DEFINE_ENUM_OPERATORS(DLG_BASE::STYLE);
00418 
00419 }  // End namespace MGUI
00420 
00421 #ifdef WIN32
00422 #pragma warning (default:4996)   // Restore warning about deprecated declaration
00423 #endif
00424 
00425 #endif   // !defined(DEPRECATE_GROUPKEY)
00426 #endif   // INC_MGUI_DLGBASE_H

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