]> git.saurik.com Git - wxWidgets.git/blame - interface/dialog.h
pen.h depends from brush.h in compat mode
[wxWidgets.git] / interface / dialog.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialog.h
e54c96f1 3// Purpose: interface of wxDialog
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxDialog
11 @wxheader{dialog.h}
7c913512 12
23324ae1
FM
13 A dialog box is a window with a title bar and sometimes a system menu, which
14 can be moved around the screen. It can contain controls and other windows and
15 is often used to allow the user to make some choice or to answer a question.
7c913512 16
23324ae1
FM
17 Dialogs can be made scrollable, automatically: please see @ref
18 overview_autoscrollingdialogs "Automatic scrolling dialogs" for further details.
7c913512 19
23324ae1
FM
20 @beginStyleTable
21 @style{wxCAPTION}:
22 Puts a caption on the dialog box.
23 @style{wxDEFAULT_DIALOG_STYLE}:
24 Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and
25 wxSYSTEM_MENU (the last one is not used under Unix)
26 @style{wxRESIZE_BORDER}:
27 Display a resizeable frame around the window.
28 @style{wxSYSTEM_MENU}:
29 Display a system menu.
30 @style{wxCLOSE_BOX}:
31 Displays a close box on the frame.
32 @style{wxMAXIMIZE_BOX}:
33 Displays a maximize box on the dialog.
34 @style{wxMINIMIZE_BOX}:
35 Displays a minimize box on the dialog.
36 @style{wxTHICK_FRAME}:
37 Display a thick frame around the window.
38 @style{wxSTAY_ON_TOP}:
39 The dialog stays on top of all other windows.
40 @style{wxNO_3D}:
41 Under Windows, specifies that the child controls should not have 3D
42 borders unless specified in the control.
43 @style{wxDIALOG_NO_PARENT}:
44 By default, a dialog created with a @NULL parent window will be
45 given the application's top level window as parent. Use this style
46 to prevent this from happening and create an orphan dialog. This is
47 not recommended for modal dialogs.
48 @style{wxDIALOG_EX_CONTEXTHELP}:
49 Under Windows, puts a query button on the caption. When pressed,
50 Windows will go into a context-sensitive help mode and wxWidgets
51 will send a wxEVT_HELP event if the user clicked on an application
52 window. Note that this is an extended style and must be set by
53 calling SetExtraStyle before Create is called (two-step
54 construction).
55 @style{wxDIALOG_EX_METAL}:
56 On Mac OS X, frames with this style will be shown with a metallic
57 look. This is an extra style.
58 @endStyleTable
7c913512 59
23324ae1
FM
60 @library{wxcore}
61 @category{cmndlg}
7c913512 62
e54c96f1 63 @see @ref overview_wxdialogoverview, wxFrame, @ref overview_validatoroverview
4cc4bfaf 64 "Validator overview"
23324ae1
FM
65*/
66class wxDialog : public wxTopLevelWindow
67{
68public:
69 //@{
70 /**
71 Constructor.
72
7c913512 73 @param parent
4cc4bfaf 74 Can be @NULL, a frame or another dialog box.
7c913512 75 @param id
4cc4bfaf 76 An identifier for the dialog. A value of -1 is taken to mean a default.
7c913512 77 @param title
4cc4bfaf 78 The title of the dialog.
7c913512 79 @param pos
4cc4bfaf
FM
80 The dialog position. The value wxDefaultPosition indicates a default position,
81 chosen by
82 either the windowing system or wxWidgets, depending on platform.
7c913512 83 @param size
4cc4bfaf
FM
84 The dialog size. The value wxDefaultSize indicates a default size, chosen by
85 either the windowing system or wxWidgets, depending on platform.
7c913512 86 @param style
4cc4bfaf 87 The window style. See wxDialog.
7c913512 88 @param name
4cc4bfaf
FM
89 Used to associate a name with the window,
90 allowing the application user to set Motif resource values for
91 individual dialog boxes.
23324ae1 92
4cc4bfaf 93 @see Create()
23324ae1
FM
94 */
95 wxDialog();
7c913512
FM
96 wxDialog(wxWindow* parent, wxWindowID id,
97 const wxString& title,
98 const wxPoint& pos = wxDefaultPosition,
99 const wxSize& size = wxDefaultSize,
100 long style = wxDEFAULT_DIALOG_STYLE,
101 const wxString& name = "dialogBox");
23324ae1
FM
102 //@}
103
104 /**
105 Destructor. Deletes any child windows before deleting the physical window.
106 */
107 ~wxDialog();
108
109 /**
110 Adds an identifier to be regarded as a main button for the non-scrolling area
111 of a dialog.
23324ae1
FM
112 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
113 more on layout adaptation.
114 */
115 void AddMainButtonId(wxWindowID id);
116
117 /**
118 Returns @true if this dialog can and should perform layout adaptation using
119 DoLayoutAdaptation(), usually if
120 the dialog is too large to fit on the display.
23324ae1
FM
121 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
122 more on layout adaptation.
123 */
124 bool CanDoLayoutAdapation();
125
126 /**
127 Centres the dialog box on the display.
128
7c913512 129 @param direction
4cc4bfaf 130 May be wxHORIZONTAL, wxVERTICAL or wxBOTH.
23324ae1
FM
131 */
132 void Centre(int direction = wxBOTH);
133
134 /**
135 Used for two-step dialog box construction. See wxDialog()
136 for details.
137 */
138 bool Create(wxWindow* parent, wxWindowID id,
139 const wxString& title,
140 const wxPoint& pos = wxDefaultPosition,
141 const wxSize& size = wxDefaultSize,
142 long style = wxDEFAULT_DIALOG_STYLE,
143 const wxString& name = "dialogBox");
144
145 /**
4cc4bfaf 146 Creates a sizer with standard buttons. @a flags is a bit list
7c913512 147 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
23324ae1 148 wxHELP, wxNO_DEFAULT.
23324ae1 149 The sizer lays out the buttons in a manner appropriate to the platform.
7c913512 150 This function uses CreateStdDialogButtonSizer()
23324ae1
FM
151 internally for most platforms but doesn't create the sizer at all for the
152 platforms with hardware buttons (such as smartphones) for which it sets up the
153 hardware buttons appropriately and returns @NULL, so don't forget to test that
154 the return value is valid before using it.
155 */
156 wxSizer* CreateButtonSizer(long flags);
157
158 /**
7c913512 159 Creates a sizer with standard buttons using
23324ae1
FM
160 CreateButtonSizer() separated from the rest
161 of the dialog contents by a horizontal wxStaticLine.
23324ae1 162 Please notice that just like CreateButtonSizer() this function may return @c
7c913512 163 @NULL
23324ae1
FM
164 if no buttons were created.
165 */
166 wxSizer* CreateSeparatedButtonSizer(long flags);
167
168 /**
4cc4bfaf 169 Creates a wxStdDialogButtonSizer with standard buttons. @a flags is a bit list
23324ae1
FM
170 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
171 wxHELP, wxNO_DEFAULT.
23324ae1
FM
172 The sizer lays out the buttons in a manner appropriate to the platform.
173 */
174 wxStdDialogButtonSizer* CreateStdDialogButtonSizer(long flags);
175
176 /**
177 Performs layout adaptation, usually if the dialog is too large to fit on the
178 display.
23324ae1
FM
179 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
180 more on layout adaptation.
181 */
182 bool DoLayoutAdapation();
183
184 /**
185 This function is called when the titlebar OK button is pressed (PocketPC only).
186 A command event for the identifier returned by GetAffirmativeId is sent by
187 default. You can override this function. If the function returns @false,
188 wxWidgets
189 will call Close() for the dialog.
190 */
4cc4bfaf 191 virtual bool DoOK();
23324ae1
FM
192
193 /**
194 A static function enabling or disabling layout adaptation for all dialogs.
23324ae1
FM
195 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
196 more on layout adaptation.
197 */
198 static void EnableLayoutAdaptation(bool enable);
199
200 /**
201 Ends a modal dialog, passing a value to be returned from the ShowModal()
202 invocation.
203
7c913512 204 @param retCode
4cc4bfaf 205 The value that should be returned by ShowModal.
23324ae1 206
4cc4bfaf 207 @see ShowModal(), GetReturnCode(), SetReturnCode()
23324ae1
FM
208 */
209 void EndModal(int retCode);
210
211 /**
212 Gets the identifier of the button which works like standard OK button in this
213 dialog.
214
4cc4bfaf 215 @see SetAffirmativeId()
23324ae1 216 */
328f5751 217 int GetAffirmativeId() const;
23324ae1
FM
218
219 /**
220 Override this to return a window containing the main content of the dialog.
221 This is
222 particularly useful when the dialog implements pages, such as
223 wxPropertySheetDialog,
224 and allows the @ref overview_wxdialogoverview "layout adaptation code" to know
225 that only the pages need to be made scrollable.
226 */
328f5751 227 wxWindow* GetContentWindow() const;
23324ae1
FM
228
229 /**
230 Gets the identifier of the button to map presses of @c ESC
231 button to.
232
4cc4bfaf 233 @see SetEscapeId()
23324ae1 234 */
328f5751 235 int GetEscapeId() const;
23324ae1
FM
236
237 /**
238 Returns @true if the dialog has been adapted, usually by making it scrollable
239 to work with a small display.
23324ae1
FM
240 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
241 more on layout adaptation.
242 */
328f5751 243 bool GetLayoutAdaptationDone() const;
23324ae1
FM
244
245 /**
246 Gets a value representing the aggressiveness of search for buttons and sizers
247 to be in the non-scrolling part of a layout-adapted dialog.
248 Zero switches off adaptation, and 3 allows search for standard buttons anywhere
249 in the dialog.
23324ae1
FM
250 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
251 more on layout adaptation.
252 */
253 int GetLayoutAdaptationLevel();
254
255 /**
256 Gets the adaptation mode, overriding the global adaptation flag.
23324ae1
FM
257 See also SetLayoutAdaptationMode() and @ref overview_autoscrollingdialogs
258 "Automatic scrolling dialogs".
259 */
328f5751 260 wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const;
23324ae1
FM
261
262 /**
263 A static function getting the current layout adapter object.
23324ae1
FM
264 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
265 more on layout adaptation.
266 */
267 static wxDialogLayoutAdapter* GetLayoutAdapter();
268
269 /**
270 Returns an array of identifiers to be regarded as the main buttons for the
271 non-scrolling area of a dialog.
23324ae1
FM
272 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
273 more on layout adaptation.
274 */
275 wxArrayInt GetMainButtonIds();
276
277 /**
278 Gets the return code for this window.
279
280 @remarks A return code is normally associated with a modal dialog, where
4cc4bfaf 281 ShowModal() returns a code to the application.
23324ae1 282
4cc4bfaf 283 @see SetReturnCode(), ShowModal(), EndModal()
23324ae1
FM
284 */
285 int GetReturnCode();
286
287 /**
288 On PocketPC, a dialog is automatically provided with an empty toolbar.
289 GetToolBar
290 allows you to access the toolbar and add tools to it. Removing tools and adding
291 arbitrary controls are not currently supported.
23324ae1
FM
292 This function is not available on any other platform.
293 */
328f5751 294 wxToolBar* GetToolBar() const;
23324ae1
FM
295
296 /**
297 Iconizes or restores the dialog. Windows only.
298
7c913512 299 @param iconize
4cc4bfaf 300 If @true, iconizes the dialog box; if @false, shows and restores it.
23324ae1
FM
301
302 @remarks Note that in Windows, iconization has no effect since dialog
4cc4bfaf
FM
303 boxes cannot be iconized. However, applications may
304 need to explicitly restore dialog boxes under Motif
305 which have user-iconizable frames, and under Windows
306 calling Iconize(@false) will bring the window to the
307 front, as does Show(@true).
23324ae1
FM
308 */
309 void Iconize(bool iconize);
310
311 /**
312 Returns @true if the dialog box is iconized. Windows only.
313
314 @remarks Always returns @false under Windows since dialogs cannot be
4cc4bfaf 315 iconized.
23324ae1 316 */
328f5751 317 bool IsIconized() const;
23324ae1
FM
318
319 /**
320 A static function returning @true if layout adaptation is enabled for all
321 dialogs.
23324ae1
FM
322 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
323 more on layout adaptation.
324 */
325 static bool IsLayoutAdaptationEnabled();
326
327 /**
4cc4bfaf 328 Returns @true if @a id is in the array of identifiers to be regarded as the
23324ae1 329 main buttons for the non-scrolling area of a dialog.
23324ae1
FM
330 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
331 more on layout adaptation.
332 */
328f5751 333 bool IsMainButton(wxWindowID& id) const;
23324ae1
FM
334
335 /**
336 Returns @true if the dialog box is modal, @false otherwise.
337 */
328f5751 338 bool IsModal() const;
23324ae1
FM
339
340 /**
341 The default handler for wxEVT_SYS_COLOUR_CHANGED.
342
7c913512 343 @param event
4cc4bfaf 344 The colour change event.
23324ae1
FM
345
346 @remarks Changes the dialog's colour to conform to the current settings
4cc4bfaf
FM
347 (Windows only). Add an event table entry for your
348 dialog class if you wish the behaviour to be different
349 (such as keeping a user-defined background colour). If
350 you do override this function, call wxEvent::Skip to
351 propagate the notification to child windows and
352 controls.
23324ae1 353
4cc4bfaf 354 @see wxSysColourChangedEvent
23324ae1
FM
355 */
356 void OnSysColourChanged(wxSysColourChangedEvent& event);
357
358 /**
359 Sets the identifier to be used as OK button. When the button with this
7c913512
FM
360 identifier is pressed, the dialog calls wxWindow::Validate
361 and wxWindow::TransferDataFromWindow
23324ae1
FM
362 and, if they both return @true, closes the dialog with @c wxID_OK return
363 code.
23324ae1
FM
364 Also, when the user presses a hardware OK button on the devices having one or
365 the special OK button in the PocketPC title bar, an event with this id is
366 generated.
23324ae1
FM
367 By default, the affirmative id is wxID_OK.
368
4cc4bfaf 369 @see GetAffirmativeId(), SetEscapeId()
23324ae1
FM
370 */
371 void SetAffirmativeId(int id);
372
373 /**
7c913512 374 Sets the identifier of the button which should work like the standard
23324ae1 375 @c CANCEL button in this dialog. When the button with this id is
7c913512 376 clicked, the dialog is closed. Also, when the user presses @c ESC
23324ae1
FM
377 key in the dialog or closes the dialog using the close button in the title bar,
378 this is mapped to the click of the button with the specified id.
7c913512 379 By default, the escape id is the special value @c wxID_ANY meaning that
23324ae1 380 @c wxID_CANCEL button is used if it's present in the dialog and
7c913512 381 otherwise the button with GetAffirmativeId()
4cc4bfaf 382 is used. Another special value for @a id is @c wxID_NONE meaning that
23324ae1
FM
383 @c ESC presses should be ignored. If any other value is given, it
384 is interpreted as the id of the button to map the escape key to.
385 */
386 void SetEscapeId(int id);
387
388 /**
389 Sets the icon for this dialog.
390
7c913512 391 @param icon
4cc4bfaf 392 The icon to associate with this dialog.
23324ae1
FM
393 */
394 void SetIcon(const wxIcon& icon);
395
396 /**
397 Sets the icons for this dialog.
398
7c913512 399 @param icons
4cc4bfaf 400 The icons to associate with this dialog.
23324ae1
FM
401 */
402 void SetIcons(const wxIconBundle& icons);
403
404 /**
405 Marks the dialog as having been adapted, usually by making it scrollable to
406 work with a small display.
23324ae1
FM
407 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
408 more on layout adaptation.
409 */
410 void SetLayoutAdaptationDone(bool done);
411
412 /**
413 Sets the aggressiveness of search for buttons and sizers to be in the
414 non-scrolling part of a layout-adapted dialog.
415 Zero switches off adaptation, and 3 allows search for standard buttons anywhere
416 in the dialog.
23324ae1
FM
417 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
418 more on layout adaptation.
419 */
420 void SetLayoutAdaptationLevel(int level);
421
422 /**
4cc4bfaf 423 Sets the adaptation mode, overriding the global adaptation flag. @a mode may be
23324ae1 424 one of the following values:
4cc4bfaf 425
23324ae1
FM
426 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
427 more on layout adaptation.
428 */
429 void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode);
430
431 /**
432 A static function for setting the current layout adapter object, returning the
433 old adapter. If you call this, you should
434 delete the old adapter object.
23324ae1
FM
435 See also wxDialogLayoutAdapter and @ref overview_autoscrollingdialogs
436 "Automatic scrolling dialogs".
437 */
438 static wxDialogLayoutAdapter* SetLayoutAdapter(wxDialogLayoutAdapter* adapter);
439
440 /**
441 @b NB: This function is deprecated and doesn't work for all ports, just use
442 ShowModal() to show a modal dialog instead.
23324ae1
FM
443 Allows the programmer to specify whether the dialog box is modal (Show() blocks
444 control
445 until the dialog is hidden) or modeless (control returns immediately).
446
7c913512 447 @param flag
4cc4bfaf 448 If @true, the dialog will be modal, otherwise it will be modeless.
23324ae1
FM
449 */
450 void SetModal(bool flag);
451
452 /**
453 Sets the return code for this window.
454
7c913512 455 @param retCode
4cc4bfaf 456 The integer return code, usually a control identifier.
23324ae1
FM
457
458 @remarks A return code is normally associated with a modal dialog, where
4cc4bfaf
FM
459 ShowModal() returns a code to the application.
460 The function EndModal() calls SetReturnCode.
23324ae1 461
4cc4bfaf 462 @see GetReturnCode(), ShowModal(), EndModal()
23324ae1
FM
463 */
464 void SetReturnCode(int retCode);
465
466 /**
467 Hides or shows the dialog.
468
7c913512 469 @param show
4cc4bfaf
FM
470 If @true, the dialog box is shown and brought to the front;
471 otherwise the box is hidden. If @false and the dialog is
472 modal, control is returned to the calling program.
23324ae1
FM
473
474 @remarks The preferred way of dismissing a modal dialog is to use
4cc4bfaf 475 EndModal().
23324ae1
FM
476 */
477 bool Show(bool show);
478
479 /**
480 Shows a modal dialog. Program flow does not return until the dialog has been
481 dismissed with
482 EndModal().
483
484 @returns The return value is the value set with SetReturnCode().
485 */
486 int ShowModal();
487};
488
489
e54c96f1 490
23324ae1
FM
491/**
492 @class wxDialogLayoutAdapter
493 @wxheader{dialog.h}
7c913512 494
23324ae1 495 This abstract class is the base for classes that help wxWidgets peform run-time
7c913512 496 layout adaptation of dialogs. Principally,
23324ae1 497 this is to cater for small displays by making part of the dialog scroll, but
7c913512
FM
498 the application developer may find other
499 uses for layout adaption.
500
501 By default, there is one instance of wxStandardDialogLayoutAdapter
23324ae1 502 which can perform adaptation for most custom dialogs and dialogs with book
7c913512
FM
503 controls
504 such as wxPropertySheetDialog.
505
23324ae1
FM
506 @library{wxcore}
507 @category{FIXME}
7c913512 508
e54c96f1 509 @see @ref overview_autoscrollingdialogs "Automatic scrolling dialogs"
23324ae1 510*/
7c913512 511class wxDialogLayoutAdapter
23324ae1
FM
512{
513public:
514 /**
515 Default constructor.
516 */
517 wxDialogLayoutAdapter();
518
519 /**
520 Override this to returns @true if adaptation can and should be done.
521 */
522 bool CanDoLayoutAdaptation(wxDialog* dialog);
523
524 /**
525 Override this to perform layout adaptation, such as making parts of the dialog
7c913512 526 scroll and resizing the dialog to fit the display.
23324ae1
FM
527 Normally this function will be called just before the dialog is shown.
528 */
529 bool DoLayoutAdaptation(wxDialog* dialog);
530};
e54c96f1 531