]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/layalgor.tex
Moved desktop margin options to a more sensible place
[wxWidgets.git] / docs / latex / wx / layalgor.tex
CommitLineData
6fb26ea3
JS
1\section{\class{wxLayoutAlgorithm}}\label{wxlayoutalgorithm}
2
3wxLayoutAlgorithm implements layout of subwindows in MDI or SDI frames.
4It sends a wxCalculateLayoutEvent event
5to children of the frame, asking them for information about
6their size. For MDI parent frames, the algorithm allocates
7the remaining space to the MDI client window (which contains the MDI child frames).
8For SDI (normal) frames, a 'main' window is specified as taking up the
9remaining space.
10
11Because the event system is used, this technique can be applied to any windows,
12which are not necessarily 'aware' of the layout classes (no virtual functions
13in wxWindow refer to wxLayoutAlgorithm or its events). However, you
14may wish to use \helpref{wxSashLayoutWindow}{wxsashlayoutwindow} for your subwindows
15since this class provides handlers for the required events, and accessors
16to specify the desired size of the window. The sash behaviour in the base class
17can be used, optionally, to make the windows user-resizable.
18
19wxLayoutAlgorithm is typically used in IDE (integrated development environment) applications,
20where there are several resizable windows in addition to the MDI client window, or
21other primary editing window. Resizable windows might include toolbars, a project
22window, and a window for displaying error and warning messages.
23
24When a window receives an OnCalculateLayout event, it should call SetRect in
25the given event object, to be the old supplied rectangle minus whatever space the
26window takes up. It should also set its own size accordingly.
27wxSashLayoutWindow::OnCalculateLayout generates an OnQueryLayoutInfo event
28which it sends to itself to determine the orientation, alignment and size of the window,
29which it gets from internal member variables set by the application.
30
31The algorithm works by starting off with a rectangle equal to the whole frame client area.
32It iterates through the frame children, generating OnCalculateLayout events which subtract
33the window size and return the remaining rectangle for the next window to process. It
34is assumed (by wxSashLayoutWindow::OnCalculateLayout) that a window stretches the full dimension
35of the frame client, according to the orientation it specifies. For example, a horizontal window
36will stretch the full width of the remaining portion of the frame client area.
37In the other orientation, the window will be fixed to whatever size was specified by
38OnQueryLayoutInfo. An alignment setting will make the window 'stick' to the left, top, right or
39bottom of the remaining client area. This scheme implies that order of window creation is important.
40Say you wish to have an extra toolbar at the top of the frame, a project window to the left of
41the MDI client window, and an output window above the status bar. You should therefore create
42the windows in this order: toolbar, output window, project window. This ensures that the toolbar and
2edb0bde 43output window take up space at the top and bottom, and then the remaining height in-between is used for
6fb26ea3
JS
44the project window.
45
46wxLayoutAlgorithm is quite independent of the way in which
47OnCalculateLayout chooses to interpret a window's size and alignment. Therefore you
48could implement a different window class with a new OnCalculateLayout event handler,
49that has a more sophisticated way of laying out the windows. It might allow
50specification of whether stretching occurs in the specified orientation, for example,
51rather than always assuming stretching. (This could, and probably should, be added to the existing
52implementation).
53
54{\it Note:} wxLayoutAlgorithm has nothing to do with wxLayoutConstraints. It is an alternative
55way of specifying layouts for which the normal constraint system is unsuitable.
56
57\wxheading{Derived from}
58
59\helpref{wxObject}{wxobject}
60
954b8ae6
JS
61\wxheading{Include files}
62
63<wx/laywin.h>
64
a7af285d
VZ
65\wxheading{Library}
66
67\helpref{wxAdv}{librarieslist}
68
6fb26ea3
JS
69\wxheading{Event handling}
70
71The algorithm object does not respond to events, but itself generates the
72following events in order to calculate window sizes.
73
74\twocolwidtha{7cm}%
75\begin{twocollist}\itemsep=0pt
76\twocolitem{{\bf EVT\_QUERY\_LAYOUT\_INFO(func)}}{Process a wxEVT\_QUERY\_LAYOUT\_INFO event,
77to get size, orientation and alignment from a window. See \helpref{wxQueryLayoutInfoEvent}{wxquerylayoutinfoevent}.}
78\twocolitem{{\bf EVT\_CALCULATE\_LAYOUT(func)}}{Process a wxEVT\_CALCULATE\_LAYOUT event,
79which asks the window to take a 'bite' out of a rectangle provided by the algorithm.
80See \helpref{wxCalculateLayoutEvent}{wxcalculatelayoutevent}.}
81\end{twocollist}
82
83\wxheading{Data types}
84
85{\small
86\begin{verbatim}
87enum wxLayoutOrientation {
88 wxLAYOUT_HORIZONTAL,
89 wxLAYOUT_VERTICAL
90};
91
92enum wxLayoutAlignment {
93 wxLAYOUT_NONE,
94 wxLAYOUT_TOP,
95 wxLAYOUT_LEFT,
96 wxLAYOUT_RIGHT,
97 wxLAYOUT_BOTTOM,
98};
99\end{verbatim}
100}
101
102\wxheading{See also}
103
104\helpref{wxSashEvent}{wxsashevent}, \helpref{wxSashLayoutWindow}{wxsashlayoutwindow}, \helpref{Event handling overview}{eventhandlingoverview}
105
106\helpref{wxCalculateLayoutEvent}{wxcalculatelayoutevent},\rtfsp
107\helpref{wxQueryLayoutInfoEvent}{wxquerylayoutinfoevent},\rtfsp
108\helpref{wxSashLayoutWindow}{wxsashlayoutwindow},\rtfsp
109\helpref{wxSashWindow}{wxsashwindow}
110
111\latexignore{\rtfignore{\wxheading{Members}}}
112
f0e8a2d0 113\membersection{wxLayoutAlgorithm::wxLayoutAlgorithm}\label{wxlayoutalgorithmctor}
6fb26ea3
JS
114
115\func{}{wxLayoutAlgorithm}{\void}
116
117Default constructor.
118
f0e8a2d0 119\membersection{wxLayoutAlgorithm::\destruct{wxLayoutAlgorithm}}\label{wxlayoutalgorithmdtor}
6fb26ea3
JS
120
121\func{}{\destruct{wxLayoutAlgorithm}}{\void}
122
123Destructor.
124
f9b1708c
JS
125\membersection{wxLayoutAlgorithm::LayoutFrame}\label{wxlayoutalgorithmlayoutframe}
126
127\constfunc{bool}{LayoutFrame}{\param{wxFrame* }{frame}, \param{wxWindow*}{ mainWindow = NULL}}
128
129Lays out the children of a normal frame. {\it mainWindow} is set to occupy the remaining space.
130
131This function simply calls \helpref{wxLayoutAlgorithm::LayoutWindow}{wxlayoutalgorithmlayoutwindow}.
132
6fb26ea3
JS
133\membersection{wxLayoutAlgorithm::LayoutMDIFrame}\label{wxlayoutalgorithmlayoutmdiframe}
134
135\constfunc{bool}{LayoutMDIFrame}{\param{wxMDIParentFrame* }{frame}, \param{wxRect*}{ rect = NULL}}
136
137Lays out the children of an MDI parent frame. If {\it rect} is non-NULL, the
138given rectangle will be used as a starting point instead of the frame's client area.
139
140The MDI client window is set to occupy the remaining space.
141
f9b1708c 142\membersection{wxLayoutAlgorithm::LayoutWindow}\label{wxlayoutalgorithmlayoutwindow}
6fb26ea3 143
f9b1708c 144\constfunc{bool}{LayoutWindow}{\param{wxWindow* }{parent}, \param{wxWindow*}{ mainWindow = NULL}}
6fb26ea3 145
f9b1708c 146Lays out the children of a normal frame or other window.
6fb26ea3 147
2f82899b
JS
148{\it mainWindow} is set to occupy the remaining space. If this is not specified, then
149the last window that responds to a calculate layout event in query mode will get the remaining space
150(that is, a non-query OnCalculateLayout event will not be sent to this window and the window will be set
151to the remaining size).
6fb26ea3 152