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