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