]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
process pending wx events before sending idle events
[wxWidgets.git] / include / wx / sizer.h
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 WXDLLEXPORT wxButton;
24 class WXDLLEXPORT wxBoxSizer;
25 class WXDLLEXPORT wxSizerItem;
26 class WXDLLEXPORT 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 bool IsWindow() const { return m_kind == Item_Window; }
302 bool IsSizer() const { return m_kind == Item_Sizer; }
303 bool IsSpacer() const { return m_kind == Item_Spacer; }
304
305 #if WXWIN_COMPATIBILITY_2_6
306 // Deprecated in 2.6, use {G,S}etProportion instead.
307 wxDEPRECATED( void SetOption( int option ) );
308 wxDEPRECATED( int GetOption() const );
309 #endif // WXWIN_COMPATIBILITY_2_6
310
311 void SetProportion( int proportion )
312 { m_proportion = proportion; }
313 int GetProportion() const
314 { return m_proportion; }
315 void SetFlag( int flag )
316 { m_flag = flag; }
317 int GetFlag() const
318 { return m_flag; }
319 void SetBorder( int border )
320 { m_border = border; }
321 int GetBorder() const
322 { return m_border; }
323
324 wxWindow *GetWindow() const
325 { return m_kind == Item_Window ? m_window : NULL; }
326 wxSizer *GetSizer() const
327 { return m_kind == Item_Sizer ? m_sizer : NULL; }
328 wxSize GetSpacer() const;
329
330 // this function behaves obviously for the windows and spacers but for the
331 // sizers it returns true if any sizer element is shown and only returns
332 // false if all of them are hidden
333 bool IsShown() const;
334 void Show(bool show);
335
336 void SetUserData(wxObject* userData)
337 { delete m_userData; m_userData = userData; }
338 wxObject* GetUserData() const
339 { return m_userData; }
340 wxPoint GetPosition() const
341 { return m_pos; }
342
343 // these functions delete the current contents of the item if it's a sizer
344 // or a spacer but not if it is a window
345 void AssignWindow(wxWindow *window)
346 {
347 Free();
348 DoSetWindow(window);
349 }
350
351 void AssignSizer(wxSizer *sizer)
352 {
353 Free();
354 DoSetSizer(sizer);
355 }
356
357 void AssignSpacer(const wxSize& size)
358 {
359 Free();
360 DoSetSpacer(size);
361 }
362
363 void AssignSpacer(int w, int h) { AssignSpacer(wxSize(w, h)); }
364
365 #if WXWIN_COMPATIBILITY_2_8
366 // these functions do not free the old sizer/spacer and so can easily
367 // provoke the memory leaks and so shouldn't be used, use Assign() instead
368 wxDEPRECATED( void SetWindow(wxWindow *window) );
369 wxDEPRECATED( void SetSizer(wxSizer *sizer) );
370 wxDEPRECATED( void SetSpacer(const wxSize& size) );
371 wxDEPRECATED( void SetSpacer(int width, int height) );
372 #endif // WXWIN_COMPATIBILITY_2_8
373
374 protected:
375 // common part of several ctors
376 void Init() { m_userData = NULL; m_kind = Item_None; }
377
378 // common part of ctors taking wxSizerFlags
379 void Init(const wxSizerFlags& flags);
380
381 // free current contents
382 void Free();
383
384 // common parts of Set/AssignXXX()
385 void DoSetWindow(wxWindow *window);
386 void DoSetSizer(wxSizer *sizer);
387 void DoSetSpacer(const wxSize& size);
388
389 // discriminated union: depending on m_kind one of the fields is valid
390 enum
391 {
392 Item_None,
393 Item_Window,
394 Item_Sizer,
395 Item_Spacer,
396 Item_Max
397 } m_kind;
398 union
399 {
400 wxWindow *m_window;
401 wxSizer *m_sizer;
402 wxSizerSpacer *m_spacer;
403 };
404
405 wxPoint m_pos;
406 wxSize m_minSize;
407 int m_proportion;
408 int m_border;
409 int m_flag;
410
411 // on screen rectangle of this item (not including borders)
412 wxRect m_rect;
413
414 // Aspect ratio can always be calculated from m_size,
415 // but this would cause precision loss when the window
416 // is shrunk. It is safer to preserve the initial value.
417 float m_ratio;
418
419 wxObject *m_userData;
420
421 private:
422 DECLARE_CLASS(wxSizerItem)
423 DECLARE_NO_COPY_CLASS(wxSizerItem)
424 };
425
426 WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
427
428
429 //---------------------------------------------------------------------------
430 // wxSizer
431 //---------------------------------------------------------------------------
432
433 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
434 {
435 public:
436 wxSizer() { m_containingWindow = NULL; }
437 virtual ~wxSizer();
438
439 // methods for adding elements to the sizer: there are Add/Insert/Prepend
440 // overloads for each of window/sizer/spacer/wxSizerItem
441 wxSizerItem* Add(wxWindow *window,
442 int proportion = 0,
443 int flag = 0,
444 int border = 0,
445 wxObject* userData = NULL);
446 wxSizerItem* Add(wxSizer *sizer,
447 int proportion = 0,
448 int flag = 0,
449 int border = 0,
450 wxObject* userData = NULL);
451 wxSizerItem* Add(int width,
452 int height,
453 int proportion = 0,
454 int flag = 0,
455 int border = 0,
456 wxObject* userData = NULL);
457 wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags);
458 wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags);
459 wxSizerItem* Add( wxSizerItem *item);
460
461 wxSizerItem* AddSpacer(int size);
462 wxSizerItem* AddStretchSpacer(int prop = 1);
463
464 wxSizerItem* Insert(size_t index,
465 wxWindow *window,
466 int proportion = 0,
467 int flag = 0,
468 int border = 0,
469 wxObject* userData = NULL);
470 wxSizerItem* Insert(size_t index,
471 wxSizer *sizer,
472 int proportion = 0,
473 int flag = 0,
474 int border = 0,
475 wxObject* userData = NULL);
476 wxSizerItem* Insert(size_t index,
477 int width,
478 int height,
479 int proportion = 0,
480 int flag = 0,
481 int border = 0,
482 wxObject* userData = NULL);
483 wxSizerItem* Insert(size_t index,
484 wxWindow *window,
485 const wxSizerFlags& flags);
486 wxSizerItem* Insert(size_t index,
487 wxSizer *sizer,
488 const wxSizerFlags& flags);
489 virtual wxSizerItem* Insert( size_t index, wxSizerItem *item);
490
491 wxSizerItem* InsertSpacer(size_t index, int size);
492 wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
493
494 wxSizerItem* Prepend(wxWindow *window,
495 int proportion = 0,
496 int flag = 0,
497 int border = 0,
498 wxObject* userData = NULL);
499 wxSizerItem* Prepend(wxSizer *sizer,
500 int proportion = 0,
501 int flag = 0,
502 int border = 0,
503 wxObject* userData = NULL);
504 wxSizerItem* Prepend(int width,
505 int height,
506 int proportion = 0,
507 int flag = 0,
508 int border = 0,
509 wxObject* userData = NULL);
510 wxSizerItem* Prepend(wxWindow *window, const wxSizerFlags& flags);
511 wxSizerItem* Prepend(wxSizer *sizer, const wxSizerFlags& flags);
512 wxSizerItem* Prepend(wxSizerItem *item);
513
514 wxSizerItem* PrependSpacer(int size);
515 wxSizerItem* PrependStretchSpacer(int prop = 1);
516
517 // set (or possibly unset if window is NULL) or get the window this sizer
518 // is used in
519 void SetContainingWindow(wxWindow *window);
520 wxWindow *GetContainingWindow() const { return m_containingWindow; }
521
522 #if WXWIN_COMPATIBILITY_2_6
523 // Deprecated in 2.6 since historically it does not delete the window,
524 // use Detach instead.
525 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
526 #endif // WXWIN_COMPATIBILITY_2_6
527
528 virtual bool Remove( wxSizer *sizer );
529 virtual bool Remove( int index );
530
531 virtual bool Detach( wxWindow *window );
532 virtual bool Detach( wxSizer *sizer );
533 virtual bool Detach( int index );
534
535 virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false );
536 virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false );
537 virtual bool Replace( size_t index, wxSizerItem *newitem );
538
539 virtual void Clear( bool delete_windows = false );
540 virtual void DeleteWindows();
541
542 void SetMinSize( int width, int height )
543 { DoSetMinSize( width, height ); }
544 void SetMinSize( const wxSize& size )
545 { DoSetMinSize( size.x, size.y ); }
546
547 // Searches recursively
548 bool SetItemMinSize( wxWindow *window, int width, int height )
549 { return DoSetItemMinSize( window, width, height ); }
550 bool SetItemMinSize( wxWindow *window, const wxSize& size )
551 { return DoSetItemMinSize( window, size.x, size.y ); }
552
553 // Searches recursively
554 bool SetItemMinSize( wxSizer *sizer, int width, int height )
555 { return DoSetItemMinSize( sizer, width, height ); }
556 bool SetItemMinSize( wxSizer *sizer, const wxSize& size )
557 { return DoSetItemMinSize( sizer, size.x, size.y ); }
558
559 bool SetItemMinSize( size_t index, int width, int height )
560 { return DoSetItemMinSize( index, width, height ); }
561 bool SetItemMinSize( size_t index, const wxSize& size )
562 { return DoSetItemMinSize( index, size.x, size.y ); }
563
564 wxSize GetSize() const
565 { return m_size; }
566 wxPoint GetPosition() const
567 { return m_position; }
568
569 // Calculate the minimal size or return m_minSize if bigger.
570 wxSize GetMinSize();
571
572 // These virtual functions are used by the layout algorithm: first
573 // CalcMin() is called to calculate the minimal size of the sizer and
574 // prepare for laying it out and then RecalcSizes() is called to really
575 // update all the sizer items
576 virtual wxSize CalcMin() = 0;
577 virtual void RecalcSizes() = 0;
578
579 virtual void Layout();
580
581 wxSize Fit( wxWindow *window );
582 void FitInside( wxWindow *window );
583 void SetSizeHints( wxWindow *window );
584 void SetVirtualSizeHints( wxWindow *window );
585
586 wxSizerItemList& GetChildren()
587 { return m_children; }
588 const wxSizerItemList& GetChildren() const
589 { return m_children; }
590
591 void SetDimension( int x, int y, int width, int height );
592
593 wxSizerItem* GetItem( wxWindow *window, bool recursive = false );
594 wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false );
595 wxSizerItem* GetItem( size_t index );
596
597 // Manage whether individual scene items are considered
598 // in the layout calculations or not.
599 bool Show( wxWindow *window, bool show = true, bool recursive = false );
600 bool Show( wxSizer *sizer, bool show = true, bool recursive = false );
601 bool Show( size_t index, bool show = true );
602
603 bool Hide( wxSizer *sizer, bool recursive = false )
604 { return Show( sizer, false, recursive ); }
605 bool Hide( wxWindow *window, bool recursive = false )
606 { return Show( window, false, recursive ); }
607 bool Hide( size_t index )
608 { return Show( index, false ); }
609
610 bool IsShown( wxWindow *window ) const;
611 bool IsShown( wxSizer *sizer ) const;
612 bool IsShown( size_t index ) const;
613
614 // Recursively call wxWindow::Show () on all sizer items.
615 virtual void ShowItems (bool show);
616
617 void Show(bool show) { ShowItems(show); }
618
619 protected:
620 wxSize m_size;
621 wxSize m_minSize;
622 wxPoint m_position;
623 wxSizerItemList m_children;
624
625 // the window this sizer is used in, can be NULL
626 wxWindow *m_containingWindow;
627
628 wxSize GetMaxWindowSize( wxWindow *window ) const;
629 wxSize GetMinWindowSize( wxWindow *window );
630 wxSize GetMaxClientSize( wxWindow *window ) const;
631 wxSize GetMinClientSize( wxWindow *window );
632 wxSize VirtualFitSize( wxWindow *window );
633
634 virtual void DoSetMinSize( int width, int height );
635 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
636 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
637 virtual bool DoSetItemMinSize( size_t index, int width, int height );
638
639 private:
640 DECLARE_CLASS(wxSizer)
641 };
642
643 //---------------------------------------------------------------------------
644 // wxGridSizer
645 //---------------------------------------------------------------------------
646
647 class WXDLLEXPORT wxGridSizer: public wxSizer
648 {
649 public:
650 wxGridSizer( int rows, int cols, int vgap, int hgap );
651 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
652
653 virtual void RecalcSizes();
654 virtual wxSize CalcMin();
655
656 void SetCols( int cols ) { m_cols = cols; }
657 void SetRows( int rows ) { m_rows = rows; }
658 void SetVGap( int gap ) { m_vgap = gap; }
659 void SetHGap( int gap ) { m_hgap = gap; }
660 int GetCols() const { return m_cols; }
661 int GetRows() const { return m_rows; }
662 int GetVGap() const { return m_vgap; }
663 int GetHGap() const { return m_hgap; }
664
665 protected:
666 int m_rows;
667 int m_cols;
668 int m_vgap;
669 int m_hgap;
670
671 // return the number of total items and the number of columns and rows
672 int CalcRowsCols(int& rows, int& cols) const;
673
674 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
675
676 private:
677 DECLARE_CLASS(wxGridSizer)
678 };
679
680 //---------------------------------------------------------------------------
681 // wxFlexGridSizer
682 //---------------------------------------------------------------------------
683
684 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
685 // direction
686 enum wxFlexSizerGrowMode
687 {
688 // don't resize the cells in non-flexible direction at all
689 wxFLEX_GROWMODE_NONE,
690
691 // uniformly resize only the specified ones (default)
692 wxFLEX_GROWMODE_SPECIFIED,
693
694 // uniformly resize all cells
695 wxFLEX_GROWMODE_ALL
696 };
697
698 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
699 {
700 public:
701 // ctors/dtor
702 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
703 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
704 virtual ~wxFlexGridSizer();
705
706
707 // set the rows/columns which will grow (the others will remain of the
708 // constant initial size)
709 void AddGrowableRow( size_t idx, int proportion = 0 );
710 void RemoveGrowableRow( size_t idx );
711 void AddGrowableCol( size_t idx, int proportion = 0 );
712 void RemoveGrowableCol( size_t idx );
713
714
715 // the sizer cells may grow in both directions, not grow at all or only
716 // grow in one direction but not the other
717
718 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
719 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
720 int GetFlexibleDirection() const { return m_flexDirection; }
721
722 // note that the grow mode only applies to the direction which is not
723 // flexible
724 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
725 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
726
727 // Read-only access to the row heights and col widths arrays
728 const wxArrayInt& GetRowHeights() const { return m_rowHeights; }
729 const wxArrayInt& GetColWidths() const { return m_colWidths; }
730
731 // implementation
732 virtual void RecalcSizes();
733 virtual wxSize CalcMin();
734
735 protected:
736 void AdjustForFlexDirection();
737 void AdjustForGrowables(const wxSize& sz);
738
739 // the heights/widths of all rows/columns
740 wxArrayInt m_rowHeights,
741 m_colWidths;
742
743 // indices of the growable columns and rows
744 wxArrayInt m_growableRows,
745 m_growableCols;
746
747 // proportion values of the corresponding growable rows and columns
748 wxArrayInt m_growableRowsProportions,
749 m_growableColsProportions;
750
751 // parameters describing whether the growable cells should be resized in
752 // both directions or only one
753 int m_flexDirection;
754 wxFlexSizerGrowMode m_growMode;
755
756 // saves CalcMin result to optimize RecalcSizes
757 wxSize m_calculatedMinSize;
758
759 private:
760 DECLARE_CLASS(wxFlexGridSizer)
761 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
762 };
763
764 //---------------------------------------------------------------------------
765 // wxBoxSizer
766 //---------------------------------------------------------------------------
767
768 class WXDLLEXPORT wxBoxSizer: public wxSizer
769 {
770 public:
771 wxBoxSizer(int orient)
772 {
773 m_orient = orient;
774
775 wxASSERT_MSG( m_orient == wxHORIZONTAL || m_orient == wxVERTICAL,
776 _T("invalid value for wxBoxSizer orientation") );
777 }
778
779 int GetOrientation() const { return m_orient; }
780
781 bool IsVertical() const { return m_orient == wxVERTICAL; }
782
783 void SetOrientation(int orient) { m_orient = orient; }
784
785 // implementation of our resizing logic
786 virtual wxSize CalcMin();
787 virtual void RecalcSizes();
788
789 protected:
790 // helpers for our code: this returns the component of the given wxSize in
791 // the direction of the sizer and in the other direction, respectively
792 int SizeInMajorDir(const wxSize& sz) const
793 {
794 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
795 }
796
797 int& SizeInMajorDir(wxSize& sz)
798 {
799 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
800 }
801
802 int& PosInMajorDir(wxPoint& pt)
803 {
804 return m_orient == wxHORIZONTAL ? pt.x : pt.y;
805 }
806
807 int SizeInMinorDir(const wxSize& sz) const
808 {
809 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
810 }
811
812 int& SizeInMinorDir(wxSize& sz)
813 {
814 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
815 }
816
817 int& PosInMinorDir(wxPoint& pt)
818 {
819 return m_orient == wxHORIZONTAL ? pt.y : pt.x;
820 }
821
822 // another helper: creates wxSize from major and minor components
823 wxSize SizeFromMajorMinor(int major, int minor) const
824 {
825 if ( m_orient == wxHORIZONTAL )
826 {
827 return wxSize(major, minor);
828 }
829 else // wxVERTICAL
830 {
831 return wxSize(minor, major);
832 }
833 }
834
835
836 // either wxHORIZONTAL or wxVERTICAL
837 int m_orient;
838
839 // the sum of proportion of all of our elements
840 int m_totalProportion;
841
842 // the minimal size needed for this sizer as calculated by the last call to
843 // our CalcMin()
844 wxSize m_minSize;
845
846 private:
847 DECLARE_CLASS(wxBoxSizer)
848 };
849
850 //---------------------------------------------------------------------------
851 // wxStaticBoxSizer
852 //---------------------------------------------------------------------------
853
854 #if wxUSE_STATBOX
855
856 class WXDLLEXPORT wxStaticBox;
857
858 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
859 {
860 public:
861 wxStaticBoxSizer(wxStaticBox *box, int orient);
862 wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
863 virtual ~wxStaticBoxSizer();
864
865 void RecalcSizes();
866 wxSize CalcMin();
867
868 wxStaticBox *GetStaticBox() const
869 { return m_staticBox; }
870
871 // override to hide/show the static box as well
872 virtual void ShowItems (bool show);
873
874 virtual bool Detach( wxWindow *window );
875 virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); }
876 virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); }
877
878 protected:
879 wxStaticBox *m_staticBox;
880
881 private:
882 DECLARE_CLASS(wxStaticBoxSizer)
883 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
884 };
885
886 #endif // wxUSE_STATBOX
887
888 #if wxUSE_BUTTON
889
890 class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer
891 {
892 public:
893 // Constructor just creates a new wxBoxSizer, not much else.
894 // Box sizer orientation is automatically determined here:
895 // vertical for PDAs, horizontal for everything else?
896 wxStdDialogButtonSizer();
897
898 // Checks button ID against system IDs and sets one of the pointers below
899 // to this button. Does not do any sizer-related things here.
900 void AddButton(wxButton *button);
901
902 // Use these if no standard ID can/should be used
903 void SetAffirmativeButton( wxButton *button );
904 void SetNegativeButton( wxButton *button );
905 void SetCancelButton( wxButton *button );
906
907 // All platform-specific code here, checks which buttons exist and add
908 // them to the sizer accordingly.
909 // Note - one potential hack on Mac we could use here,
910 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
911 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
912 // I wouldn't add any other hacks like that into here,
913 // but this one I can see being useful.
914 void Realize();
915
916 wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; }
917 wxButton *GetApplyButton() const { return m_buttonApply; }
918 wxButton *GetNegativeButton() const { return m_buttonNegative; }
919 wxButton *GetCancelButton() const { return m_buttonCancel; }
920 wxButton *GetHelpButton() const { return m_buttonHelp; }
921
922 protected:
923 wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here
924 wxButton *m_buttonApply; // wxID_APPLY
925 wxButton *m_buttonNegative; // wxID_NO
926 wxButton *m_buttonCancel; // wxID_CANCEL, wxID_CLOSE
927 wxButton *m_buttonHelp; // wxID_HELP, wxID_CONTEXT_HELP
928
929 private:
930 DECLARE_CLASS(wxStdDialogButtonSizer)
931 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer)
932 };
933
934 #endif // wxUSE_BUTTON
935
936
937 // ----------------------------------------------------------------------------
938 // inline functions implementation
939 // ----------------------------------------------------------------------------
940
941 #if WXWIN_COMPATIBILITY_2_8
942
943 inline void wxSizerItem::SetWindow(wxWindow *window)
944 {
945 DoSetWindow(window);
946 }
947
948 inline void wxSizerItem::SetSizer(wxSizer *sizer)
949 {
950 DoSetSizer(sizer);
951 }
952
953 inline void wxSizerItem::SetSpacer(const wxSize& size)
954 {
955 DoSetSpacer(size);
956 }
957
958 inline void wxSizerItem::SetSpacer(int width, int height)
959 {
960 DoSetSpacer(wxSize(width, height));
961 }
962
963 #endif // WXWIN_COMPATIBILITY_2_8
964
965
966 inline wxSizerItem*
967 wxSizer::Add( wxSizerItem *item )
968 {
969 return Insert( m_children.GetCount(), item );
970 }
971
972 inline wxSizerItem*
973 wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
974 {
975 return Add( new wxSizerItem( window, proportion, flag, border, userData ) );
976 }
977
978 inline wxSizerItem*
979 wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
980 {
981 return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) );
982 }
983
984 inline wxSizerItem*
985 wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData )
986 {
987 return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) );
988 }
989
990 inline wxSizerItem*
991 wxSizer::Add( wxWindow *window, const wxSizerFlags& flags )
992 {
993 return Add( new wxSizerItem(window, flags) );
994 }
995
996 inline wxSizerItem*
997 wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
998 {
999 return Add( new wxSizerItem(sizer, flags) );
1000 }
1001
1002 inline wxSizerItem*
1003 wxSizer::AddSpacer(int size)
1004 {
1005 return Add(size, size);
1006 }
1007
1008 inline wxSizerItem*
1009 wxSizer::AddStretchSpacer(int prop)
1010 {
1011 return Add(0, 0, prop);
1012 }
1013
1014 inline wxSizerItem*
1015 wxSizer::Prepend( wxSizerItem *item )
1016 {
1017 return Insert( 0, item );
1018 }
1019
1020 inline wxSizerItem*
1021 wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
1022 {
1023 return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) );
1024 }
1025
1026 inline wxSizerItem*
1027 wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
1028 {
1029 return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1030 }
1031
1032 inline wxSizerItem*
1033 wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData )
1034 {
1035 return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1036 }
1037
1038 inline wxSizerItem*
1039 wxSizer::PrependSpacer(int size)
1040 {
1041 return Prepend(size, size);
1042 }
1043
1044 inline wxSizerItem*
1045 wxSizer::PrependStretchSpacer(int prop)
1046 {
1047 return Prepend(0, 0, prop);
1048 }
1049
1050 inline wxSizerItem*
1051 wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags )
1052 {
1053 return Prepend( new wxSizerItem(window, flags) );
1054 }
1055
1056 inline wxSizerItem*
1057 wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags )
1058 {
1059 return Prepend( new wxSizerItem(sizer, flags) );
1060 }
1061
1062 inline wxSizerItem*
1063 wxSizer::Insert( size_t index,
1064 wxWindow *window,
1065 int proportion,
1066 int flag,
1067 int border,
1068 wxObject* userData )
1069 {
1070 return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) );
1071 }
1072
1073 inline wxSizerItem*
1074 wxSizer::Insert( size_t index,
1075 wxSizer *sizer,
1076 int proportion,
1077 int flag,
1078 int border,
1079 wxObject* userData )
1080 {
1081 return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) );
1082 }
1083
1084 inline wxSizerItem*
1085 wxSizer::Insert( size_t index,
1086 int width,
1087 int height,
1088 int proportion,
1089 int flag,
1090 int border,
1091 wxObject* userData )
1092 {
1093 return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) );
1094 }
1095
1096 inline wxSizerItem*
1097 wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags )
1098 {
1099 return Insert( index, new wxSizerItem(window, flags) );
1100 }
1101
1102 inline wxSizerItem*
1103 wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags )
1104 {
1105 return Insert( index, new wxSizerItem(sizer, flags) );
1106 }
1107
1108 inline wxSizerItem*
1109 wxSizer::InsertSpacer(size_t index, int size)
1110 {
1111 return Insert(index, size, size);
1112 }
1113
1114 inline wxSizerItem*
1115 wxSizer::InsertStretchSpacer(size_t index, int prop)
1116 {
1117 return Insert(index, 0, 0, prop);
1118 }
1119
1120 #endif // __WXSIZER_H__