]>
Commit | Line | Data |
---|---|---|
dfe1eee3 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/dialog.h | |
3 | // Purpose: wxDialogBase class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 29.06.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
dfe1eee3 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_DIALOG_H_BASE_ |
13 | #define _WX_DIALOG_H_BASE_ | |
c801d85f | 14 | |
9f3a38fc | 15 | #include "wx/defs.h" |
7d9f12f3 | 16 | #include "wx/toplevel.h" |
9f3a38fc | 17 | |
b5dbe15d VS |
18 | class WXDLLIMPEXP_FWD_CORE wxSizer; |
19 | class WXDLLIMPEXP_FWD_CORE wxStdDialogButtonSizer; | |
3aa8e4ea JS |
20 | class WXDLLIMPEXP_FWD_CORE wxBoxSizer; |
21 | class WXDLLIMPEXP_FWD_CORE wxDialogLayoutAdapter; | |
22 | class WXDLLIMPEXP_FWD_CORE wxDialog; | |
23 | class WXDLLIMPEXP_FWD_CORE wxButton; | |
24 | class WXDLLIMPEXP_FWD_CORE wxScrolledWindow; | |
acf2ac37 | 25 | |
8b5ef6cf VZ |
26 | #define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window |
27 | ||
568883a4 | 28 | #ifdef __WXWINCE__ |
30dfe2ff | 29 | #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER) |
9ceeecb9 JS |
30 | #else |
31 | #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX) | |
568883a4 | 32 | #endif |
8b5ef6cf | 33 | |
3aa8e4ea JS |
34 | // Layout adaptation levels, for SetLayoutAdaptationLevel |
35 | ||
36 | // Don't do any layout adaptation | |
37 | #define wxDIALOG_ADAPTATION_NONE 0 | |
38 | ||
39 | // Only look for wxStdDialogButtonSizer for non-scrolling part | |
40 | #define wxDIALOG_ADAPTATION_STANDARD_SIZER 1 | |
41 | ||
42 | // Also look for any suitable sizer for non-scrolling part | |
43 | #define wxDIALOG_ADAPTATION_ANY_SIZER 2 | |
44 | ||
45 | // Also look for 'loose' standard buttons for non-scrolling part | |
46 | #define wxDIALOG_ADAPTATION_LOOSE_BUTTONS 3 | |
47 | ||
48 | // Layout adaptation mode, for SetLayoutAdaptationMode | |
49 | enum wxDialogLayoutAdaptationMode | |
50 | { | |
51 | wxDIALOG_ADAPTATION_MODE_DEFAULT = 0, // use global adaptation enabled status | |
52 | wxDIALOG_ADAPTATION_MODE_ENABLED = 1, // enable this dialog overriding global status | |
53 | wxDIALOG_ADAPTATION_MODE_DISABLED = 2 // disable this dialog overriding global status | |
54 | }; | |
55 | ||
94b4dd54 SC |
56 | enum wxDialogModality |
57 | { | |
03647350 VZ |
58 | wxDIALOG_MODALITY_NONE = 0, |
59 | wxDIALOG_MODALITY_WINDOW_MODAL = 1, | |
60 | wxDIALOG_MODALITY_APP_MODAL = 2 | |
94b4dd54 SC |
61 | }; |
62 | ||
53a2db12 | 63 | extern WXDLLIMPEXP_DATA_CORE(const char) wxDialogNameStr[]; |
0cc1d4ff | 64 | |
53a2db12 | 65 | class WXDLLIMPEXP_CORE wxDialogBase : public wxTopLevelWindow |
c50f1fb9 | 66 | { |
dfe1eee3 | 67 | public: |
6463b9f5 | 68 | wxDialogBase() { Init(); } |
82c9f85c VZ |
69 | virtual ~wxDialogBase() { } |
70 | ||
a9f620da | 71 | // define public wxDialog methods to be implemented by the derived classes |
2158f4d7 VZ |
72 | virtual int ShowModal() = 0; |
73 | virtual void EndModal(int retCode) = 0; | |
74 | virtual bool IsModal() const = 0; | |
94b4dd54 SC |
75 | // show the dialog frame-modally (needs a parent), using app-modal |
76 | // dialogs on platforms that don't support it | |
77 | virtual bool ShowWindowModal () ; | |
78 | virtual void SendWindowModalDialogEvent ( wxEventType type ); | |
82c9f85c | 79 | |
9ceeecb9 | 80 | // Modal dialogs have a return code - usually the id of the last |
dfe1eee3 VZ |
81 | // pressed button |
82 | void SetReturnCode(int returnCode) { m_returnCode = returnCode; } | |
83 | int GetReturnCode() const { return m_returnCode; } | |
84 | ||
551f281b VZ |
85 | // Set the identifier for the affirmative button: this button will close |
86 | // the dialog after validating data and calling TransferDataFromWindow() | |
87 | void SetAffirmativeId(int affirmativeId); | |
9ceeecb9 JS |
88 | int GetAffirmativeId() const { return m_affirmativeId; } |
89 | ||
551f281b VZ |
90 | // Set identifier for Esc key translation: the button with this id will |
91 | // close the dialog without doing anything else; special value wxID_NONE | |
92 | // means to not handle Esc at all while wxID_ANY means to map Esc to | |
93 | // wxID_CANCEL if present and GetAffirmativeId() otherwise | |
94 | void SetEscapeId(int escapeId); | |
2b4f7fbc | 95 | int GetEscapeId() const { return m_escapeId; } |
2b4f7fbc | 96 | |
4f73f25c VZ |
97 | // Find the parent to use for modal dialog: try to use the specified parent |
98 | // but fall back to the current active window or main application window as | |
99 | // last resort if it is unsuitable. | |
100 | // | |
101 | // This function always returns a valid top level window or NULL. | |
2229243b VZ |
102 | wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const; |
103 | ||
d7260478 | 104 | #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL |
92afa2b1 RR |
105 | // splits text up at newlines and places the |
106 | // lines into a vertical wxBoxSizer | |
107 | wxSizer *CreateTextSizer( const wxString &message ); | |
d7260478 | 108 | #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL |
82c9f85c | 109 | |
25eb10d2 VZ |
110 | // returns a horizontal wxBoxSizer containing the given buttons |
111 | // | |
112 | // notice that the returned sizer can be NULL if no buttons are put in the | |
113 | // sizer (this mostly happens under smart phones and other atypical | |
114 | // platforms which have hardware buttons replacing OK/Cancel and such) | |
115 | wxSizer *CreateButtonSizer(long flags); | |
116 | ||
117 | // returns the sizer containing CreateButtonSizer() below a separating | |
118 | // static line for the platforms which use static lines for items | |
119 | // separation (i.e. not Mac) | |
120 | wxSizer *CreateSeparatedButtonSizer(long flags); | |
121 | ||
897b24cf | 122 | #if wxUSE_BUTTON |
acf2ac37 | 123 | wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags ); |
1e6feb95 | 124 | #endif // wxUSE_BUTTON |
dfe1eee3 | 125 | |
3aa8e4ea JS |
126 | // Do layout adaptation |
127 | virtual bool DoLayoutAdaptation(); | |
128 | ||
129 | // Can we do layout adaptation? | |
130 | virtual bool CanDoLayoutAdaptation(); | |
131 | ||
132 | // Returns a content window if there is one. This can be used by the layout adapter, for | |
133 | // example to make the pages of a book control into scrolling windows | |
134 | virtual wxWindow* GetContentWindow() const { return NULL; } | |
135 | ||
136 | // Add an id to the list of main button identifiers that should be in the button sizer | |
137 | void AddMainButtonId(wxWindowID id) { m_mainButtonIds.Add((int) id); } | |
138 | wxArrayInt& GetMainButtonIds() { return m_mainButtonIds; } | |
139 | ||
140 | // Is this id in the main button id array? | |
141 | bool IsMainButtonId(wxWindowID id) const { return (m_mainButtonIds.Index((int) id) != wxNOT_FOUND); } | |
142 | ||
143 | // Level of adaptation, from none (Level 0) to full (Level 3). To disable adaptation, | |
144 | // set level 0, for example in your dialog constructor. You might | |
145 | // do this if you know that you are displaying on a large screen and you don't want the | |
146 | // dialog changed. | |
147 | void SetLayoutAdaptationLevel(int level) { m_layoutAdaptationLevel = level; } | |
148 | int GetLayoutAdaptationLevel() const { return m_layoutAdaptationLevel; } | |
149 | ||
150 | /// Override global adaptation enabled/disabled status | |
151 | void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode) { m_layoutAdaptationMode = mode; } | |
152 | wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const { return m_layoutAdaptationMode; } | |
153 | ||
154 | // Returns true if the adaptation has been done | |
155 | void SetLayoutAdaptationDone(bool adaptationDone) { m_layoutAdaptationDone = adaptationDone; } | |
156 | bool GetLayoutAdaptationDone() const { return m_layoutAdaptationDone; } | |
157 | ||
158 | // Set layout adapter class, returning old adapter | |
159 | static wxDialogLayoutAdapter* SetLayoutAdapter(wxDialogLayoutAdapter* adapter); | |
160 | static wxDialogLayoutAdapter* GetLayoutAdapter() { return sm_layoutAdapter; } | |
161 | ||
162 | // Global switch for layout adaptation | |
163 | static bool IsLayoutAdaptationEnabled() { return sm_layoutAdaptation; } | |
164 | static void EnableLayoutAdaptation(bool enable) { sm_layoutAdaptation = enable; } | |
165 | ||
94b4dd54 SC |
166 | // modality kind |
167 | wxDialogModality GetModality() const; | |
f6bcfd97 | 168 | protected: |
0be27418 VZ |
169 | // emulate click of a button with the given id if it's present in the dialog |
170 | // | |
171 | // return true if button was "clicked" or false if we don't have it | |
172 | bool EmulateButtonClickIfPresent(int id); | |
173 | ||
174 | // this function is used by OnCharHook() to decide whether the given key | |
175 | // should close the dialog | |
176 | // | |
177 | // for most platforms the default implementation (which just checks for | |
178 | // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports | |
179 | // could do something different if needed | |
180 | virtual bool IsEscapeKey(const wxKeyEvent& event); | |
181 | ||
2158f4d7 VZ |
182 | // end either modal or modeless dialog, for the modal dialog rc is used as |
183 | // the dialog return code | |
184 | void EndDialog(int rc); | |
185 | ||
551f281b VZ |
186 | // call Validate() and TransferDataFromWindow() and close dialog with |
187 | // wxID_OK return code | |
188 | void AcceptAndClose(); | |
189 | ||
9ceeecb9 | 190 | // The return code from modal dialog |
dfe1eee3 | 191 | int m_returnCode; |
7d9f12f3 | 192 | |
9ceeecb9 JS |
193 | // The identifier for the affirmative button (usually wxID_OK) |
194 | int m_affirmativeId; | |
195 | ||
c6ece595 VZ |
196 | // The identifier for cancel button (usually wxID_CANCEL) |
197 | int m_escapeId; | |
198 | ||
3aa8e4ea JS |
199 | // Flags whether layout adaptation has been done for this dialog |
200 | bool m_layoutAdaptationDone; | |
201 | ||
202 | // Extra button identifiers to be taken as 'main' button identifiers | |
203 | // to be placed in the non-scrolling area | |
204 | wxArrayInt m_mainButtonIds; | |
205 | ||
206 | // Adaptation level | |
207 | int m_layoutAdaptationLevel; | |
208 | ||
209 | // Local override for global adaptation enabled status | |
210 | wxDialogLayoutAdaptationMode m_layoutAdaptationMode; | |
211 | ||
212 | // Global layout adapter | |
213 | static wxDialogLayoutAdapter* sm_layoutAdapter; | |
214 | ||
215 | // Global adaptation switch | |
216 | static bool sm_layoutAdaptation; | |
217 | ||
0be27418 | 218 | private: |
2158f4d7 VZ |
219 | // common part of all ctors |
220 | void Init(); | |
221 | ||
8bda0ec6 VZ |
222 | // helper of GetParentForModalDialog(): returns the passed in window if it |
223 | // can be used as our parent or NULL if it can't | |
224 | wxWindow *CheckIfCanBeUsedAsParent(wxWindow *parent) const; | |
225 | ||
0be27418 VZ |
226 | // handle Esc key presses |
227 | void OnCharHook(wxKeyEvent& event); | |
228 | ||
2158f4d7 VZ |
229 | // handle closing the dialog window |
230 | void OnCloseWindow(wxCloseEvent& event); | |
231 | ||
232 | // handle the standard buttons | |
a9f620da | 233 | void OnButton(wxCommandEvent& event); |
2158f4d7 VZ |
234 | |
235 | // update the background colour | |
236 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
237 | ||
238 | ||
c0c133e1 | 239 | wxDECLARE_NO_COPY_CLASS(wxDialogBase); |
7d9f12f3 | 240 | DECLARE_EVENT_TABLE() |
c50f1fb9 VZ |
241 | }; |
242 | ||
3aa8e4ea JS |
243 | /*! |
244 | * Base class for layout adapters - code that, for example, turns a dialog into a | |
245 | * scrolling dialog if there isn't enough screen space. You can derive further | |
246 | * adapter classes to do any other kind of adaptation, such as applying a watermark, or adding | |
247 | * a help mechanism. | |
248 | */ | |
249 | ||
53a2db12 | 250 | class WXDLLIMPEXP_CORE wxDialogLayoutAdapter: public wxObject |
3aa8e4ea JS |
251 | { |
252 | DECLARE_CLASS(wxDialogLayoutAdapter) | |
253 | public: | |
254 | wxDialogLayoutAdapter() {} | |
255 | ||
256 | // Override this function to indicate that adaptation should be done | |
257 | virtual bool CanDoLayoutAdaptation(wxDialog* dialog) = 0; | |
258 | ||
259 | // Override this function to do the adaptation | |
260 | virtual bool DoLayoutAdaptation(wxDialog* dialog) = 0; | |
261 | }; | |
262 | ||
263 | /*! | |
264 | * Standard adapter. Does scrolling adaptation for paged and regular dialogs. | |
265 | * | |
266 | */ | |
267 | ||
53a2db12 | 268 | class WXDLLIMPEXP_CORE wxStandardDialogLayoutAdapter: public wxDialogLayoutAdapter |
3aa8e4ea JS |
269 | { |
270 | DECLARE_CLASS(wxStandardDialogLayoutAdapter) | |
271 | public: | |
272 | wxStandardDialogLayoutAdapter() {} | |
273 | ||
274 | // Overrides | |
275 | ||
276 | // Indicate that adaptation should be done | |
277 | virtual bool CanDoLayoutAdaptation(wxDialog* dialog); | |
278 | ||
279 | // Do layout adaptation | |
280 | virtual bool DoLayoutAdaptation(wxDialog* dialog); | |
281 | ||
282 | // Implementation | |
283 | ||
284 | // Create the scrolled window | |
285 | virtual wxScrolledWindow* CreateScrolledWindow(wxWindow* parent); | |
286 | ||
287 | // Find a standard or horizontal box sizer | |
288 | virtual wxSizer* FindButtonSizer(bool stdButtonSizer, wxDialog* dialog, wxSizer* sizer, int& retBorder, int accumlatedBorder = 0); | |
289 | ||
290 | // Check if this sizer contains standard buttons, and so can be repositioned in the dialog | |
291 | virtual bool IsOrdinaryButtonSizer(wxDialog* dialog, wxBoxSizer* sizer); | |
292 | ||
293 | // Check if this is a standard button | |
294 | virtual bool IsStandardButton(wxDialog* dialog, wxButton* button); | |
295 | ||
296 | // Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer | |
297 | virtual bool FindLooseButtons(wxDialog* dialog, wxStdDialogButtonSizer* buttonSizer, wxSizer* sizer, int& count); | |
298 | ||
299 | // Reparent the controls to the scrolled window, except those in buttonSizer | |
300 | virtual void ReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL); | |
301 | static void DoReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL); | |
302 | ||
303 | // A function to fit the dialog around its contents, and then adjust for screen size. | |
304 | // If scrolled windows are passed, scrolling is enabled in the required orientation(s). | |
305 | virtual bool FitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow); | |
306 | virtual bool FitWithScrolling(wxDialog* dialog, wxWindowList& windows); | |
307 | static bool DoFitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow); | |
308 | static bool DoFitWithScrolling(wxDialog* dialog, wxWindowList& windows); | |
309 | ||
310 | // Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both | |
311 | virtual int MustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize); | |
312 | static int DoMustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize); | |
313 | }; | |
7d9f12f3 | 314 | |
c67d6888 | 315 | #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__) |
0e0de6b8 VS |
316 | #include "wx/univ/dialog.h" |
317 | #else | |
4055ed82 | 318 | #if defined(__WXPALMOS__) |
ffecfa5a JS |
319 | #include "wx/palmos/dialog.h" |
320 | #elif defined(__WXMSW__) | |
0e0de6b8 VS |
321 | #include "wx/msw/dialog.h" |
322 | #elif defined(__WXMOTIF__) | |
323 | #include "wx/motif/dialog.h" | |
1be7a35c | 324 | #elif defined(__WXGTK20__) |
0e0de6b8 | 325 | #include "wx/gtk/dialog.h" |
1be7a35c MR |
326 | #elif defined(__WXGTK__) |
327 | #include "wx/gtk1/dialog.h" | |
0e0de6b8 | 328 | #elif defined(__WXMAC__) |
ef0e9220 | 329 | #include "wx/osx/dialog.h" |
e64df9bc DE |
330 | #elif defined(__WXCOCOA__) |
331 | #include "wx/cocoa/dialog.h" | |
0e0de6b8 VS |
332 | #elif defined(__WXPM__) |
333 | #include "wx/os2/dialog.h" | |
0e0de6b8 | 334 | #endif |
c801d85f KB |
335 | #endif |
336 | ||
94b4dd54 SC |
337 | class WXDLLIMPEXP_CORE wxWindowModalDialogEvent : public wxCommandEvent |
338 | { | |
339 | public: | |
340 | wxWindowModalDialogEvent (wxEventType commandType = wxEVT_NULL, int id = 0) | |
341 | : wxCommandEvent(commandType, id) { } | |
342 | ||
343 | wxDialog *GetDialog() const | |
344 | { return wxStaticCast(GetEventObject(), wxDialog); } | |
03647350 VZ |
345 | |
346 | int GetReturnCode() const | |
94b4dd54 SC |
347 | { return GetDialog()->GetReturnCode(); } |
348 | ||
349 | virtual wxEvent *Clone() const { return new wxWindowModalDialogEvent (*this); } | |
350 | ||
351 | private: | |
352 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowModalDialogEvent ) | |
353 | }; | |
354 | ||
355 | wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_WINDOW_MODAL_DIALOG_CLOSED , wxWindowModalDialogEvent ); | |
356 | ||
357 | typedef void (wxEvtHandler::*wxWindowModalDialogEventFunction)(wxWindowModalDialogEvent &); | |
358 | ||
359 | #define wxWindowModalDialogEventHandler(func) \ | |
360 | wxEVENT_HANDLER_CAST(wxWindowModalDialogEventFunction, func) | |
361 | ||
c801d85f | 362 | #endif |
34138703 | 363 | // _WX_DIALOG_H_BASE_ |