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