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