]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/laywin.h
Fixed and clarified editor control event handling
[wxWidgets.git] / interface / wx / laywin.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: laywin.h
e54c96f1 3// Purpose: interface of wxLayoutAlgorithm
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxLayoutAlgorithm
7c913512 11
23324ae1
FM
12 wxLayoutAlgorithm implements layout of subwindows in MDI or SDI frames.
13 It sends a wxCalculateLayoutEvent event
14 to children of the frame, asking them for information about
15 their size. For MDI parent frames, the algorithm allocates
16 the remaining space to the MDI client window (which contains the MDI child
17 frames).
18 For SDI (normal) frames, a 'main' window is specified as taking up the
19 remaining space.
7c913512 20
23324ae1
FM
21 Because the event system is used, this technique can be applied to any windows,
22 which are not necessarily 'aware' of the layout classes (no virtual functions
23 in wxWindow refer to wxLayoutAlgorithm or its events). However, you
24 may wish to use wxSashLayoutWindow for your subwindows
25 since this class provides handlers for the required events, and accessors
26 to specify the desired size of the window. The sash behaviour in the base class
27 can be used, optionally, to make the windows user-resizable.
7c913512 28
23324ae1
FM
29 wxLayoutAlgorithm is typically used in IDE (integrated development environment)
30 applications,
31 where there are several resizable windows in addition to the MDI client window,
32 or
33 other primary editing window. Resizable windows might include toolbars, a
34 project
35 window, and a window for displaying error and warning messages.
7c913512 36
23324ae1
FM
37 When a window receives an OnCalculateLayout event, it should call SetRect in
38 the given event object, to be the old supplied rectangle minus whatever space
39 the
40 window takes up. It should also set its own size accordingly.
41 wxSashLayoutWindow::OnCalculateLayout generates an OnQueryLayoutInfo event
42 which it sends to itself to determine the orientation, alignment and size of
43 the window,
44 which it gets from internal member variables set by the application.
7c913512 45
23324ae1
FM
46 The algorithm works by starting off with a rectangle equal to the whole frame
47 client area.
48 It iterates through the frame children, generating OnCalculateLayout events
49 which subtract
50 the window size and return the remaining rectangle for the next window to
51 process. It
52 is assumed (by wxSashLayoutWindow::OnCalculateLayout) that a window stretches
53 the full dimension
54 of the frame client, according to the orientation it specifies. For example, a
55 horizontal window
56 will stretch the full width of the remaining portion of the frame client area.
57 In the other orientation, the window will be fixed to whatever size was
58 specified by
59 OnQueryLayoutInfo. An alignment setting will make the window 'stick' to the
60 left, top, right or
61 bottom of the remaining client area. This scheme implies that order of window
62 creation is important.
63 Say you wish to have an extra toolbar at the top of the frame, a project window
64 to the left of
65 the MDI client window, and an output window above the status bar. You should
66 therefore create
67 the windows in this order: toolbar, output window, project window. This ensures
68 that the toolbar and
69 output window take up space at the top and bottom, and then the remaining
70 height in-between is used for
71 the project window.
7c913512 72
23324ae1
FM
73 wxLayoutAlgorithm is quite independent of the way in which
74 OnCalculateLayout chooses to interpret a window's size and alignment. Therefore
75 you
76 could implement a different window class with a new OnCalculateLayout event
77 handler,
78 that has a more sophisticated way of laying out the windows. It might allow
79 specification of whether stretching occurs in the specified orientation, for
80 example,
81 rather than always assuming stretching. (This could, and probably should, be
82 added to the existing
83 implementation).
7c913512 84
23324ae1
FM
85 @e Note: wxLayoutAlgorithm has nothing to do with wxLayoutConstraints. It is an
86 alternative
87 way of specifying layouts for which the normal constraint system is unsuitable.
7c913512 88
23324ae1
FM
89 @library{wxadv}
90 @category{winlayout}
7c913512 91
e54c96f1 92 @see wxSashEvent, wxSashLayoutWindow, @ref overview_eventhandlingoverview
23324ae1
FM
93*/
94class wxLayoutAlgorithm : public wxObject
95{
96public:
97 /**
98 Default constructor.
99 */
100 wxLayoutAlgorithm();
101
102 /**
103 Destructor.
104 */
105 ~wxLayoutAlgorithm();
106
107 /**
4cc4bfaf 108 Lays out the children of a normal frame. @a mainWindow is set to occupy the
23324ae1 109 remaining space.
23324ae1
FM
110 This function simply calls LayoutWindow().
111 */
328f5751 112 bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = NULL) const;
23324ae1
FM
113
114 /**
4cc4bfaf 115 Lays out the children of an MDI parent frame. If @a rect is non-@NULL, the
23324ae1
FM
116 given rectangle will be used as a starting point instead of the frame's client
117 area.
23324ae1
FM
118 The MDI client window is set to occupy the remaining space.
119 */
328f5751 120 bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = NULL) const;
23324ae1
FM
121
122 /**
123 Lays out the children of a normal frame or other window.
4cc4bfaf 124 @a mainWindow is set to occupy the remaining space. If this is not specified,
23324ae1
FM
125 then
126 the last window that responds to a calculate layout event in query mode will
127 get the remaining space
128 (that is, a non-query OnCalculateLayout event will not be sent to this window
129 and the window will be set
130 to the remaining size).
131 */
328f5751 132 bool LayoutWindow(wxWindow* parent, wxWindow* mainWindow = NULL) const;
23324ae1
FM
133};
134
135
e54c96f1 136
23324ae1
FM
137/**
138 @class wxSashLayoutWindow
7c913512 139
23324ae1
FM
140 wxSashLayoutWindow responds to OnCalculateLayout events generated
141 by wxLayoutAlgorithm. It allows the
142 application to use simple accessors to specify how the window should be
143 laid out, rather than having to respond to events. The fact that
144 the class derives from wxSashWindow allows sashes to be used if required,
145 to allow the windows to be user-resizable.
7c913512 146
23324ae1
FM
147 The documentation for wxLayoutAlgorithm explains
148 the purpose of this class in more detail.
7c913512 149
23324ae1
FM
150 @library{wxadv}
151 @category{miscwnd}
7c913512 152
e54c96f1 153 @see wxLayoutAlgorithm, wxSashWindow, @ref overview_eventhandlingoverview
23324ae1
FM
154*/
155class wxSashLayoutWindow : public wxSashWindow
156{
157public:
158 //@{
159 /**
160 Constructs a sash layout window, which can be a child of a frame, dialog or any
161 other non-control window.
3c4f71cc 162
7c913512 163 @param parent
4cc4bfaf 164 Pointer to a parent window.
7c913512 165 @param id
4cc4bfaf 166 Window identifier. If -1, will automatically create an identifier.
7c913512 167 @param pos
4cc4bfaf 168 Window position. wxDefaultPosition is (-1, -1) which indicates that
23324ae1 169 wxSashLayoutWindows
4cc4bfaf 170 should generate a default position for the window. If using the
23324ae1 171 wxSashLayoutWindow class directly, supply
4cc4bfaf 172 an actual position.
7c913512 173 @param size
4cc4bfaf
FM
174 Window size. wxDefaultSize is (-1, -1) which indicates that
175 wxSashLayoutWindows
176 should generate a default size for the window.
7c913512 177 @param style
4cc4bfaf 178 Window style. For window styles, please see wxSashLayoutWindow.
7c913512 179 @param name
4cc4bfaf 180 Window name.
23324ae1
FM
181 */
182 wxSashLayoutWindow();
7c913512
FM
183 wxSashLayoutWindow(wxSashLayoutWindow* parent, wxWindowID id,
184 const wxPoint& pos = wxDefaultPosition,
185 const wxSize& size = wxDefaultSize,
4cc4bfaf 186 long style = wxCLIP_CHILDREN | wxSW_3D,
7c913512 187 const wxString& name = "layoutWindow");
23324ae1
FM
188 //@}
189
190 /**
191 Initializes a sash layout window, which can be a child of a frame, dialog or
192 any other non-control window.
3c4f71cc 193
7c913512 194 @param parent
4cc4bfaf 195 Pointer to a parent window.
7c913512 196 @param id
4cc4bfaf 197 Window identifier. If -1, will automatically create an identifier.
7c913512 198 @param pos
4cc4bfaf 199 Window position. wxDefaultPosition is (-1, -1) which indicates that
23324ae1 200 wxSashLayoutWindows
4cc4bfaf 201 should generate a default position for the window. If using the
23324ae1 202 wxSashLayoutWindow class directly, supply
4cc4bfaf 203 an actual position.
7c913512 204 @param size
4cc4bfaf
FM
205 Window size. wxDefaultSize is (-1, -1) which indicates that
206 wxSashLayoutWindows
207 should generate a default size for the window.
7c913512 208 @param style
4cc4bfaf 209 Window style. For window styles, please see wxSashLayoutWindow.
7c913512 210 @param name
4cc4bfaf 211 Window name.
23324ae1
FM
212 */
213 bool Create(wxSashLayoutWindow* parent, wxWindowID id,
214 const wxPoint& pos = wxDefaultPosition,
215 const wxSize& size = wxDefaultSize,
4cc4bfaf 216 long style = wxCLIP_CHILDREN | wxSW_3D,
23324ae1
FM
217 const wxString& name = "layoutWindow");
218
219 /**
220 Returns the alignment of the window: one of wxLAYOUT_TOP, wxLAYOUT_LEFT,
221 wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
222 */
328f5751 223 wxLayoutAlignment GetAlignment() const;
23324ae1
FM
224
225 /**
226 Returns the orientation of the window: one of wxLAYOUT_HORIZONTAL,
227 wxLAYOUT_VERTICAL.
228 */
328f5751 229 wxLayoutOrientation GetOrientation() const;
23324ae1
FM
230
231 /**
232 The default handler for the event that is generated by wxLayoutAlgorithm. The
233 implementation
234 of this function calls wxCalculateLayoutEvent::SetRect to shrink the provided
235 size according to
236 how much space this window takes up. For further details,
237 see wxLayoutAlgorithm and wxCalculateLayoutEvent.
238 */
239 void OnCalculateLayout(wxCalculateLayoutEvent& event);
240
241 /**
242 The default handler for the event that is generated by OnCalculateLayout to get
243 size, alignment and orientation information for the window. The implementation
244 of this function uses member variables as set by accessors called by the
245 application.
246 For further details, see wxLayoutAlgorithm and wxQueryLayoutInfoEvent.
247 */
248 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
249
250 /**
251 Sets the alignment of the window (which edge of the available parent client
252 area the window
4cc4bfaf 253 is attached to). @a alignment is one of wxLAYOUT_TOP, wxLAYOUT_LEFT,
23324ae1
FM
254 wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
255 */
256 void SetAlignment(wxLayoutAlignment alignment);
257
258 /**
259 Sets the default dimensions of the window. The dimension other than the
260 orientation will be fixed to this
261 value, and the orientation dimension will be ignored and the window stretched
262 to fit the available space.
263 */
264 void SetDefaultSize(const wxSize& size);
265
266 /**
267 Sets the orientation of the window (the direction the window will stretch in,
268 to fill the available
4cc4bfaf 269 parent client area). @a orientation is one of wxLAYOUT_HORIZONTAL,
23324ae1
FM
270 wxLAYOUT_VERTICAL.
271 */
272 void SetOrientation(wxLayoutOrientation orientation);
273};
274
275
e54c96f1 276
23324ae1
FM
277/**
278 @class wxQueryLayoutInfoEvent
7c913512 279
23324ae1
FM
280 This event is sent when wxLayoutAlgorithm wishes to get
281 the size, orientation and alignment of a window. More precisely, the event is
282 sent
283 by the OnCalculateLayout handler which is itself invoked by wxLayoutAlgorithm.
7c913512 284
23324ae1
FM
285 @library{wxadv}
286 @category{events}
7c913512 287
e54c96f1 288 @see wxCalculateLayoutEvent, wxSashLayoutWindow, wxLayoutAlgorithm.
23324ae1
FM
289*/
290class wxQueryLayoutInfoEvent : public wxEvent
291{
292public:
293 /**
294 Constructor.
295 */
296 wxQueryLayoutInfoEvent(wxWindowID id = 0);
297
298 /**
299 Specifies the alignment of the window (which side of the remaining parent
300 client area
301 the window sticks to). One of wxLAYOUT_TOP, wxLAYOUT_LEFT, wxLAYOUT_RIGHT,
302 wxLAYOUT_BOTTOM.
303 */
328f5751 304 void GetAlignment() const;
23324ae1
FM
305
306 /**
307 Returns the flags associated with this event. Not currently used.
308 */
328f5751 309 int GetFlags() const;
23324ae1
FM
310
311 /**
312 Returns the orientation that the event handler specified to the event object.
313 May be one of wxLAYOUT_HORIZONTAL,
314 wxLAYOUT_VERTICAL.
315 */
328f5751 316 wxLayoutOrientation GetOrientation() const;
23324ae1
FM
317
318 /**
319 Returns the requested length of the window in the direction of the window
320 orientation. This information
321 is not yet used.
322 */
328f5751 323 int GetRequestedLength() const;
23324ae1
FM
324
325 /**
326 Returns the size that the event handler specified to the event object as being
327 the requested size of the window.
328 */
328f5751 329 wxSize GetSize() const;
23324ae1
FM
330
331 /**
332 Call this to specify the alignment of the window (which side of the remaining
333 parent client area
334 the window sticks to). May be one of wxLAYOUT_TOP, wxLAYOUT_LEFT,
335 wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
336 */
337 void SetAlignment(wxLayoutAlignment alignment);
338
339 /**
340 Sets the flags associated with this event. Not currently used.
341 */
342 void SetFlags(int flags);
343
344 /**
345 Call this to specify the orientation of the window. May be one of
346 wxLAYOUT_HORIZONTAL,
347 wxLAYOUT_VERTICAL.
348 */
349 void SetOrientation(wxLayoutOrientation orientation);
350
351 /**
352 Sets the requested length of the window in the direction of the window
353 orientation. This information
354 is not yet used.
355 */
356 void SetRequestedLength(int length);
357
358 /**
359 Call this to let the calling code know what the size of the window is.
360 */
361 void SetSize(const wxSize& size);
362};
363
364
e54c96f1 365
23324ae1
FM
366/**
367 @class wxCalculateLayoutEvent
7c913512 368
23324ae1
FM
369 This event is sent by wxLayoutAlgorithm to
370 calculate the amount of the remaining client area that the window should
371 occupy.
7c913512 372
23324ae1
FM
373 @library{wxadv}
374 @category{events}
7c913512 375
e54c96f1 376 @see wxQueryLayoutInfoEvent, wxSashLayoutWindow, wxLayoutAlgorithm.
23324ae1
FM
377*/
378class wxCalculateLayoutEvent : public wxEvent
379{
380public:
381 /**
382 Constructor.
383 */
384 wxCalculateLayoutEvent(wxWindowID id = 0);
385
386 /**
387 Returns the flags associated with this event. Not currently used.
388 */
328f5751 389 int GetFlags() const;
23324ae1
FM
390
391 /**
392 Before the event handler is entered, returns the remaining parent client area
393 that the window
394 could occupy. When the event handler returns, this should contain the remaining
395 parent client rectangle,
396 after the event handler has subtracted the area that its window occupies.
397 */
328f5751 398 wxRect GetRect() const;
23324ae1
FM
399
400 /**
401 Sets the flags associated with this event. Not currently used.
402 */
403 void SetFlags(int flags);
404
405 /**
406 Call this to specify the new remaining parent client area, after the space
407 occupied by the
408 window has been subtracted.
409 */
410 void SetRect(const wxRect& rect);
411};
e54c96f1 412