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