midialog.h

Go to the documentation of this file.
00001 /**
00002  * \file midialog.h <mi32/midialog.h>
00003  * \brief MIDIALOG class definition
00004  *
00005  * \if NODOC
00006  * $Id: midialog.h_v 1.10 2003/09/15 13:49:56 fileserver!dwilliss Exp $
00007  *
00008  * $Log: midialog.h_v $
00009  * Revision 1.10  2003/09/15 13:49:56  fileserver!dwilliss
00010  * Doxygen
00011  *
00012  * Revision 1.9  2000/10/05 15:42:43  mju
00013  * WIN32-native.
00014  *
00015  * Revision 1.8  2000/09/14 17:18:57  mju
00016  * Make SetApplySensitive const.
00017  *
00018  * Revision 1.7  2000/08/02 15:40:06  mju
00019  * Add OnOK/OnCancel and make work like MFC.
00020  *
00021  * Revision 1.6  2000/07/31 15:23:42  mju
00022  * Change interface to use OnInitDialog() for creation and eliminate base hierarchy.
00023  *
00024  * Revision 1.5  2000/07/25 17:35:38  mju
00025  * Add notify parm to Close().
00026  *
00027  * Revision 1.4  2000/07/24 21:03:19  mju
00028  * Add AddForm().
00029  *
00030  * Revision 1.3  2000/07/24 20:11:41  mju
00031  * Make SetupButton... non-const.
00032  *
00033  * Revision 1.2  2000/07/24 15:03:37  mju
00034  * Add IsCreated().
00035  *
00036  * Revision 1.1  2000/07/21 21:12:20  mju
00037  * Initial revision
00038  *
00039  * \endif
00040 **/
00041 
00042 #ifndef  INC_MI32_MIDIALOG_H
00043 #define  INC_MI32_MIDIALOG_H
00044 
00045 #ifndef  INC_MI32_STDDEFNS_H
00046 #include <mi32/stddefns.h>
00047 #endif
00048 
00049 #ifndef  INC_MI32_XDEFNS_H
00050 #include <mi32/xdefns.h>
00051 #endif
00052 
00053 struct BUTTONITEM;
00054 
00055 
00056 //! Base class for general dialog support for both modeless and modal behavior.
00057 //!
00058 //! The derived class must override the GetDialogName(), GetDialogHelpID() and
00059 //! OnInitDialog() methods.
00060 //! Most derived classes will also override the OnApply to perform the desired
00061 //! update of the external data when the user presses "OK" or "Apply".
00062 //! When overriding the On...() virtual methods pay close attention to when (or if)
00063 //! the corresponding superclass method is to be called.
00064 class MIDIALOG {
00065 public:
00066 
00067    // ENUMERATIONS
00068 
00069    enum BUTTONS {
00070       BUTTONS_Default =    0x00,       //!< Default buttons per dialog style
00071       BUTTON_OK =          0x01,
00072       BUTTON_Cancel =      0x02,
00073       BUTTON_Apply =       0x04,
00074       BUTTON_Close =       0x08
00075       };
00076 
00077    // CONSTRUCTION / DESTRUCTION
00078 
00079    //! Default constructor, initialize only.
00080    MIDIALOG (
00081       );
00082 
00083    //! Destructor.
00084    virtual ~MIDIALOG (
00085       ) = 0;
00086 
00087    // METHODS
00088 
00089    //! Close the dialog if modeless.
00090    void Close (
00091       bool notify = true                     //!< Notify via OnClose()
00092       );
00093 
00094    //! Create "modeless" dialog (without opening it).
00095    ERRVALUE CreateModeless (
00096       MDLGPARENT dlgparent                   //!< Parent for dialog
00097       );
00098 
00099    //! Open dialog in modal state and wait for user to dismiss via OK/Cancel.
00100    //!
00101    //! @return 0 if OK, EUserCancel if Cancel, < 0 if error
00102    ERRVALUE DoModal (
00103       MDLGPARENT dlgparent                   //!< Parent for modal dialog
00104       );
00105 
00106    //! Determine if dialog has been created.
00107    bool IsCreated (
00108       ) const {
00109       return (m_form != 0);
00110       }
00111 
00112    //! Determine if dialog is currently open.
00113    bool IsOpen (
00114       ) const {
00115       #ifndef WIN32_NATIVE
00116          return (m_form != 0 && XtIsManaged(m_form));
00117       #else
00118          return (false);
00119       #endif
00120       }
00121 
00122    //! Open dialog if created in modeless state.
00123    ERRVALUE Open (
00124       );
00125 
00126    //! Set "Apply" (if exists) button sensitivity.
00127    void SetApplySensitive (
00128       bool sensitive
00129       ) const {
00130       #ifndef WIN32_NATIVE
00131          MxSetSensitive(m_ApplyPB,sensitive);
00132       #endif
00133       return;
00134       }
00135 
00136 protected:
00137 
00138    // VIRTUAL METHODS
00139 
00140    //! Get dialog HelpID.
00141    //!
00142    //! @return String for HelpID.
00143    virtual const char* GetDialogHelpID (
00144       ) const = 0;
00145 
00146    //! Get dialog name for title resource.
00147    //!
00148    //! @return String for title resource lookup.
00149    virtual const char* GetDialogName (
00150       ) const = 0;
00151 
00152    //! Called when user presses "Apply" button.
00153    //! Will also be called when "OK" button is pressed if have "Apply" button
00154    //! and "Apply" is not disabled.
00155    //! Derived class must call superclass OnApply() method BEFORE
00156    //! performing its own processing.
00157    virtual void OnApply (
00158       );
00159 
00160    //! Called when "Cancel" button is pressed.
00161    //!
00162    //! Derived class must call superclass OnCancel() method AFTER performing its own processing
00163    //! to properly close the dialog.  In some cases the user may be given an opportunity to 
00164    //! verify that they intended to press the Cancel button.  If they elect not to cancel then
00165    //! the superclass OnCancel() method should not be called.  This will cause the dialog to
00166    //! remain open and allow the user to retain the settings.
00167    virtual void OnCancel (
00168       );
00169 
00170    //! Called when dialog is closed.
00171    virtual void OnClose (
00172       );
00173 
00174    //! Create dialog contents.
00175    //!
00176    //! Derived class MUST implement this.  Function must return 0 for success or an error code.
00177    //! This will be called by the dialog creation code and thus should not be called
00178    //! directly.  This is normally overridden only by the specific dialog implementation and
00179    //! not by the code that actually uses that dialog implementation.
00180    virtual ERRVALUE OnInitDialog (
00181       Widget form                            //!< Form to create contents in
00182       ) = 0;
00183 
00184    //! Called when "OK" button is pressed.
00185    //!
00186    //! Derived class must call superclass OnOK() method AFTER performing its own processing
00187    //! to properly close the dialog.  If the dialog settings do not pass their associated
00188    //! validation test then an appropriate message should be displayed for the user and
00189    //! the superclass OnOK() method should not be called.  This will cause the dialog to
00190    //! remain open and allow the user to correct the settings.
00191    virtual void OnOK (
00192       );
00193 
00194    //! Called when dialog is opened after the dialog is actually "managed" and displayed.
00195    //!
00196    //! Derived class must call superclass OnOpen() method BEFORE
00197    //! performing its own processing.
00198    virtual void OnOpen (
00199       );
00200 
00201    // METHODS
00202 
00203    //! Create buttons at bottom of form.
00204    //!
00205    //! @return Separator Widget attached above buttons
00206    Widget CreateButtonRow (
00207       const BUTTONITEM* ButtonItems,
00208       void *cbdata = 0,
00209       void *userdata = 0
00210       );
00211 
00212    //! Create standard buttons at bottom of form.
00213    //! Default button labels will depend on the dialog style.
00214    //! Modal dialog buttons will be "OK", "Cancel" and "Help".
00215    //! Modeless dialog buttons will be "OK", "Cancel", "Apply" and "Help".
00216    //! For modeless dialogs, pressing "OK" has the same effect as pressing
00217    //! "Apply" followed by "Close".
00218    //!
00219    //! @return Separator Widget attached above buttons
00220    Widget CreateButtons (
00221       BUTTONS buttons = BUTTONS_Default      //!< Buttons to create
00222       );
00223 
00224    //! Get outermost Form widget.
00225    Widget GetMainForm (
00226       ) const {
00227       return (m_form);
00228       }
00229 
00230    //! Setup BUTTONITEM for "Apply" button.
00231    void SetupButtonApply (
00232       BUTTONITEM& bi
00233       );
00234 
00235    //! Setup BUTTONITEM for Cancel button.
00236    void SetupButtonCancel (
00237       BUTTONITEM& bi
00238       );
00239 
00240    //! Setup BUTTONITEM for Close button.
00241    void SetupButtonClose (
00242       BUTTONITEM& bi
00243       );
00244 
00245    //! Setup BUTTONITEM for "OK" button.
00246    void SetupButtonOK (
00247       BUTTONITEM& bi
00248       );
00249 
00250 private:
00251    #ifndef GENERATING_DOXYGEN_OUTPUT
00252    //! MEMBERS
00253    Widget m_form;
00254    Widget m_ApplyPB;
00255    bool m_IsModal;
00256    ERRVALUE m_RetValue;
00257 
00258    // METHODS
00259 
00260    //! Create FormDialog widget.
00261    ERRVALUE CreateDialog (
00262       MDLGPARENT dlgparent,                  //!< Parent for dialog, NULL for TopLevel
00263       bool modal = false                     //!< Create as modal
00264       );
00265 
00266    static void CB_Apply (Widget, MIDIALOG*, void*);
00267    static void CB_Cancel (Widget, MIDIALOG*, void*);
00268    static void CB_Destroy (Widget, MIDIALOG*, void*);
00269    static void CB_OK (Widget, MIDIALOG*, void*);
00270 
00271    MXXTCB_ADD(MIDIALOG);
00272    MXXTCB_REMOVE(MIDIALOG);
00273 
00274    // UNIMPLEMENTED / UNSUPPORTED
00275 
00276    MIDIALOG (
00277       const MIDIALOG& rhs
00278       );
00279 
00280    MIDIALOG& operator= (
00281       const MIDIALOG& rhs
00282       );
00283    #endif // GENERATING_DOXYGEN_OUTPUT
00284 
00285    };
00286 
00287 DEFINE_ENUM_OPERATORS(MIDIALOG::BUTTONS);
00288 
00289 
00290 #endif   //!< INC_MI32_MIDIALOG_H

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