1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
8 // Copyright: (c) Robin Dunn, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/window.h"
19 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
23 class WXDLLIMPEXP_FWD_CORE wxButton
;
24 class WXDLLIMPEXP_FWD_CORE wxBoxSizer
;
25 class WXDLLIMPEXP_FWD_CORE wxSizerItem
;
26 class WXDLLIMPEXP_FWD_CORE wxSizer
;
28 #ifndef wxUSE_BORDER_BY_DEFAULT
30 // no borders by default on limited size screen
31 #define wxUSE_BORDER_BY_DEFAULT 0
33 #define wxUSE_BORDER_BY_DEFAULT 1
37 // ----------------------------------------------------------------------------
38 // wxSizerFlags: flags used for an item in the sizer
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxSizerFlags
44 // construct the flags object initialized with the given proportion (0 by
46 wxSizerFlags(int proportion
= 0) : m_proportion(proportion
)
52 // setters for all sizer flags, they all return the object itself so that
53 // calls to them can be chained
55 wxSizerFlags
& Proportion(int proportion
)
57 m_proportion
= proportion
;
61 wxSizerFlags
& Expand()
67 // notice that Align() replaces the current alignment flags, use specific
68 // methods below such as Top(), Left() &c if you want to set just the
69 // vertical or horizontal alignment
70 wxSizerFlags
& Align(int alignment
) // combination of wxAlignment values
72 m_flags
&= ~wxALIGN_MASK
;
78 // some shortcuts for Align()
79 wxSizerFlags
& Centre() { return Align(wxALIGN_CENTRE
); }
80 wxSizerFlags
& Center() { return Centre(); }
84 m_flags
&= ~(wxALIGN_BOTTOM
| wxALIGN_CENTRE_VERTICAL
);
90 m_flags
&= ~(wxALIGN_RIGHT
| wxALIGN_CENTRE_HORIZONTAL
);
96 m_flags
= (m_flags
& ~wxALIGN_CENTRE_HORIZONTAL
) | wxALIGN_RIGHT
;
100 wxSizerFlags
& Bottom()
102 m_flags
= (m_flags
& ~wxALIGN_CENTRE_VERTICAL
) | wxALIGN_BOTTOM
;
107 // default border size used by Border() below
108 static int GetDefaultBorder()
110 #if wxUSE_BORDER_BY_DEFAULT
112 // GNOME HIG says to use 6px as the base unit:
113 // http://library.gnome.org/devel/hig-book/stable/design-window.html.en
116 // FIXME: default border size shouldn't be hardcoded and at the very
117 // least they should depend on the current font size
126 wxSizerFlags
& Border(int direction
, int borderInPixels
)
129 m_flags
|= direction
;
131 m_borderInPixels
= borderInPixels
;
136 wxSizerFlags
& Border(int direction
= wxALL
)
138 #if wxUSE_BORDER_BY_DEFAULT
139 return Border(direction
, GetDefaultBorder());
141 // no borders by default on limited size screen
142 wxUnusedVar(direction
);
148 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
150 #if wxUSE_BORDER_BY_DEFAULT
151 return Border(direction
, 2*GetDefaultBorder());
153 wxUnusedVar(direction
);
159 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
161 #if wxUSE_BORDER_BY_DEFAULT
162 return Border(direction
, 3*GetDefaultBorder());
164 wxUnusedVar(direction
);
170 wxSizerFlags
& HorzBorder()
172 #if wxUSE_BORDER_BY_DEFAULT
173 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
179 wxSizerFlags
& DoubleHorzBorder()
181 #if wxUSE_BORDER_BY_DEFAULT
182 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
188 // setters for the others flags
189 wxSizerFlags
& Shaped()
196 wxSizerFlags
& FixedMinSize()
198 m_flags
|= wxFIXED_MINSIZE
;
203 // makes the item ignore window's visibility status
204 wxSizerFlags
& ReserveSpaceEvenIfHidden()
206 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
210 // accessors for wxSizer only
211 int GetProportion() const { return m_proportion
; }
212 int GetFlags() const { return m_flags
; }
213 int GetBorderInPixels() const { return m_borderInPixels
; }
218 int m_borderInPixels
;
222 // ----------------------------------------------------------------------------
223 // wxSizerSpacer: used by wxSizerItem to represent a spacer
224 // ----------------------------------------------------------------------------
226 class WXDLLIMPEXP_CORE wxSizerSpacer
229 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
231 void SetSize(const wxSize
& size
) { m_size
= size
; }
232 const wxSize
& GetSize() const { return m_size
; }
234 void Show(bool show
) { m_isShown
= show
; }
235 bool IsShown() const { return m_isShown
; }
238 // the size, in pixel
241 // is the spacer currently shown?
245 // ----------------------------------------------------------------------------
247 // ----------------------------------------------------------------------------
249 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
253 wxSizerItem( wxWindow
*window
,
257 wxObject
* userData
);
260 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
268 wxSizerItem( wxSizer
*sizer
,
272 wxObject
* userData
);
275 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
283 wxSizerItem( int width
,
291 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
295 DoSetSpacer(wxSize(width
, height
));
299 virtual ~wxSizerItem();
301 virtual void DeleteWindows();
303 // Enable deleting the SizerItem without destroying the contained sizer.
304 void DetachSizer() { m_sizer
= NULL
; }
306 virtual wxSize
GetSize() const;
307 virtual wxSize
CalcMin();
308 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
310 wxSize
GetMinSize() const
311 { return m_minSize
; }
312 wxSize
GetMinSizeWithBorder() const;
314 void SetMinSize(const wxSize
& size
)
317 m_window
->SetMinSize(size
);
320 void SetMinSize( int x
, int y
)
321 { SetMinSize(wxSize(x
, y
)); }
322 void SetInitSize( int x
, int y
)
323 { SetMinSize(wxSize(x
, y
)); }
325 // if either of dimensions is zero, ratio is assumed to be 1
326 // to avoid "divide by zero" errors
327 void SetRatio(int width
, int height
)
328 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
329 void SetRatio(const wxSize
& size
)
330 { SetRatio(size
.x
, size
.y
); }
331 void SetRatio(float ratio
)
333 float GetRatio() const
336 virtual wxRect
GetRect() { return m_rect
; }
338 // set a sizer item id (different from a window id, all sizer items,
339 // including spacers, can have an associated id)
340 void SetId(int id
) { m_id
= id
; }
341 int GetId() const { return m_id
; }
343 bool IsWindow() const { return m_kind
== Item_Window
; }
344 bool IsSizer() const { return m_kind
== Item_Sizer
; }
345 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
347 #if WXWIN_COMPATIBILITY_2_6
348 // Deprecated in 2.6, use {G,S}etProportion instead.
349 wxDEPRECATED( void SetOption( int option
) );
350 wxDEPRECATED( int GetOption() const );
351 #endif // WXWIN_COMPATIBILITY_2_6
353 void SetProportion( int proportion
)
354 { m_proportion
= proportion
; }
355 int GetProportion() const
356 { return m_proportion
; }
357 void SetFlag( int flag
)
361 void SetBorder( int border
)
362 { m_border
= border
; }
363 int GetBorder() const
366 wxWindow
*GetWindow() const
367 { return m_kind
== Item_Window
? m_window
: NULL
; }
368 wxSizer
*GetSizer() const
369 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
370 wxSize
GetSpacer() const;
372 // This function behaves obviously for the windows and spacers but for the
373 // sizers it returns true if any sizer element is shown and only returns
374 // false if all of them are hidden. Also, it always returns true if
375 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
376 bool IsShown() const;
378 void Show(bool show
);
380 void SetUserData(wxObject
* userData
)
381 { delete m_userData
; m_userData
= userData
; }
382 wxObject
* GetUserData() const
383 { return m_userData
; }
384 wxPoint
GetPosition() const
387 // Called once the first component of an item has been decided. This is
388 // used in algorithms that depend on knowing the size in one direction
389 // before the min size in the other direction can be known.
390 // Returns true if it made use of the information (and min size was changed).
391 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
393 // these functions delete the current contents of the item if it's a sizer
394 // or a spacer but not if it is a window
395 void AssignWindow(wxWindow
*window
)
401 void AssignSizer(wxSizer
*sizer
)
407 void AssignSpacer(const wxSize
& size
)
413 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
415 #if WXWIN_COMPATIBILITY_2_8
416 // these functions do not free the old sizer/spacer and so can easily
417 // provoke the memory leaks and so shouldn't be used, use Assign() instead
418 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
419 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
420 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
421 wxDEPRECATED( void SetSpacer(int width
, int height
) );
422 #endif // WXWIN_COMPATIBILITY_2_8
425 // common part of several ctors
426 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
428 // common part of ctors taking wxSizerFlags
429 void Init(const wxSizerFlags
& flags
);
431 // free current contents
434 // common parts of Set/AssignXXX()
435 void DoSetWindow(wxWindow
*window
);
436 void DoSetSizer(wxSizer
*sizer
);
437 void DoSetSpacer(const wxSize
& size
);
439 // discriminated union: depending on m_kind one of the fields is valid
452 wxSizerSpacer
*m_spacer
;
462 // on screen rectangle of this item (not including borders)
465 // Aspect ratio can always be calculated from m_size,
466 // but this would cause precision loss when the window
467 // is shrunk. It is safer to preserve the initial value.
470 wxObject
*m_userData
;
473 DECLARE_CLASS(wxSizerItem
)
474 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
477 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
480 //---------------------------------------------------------------------------
482 //---------------------------------------------------------------------------
484 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
487 wxSizer() { m_containingWindow
= NULL
; }
490 // methods for adding elements to the sizer: there are Add/Insert/Prepend
491 // overloads for each of window/sizer/spacer/wxSizerItem
492 wxSizerItem
* Add(wxWindow
*window
,
496 wxObject
* userData
= NULL
);
497 wxSizerItem
* Add(wxSizer
*sizer
,
501 wxObject
* userData
= NULL
);
502 wxSizerItem
* Add(int width
,
507 wxObject
* userData
= NULL
);
508 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
509 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
510 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
511 wxSizerItem
* Add( wxSizerItem
*item
);
513 wxSizerItem
* AddSpacer(int size
);
514 wxSizerItem
* AddStretchSpacer(int prop
= 1);
516 wxSizerItem
* Insert(size_t index
,
521 wxObject
* userData
= NULL
);
522 wxSizerItem
* Insert(size_t index
,
527 wxObject
* userData
= NULL
);
528 wxSizerItem
* Insert(size_t index
,
534 wxObject
* userData
= NULL
);
535 wxSizerItem
* Insert(size_t index
,
537 const wxSizerFlags
& flags
);
538 wxSizerItem
* Insert(size_t index
,
540 const wxSizerFlags
& flags
);
541 wxSizerItem
* Insert(size_t index
,
544 const wxSizerFlags
& flags
);
545 virtual wxSizerItem
* Insert( size_t index
, wxSizerItem
*item
);
547 wxSizerItem
* InsertSpacer(size_t index
, int size
);
548 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
550 wxSizerItem
* Prepend(wxWindow
*window
,
554 wxObject
* userData
= NULL
);
555 wxSizerItem
* Prepend(wxSizer
*sizer
,
559 wxObject
* userData
= NULL
);
560 wxSizerItem
* Prepend(int width
,
565 wxObject
* userData
= NULL
);
566 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
567 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
568 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
569 wxSizerItem
* Prepend(wxSizerItem
*item
);
571 wxSizerItem
* PrependSpacer(int size
);
572 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
574 // set (or possibly unset if window is NULL) or get the window this sizer
576 void SetContainingWindow(wxWindow
*window
);
577 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
579 #if WXWIN_COMPATIBILITY_2_6
580 // Deprecated in 2.6 since historically it does not delete the window,
581 // use Detach instead.
582 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
583 #endif // WXWIN_COMPATIBILITY_2_6
585 virtual bool Remove( wxSizer
*sizer
);
586 virtual bool Remove( int index
);
588 virtual bool Detach( wxWindow
*window
);
589 virtual bool Detach( wxSizer
*sizer
);
590 virtual bool Detach( int index
);
592 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
593 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
594 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
596 virtual void Clear( bool delete_windows
= false );
597 virtual void DeleteWindows();
599 // Inform sizer about the first direction that has been decided (by parent item)
600 // Returns true if it made use of the informtion (and recalculated min size)
601 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
604 void SetMinSize( int width
, int height
)
605 { DoSetMinSize( width
, height
); }
606 void SetMinSize( const wxSize
& size
)
607 { DoSetMinSize( size
.x
, size
.y
); }
609 // Searches recursively
610 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
611 { return DoSetItemMinSize( window
, width
, height
); }
612 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
613 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
615 // Searches recursively
616 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
617 { return DoSetItemMinSize( sizer
, width
, height
); }
618 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
619 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
621 bool SetItemMinSize( size_t index
, int width
, int height
)
622 { return DoSetItemMinSize( index
, width
, height
); }
623 bool SetItemMinSize( size_t index
, const wxSize
& size
)
624 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
626 wxSize
GetSize() const
628 wxPoint
GetPosition() const
629 { return m_position
; }
631 // Calculate the minimal size or return m_minSize if bigger.
634 // These virtual functions are used by the layout algorithm: first
635 // CalcMin() is called to calculate the minimal size of the sizer and
636 // prepare for laying it out and then RecalcSizes() is called to really
637 // update all the sizer items
638 virtual wxSize
CalcMin() = 0;
639 virtual void RecalcSizes() = 0;
641 virtual void Layout();
643 wxSize
ComputeFittingClientSize(wxWindow
*window
);
644 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
646 wxSize
Fit( wxWindow
*window
);
647 void FitInside( wxWindow
*window
);
648 void SetSizeHints( wxWindow
*window
);
649 #if WXWIN_COMPATIBILITY_2_8
650 // This only calls FitInside() since 2.9
651 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
654 wxSizerItemList
& GetChildren()
655 { return m_children
; }
656 const wxSizerItemList
& GetChildren() const
657 { return m_children
; }
659 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
665 void SetDimension(int x
, int y
, int width
, int height
)
666 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
668 size_t GetItemCount() const { return m_children
.GetCount(); }
669 bool IsEmpty() const { return m_children
.IsEmpty(); }
671 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
672 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
673 wxSizerItem
* GetItem( size_t index
);
674 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
676 // Manage whether individual scene items are considered
677 // in the layout calculations or not.
678 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
679 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
680 bool Show( size_t index
, bool show
= true );
682 bool Hide( wxSizer
*sizer
, bool recursive
= false )
683 { return Show( sizer
, false, recursive
); }
684 bool Hide( wxWindow
*window
, bool recursive
= false )
685 { return Show( window
, false, recursive
); }
686 bool Hide( size_t index
)
687 { return Show( index
, false ); }
689 bool IsShown( wxWindow
*window
) const;
690 bool IsShown( wxSizer
*sizer
) const;
691 bool IsShown( size_t index
) const;
693 // Recursively call wxWindow::Show () on all sizer items.
694 virtual void ShowItems (bool show
);
696 void Show(bool show
) { ShowItems(show
); }
702 wxSizerItemList m_children
;
704 // the window this sizer is used in, can be NULL
705 wxWindow
*m_containingWindow
;
707 wxSize
GetMaxClientSize( wxWindow
*window
) const;
708 wxSize
GetMinClientSize( wxWindow
*window
);
709 wxSize
VirtualFitSize( wxWindow
*window
);
711 virtual void DoSetMinSize( int width
, int height
);
712 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
713 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
714 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
717 DECLARE_CLASS(wxSizer
)
720 //---------------------------------------------------------------------------
722 //---------------------------------------------------------------------------
724 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
727 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
728 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
730 virtual wxSizerItem
*Insert(size_t index
, wxSizerItem
*item
);
732 virtual void RecalcSizes();
733 virtual wxSize
CalcMin();
735 void SetCols( int cols
) { m_cols
= cols
; }
736 void SetRows( int rows
) { m_rows
= rows
; }
737 void SetVGap( int gap
) { m_vgap
= gap
; }
738 void SetHGap( int gap
) { m_hgap
= gap
; }
739 int GetCols() const { return m_cols
; }
740 int GetRows() const { return m_rows
; }
741 int GetVGap() const { return m_vgap
; }
742 int GetHGap() const { return m_hgap
; }
744 // return the number of total items and the number of columns and rows
745 // (for internal use only)
746 int CalcRowsCols(int& rows
, int& cols
) const;
754 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
757 DECLARE_CLASS(wxGridSizer
)
760 //---------------------------------------------------------------------------
762 //---------------------------------------------------------------------------
764 // values which define the behaviour for resizing wxFlexGridSizer cells in the
765 // "non-flexible" direction
766 enum wxFlexSizerGrowMode
768 // don't resize the cells in non-flexible direction at all
769 wxFLEX_GROWMODE_NONE
,
771 // uniformly resize only the specified ones (default)
772 wxFLEX_GROWMODE_SPECIFIED
,
774 // uniformly resize all cells
778 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
782 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
783 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
784 virtual ~wxFlexGridSizer();
787 // set the rows/columns which will grow (the others will remain of the
788 // constant initial size)
789 void AddGrowableRow( size_t idx
, int proportion
= 0 );
790 void RemoveGrowableRow( size_t idx
);
791 void AddGrowableCol( size_t idx
, int proportion
= 0 );
792 void RemoveGrowableCol( size_t idx
);
794 bool IsRowGrowable( size_t idx
);
795 bool IsColGrowable( size_t idx
);
797 // the sizer cells may grow in both directions, not grow at all or only
798 // grow in one direction but not the other
800 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
801 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
802 int GetFlexibleDirection() const { return m_flexDirection
; }
804 // note that the grow mode only applies to the direction which is not
806 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
807 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
809 // Read-only access to the row heights and col widths arrays
810 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
811 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
814 virtual void RecalcSizes();
815 virtual wxSize
CalcMin();
818 void AdjustForFlexDirection();
819 void AdjustForGrowables(const wxSize
& sz
);
820 void FindWidthsAndHeights(int nrows
, int ncols
);
822 // the heights/widths of all rows/columns
823 wxArrayInt m_rowHeights
,
826 // indices of the growable columns and rows
827 wxArrayInt m_growableRows
,
830 // proportion values of the corresponding growable rows and columns
831 wxArrayInt m_growableRowsProportions
,
832 m_growableColsProportions
;
834 // parameters describing whether the growable cells should be resized in
835 // both directions or only one
837 wxFlexSizerGrowMode m_growMode
;
839 // saves CalcMin result to optimize RecalcSizes
840 wxSize m_calculatedMinSize
;
843 DECLARE_CLASS(wxFlexGridSizer
)
844 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
847 //---------------------------------------------------------------------------
849 //---------------------------------------------------------------------------
851 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
854 wxBoxSizer(int orient
)
857 m_totalProportion
= 0;
859 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
860 _T("invalid value for wxBoxSizer orientation") );
863 int GetOrientation() const { return m_orient
; }
865 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
867 void SetOrientation(int orient
) { m_orient
= orient
; }
869 // implementation of our resizing logic
870 virtual wxSize
CalcMin();
871 virtual void RecalcSizes();
874 // helpers for our code: this returns the component of the given wxSize in
875 // the direction of the sizer and in the other direction, respectively
876 int GetSizeInMajorDir(const wxSize
& sz
) const
878 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
881 int& SizeInMajorDir(wxSize
& sz
)
883 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
886 int& PosInMajorDir(wxPoint
& pt
)
888 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
891 int GetSizeInMinorDir(const wxSize
& sz
) const
893 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
896 int& SizeInMinorDir(wxSize
& sz
)
898 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
901 int& PosInMinorDir(wxPoint
& pt
)
903 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
906 // another helper: creates wxSize from major and minor components
907 wxSize
SizeFromMajorMinor(int major
, int minor
) const
909 if ( m_orient
== wxHORIZONTAL
)
911 return wxSize(major
, minor
);
915 return wxSize(minor
, major
);
920 // either wxHORIZONTAL or wxVERTICAL
923 // the sum of proportion of all of our elements
924 int m_totalProportion
;
926 // the minimal size needed for this sizer as calculated by the last call to
931 DECLARE_CLASS(wxBoxSizer
)
934 //---------------------------------------------------------------------------
936 //---------------------------------------------------------------------------
940 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
942 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
945 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
946 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
947 virtual ~wxStaticBoxSizer();
952 wxStaticBox
*GetStaticBox() const
953 { return m_staticBox
; }
955 // override to hide/show the static box as well
956 virtual void ShowItems (bool show
);
958 virtual bool Detach( wxWindow
*window
);
959 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
960 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
963 wxStaticBox
*m_staticBox
;
966 DECLARE_CLASS(wxStaticBoxSizer
)
967 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
970 #endif // wxUSE_STATBOX
972 //---------------------------------------------------------------------------
973 // wxStdDialogButtonSizer
974 //---------------------------------------------------------------------------
978 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
981 // Constructor just creates a new wxBoxSizer, not much else.
982 // Box sizer orientation is automatically determined here:
983 // vertical for PDAs, horizontal for everything else?
984 wxStdDialogButtonSizer();
986 // Checks button ID against system IDs and sets one of the pointers below
987 // to this button. Does not do any sizer-related things here.
988 void AddButton(wxButton
*button
);
990 // Use these if no standard ID can/should be used
991 void SetAffirmativeButton( wxButton
*button
);
992 void SetNegativeButton( wxButton
*button
);
993 void SetCancelButton( wxButton
*button
);
995 // All platform-specific code here, checks which buttons exist and add
996 // them to the sizer accordingly.
997 // Note - one potential hack on Mac we could use here,
998 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
999 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1000 // I wouldn't add any other hacks like that into here,
1001 // but this one I can see being useful.
1004 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1005 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1006 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1007 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1008 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1011 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1012 wxButton
*m_buttonApply
; // wxID_APPLY
1013 wxButton
*m_buttonNegative
; // wxID_NO
1014 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1015 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1018 DECLARE_CLASS(wxStdDialogButtonSizer
)
1019 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1022 #endif // wxUSE_BUTTON
1025 // ----------------------------------------------------------------------------
1026 // inline functions implementation
1027 // ----------------------------------------------------------------------------
1029 #if WXWIN_COMPATIBILITY_2_8
1031 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1033 DoSetWindow(window
);
1036 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1041 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1046 inline void wxSizerItem::SetSpacer(int width
, int height
)
1048 DoSetSpacer(wxSize(width
, height
));
1051 #endif // WXWIN_COMPATIBILITY_2_8
1055 wxSizer::Add( wxSizerItem
*item
)
1057 return Insert( m_children
.GetCount(), item
);
1061 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1063 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1067 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1069 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1073 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1075 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1079 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1081 return Add( new wxSizerItem(window
, flags
) );
1085 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1087 return Add( new wxSizerItem(sizer
, flags
) );
1091 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1093 return Add( new wxSizerItem(width
, height
, flags
) );
1097 wxSizer::AddSpacer(int size
)
1099 return Add(size
, size
);
1103 wxSizer::AddStretchSpacer(int prop
)
1105 return Add(0, 0, prop
);
1109 wxSizer::Prepend( wxSizerItem
*item
)
1111 return Insert( 0, item
);
1115 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1117 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1121 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1123 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1127 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1129 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1133 wxSizer::PrependSpacer(int size
)
1135 return Prepend(size
, size
);
1139 wxSizer::PrependStretchSpacer(int prop
)
1141 return Prepend(0, 0, prop
);
1145 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1147 return Prepend( new wxSizerItem(window
, flags
) );
1151 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1153 return Prepend( new wxSizerItem(sizer
, flags
) );
1157 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1159 return Prepend( new wxSizerItem(width
, height
, flags
) );
1163 wxSizer::Insert( size_t index
,
1168 wxObject
* userData
)
1170 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1174 wxSizer::Insert( size_t index
,
1179 wxObject
* userData
)
1181 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1185 wxSizer::Insert( size_t index
,
1191 wxObject
* userData
)
1193 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1197 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1199 return Insert( index
, new wxSizerItem(window
, flags
) );
1203 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1205 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1209 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1211 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1215 wxSizer::InsertSpacer(size_t index
, int size
)
1217 return Insert(index
, size
, size
);
1221 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1223 return Insert(index
, 0, 0, prop
);
1226 #endif // __WXSIZER_H__