00001 /** 00002 * \file mgui/dlgshell.h 00003 * \brief MGUI::DLGSHELL class definition 00004 * 00005 * \if NODOC 00006 * $Id: dlgshell.h_v 1.13 2004/11/09 18:24:27 mju Exp $ 00007 * 00008 * $Log: dlgshell.h_v $ 00009 * Revision 1.13 2004/11/09 18:24:27 mju 00010 * Add parm to getButtonPane so can put some buttons at left. 00011 * 00012 * Revision 1.12 2004/09/24 17:21:50 mju 00013 * Add isModal method. 00014 * 00015 * Revision 1.11 2004/06/04 20:58:51 dwilliss 00016 * added Tool style enum 00017 * 00018 * Revision 1.10 2004/03/16 17:54:53 mju 00019 * Don't allow further override of v_OnDestroy or v_GetMainPane. 00020 * 00021 * Revision 1.9 2003/11/19 14:33:26 mju 00022 * Add SetDeleteOnClose. 00023 * 00024 * Revision 1.8 2003/11/12 18:01:41 mju 00025 * Refine docs. 00026 * 00027 * Revision 1.7 2003/10/03 19:58:19 linux32build!build 00028 * Doxygen 00029 * 00030 * Revision 1.6 2003/09/15 13:49:32 fileserver!dwilliss 00031 * Doxygen 00032 * 00033 * Revision 1.5 2003/08/29 16:44:00 mju 00034 * Use mistring ref. 00035 * 00036 * Revision 1.4 2003/07/28 15:47:52 dwilliss 00037 * Added SetRootMargin() method 00038 * 00039 * Revision 1.3 2003/06/04 17:43:18 scowan 00040 * Fixed? for MFC. 00041 * 00042 * Revision 1.2 2003/05/28 17:51:08 mju 00043 * Add parm to ctor to specify title and eliminate virtual method to get name. 00044 * 00045 * Revision 1.1 2003/05/28 16:08:55 mju 00046 * Initial revision 00047 * 00048 * \endif 00049 **/ 00050 00051 #ifndef INC_MGUI_DLGSHELL_H 00052 #define INC_MGUI_DLGSHELL_H 00053 00054 #ifndef INC_MGUI_SHELL_H 00055 #include <mgui/shell.h> 00056 #endif 00057 00058 #ifndef INC_MGUI_CTRL_H 00059 #include <mgui/ctrl.h> 00060 #endif 00061 00062 00063 namespace MGUI { 00064 00065 //! Base class for general dialog support for both modeless and modal behavior. 00066 //! 00067 //! This class is available for both X and MFC with identical public and protected 00068 //! interfaces. The derived dialog implementation class must override the 00069 //! v_CreateContent() method. Most derived classes will also override v_OnApply 00070 //! to perform the desired update of the external data when the user presses 'OK' 00071 //! or 'Apply'. When overriding the protected v_On...() virtual methods pay close 00072 //! attention to when the corresponding base method is to be called to ensure correct 00073 //! behavior. 00074 class DLGSHELL : public MGUI::SHELL { 00075 public: 00076 00077 //! Style settings, may be combined. 00078 enum STYLE { 00079 STYLE_Default = 0x00, //!< Default style 00080 STYLE_Resizable = 0x01, //!< Dialog is resizable 00081 STYLE_ContextHelp = 0x02, //!< (Non-X) Include '?' icon in titlebar, cannot combine with AllowMinimize or AllowMaximize 00082 STYLE_AllowMinimize = 0x04, //!< (Non-X) Include minimize box in titlebar, cannot combine with STYLE_ContextHelp 00083 STYLE_AllowMaximize = 0x08, //!< (Non-X) Include maximize box in titlebar, cannot combine with STYLE_ContextHelp 00084 STYLE_CenterOnScreen = 0x10, //!< Initially center dialog on monitor containing parent window 00085 STYLE_CenterOnMouse = 0x20, //!< Initially center dialog on mouse cursor 00086 STYLE_DeleteOnClose = 0x40, //!< Delete (destroy) dialog on closing, only used for modeless dialogs 00087 STYLE_ToolWindow = 0x80 //!< Window is a "tool controls" or "pallette" window. Gets a smaller title bar than normal windows 00088 }; 00089 00090 //! Standard dialog button selections, may be combined for some methods. 00091 enum BUTTONS { 00092 BUTTONS_Default = 0x00, //!< Default buttons per dialog style 00093 BUTTON_OK = 0x01, 00094 BUTTON_Cancel = 0x02, 00095 BUTTON_Apply = 0x04, 00096 BUTTON_Close = 0x08, 00097 BUTTON_Help = 0x10 00098 }; 00099 00100 //! Destructor. 00101 virtual ~DLGSHELL ( 00102 ) = 0; 00103 00104 //! Cast to MDLGPARENT for use as parent for other dialogs. 00105 operator MDLGPARENT ( 00106 ) const { return (GetDlgParent()); } 00107 00108 //! Close the dialog if modeless. 00109 void Close ( 00110 bool notify = true //!< Notify via OnClose() 00111 ); 00112 00113 //! Create 'modeless' dialog (without opening it). 00114 ERRVALUE CreateModeless ( 00115 MDLGPARENT dlgparent, //!< Parent for dialog 00116 bool AllowMinimize = false //!< (Non-X) Allow dialog to be "minimized" 00117 ); 00118 00119 //! Open dialog in modal state and wait for user to dismiss via OK/Cancel. 00120 //! @return 0 if OK, EUserCancel if Cancel, < 0 if error 00121 ERRVALUE DoModal ( 00122 MDLGPARENT dlgparent //!< Parent for modal dialog 00123 ); 00124 00125 //! Determine if dialog is currently open. 00126 bool IsOpen ( 00127 ) const; 00128 00129 //! Open dialog if created in modeless state. 00130 ERRVALUE Open ( 00131 ); 00132 00133 //! Set whether 'Apply' (if exists) button is enabled. 00134 void SetApplyEnabled ( 00135 bool enabled = true 00136 ) { m_ApplyPB.SetEnabled(enabled); } 00137 00138 //! Set to delete shell instance when closed (for modal dialogs). 00139 //! This allows the dialog to be created via 'new' without retaining the 00140 //! pointer instance. 00141 void SetDeleteOnClose ( 00142 bool DeleteOnClose = true 00143 ); 00144 00145 //! Set whether 'OK' button (if exists) is enabled. 00146 void SetOkEnabled ( 00147 bool enabled = true 00148 ) { m_OkPB.SetEnabled(enabled); } 00149 00150 protected: 00151 00152 //! Constructor, initializes only. 00153 DLGSHELL ( 00154 const MISTRING& title, //!< Title string, can use TEXTID also 00155 HELPID HelpID, //!< Help ID, use HELPID__None if no 'help' available 00156 STYLE style = STYLE_Default //!< Dialog style settings 00157 ); 00158 00159 //! Create standard button. 00160 //! @return Reference to button created (usually for alignment only). 00161 MGUI::CTRL_PUSHBUTTON& CreateButton ( 00162 BUTTONS button, //!< Button to create 00163 const char *label = 0 //!< Override for label, used for resource lookup 00164 ); 00165 00166 //! Create standard buttons at bottom of dialog. 00167 //! Default button labels will depend on the dialog style. 00168 //! Modal dialog buttons will be 'OK', 'Cancel' and 'Help'. 00169 //! Modeless dialog buttons will be 'OK', 'Cancel', 'Apply' and 'Help'. 00170 //! For modeless dialogs, pressing 'OK' has the same effect as pressing 00171 //! 'Apply' followed by 'Close'. 00172 void CreateButtons ( 00173 BUTTONS buttons = BUTTONS_Default //!< Buttons to create 00174 ); 00175 00176 //! Determine if dialog was open as modal. 00177 bool IsModal ( 00178 ) const { return (m_IsModal); } 00179 00180 //! Get pane to create buttons at bottom of dialog. 00181 //! This allows additional 'non-standard' buttons to be added to the dialog. 00182 //! This will create the pane if it has not been created already. 00183 MGUI::LAYOUT_PANE& GetButtonPane ( 00184 bool AddSpace = true //!< Add space if creating so buttons placed at right 00185 ); 00186 00187 //! Send 'Cancel' notification to dialog. 00188 void NotifyCancel ( 00189 ) { v_OnCancel(); } 00190 00191 //! Send 'OK' notification to dialog. 00192 void NotifyOK ( 00193 ) { v_OnOK(); } 00194 00195 //! Set to ignore nonvisible items when doing layout. 00196 //! This must be called before CreateModeless() or DoModal() and is usually done in 00197 //! the subclass constructor. 00198 void SetIgnoreNonVisible ( 00199 bool IgnoreNonVisible = true 00200 ) { m_IgnoreNonVisible = IgnoreNonVisible; return; } 00201 00202 //! Set value to return from dialog. 00203 void SetReturnValue ( 00204 int RetValue 00205 ) { m_RetValue = RetValue; } 00206 00207 //! Set margin for root pane. 00208 //! This must be called before CreateModeless() or DoModal() and is usually done in 00209 //! the subclass constructor. 00210 void SetRootMargin ( 00211 int RootMargin 00212 ) { m_RootMargin = RootMargin; } 00213 00214 //! Set spacing for root pane. 00215 //! This must be called before CreateModeless() or DoModal() and is usually done in 00216 //! the subclass constructor. 00217 void SetRootSpacing ( 00218 int RootSpacing 00219 ) { m_RootSpacing = RootSpacing; } 00220 00221 //! Set dialog style. 00222 //! This must be called before CreateModeless() or DoModal() and not in 00223 //! v_OnInitDialog() for proper behavior. 00224 void SetStyle ( 00225 STYLE style 00226 ) { m_Style = style; } 00227 00228 //! Force update of dialog layout. 00229 void UpdateLayout ( 00230 ) 00231 #ifdef X_NATIVE 00232 { } 00233 #endif 00234 ; 00235 00236 // Overridables which may be called from derived classes. 00237 00238 //! Called when 'Cancel' button is pressed. 00239 //! Derived class must call base class v_OnCancel() method AFTER performing its own processing 00240 //! to actually close the dialog. In some cases the user may be given an opportunity to 00241 //! verify that they intended to press the Cancel button. If they elect not to cancel then 00242 //! the base class v_OnCancel() method should not be called. This will cause the dialog to 00243 //! remain open and allow the user to retain the settings. 00244 //! Derived classes should generally declare this method as private. 00245 virtual void v_OnCancel (); 00246 00247 //! Called when 'OK' button is pressed. 00248 //! Derived class must call base class v_OnOK() method AFTER performing its own processing 00249 //! to actually close the dialog. If the dialog settings do not pass their associated 00250 //! validation test then an appropriate message should be displayed for the user and 00251 //! the base class v_OnOK() method should not be called. This will cause the dialog to 00252 //! remain open and allow the user to correct the settings. In addition, if an 'Apply' 00253 //! button has been created using the appropriate DLGSHELL methods then v_OnApply will 00254 //! be called before closing. 00255 //! Derived classes should generally declare this method as private. 00256 virtual void v_OnOK (); 00257 00258 private: 00259 00260 #ifndef GENERATING_DOXYGEN_OUTPUT 00261 #ifdef WIN32_MFC 00262 public: 00263 class MFCDLG; 00264 private: 00265 friend class MFCDLG; 00266 MFCDLG *m_pmfcdlg; 00267 UINT8 *m_TemplateBuf; 00268 #endif 00269 00270 STYLE m_Style; 00271 bool m_IsModal; 00272 bool m_IgnoreNonVisible; 00273 ERRVALUE m_RetValue; 00274 int m_RootSpacing; 00275 int m_RootMargin; 00276 00277 LAYOUT_PANE m_ButtonPane; 00278 CTRL_PUSHBUTTON_T<DLGSHELL> m_OkPB; 00279 CTRL_PUSHBUTTON_T<DLGSHELL> m_CancelPB; 00280 CTRL_PUSHBUTTON_T<DLGSHELL> m_ApplyPB; 00281 CTRL_PUSHBUTTON_T<DLGSHELL> m_HelpPB; 00282 00283 //! Create actual dialog and root pane. 00284 ERRVALUE CreateDlg ( 00285 MDLGPARENT dlgparent, //!< Parent for dialog, NULL for default 00286 bool modal = false, //!< Create as modal 00287 bool AllowMinimize = false 00288 ); 00289 00290 #ifdef WIN32_MFC //!< XXXX Mike, please confirm the hack 00291 CTRL_STATUSBAR* GetStatusBar ( 00292 ) { return (m_pStatusBar); } 00293 #endif 00294 00295 void OnHelp (); 00296 void OnOpen () { v_OnOpen(); } 00297 00298 #ifdef WIN32_MFC //!< XXXX Mike, please confirm the hack 00299 void SetParentWindow ( 00300 CWnd* cwnd 00301 ) { m_pWnd = cwnd;; } 00302 #endif 00303 00304 DLGSHELL (const DLGSHELL&); 00305 DLGSHELL& operator= (const DLGSHELL&); 00306 00307 // Overrides from SHELL. 00308 #ifdef WIN32_MFC 00309 MGUI::COMMAND_ROUTER* v_GetCmdRouter () const; 00310 #endif 00311 LAYOUT_PANE_MAIN& v_GetMainPane (); 00312 void v_Destroy (); 00313 00314 #endif // GENERATING_DOXYGEN_OUTPUT 00315 00316 // Overridables. 00317 00318 //! Create dialog shell contents. 00319 //! Derived class MUST implement this. Function must return 0 for success or an error code. 00320 //! This will be called by the dialog creation code and must not be called directly. 00321 //! This is normally overridden only by the specific dialog implementation and not by the 00322 //! code that actually uses that dialog implementation. Implementation should call 00323 //! GetMainForm() or GetMainPane() to determine the form or pane to create the controls in. 00324 //! Note that you cannot override the dialog title in v_CreateContent, title must be set first. 00325 virtual ERRVALUE v_CreateContent () = 0; 00326 00327 //! Called when user presses 'Apply' button. 00328 //! Will also be called by default v_OnOK implementation if 'Apply' button exists and is not disabled. 00329 virtual void v_OnApply (); 00330 00331 //! Called when dialog gets closed. 00332 virtual void v_OnClose (); 00333 00334 //! Called when user requests that shell be 'closed'. 00335 //! Default implementation simply calls Close(). May be overridden if different behavior desired. 00336 virtual void v_OnCloseRequest (); 00337 00338 //! Called when dialog is destroyed. 00339 virtual void v_OnDestroy (); 00340 00341 //! Called after dialog is actually opened. 00342 virtual void v_OnOpen (); 00343 00344 }; 00345 00346 DEFINE_ENUM_OPERATORS(DLGSHELL::BUTTONS); 00347 DEFINE_ENUM_OPERATORS(DLGSHELL::STYLE); 00348 00349 00350 } // End namespace MGUI 00351 00352 00353 #endif // INC_MGUI_DLGSHELL_H
1.3.8-20040913