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

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