]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/tdialog.tex
Corrected docs of ::release and ::reset in smart pointers
[wxWidgets.git] / docs / latex / wx / tdialog.tex
1 \section{wxDialog overview}\label{wxdialogoverview}
2
3 Classes: \helpref{wxDialog}{wxdialog}, \helpref{wxDialogLayoutAdapter}{wxdialoglayoutadapter}
4
5 A dialog box is similar to a panel, in that it is a window which can
6 be used for placing controls, with the following exceptions:
7
8 \begin{enumerate}
9 \item A surrounding frame is implicitly created.
10 \item Extra functionality is automatically given to the dialog box,
11 such as tabbing between items (currently Windows only).
12 \item If the dialog box is {\it modal}, the calling program is blocked
13 until the dialog box is dismissed.
14 \end{enumerate}
15
16 For a set of dialog convenience functions, including file selection, see
17 \rtfsp\helpref{Dialog functions}{dialogfunctions}.
18
19 See also \helpref{wxTopLevelWindow}{wxtoplevelwindow} and \helpref{wxWindow}{wxwindow} for inherited
20 member functions. Validation of data in controls is covered in \helpref{Validator overview}{validatoroverview}.
21
22 \subsection{Automatic scrolling dialogs}\label{autoscrollingdialogs}
23
24 As an ever greater variety of mobile hardware comes to market, it becomes more imperative for wxWidgets applications to adapt
25 to these platforms without putting too much burden on the programmer. One area where wxWidgets can help is in adapting
26 dialogs for the lower resolution screens that inevitably accompany a smaller form factor. wxDialog therefore supplies
27 a global \helpref{wxDialogLayoutAdapter}{wxdialoglayoutadapter} class that implements automatic scrolling adaptation for most sizer-based custom dialogs.
28 Many applications should therefore be able to adapt to small displays with little or no work, as far as dialogs are concerned.
29
30 By default this adaptation is off. To switch scrolling adaptation on globally in your application, call the static function\rtfsp
31 \helpref{wxDialog::EnableLayoutAdaptation}{wxdialogenablelayoutadaptation} passing \true. You can also adjust adaptation on a per-dialog basis by calling\rtfsp
32 \helpref{wxDialog::SetLayoutAdaptationMode}{wxdialogsetlayoutadaptationmode} with one of {\tt wxDIALOG\_ADAPTATION\_MODE\_DEFAULT} (use the global setting), {\tt wxDIALOG\_ADAPTATION\_MODE\_ENABLED} or {\tt wxDIALOG\_ADAPTATION\_MODE\_DISABLED}.
33 The last two modes override the global adaptation setting.
34
35 With adaptation enabled, if the display size is too small for the dialog, wxWidgets (or rather the
36 standard adapter class wxStandardDialogLayoutAdapter) will
37 make part of the dialog scrolling, leaving standard buttons in a non-scrolling part at the bottom of the dialog.
38
39 This is done as follows, in \helpref{wxDialogLayoutAdapter::DoLayoutAdaptation}{wxdialoglayoutadapterdolayoutadaptation} called from within wxDialog::Show or wxDialog::ShowModal:
40
41 \begin{enumerate}
42 \item If \helpref{wxDialog::GetContentWindow}{wxdialoggetcontentwindow} returns a window derived from wxBookCtrlBase, the pages are made scrollable and
43 no other adaptation is done.
44 \item wxWidgets looks for a \helpref{wxStdDialogButtonSizer}{wxstddialogbuttonsizer} and uses it for the non-scrolling part.
45 \item If that search failed, wxWidgets looks for a horizontal \helpref{wxBoxSizer}{wxboxsizer} with one or more
46 standard buttons, with identifiers such as {\tt wxID\_OK} and {\tt wxID\_CANCEL}.
47 \item If that search failed too, wxWidgets finds 'loose' standard buttons (in any kind of sizer) and adds them to a \helpref{wxStdDialogButtonSizer}{wxstddialogbuttonsizer}.
48 If no standard buttons were found, the whole dialog content will scroll.
49 \item All the children apart from standard buttons are reparented onto a new \helpref{wxScrolledWindow}{wxscrolledwindow} object,
50 using the old top-level sizer for the scrolled window and creating a new top-level sizer to lay out the scrolled window and
51 standard button sizer.
52 \end{enumerate}
53
54 \wxheading{Customising scrolling adaptation}
55
56 In addition to switching adaptation on and off globally and per dialog, you can choose how aggressively wxWidgets will
57 search for standard buttons by setting \helpref{wxDialog::SetLayoutAdaptationLevel}{wxdialogsetlayoutadaptationlevel}. By default,
58 all the steps described above will be performed but by setting the level to 1, for example, you can choose to only look for wxStdDialogButtonSizer.
59
60 You can use \helpref{wxDialog::AddMainButtonId}{wxdialogaddmainbuttonid} to add identifiers for buttons that should also be
61 treated as standard buttons for the non-scrolling area.
62
63 You can derive your own class from \helpref{wxDialogLayoutAdapter}{wxdialoglayoutadapter} or wxStandardDialogLayoutAdapter and call\rtfsp
64 \helpref{wxDialog::SetLayoutAdapter}{wxdialogsetlayoutadapter}, deleting the old object that this function returns. Override
65 the functions CanDoLayoutAdaptation and DoLayoutAdaptation to test for adaptation applicability and perform the adaptation.
66
67 You can also override \helpref{wxDialog::CanDoLayoutAdaptation}{wxdialogcandolayoutadaptation} and \helpref{wxDialog::DoLayoutAdaptation}{wxdialogdolayoutadaptation} in a class derived from wxDialog.
68
69 \wxheading{Situations where automatic scrolling adaptation may fail}
70
71 Because adaptation rearranges your sizer and window hierarchy, it is not fool-proof, and may fail in the following situations.
72
73 \begin{itemize}
74 \item The dialog doesn't use sizers.
75 \item The dialog implementation makes assumptions about the window hierarchy, for example getting the parent of a control and casting to the dialog class.
76 \item The dialog does custom painting and/or event handling not handled by the scrolled window. If this problem can be solved globally,
77 you can derive a new adapter class from wxStandardDialogLayoutAdapter and override its CreateScrolledWindow function to return an instance of your own class.
78 \item The dialog has unusual layout, for example a vertical sizer containing a mixture of standard buttons and other controls.
79 \item The dialog makes assumptions about the sizer hierarchy, for example to show or hide children of the top-level sizer. However, the original sizer hierarchy will still hold
80 until Show or ShowModal is called.
81 \end{itemize}
82
83 You can help make sure that your dialogs will continue to function after adaptation by:
84
85 \begin{itemize}
86 \item avoiding the above situations and assumptions;
87 \item using \helpref{wxStdDialogButtonSizer}{wxstddialogbuttonsizer};
88 \item only making assumptions about hierarchy immediately after the dialog is created;
89 \item using an intermediate sizer under the main sizer, a false top-level sizer that can be relied on to exist
90 for the purposes of manipulating child sizers and windows;
91 \item overriding \helpref{wxDialog::GetContentWindow}{wxdialoggetcontentwindow} to return a book control if your dialog implements pages: wxWidgets will then only make the pages
92 scrollable.
93 \end{itemize}
94
95 \wxheading{wxPropertySheetDialog and wxWizard}
96
97 Adaptation for wxPropertySheetDialog is always done by simply making the pages scrollable, since \helpref{wxDialog::GetContentWindow}{wxdialoggetcontentwindow} returns
98 the dialog's book control and this is handled by the standard layout adapter.
99
100 wxWizard uses its own CanDoLayoutAdaptation and DoLayoutAdaptation functions rather than the global adapter: again, only the wizard pages are made scrollable.
101