]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/sizer.h | |
3 | // Purpose: provide wxSizer class for layout | |
4 | // Author: Robert Roebling and Robin Dunn | |
5 | // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags) | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robin Dunn, Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __WXSIZER_H__ | |
13 | #define __WXSIZER_H__ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #include "wx/window.h" | |
18 | ||
19 | //--------------------------------------------------------------------------- | |
20 | // classes | |
21 | //--------------------------------------------------------------------------- | |
22 | ||
23 | class WXDLLIMPEXP_FWD_CORE wxButton; | |
24 | class WXDLLIMPEXP_FWD_CORE wxBoxSizer; | |
25 | class WXDLLIMPEXP_FWD_CORE wxSizerItem; | |
26 | class WXDLLIMPEXP_FWD_CORE wxSizer; | |
27 | ||
28 | #ifndef wxUSE_BORDER_BY_DEFAULT | |
29 | #ifdef __SMARTPHONE__ | |
30 | // no borders by default on limited size screen | |
31 | #define wxUSE_BORDER_BY_DEFAULT 0 | |
32 | #else | |
33 | #define wxUSE_BORDER_BY_DEFAULT 1 | |
34 | #endif | |
35 | #endif | |
36 | ||
37 | // ---------------------------------------------------------------------------- | |
38 | // wxSizerFlags: flags used for an item in the sizer | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
41 | class WXDLLEXPORT wxSizerFlags | |
42 | { | |
43 | public: | |
44 | // construct the flags object initialized with the given proportion (0 by | |
45 | // default) | |
46 | wxSizerFlags(int proportion = 0) : m_proportion(proportion) | |
47 | { | |
48 | m_flags = 0; | |
49 | m_borderInPixels = 0; | |
50 | } | |
51 | ||
52 | // setters for all sizer flags, they all return the object itself so that | |
53 | // calls to them can be chained | |
54 | ||
55 | wxSizerFlags& Proportion(int proportion) | |
56 | { | |
57 | m_proportion = proportion; | |
58 | return *this; | |
59 | } | |
60 | ||
61 | wxSizerFlags& Align(int alignment) // combination of wxAlignment values | |
62 | { | |
63 | m_flags &= ~wxALIGN_MASK; | |
64 | m_flags |= alignment; | |
65 | ||
66 | return *this; | |
67 | } | |
68 | ||
69 | wxSizerFlags& Expand() | |
70 | { | |
71 | m_flags |= wxEXPAND; | |
72 | return *this; | |
73 | } | |
74 | ||
75 | // some shortcuts for Align() | |
76 | wxSizerFlags& Centre() { return Align(wxALIGN_CENTRE); } | |
77 | wxSizerFlags& Center() { return Centre(); } | |
78 | wxSizerFlags& Top() { return Align(wxALIGN_TOP); } | |
79 | wxSizerFlags& Left() { return Align(wxALIGN_LEFT); } | |
80 | wxSizerFlags& Right() { return Align(wxALIGN_RIGHT); } | |
81 | wxSizerFlags& Bottom() { return Align(wxALIGN_BOTTOM); } | |
82 | ||
83 | // default border size used by Border() below | |
84 | static int GetDefaultBorder() | |
85 | { | |
86 | #if wxUSE_BORDER_BY_DEFAULT | |
87 | // FIXME: default border size shouldn't be hardcoded and at the very | |
88 | // least they should depend on the current font size | |
89 | return 5; | |
90 | #else | |
91 | return 0; | |
92 | #endif | |
93 | } | |
94 | ||
95 | ||
96 | wxSizerFlags& Border(int direction, int borderInPixels) | |
97 | { | |
98 | m_flags &= ~wxALL; | |
99 | m_flags |= direction; | |
100 | ||
101 | m_borderInPixels = borderInPixels; | |
102 | ||
103 | return *this; | |
104 | } | |
105 | ||
106 | wxSizerFlags& Border(int direction = wxALL) | |
107 | { | |
108 | #if wxUSE_BORDER_BY_DEFAULT | |
109 | return Border(direction, GetDefaultBorder()); | |
110 | #else | |
111 | // no borders by default on limited size screen | |
112 | wxUnusedVar(direction); | |
113 | ||
114 | return *this; | |
115 | #endif | |
116 | } | |
117 | ||
118 | wxSizerFlags& DoubleBorder(int direction = wxALL) | |
119 | { | |
120 | #if wxUSE_BORDER_BY_DEFAULT | |
121 | return Border(direction, 2*GetDefaultBorder()); | |
122 | #else | |
123 | wxUnusedVar(direction); | |
124 | ||
125 | return *this; | |
126 | #endif | |
127 | } | |
128 | ||
129 | wxSizerFlags& TripleBorder(int direction = wxALL) | |
130 | { | |
131 | #if wxUSE_BORDER_BY_DEFAULT | |
132 | return Border(direction, 3*GetDefaultBorder()); | |
133 | #else | |
134 | wxUnusedVar(direction); | |
135 | ||
136 | return *this; | |
137 | #endif | |
138 | } | |
139 | ||
140 | wxSizerFlags& HorzBorder() | |
141 | { | |
142 | #if wxUSE_BORDER_BY_DEFAULT | |
143 | return Border(wxLEFT | wxRIGHT, GetDefaultBorder()); | |
144 | #else | |
145 | return *this; | |
146 | #endif | |
147 | } | |
148 | ||
149 | wxSizerFlags& DoubleHorzBorder() | |
150 | { | |
151 | #if wxUSE_BORDER_BY_DEFAULT | |
152 | return Border(wxLEFT | wxRIGHT, 2*GetDefaultBorder()); | |
153 | #else | |
154 | return *this; | |
155 | #endif | |
156 | } | |
157 | ||
158 | // setters for the others flags | |
159 | wxSizerFlags& Shaped() | |
160 | { | |
161 | m_flags |= wxSHAPED; | |
162 | ||
163 | return *this; | |
164 | } | |
165 | ||
166 | wxSizerFlags& FixedMinSize() | |
167 | { | |
168 | m_flags |= wxFIXED_MINSIZE; | |
169 | ||
170 | return *this; | |
171 | } | |
172 | ||
173 | // accessors for wxSizer only | |
174 | int GetProportion() const { return m_proportion; } | |
175 | int GetFlags() const { return m_flags; } | |
176 | int GetBorderInPixels() const { return m_borderInPixels; } | |
177 | ||
178 | private: | |
179 | int m_proportion; | |
180 | int m_flags; | |
181 | int m_borderInPixels; | |
182 | }; | |
183 | ||
184 | ||
185 | // ---------------------------------------------------------------------------- | |
186 | // wxSizerSpacer: used by wxSizerItem to represent a spacer | |
187 | // ---------------------------------------------------------------------------- | |
188 | ||
189 | class WXDLLEXPORT wxSizerSpacer | |
190 | { | |
191 | public: | |
192 | wxSizerSpacer(const wxSize& size) : m_size(size), m_isShown(true) { } | |
193 | ||
194 | void SetSize(const wxSize& size) { m_size = size; } | |
195 | const wxSize& GetSize() const { return m_size; } | |
196 | ||
197 | void Show(bool show) { m_isShown = show; } | |
198 | bool IsShown() const { return m_isShown; } | |
199 | ||
200 | private: | |
201 | // the size, in pixel | |
202 | wxSize m_size; | |
203 | ||
204 | // is the spacer currently shown? | |
205 | bool m_isShown; | |
206 | }; | |
207 | ||
208 | // ---------------------------------------------------------------------------- | |
209 | // wxSizerItem | |
210 | // ---------------------------------------------------------------------------- | |
211 | ||
212 | class WXDLLEXPORT wxSizerItem : public wxObject | |
213 | { | |
214 | public: | |
215 | // window | |
216 | wxSizerItem( wxWindow *window, | |
217 | int proportion, | |
218 | int flag, | |
219 | int border, | |
220 | wxObject* userData ); | |
221 | ||
222 | // window with flags | |
223 | wxSizerItem(wxWindow *window, const wxSizerFlags& flags) | |
224 | { | |
225 | Init(flags); | |
226 | ||
227 | DoSetWindow(window); | |
228 | } | |
229 | ||
230 | // subsizer | |
231 | wxSizerItem( wxSizer *sizer, | |
232 | int proportion, | |
233 | int flag, | |
234 | int border, | |
235 | wxObject* userData ); | |
236 | ||
237 | // sizer with flags | |
238 | wxSizerItem(wxSizer *sizer, const wxSizerFlags& flags) | |
239 | { | |
240 | Init(flags); | |
241 | ||
242 | DoSetSizer(sizer); | |
243 | } | |
244 | ||
245 | // spacer | |
246 | wxSizerItem( int width, | |
247 | int height, | |
248 | int proportion, | |
249 | int flag, | |
250 | int border, | |
251 | wxObject* userData); | |
252 | ||
253 | // spacer with flags | |
254 | wxSizerItem(int width, int height, const wxSizerFlags& flags) | |
255 | { | |
256 | Init(flags); | |
257 | ||
258 | DoSetSpacer(wxSize(width, height)); | |
259 | } | |
260 | ||
261 | wxSizerItem(); | |
262 | virtual ~wxSizerItem(); | |
263 | ||
264 | virtual void DeleteWindows(); | |
265 | ||
266 | // Enable deleting the SizerItem without destroying the contained sizer. | |
267 | void DetachSizer() { m_sizer = NULL; } | |
268 | ||
269 | virtual wxSize GetSize() const; | |
270 | virtual wxSize CalcMin(); | |
271 | virtual void SetDimension( const wxPoint& pos, const wxSize& size ); | |
272 | ||
273 | wxSize GetMinSize() const | |
274 | { return m_minSize; } | |
275 | wxSize GetMinSizeWithBorder() const; | |
276 | ||
277 | void SetMinSize(const wxSize& size) | |
278 | { | |
279 | if ( IsWindow() ) | |
280 | m_window->SetMinSize(size); | |
281 | m_minSize = size; | |
282 | } | |
283 | void SetMinSize( int x, int y ) | |
284 | { SetMinSize(wxSize(x, y)); } | |
285 | void SetInitSize( int x, int y ) | |
286 | { SetMinSize(wxSize(x, y)); } | |
287 | ||
288 | // if either of dimensions is zero, ratio is assumed to be 1 | |
289 | // to avoid "divide by zero" errors | |
290 | void SetRatio(int width, int height) | |
291 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
292 | void SetRatio(const wxSize& size) | |
293 | { SetRatio(size.x, size.y); } | |
294 | void SetRatio(float ratio) | |
295 | { m_ratio = ratio; } | |
296 | float GetRatio() const | |
297 | { return m_ratio; } | |
298 | ||
299 | virtual wxRect GetRect() { return m_rect; } | |
300 | ||
301 | // set a sizer item id (different from a window id, all sizer items, | |
302 | // including spacers, can have an associated id) | |
303 | void SetId(int id) { m_id = id; } | |
304 | int GetId() const { return m_id; } | |
305 | ||
306 | bool IsWindow() const { return m_kind == Item_Window; } | |
307 | bool IsSizer() const { return m_kind == Item_Sizer; } | |
308 | bool IsSpacer() const { return m_kind == Item_Spacer; } | |
309 | ||
310 | #if WXWIN_COMPATIBILITY_2_6 | |
311 | // Deprecated in 2.6, use {G,S}etProportion instead. | |
312 | wxDEPRECATED( void SetOption( int option ) ); | |
313 | wxDEPRECATED( int GetOption() const ); | |
314 | #endif // WXWIN_COMPATIBILITY_2_6 | |
315 | ||
316 | void SetProportion( int proportion ) | |
317 | { m_proportion = proportion; } | |
318 | int GetProportion() const | |
319 | { return m_proportion; } | |
320 | void SetFlag( int flag ) | |
321 | { m_flag = flag; } | |
322 | int GetFlag() const | |
323 | { return m_flag; } | |
324 | void SetBorder( int border ) | |
325 | { m_border = border; } | |
326 | int GetBorder() const | |
327 | { return m_border; } | |
328 | ||
329 | wxWindow *GetWindow() const | |
330 | { return m_kind == Item_Window ? m_window : NULL; } | |
331 | wxSizer *GetSizer() const | |
332 | { return m_kind == Item_Sizer ? m_sizer : NULL; } | |
333 | wxSize GetSpacer() const; | |
334 | ||
335 | // this function behaves obviously for the windows and spacers but for the | |
336 | // sizers it returns true if any sizer element is shown and only returns | |
337 | // false if all of them are hidden | |
338 | bool IsShown() const; | |
339 | void Show(bool show); | |
340 | ||
341 | void SetUserData(wxObject* userData) | |
342 | { delete m_userData; m_userData = userData; } | |
343 | wxObject* GetUserData() const | |
344 | { return m_userData; } | |
345 | wxPoint GetPosition() const | |
346 | { return m_pos; } | |
347 | ||
348 | // these functions delete the current contents of the item if it's a sizer | |
349 | // or a spacer but not if it is a window | |
350 | void AssignWindow(wxWindow *window) | |
351 | { | |
352 | Free(); | |
353 | DoSetWindow(window); | |
354 | } | |
355 | ||
356 | void AssignSizer(wxSizer *sizer) | |
357 | { | |
358 | Free(); | |
359 | DoSetSizer(sizer); | |
360 | } | |
361 | ||
362 | void AssignSpacer(const wxSize& size) | |
363 | { | |
364 | Free(); | |
365 | DoSetSpacer(size); | |
366 | } | |
367 | ||
368 | void AssignSpacer(int w, int h) { AssignSpacer(wxSize(w, h)); } | |
369 | ||
370 | #if WXWIN_COMPATIBILITY_2_8 | |
371 | // these functions do not free the old sizer/spacer and so can easily | |
372 | // provoke the memory leaks and so shouldn't be used, use Assign() instead | |
373 | wxDEPRECATED( void SetWindow(wxWindow *window) ); | |
374 | wxDEPRECATED( void SetSizer(wxSizer *sizer) ); | |
375 | wxDEPRECATED( void SetSpacer(const wxSize& size) ); | |
376 | wxDEPRECATED( void SetSpacer(int width, int height) ); | |
377 | #endif // WXWIN_COMPATIBILITY_2_8 | |
378 | ||
379 | protected: | |
380 | // common part of several ctors | |
381 | void Init() { m_userData = NULL; m_kind = Item_None; } | |
382 | ||
383 | // common part of ctors taking wxSizerFlags | |
384 | void Init(const wxSizerFlags& flags); | |
385 | ||
386 | // free current contents | |
387 | void Free(); | |
388 | ||
389 | // common parts of Set/AssignXXX() | |
390 | void DoSetWindow(wxWindow *window); | |
391 | void DoSetSizer(wxSizer *sizer); | |
392 | void DoSetSpacer(const wxSize& size); | |
393 | ||
394 | // discriminated union: depending on m_kind one of the fields is valid | |
395 | enum | |
396 | { | |
397 | Item_None, | |
398 | Item_Window, | |
399 | Item_Sizer, | |
400 | Item_Spacer, | |
401 | Item_Max | |
402 | } m_kind; | |
403 | union | |
404 | { | |
405 | wxWindow *m_window; | |
406 | wxSizer *m_sizer; | |
407 | wxSizerSpacer *m_spacer; | |
408 | }; | |
409 | ||
410 | wxPoint m_pos; | |
411 | wxSize m_minSize; | |
412 | int m_proportion; | |
413 | int m_border; | |
414 | int m_flag; | |
415 | int m_id; | |
416 | ||
417 | // on screen rectangle of this item (not including borders) | |
418 | wxRect m_rect; | |
419 | ||
420 | // Aspect ratio can always be calculated from m_size, | |
421 | // but this would cause precision loss when the window | |
422 | // is shrunk. It is safer to preserve the initial value. | |
423 | float m_ratio; | |
424 | ||
425 | wxObject *m_userData; | |
426 | ||
427 | private: | |
428 | DECLARE_CLASS(wxSizerItem) | |
429 | DECLARE_NO_COPY_CLASS(wxSizerItem) | |
430 | }; | |
431 | ||
432 | WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList ); | |
433 | ||
434 | ||
435 | //--------------------------------------------------------------------------- | |
436 | // wxSizer | |
437 | //--------------------------------------------------------------------------- | |
438 | ||
439 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer | |
440 | { | |
441 | public: | |
442 | wxSizer() { m_containingWindow = NULL; } | |
443 | virtual ~wxSizer(); | |
444 | ||
445 | // methods for adding elements to the sizer: there are Add/Insert/Prepend | |
446 | // overloads for each of window/sizer/spacer/wxSizerItem | |
447 | wxSizerItem* Add(wxWindow *window, | |
448 | int proportion = 0, | |
449 | int flag = 0, | |
450 | int border = 0, | |
451 | wxObject* userData = NULL); | |
452 | wxSizerItem* Add(wxSizer *sizer, | |
453 | int proportion = 0, | |
454 | int flag = 0, | |
455 | int border = 0, | |
456 | wxObject* userData = NULL); | |
457 | wxSizerItem* Add(int width, | |
458 | int height, | |
459 | int proportion = 0, | |
460 | int flag = 0, | |
461 | int border = 0, | |
462 | wxObject* userData = NULL); | |
463 | wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags); | |
464 | wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags); | |
465 | wxSizerItem* Add( wxSizerItem *item); | |
466 | ||
467 | wxSizerItem* AddSpacer(int size); | |
468 | wxSizerItem* AddStretchSpacer(int prop = 1); | |
469 | ||
470 | wxSizerItem* Insert(size_t index, | |
471 | wxWindow *window, | |
472 | int proportion = 0, | |
473 | int flag = 0, | |
474 | int border = 0, | |
475 | wxObject* userData = NULL); | |
476 | wxSizerItem* Insert(size_t index, | |
477 | wxSizer *sizer, | |
478 | int proportion = 0, | |
479 | int flag = 0, | |
480 | int border = 0, | |
481 | wxObject* userData = NULL); | |
482 | wxSizerItem* Insert(size_t index, | |
483 | int width, | |
484 | int height, | |
485 | int proportion = 0, | |
486 | int flag = 0, | |
487 | int border = 0, | |
488 | wxObject* userData = NULL); | |
489 | wxSizerItem* Insert(size_t index, | |
490 | wxWindow *window, | |
491 | const wxSizerFlags& flags); | |
492 | wxSizerItem* Insert(size_t index, | |
493 | wxSizer *sizer, | |
494 | const wxSizerFlags& flags); | |
495 | virtual wxSizerItem* Insert( size_t index, wxSizerItem *item); | |
496 | ||
497 | wxSizerItem* InsertSpacer(size_t index, int size); | |
498 | wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); | |
499 | ||
500 | wxSizerItem* Prepend(wxWindow *window, | |
501 | int proportion = 0, | |
502 | int flag = 0, | |
503 | int border = 0, | |
504 | wxObject* userData = NULL); | |
505 | wxSizerItem* Prepend(wxSizer *sizer, | |
506 | int proportion = 0, | |
507 | int flag = 0, | |
508 | int border = 0, | |
509 | wxObject* userData = NULL); | |
510 | wxSizerItem* Prepend(int width, | |
511 | int height, | |
512 | int proportion = 0, | |
513 | int flag = 0, | |
514 | int border = 0, | |
515 | wxObject* userData = NULL); | |
516 | wxSizerItem* Prepend(wxWindow *window, const wxSizerFlags& flags); | |
517 | wxSizerItem* Prepend(wxSizer *sizer, const wxSizerFlags& flags); | |
518 | wxSizerItem* Prepend(wxSizerItem *item); | |
519 | ||
520 | wxSizerItem* PrependSpacer(int size); | |
521 | wxSizerItem* PrependStretchSpacer(int prop = 1); | |
522 | ||
523 | // set (or possibly unset if window is NULL) or get the window this sizer | |
524 | // is used in | |
525 | void SetContainingWindow(wxWindow *window); | |
526 | wxWindow *GetContainingWindow() const { return m_containingWindow; } | |
527 | ||
528 | #if WXWIN_COMPATIBILITY_2_6 | |
529 | // Deprecated in 2.6 since historically it does not delete the window, | |
530 | // use Detach instead. | |
531 | wxDEPRECATED( virtual bool Remove( wxWindow *window ) ); | |
532 | #endif // WXWIN_COMPATIBILITY_2_6 | |
533 | ||
534 | virtual bool Remove( wxSizer *sizer ); | |
535 | virtual bool Remove( int index ); | |
536 | ||
537 | virtual bool Detach( wxWindow *window ); | |
538 | virtual bool Detach( wxSizer *sizer ); | |
539 | virtual bool Detach( int index ); | |
540 | ||
541 | virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false ); | |
542 | virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false ); | |
543 | virtual bool Replace( size_t index, wxSizerItem *newitem ); | |
544 | ||
545 | virtual void Clear( bool delete_windows = false ); | |
546 | virtual void DeleteWindows(); | |
547 | ||
548 | void SetMinSize( int width, int height ) | |
549 | { DoSetMinSize( width, height ); } | |
550 | void SetMinSize( const wxSize& size ) | |
551 | { DoSetMinSize( size.x, size.y ); } | |
552 | ||
553 | // Searches recursively | |
554 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
555 | { return DoSetItemMinSize( window, width, height ); } | |
556 | bool SetItemMinSize( wxWindow *window, const wxSize& size ) | |
557 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
558 | ||
559 | // Searches recursively | |
560 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
561 | { return DoSetItemMinSize( sizer, width, height ); } | |
562 | bool SetItemMinSize( wxSizer *sizer, const wxSize& size ) | |
563 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
564 | ||
565 | bool SetItemMinSize( size_t index, int width, int height ) | |
566 | { return DoSetItemMinSize( index, width, height ); } | |
567 | bool SetItemMinSize( size_t index, const wxSize& size ) | |
568 | { return DoSetItemMinSize( index, size.x, size.y ); } | |
569 | ||
570 | wxSize GetSize() const | |
571 | { return m_size; } | |
572 | wxPoint GetPosition() const | |
573 | { return m_position; } | |
574 | ||
575 | // Calculate the minimal size or return m_minSize if bigger. | |
576 | wxSize GetMinSize(); | |
577 | ||
578 | // These virtual functions are used by the layout algorithm: first | |
579 | // CalcMin() is called to calculate the minimal size of the sizer and | |
580 | // prepare for laying it out and then RecalcSizes() is called to really | |
581 | // update all the sizer items | |
582 | virtual wxSize CalcMin() = 0; | |
583 | virtual void RecalcSizes() = 0; | |
584 | ||
585 | virtual void Layout(); | |
586 | ||
587 | wxSize Fit( wxWindow *window ); | |
588 | void FitInside( wxWindow *window ); | |
589 | void SetSizeHints( wxWindow *window ); | |
590 | void SetVirtualSizeHints( wxWindow *window ); | |
591 | ||
592 | wxSizerItemList& GetChildren() | |
593 | { return m_children; } | |
594 | const wxSizerItemList& GetChildren() const | |
595 | { return m_children; } | |
596 | ||
597 | void SetDimension( int x, int y, int width, int height ); | |
598 | ||
599 | wxSizerItem* GetItem( wxWindow *window, bool recursive = false ); | |
600 | wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false ); | |
601 | wxSizerItem* GetItem( size_t index ); | |
602 | wxSizerItem* GetItemById( int id, bool recursive = false ); | |
603 | ||
604 | // Manage whether individual scene items are considered | |
605 | // in the layout calculations or not. | |
606 | bool Show( wxWindow *window, bool show = true, bool recursive = false ); | |
607 | bool Show( wxSizer *sizer, bool show = true, bool recursive = false ); | |
608 | bool Show( size_t index, bool show = true ); | |
609 | ||
610 | bool Hide( wxSizer *sizer, bool recursive = false ) | |
611 | { return Show( sizer, false, recursive ); } | |
612 | bool Hide( wxWindow *window, bool recursive = false ) | |
613 | { return Show( window, false, recursive ); } | |
614 | bool Hide( size_t index ) | |
615 | { return Show( index, false ); } | |
616 | ||
617 | bool IsShown( wxWindow *window ) const; | |
618 | bool IsShown( wxSizer *sizer ) const; | |
619 | bool IsShown( size_t index ) const; | |
620 | ||
621 | // Recursively call wxWindow::Show () on all sizer items. | |
622 | virtual void ShowItems (bool show); | |
623 | ||
624 | void Show(bool show) { ShowItems(show); } | |
625 | ||
626 | protected: | |
627 | wxSize m_size; | |
628 | wxSize m_minSize; | |
629 | wxPoint m_position; | |
630 | wxSizerItemList m_children; | |
631 | ||
632 | // the window this sizer is used in, can be NULL | |
633 | wxWindow *m_containingWindow; | |
634 | ||
635 | wxSize GetMaxWindowSize( wxWindow *window ) const; | |
636 | wxSize GetMinWindowSize( wxWindow *window ); | |
637 | wxSize GetMaxClientSize( wxWindow *window ) const; | |
638 | wxSize GetMinClientSize( wxWindow *window ); | |
639 | wxSize VirtualFitSize( wxWindow *window ); | |
640 | ||
641 | virtual void DoSetMinSize( int width, int height ); | |
642 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
643 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
644 | virtual bool DoSetItemMinSize( size_t index, int width, int height ); | |
645 | ||
646 | private: | |
647 | DECLARE_CLASS(wxSizer) | |
648 | }; | |
649 | ||
650 | //--------------------------------------------------------------------------- | |
651 | // wxGridSizer | |
652 | //--------------------------------------------------------------------------- | |
653 | ||
654 | class WXDLLEXPORT wxGridSizer: public wxSizer | |
655 | { | |
656 | public: | |
657 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
658 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
659 | ||
660 | virtual void RecalcSizes(); | |
661 | virtual wxSize CalcMin(); | |
662 | ||
663 | void SetCols( int cols ) { m_cols = cols; } | |
664 | void SetRows( int rows ) { m_rows = rows; } | |
665 | void SetVGap( int gap ) { m_vgap = gap; } | |
666 | void SetHGap( int gap ) { m_hgap = gap; } | |
667 | int GetCols() const { return m_cols; } | |
668 | int GetRows() const { return m_rows; } | |
669 | int GetVGap() const { return m_vgap; } | |
670 | int GetHGap() const { return m_hgap; } | |
671 | ||
672 | protected: | |
673 | int m_rows; | |
674 | int m_cols; | |
675 | int m_vgap; | |
676 | int m_hgap; | |
677 | ||
678 | // return the number of total items and the number of columns and rows | |
679 | int CalcRowsCols(int& rows, int& cols) const; | |
680 | ||
681 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); | |
682 | ||
683 | private: | |
684 | DECLARE_CLASS(wxGridSizer) | |
685 | }; | |
686 | ||
687 | //--------------------------------------------------------------------------- | |
688 | // wxFlexGridSizer | |
689 | //--------------------------------------------------------------------------- | |
690 | ||
691 | // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible" | |
692 | // direction | |
693 | enum wxFlexSizerGrowMode | |
694 | { | |
695 | // don't resize the cells in non-flexible direction at all | |
696 | wxFLEX_GROWMODE_NONE, | |
697 | ||
698 | // uniformly resize only the specified ones (default) | |
699 | wxFLEX_GROWMODE_SPECIFIED, | |
700 | ||
701 | // uniformly resize all cells | |
702 | wxFLEX_GROWMODE_ALL | |
703 | }; | |
704 | ||
705 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer | |
706 | { | |
707 | public: | |
708 | // ctors/dtor | |
709 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
710 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
711 | virtual ~wxFlexGridSizer(); | |
712 | ||
713 | ||
714 | // set the rows/columns which will grow (the others will remain of the | |
715 | // constant initial size) | |
716 | void AddGrowableRow( size_t idx, int proportion = 0 ); | |
717 | void RemoveGrowableRow( size_t idx ); | |
718 | void AddGrowableCol( size_t idx, int proportion = 0 ); | |
719 | void RemoveGrowableCol( size_t idx ); | |
720 | ||
721 | ||
722 | // the sizer cells may grow in both directions, not grow at all or only | |
723 | // grow in one direction but not the other | |
724 | ||
725 | // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default) | |
726 | void SetFlexibleDirection(int direction) { m_flexDirection = direction; } | |
727 | int GetFlexibleDirection() const { return m_flexDirection; } | |
728 | ||
729 | // note that the grow mode only applies to the direction which is not | |
730 | // flexible | |
731 | void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; } | |
732 | wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; } | |
733 | ||
734 | // Read-only access to the row heights and col widths arrays | |
735 | const wxArrayInt& GetRowHeights() const { return m_rowHeights; } | |
736 | const wxArrayInt& GetColWidths() const { return m_colWidths; } | |
737 | ||
738 | // implementation | |
739 | virtual void RecalcSizes(); | |
740 | virtual wxSize CalcMin(); | |
741 | ||
742 | protected: | |
743 | void AdjustForFlexDirection(); | |
744 | void AdjustForGrowables(const wxSize& sz); | |
745 | ||
746 | // the heights/widths of all rows/columns | |
747 | wxArrayInt m_rowHeights, | |
748 | m_colWidths; | |
749 | ||
750 | // indices of the growable columns and rows | |
751 | wxArrayInt m_growableRows, | |
752 | m_growableCols; | |
753 | ||
754 | // proportion values of the corresponding growable rows and columns | |
755 | wxArrayInt m_growableRowsProportions, | |
756 | m_growableColsProportions; | |
757 | ||
758 | // parameters describing whether the growable cells should be resized in | |
759 | // both directions or only one | |
760 | int m_flexDirection; | |
761 | wxFlexSizerGrowMode m_growMode; | |
762 | ||
763 | // saves CalcMin result to optimize RecalcSizes | |
764 | wxSize m_calculatedMinSize; | |
765 | ||
766 | private: | |
767 | DECLARE_CLASS(wxFlexGridSizer) | |
768 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) | |
769 | }; | |
770 | ||
771 | //--------------------------------------------------------------------------- | |
772 | // wxBoxSizer | |
773 | //--------------------------------------------------------------------------- | |
774 | ||
775 | class WXDLLEXPORT wxBoxSizer: public wxSizer | |
776 | { | |
777 | public: | |
778 | wxBoxSizer(int orient) | |
779 | { | |
780 | m_orient = orient; | |
781 | ||
782 | wxASSERT_MSG( m_orient == wxHORIZONTAL || m_orient == wxVERTICAL, | |
783 | _T("invalid value for wxBoxSizer orientation") ); | |
784 | } | |
785 | ||
786 | int GetOrientation() const { return m_orient; } | |
787 | ||
788 | bool IsVertical() const { return m_orient == wxVERTICAL; } | |
789 | ||
790 | void SetOrientation(int orient) { m_orient = orient; } | |
791 | ||
792 | // implementation of our resizing logic | |
793 | virtual wxSize CalcMin(); | |
794 | virtual void RecalcSizes(); | |
795 | ||
796 | protected: | |
797 | // helpers for our code: this returns the component of the given wxSize in | |
798 | // the direction of the sizer and in the other direction, respectively | |
799 | int SizeInMajorDir(const wxSize& sz) const | |
800 | { | |
801 | return m_orient == wxHORIZONTAL ? sz.x : sz.y; | |
802 | } | |
803 | ||
804 | int& SizeInMajorDir(wxSize& sz) | |
805 | { | |
806 | return m_orient == wxHORIZONTAL ? sz.x : sz.y; | |
807 | } | |
808 | ||
809 | int& PosInMajorDir(wxPoint& pt) | |
810 | { | |
811 | return m_orient == wxHORIZONTAL ? pt.x : pt.y; | |
812 | } | |
813 | ||
814 | int SizeInMinorDir(const wxSize& sz) const | |
815 | { | |
816 | return m_orient == wxHORIZONTAL ? sz.y : sz.x; | |
817 | } | |
818 | ||
819 | int& SizeInMinorDir(wxSize& sz) | |
820 | { | |
821 | return m_orient == wxHORIZONTAL ? sz.y : sz.x; | |
822 | } | |
823 | ||
824 | int& PosInMinorDir(wxPoint& pt) | |
825 | { | |
826 | return m_orient == wxHORIZONTAL ? pt.y : pt.x; | |
827 | } | |
828 | ||
829 | // another helper: creates wxSize from major and minor components | |
830 | wxSize SizeFromMajorMinor(int major, int minor) const | |
831 | { | |
832 | if ( m_orient == wxHORIZONTAL ) | |
833 | { | |
834 | return wxSize(major, minor); | |
835 | } | |
836 | else // wxVERTICAL | |
837 | { | |
838 | return wxSize(minor, major); | |
839 | } | |
840 | } | |
841 | ||
842 | ||
843 | // either wxHORIZONTAL or wxVERTICAL | |
844 | int m_orient; | |
845 | ||
846 | // the sum of proportion of all of our elements | |
847 | int m_totalProportion; | |
848 | ||
849 | // the minimal size needed for this sizer as calculated by the last call to | |
850 | // our CalcMin() | |
851 | wxSize m_minSize; | |
852 | ||
853 | private: | |
854 | DECLARE_CLASS(wxBoxSizer) | |
855 | }; | |
856 | ||
857 | //--------------------------------------------------------------------------- | |
858 | // wxStaticBoxSizer | |
859 | //--------------------------------------------------------------------------- | |
860 | ||
861 | #if wxUSE_STATBOX | |
862 | ||
863 | class WXDLLIMPEXP_FWD_CORE wxStaticBox; | |
864 | ||
865 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
866 | { | |
867 | public: | |
868 | wxStaticBoxSizer(wxStaticBox *box, int orient); | |
869 | wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); | |
870 | virtual ~wxStaticBoxSizer(); | |
871 | ||
872 | void RecalcSizes(); | |
873 | wxSize CalcMin(); | |
874 | ||
875 | wxStaticBox *GetStaticBox() const | |
876 | { return m_staticBox; } | |
877 | ||
878 | // override to hide/show the static box as well | |
879 | virtual void ShowItems (bool show); | |
880 | ||
881 | virtual bool Detach( wxWindow *window ); | |
882 | virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); } | |
883 | virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); } | |
884 | ||
885 | protected: | |
886 | wxStaticBox *m_staticBox; | |
887 | ||
888 | private: | |
889 | DECLARE_CLASS(wxStaticBoxSizer) | |
890 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) | |
891 | }; | |
892 | ||
893 | #endif // wxUSE_STATBOX | |
894 | ||
895 | #if wxUSE_BUTTON | |
896 | ||
897 | class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer | |
898 | { | |
899 | public: | |
900 | // Constructor just creates a new wxBoxSizer, not much else. | |
901 | // Box sizer orientation is automatically determined here: | |
902 | // vertical for PDAs, horizontal for everything else? | |
903 | wxStdDialogButtonSizer(); | |
904 | ||
905 | // Checks button ID against system IDs and sets one of the pointers below | |
906 | // to this button. Does not do any sizer-related things here. | |
907 | void AddButton(wxButton *button); | |
908 | ||
909 | // Use these if no standard ID can/should be used | |
910 | void SetAffirmativeButton( wxButton *button ); | |
911 | void SetNegativeButton( wxButton *button ); | |
912 | void SetCancelButton( wxButton *button ); | |
913 | ||
914 | // All platform-specific code here, checks which buttons exist and add | |
915 | // them to the sizer accordingly. | |
916 | // Note - one potential hack on Mac we could use here, | |
917 | // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE | |
918 | // is set to _("Save") and m_buttonNegative is set to _("Don't Save") | |
919 | // I wouldn't add any other hacks like that into here, | |
920 | // but this one I can see being useful. | |
921 | void Realize(); | |
922 | ||
923 | wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; } | |
924 | wxButton *GetApplyButton() const { return m_buttonApply; } | |
925 | wxButton *GetNegativeButton() const { return m_buttonNegative; } | |
926 | wxButton *GetCancelButton() const { return m_buttonCancel; } | |
927 | wxButton *GetHelpButton() const { return m_buttonHelp; } | |
928 | ||
929 | protected: | |
930 | wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here | |
931 | wxButton *m_buttonApply; // wxID_APPLY | |
932 | wxButton *m_buttonNegative; // wxID_NO | |
933 | wxButton *m_buttonCancel; // wxID_CANCEL, wxID_CLOSE | |
934 | wxButton *m_buttonHelp; // wxID_HELP, wxID_CONTEXT_HELP | |
935 | ||
936 | private: | |
937 | DECLARE_CLASS(wxStdDialogButtonSizer) | |
938 | DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer) | |
939 | }; | |
940 | ||
941 | #endif // wxUSE_BUTTON | |
942 | ||
943 | ||
944 | // ---------------------------------------------------------------------------- | |
945 | // inline functions implementation | |
946 | // ---------------------------------------------------------------------------- | |
947 | ||
948 | #if WXWIN_COMPATIBILITY_2_8 | |
949 | ||
950 | inline void wxSizerItem::SetWindow(wxWindow *window) | |
951 | { | |
952 | DoSetWindow(window); | |
953 | } | |
954 | ||
955 | inline void wxSizerItem::SetSizer(wxSizer *sizer) | |
956 | { | |
957 | DoSetSizer(sizer); | |
958 | } | |
959 | ||
960 | inline void wxSizerItem::SetSpacer(const wxSize& size) | |
961 | { | |
962 | DoSetSpacer(size); | |
963 | } | |
964 | ||
965 | inline void wxSizerItem::SetSpacer(int width, int height) | |
966 | { | |
967 | DoSetSpacer(wxSize(width, height)); | |
968 | } | |
969 | ||
970 | #endif // WXWIN_COMPATIBILITY_2_8 | |
971 | ||
972 | ||
973 | inline wxSizerItem* | |
974 | wxSizer::Add( wxSizerItem *item ) | |
975 | { | |
976 | return Insert( m_children.GetCount(), item ); | |
977 | } | |
978 | ||
979 | inline wxSizerItem* | |
980 | wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) | |
981 | { | |
982 | return Add( new wxSizerItem( window, proportion, flag, border, userData ) ); | |
983 | } | |
984 | ||
985 | inline wxSizerItem* | |
986 | wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) | |
987 | { | |
988 | return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
989 | } | |
990 | ||
991 | inline wxSizerItem* | |
992 | wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData ) | |
993 | { | |
994 | return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
995 | } | |
996 | ||
997 | inline wxSizerItem* | |
998 | wxSizer::Add( wxWindow *window, const wxSizerFlags& flags ) | |
999 | { | |
1000 | return Add( new wxSizerItem(window, flags) ); | |
1001 | } | |
1002 | ||
1003 | inline wxSizerItem* | |
1004 | wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags ) | |
1005 | { | |
1006 | return Add( new wxSizerItem(sizer, flags) ); | |
1007 | } | |
1008 | ||
1009 | inline wxSizerItem* | |
1010 | wxSizer::AddSpacer(int size) | |
1011 | { | |
1012 | return Add(size, size); | |
1013 | } | |
1014 | ||
1015 | inline wxSizerItem* | |
1016 | wxSizer::AddStretchSpacer(int prop) | |
1017 | { | |
1018 | return Add(0, 0, prop); | |
1019 | } | |
1020 | ||
1021 | inline wxSizerItem* | |
1022 | wxSizer::Prepend( wxSizerItem *item ) | |
1023 | { | |
1024 | return Insert( 0, item ); | |
1025 | } | |
1026 | ||
1027 | inline wxSizerItem* | |
1028 | wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) | |
1029 | { | |
1030 | return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) ); | |
1031 | } | |
1032 | ||
1033 | inline wxSizerItem* | |
1034 | wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) | |
1035 | { | |
1036 | return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
1037 | } | |
1038 | ||
1039 | inline wxSizerItem* | |
1040 | wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData ) | |
1041 | { | |
1042 | return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
1043 | } | |
1044 | ||
1045 | inline wxSizerItem* | |
1046 | wxSizer::PrependSpacer(int size) | |
1047 | { | |
1048 | return Prepend(size, size); | |
1049 | } | |
1050 | ||
1051 | inline wxSizerItem* | |
1052 | wxSizer::PrependStretchSpacer(int prop) | |
1053 | { | |
1054 | return Prepend(0, 0, prop); | |
1055 | } | |
1056 | ||
1057 | inline wxSizerItem* | |
1058 | wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags ) | |
1059 | { | |
1060 | return Prepend( new wxSizerItem(window, flags) ); | |
1061 | } | |
1062 | ||
1063 | inline wxSizerItem* | |
1064 | wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags ) | |
1065 | { | |
1066 | return Prepend( new wxSizerItem(sizer, flags) ); | |
1067 | } | |
1068 | ||
1069 | inline wxSizerItem* | |
1070 | wxSizer::Insert( size_t index, | |
1071 | wxWindow *window, | |
1072 | int proportion, | |
1073 | int flag, | |
1074 | int border, | |
1075 | wxObject* userData ) | |
1076 | { | |
1077 | return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) ); | |
1078 | } | |
1079 | ||
1080 | inline wxSizerItem* | |
1081 | wxSizer::Insert( size_t index, | |
1082 | wxSizer *sizer, | |
1083 | int proportion, | |
1084 | int flag, | |
1085 | int border, | |
1086 | wxObject* userData ) | |
1087 | { | |
1088 | return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
1089 | } | |
1090 | ||
1091 | inline wxSizerItem* | |
1092 | wxSizer::Insert( size_t index, | |
1093 | int width, | |
1094 | int height, | |
1095 | int proportion, | |
1096 | int flag, | |
1097 | int border, | |
1098 | wxObject* userData ) | |
1099 | { | |
1100 | return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
1101 | } | |
1102 | ||
1103 | inline wxSizerItem* | |
1104 | wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags ) | |
1105 | { | |
1106 | return Insert( index, new wxSizerItem(window, flags) ); | |
1107 | } | |
1108 | ||
1109 | inline wxSizerItem* | |
1110 | wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags ) | |
1111 | { | |
1112 | return Insert( index, new wxSizerItem(sizer, flags) ); | |
1113 | } | |
1114 | ||
1115 | inline wxSizerItem* | |
1116 | wxSizer::InsertSpacer(size_t index, int size) | |
1117 | { | |
1118 | return Insert(index, size, size); | |
1119 | } | |
1120 | ||
1121 | inline wxSizerItem* | |
1122 | wxSizer::InsertStretchSpacer(size_t index, int prop) | |
1123 | { | |
1124 | return Insert(index, 0, 0, prop); | |
1125 | } | |
1126 | ||
1127 | #endif // __WXSIZER_H__ |