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