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