]> git.saurik.com Git - wxWidgets.git/blame_incremental - interface/dialog.h
fixed category
[wxWidgets.git] / interface / dialog.h
... / ...
CommitLineData
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}
12
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.
16
17 Dialogs can be made scrollable, automatically: please see @ref
18 overview_autoscrollingdialogs "Automatic scrolling dialogs" for further details.
19
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
59
60 @library{wxcore}
61 @category{cmndlg}
62
63 @seealso
64 @ref overview_wxdialogoverview, wxFrame, @ref overview_validatoroverview
65 "Validator overview"
66*/
67class wxDialog : public wxTopLevelWindow
68{
69public:
70 //@{
71 /**
72 Constructor.
73
74 @param parent
75 Can be @NULL, a frame or another dialog box.
76 @param id
77 An identifier for the dialog. A value of -1 is taken to mean a default.
78 @param title
79 The title of the dialog.
80 @param pos
81 The dialog position. The value wxDefaultPosition indicates a default position,
82 chosen by
83 either the windowing system or wxWidgets, depending on platform.
84 @param size
85 The dialog size. The value wxDefaultSize indicates a default size, chosen by
86 either the windowing system or wxWidgets, depending on platform.
87 @param style
88 The window style. See wxDialog.
89 @param name
90 Used to associate a name with the window,
91 allowing the application user to set Motif resource values for
92 individual dialog boxes.
93
94 @see Create()
95 */
96 wxDialog();
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");
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.
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.
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
130 @param direction
131 May be wxHORIZONTAL, wxVERTICAL or wxBOTH.
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 /**
147 Creates a sizer with standard buttons. @a flags is a bit list
148 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
149 wxHELP, wxNO_DEFAULT.
150 The sizer lays out the buttons in a manner appropriate to the platform.
151 This function uses CreateStdDialogButtonSizer()
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 /**
160 Creates a sizer with standard buttons using
161 CreateButtonSizer() separated from the rest
162 of the dialog contents by a horizontal wxStaticLine.
163 Please notice that just like CreateButtonSizer() this function may return @c
164 @NULL
165 if no buttons were created.
166 */
167 wxSizer* CreateSeparatedButtonSizer(long flags);
168
169 /**
170 Creates a wxStdDialogButtonSizer with standard buttons. @a flags is a bit list
171 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
172 wxHELP, wxNO_DEFAULT.
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.
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 */
192 virtual bool DoOK();
193
194 /**
195 A static function enabling or disabling layout adaptation for all dialogs.
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
205 @param retCode
206 The value that should be returned by ShowModal.
207
208 @see ShowModal(), GetReturnCode(), SetReturnCode()
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
216 @see SetAffirmativeId()
217 */
218 int GetAffirmativeId() const;
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 */
228 wxWindow* GetContentWindow() const;
229
230 /**
231 Gets the identifier of the button to map presses of @c ESC
232 button to.
233
234 @see SetEscapeId()
235 */
236 int GetEscapeId() const;
237
238 /**
239 Returns @true if the dialog has been adapted, usually by making it scrollable
240 to work with a small display.
241 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
242 more on layout adaptation.
243 */
244 bool GetLayoutAdaptationDone() const;
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.
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.
258 See also SetLayoutAdaptationMode() and @ref overview_autoscrollingdialogs
259 "Automatic scrolling dialogs".
260 */
261 wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const;
262
263 /**
264 A static function getting the current layout adapter object.
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.
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
282 ShowModal() returns a code to the application.
283
284 @see SetReturnCode(), ShowModal(), EndModal()
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.
293 This function is not available on any other platform.
294 */
295 wxToolBar* GetToolBar() const;
296
297 /**
298 Iconizes or restores the dialog. Windows only.
299
300 @param iconize
301 If @true, iconizes the dialog box; if @false, shows and restores it.
302
303 @remarks Note that in Windows, iconization has no effect since dialog
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).
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
316 iconized.
317 */
318 bool IsIconized() const;
319
320 /**
321 A static function returning @true if layout adaptation is enabled for all
322 dialogs.
323 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
324 more on layout adaptation.
325 */
326 static bool IsLayoutAdaptationEnabled();
327
328 /**
329 Returns @true if @a id is in the array of identifiers to be regarded as the
330 main buttons for the non-scrolling area of a dialog.
331 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
332 more on layout adaptation.
333 */
334 bool IsMainButton(wxWindowID& id) const;
335
336 /**
337 Returns @true if the dialog box is modal, @false otherwise.
338 */
339 bool IsModal() const;
340
341 /**
342 The default handler for wxEVT_SYS_COLOUR_CHANGED.
343
344 @param event
345 The colour change event.
346
347 @remarks Changes the dialog's colour to conform to the current settings
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.
354
355 @see wxSysColourChangedEvent
356 */
357 void OnSysColourChanged(wxSysColourChangedEvent& event);
358
359 /**
360 Sets the identifier to be used as OK button. When the button with this
361 identifier is pressed, the dialog calls wxWindow::Validate
362 and wxWindow::TransferDataFromWindow
363 and, if they both return @true, closes the dialog with @c wxID_OK return
364 code.
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.
368 By default, the affirmative id is wxID_OK.
369
370 @see GetAffirmativeId(), SetEscapeId()
371 */
372 void SetAffirmativeId(int id);
373
374 /**
375 Sets the identifier of the button which should work like the standard
376 @c CANCEL button in this dialog. When the button with this id is
377 clicked, the dialog is closed. Also, when the user presses @c ESC
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.
380 By default, the escape id is the special value @c wxID_ANY meaning that
381 @c wxID_CANCEL button is used if it's present in the dialog and
382 otherwise the button with GetAffirmativeId()
383 is used. Another special value for @a id is @c wxID_NONE meaning that
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
392 @param icon
393 The icon to associate with this dialog.
394 */
395 void SetIcon(const wxIcon& icon);
396
397 /**
398 Sets the icons for this dialog.
399
400 @param icons
401 The icons to associate with this dialog.
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.
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.
418 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
419 more on layout adaptation.
420 */
421 void SetLayoutAdaptationLevel(int level);
422
423 /**
424 Sets the adaptation mode, overriding the global adaptation flag. @a mode may be
425 one of the following values:
426
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.
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.
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
448 @param flag
449 If @true, the dialog will be modal, otherwise it will be modeless.
450 */
451 void SetModal(bool flag);
452
453 /**
454 Sets the return code for this window.
455
456 @param retCode
457 The integer return code, usually a control identifier.
458
459 @remarks A return code is normally associated with a modal dialog, where
460 ShowModal() returns a code to the application.
461 The function EndModal() calls SetReturnCode.
462
463 @see GetReturnCode(), ShowModal(), EndModal()
464 */
465 void SetReturnCode(int retCode);
466
467 /**
468 Hides or shows the dialog.
469
470 @param show
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.
474
475 @remarks The preferred way of dismissing a modal dialog is to use
476 EndModal().
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}
494
495 This abstract class is the base for classes that help wxWidgets peform run-time
496 layout adaptation of dialogs. Principally,
497 this is to cater for small displays by making part of the dialog scroll, but
498 the application developer may find other
499 uses for layout adaption.
500
501 By default, there is one instance of wxStandardDialogLayoutAdapter
502 which can perform adaptation for most custom dialogs and dialogs with book
503 controls
504 such as wxPropertySheetDialog.
505
506 @library{wxcore}
507 @category{FIXME}
508
509 @seealso
510 @ref overview_autoscrollingdialogs "Automatic scrolling dialogs"
511*/
512class wxDialogLayoutAdapter
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
527 scroll and resizing the dialog to fit the display.
528 Normally this function will be called just before the dialog is shown.
529 */
530 bool DoLayoutAdaptation(wxDialog* dialog);
531};