1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDialogBase class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DIALOG_H_BASE_
13 #define _WX_DIALOG_H_BASE_
16 #include "wx/toplevel.h"
18 class WXDLLEXPORT wxSizer
;
19 class WXDLLEXPORT wxStdDialogButtonSizer
;
21 #define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
24 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
26 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
29 extern WXDLLEXPORT_DATA(const wxChar
) wxDialogNameStr
[];
31 class WXDLLEXPORT wxDialogBase
: public wxTopLevelWindow
36 // all flags allowed in wxDialogBase::CreateButtonSizer()
37 ButtonSizerFlags
= wxOK
|wxCANCEL
|wxYES
|wxNO
|wxHELP
|wxNO_DEFAULT
40 wxDialogBase() { Init(); }
41 virtual ~wxDialogBase() { }
43 // define public wxDialog methods to be implemented by the derived classes
44 virtual int ShowModal() = 0;
45 virtual void EndModal(int retCode
) = 0;
46 virtual bool IsModal() const = 0;
49 // Modal dialogs have a return code - usually the id of the last
51 void SetReturnCode(int returnCode
) { m_returnCode
= returnCode
; }
52 int GetReturnCode() const { return m_returnCode
; }
54 // Set the identifier for the affirmative button: this button will close
55 // the dialog after validating data and calling TransferDataFromWindow()
56 void SetAffirmativeId(int affirmativeId
);
57 int GetAffirmativeId() const { return m_affirmativeId
; }
59 // Set identifier for Esc key translation: the button with this id will
60 // close the dialog without doing anything else; special value wxID_NONE
61 // means to not handle Esc at all while wxID_ANY means to map Esc to
62 // wxID_CANCEL if present and GetAffirmativeId() otherwise
63 void SetEscapeId(int escapeId
);
64 int GetEscapeId() const { return m_escapeId
; }
66 // Returns the parent to use for modal dialogs if the user did not specify it
68 wxWindow
*GetParentForModalDialog(wxWindow
*parent
= NULL
) const;
70 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
71 // splits text up at newlines and places the
72 // lines into a vertical wxBoxSizer
73 wxSizer
*CreateTextSizer( const wxString
&message
);
74 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
76 // returns a horizontal wxBoxSizer containing the given buttons
78 // notice that the returned sizer can be NULL if no buttons are put in the
79 // sizer (this mostly happens under smart phones and other atypical
80 // platforms which have hardware buttons replacing OK/Cancel and such)
81 wxSizer
*CreateButtonSizer(long flags
);
83 // returns the sizer containing CreateButtonSizer() below a separating
84 // static line for the platforms which use static lines for items
85 // separation (i.e. not Mac)
86 wxSizer
*CreateSeparatedButtonSizer(long flags
);
89 wxStdDialogButtonSizer
*CreateStdDialogButtonSizer( long flags
);
90 #endif // wxUSE_BUTTON
93 // emulate click of a button with the given id if it's present in the dialog
95 // return true if button was "clicked" or false if we don't have it
96 bool EmulateButtonClickIfPresent(int id
);
98 // this function is used by OnCharHook() to decide whether the given key
99 // should close the dialog
101 // for most platforms the default implementation (which just checks for
102 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
103 // could do something different if needed
104 virtual bool IsEscapeKey(const wxKeyEvent
& event
);
106 // end either modal or modeless dialog, for the modal dialog rc is used as
107 // the dialog return code
108 void EndDialog(int rc
);
110 // call Validate() and TransferDataFromWindow() and close dialog with
111 // wxID_OK return code
112 void AcceptAndClose();
115 // The return code from modal dialog
118 // The identifier for the affirmative button (usually wxID_OK)
121 // The identifier for cancel button (usually wxID_CANCEL)
125 // common part of all ctors
128 // handle Esc key presses
129 void OnCharHook(wxKeyEvent
& event
);
131 // handle closing the dialog window
132 void OnCloseWindow(wxCloseEvent
& event
);
134 // handle the standard buttons
135 void OnButton(wxCommandEvent
& event
);
137 // update the background colour
138 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
141 DECLARE_NO_COPY_CLASS(wxDialogBase
)
142 DECLARE_EVENT_TABLE()
146 #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
147 #include "wx/univ/dialog.h"
149 #if defined(__WXPALMOS__)
150 #include "wx/palmos/dialog.h"
151 #elif defined(__WXMSW__)
152 #include "wx/msw/dialog.h"
153 #elif defined(__WXMOTIF__)
154 #include "wx/motif/dialog.h"
155 #elif defined(__WXGTK20__)
156 #include "wx/gtk/dialog.h"
157 #elif defined(__WXGTK__)
158 #include "wx/gtk1/dialog.h"
159 #elif defined(__WXMAC__)
160 #include "wx/mac/dialog.h"
161 #elif defined(__WXCOCOA__)
162 #include "wx/cocoa/dialog.h"
163 #elif defined(__WXPM__)
164 #include "wx/os2/dialog.h"
169 // _WX_DIALOG_H_BASE_