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
)
128 wxCHECK_MSG( !(direction
& ~wxALL
), *this,
129 wxS("direction must be a combination of wxDirection ")
130 wxS("enum values.") );
133 m_flags
|= direction
;
135 m_borderInPixels
= borderInPixels
;
140 wxSizerFlags
& Border(int direction
= wxALL
)
142 #if wxUSE_BORDER_BY_DEFAULT
143 return Border(direction
, GetDefaultBorder());
145 // no borders by default on limited size screen
146 wxUnusedVar(direction
);
152 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
154 #if wxUSE_BORDER_BY_DEFAULT
155 return Border(direction
, 2*GetDefaultBorder());
157 wxUnusedVar(direction
);
163 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
165 #if wxUSE_BORDER_BY_DEFAULT
166 return Border(direction
, 3*GetDefaultBorder());
168 wxUnusedVar(direction
);
174 wxSizerFlags
& HorzBorder()
176 #if wxUSE_BORDER_BY_DEFAULT
177 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
183 wxSizerFlags
& DoubleHorzBorder()
185 #if wxUSE_BORDER_BY_DEFAULT
186 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
192 // setters for the others flags
193 wxSizerFlags
& Shaped()
200 wxSizerFlags
& FixedMinSize()
202 m_flags
|= wxFIXED_MINSIZE
;
207 // makes the item ignore window's visibility status
208 wxSizerFlags
& ReserveSpaceEvenIfHidden()
210 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
214 // accessors for wxSizer only
215 int GetProportion() const { return m_proportion
; }
216 int GetFlags() const { return m_flags
; }
217 int GetBorderInPixels() const { return m_borderInPixels
; }
222 int m_borderInPixels
;
226 // ----------------------------------------------------------------------------
227 // wxSizerSpacer: used by wxSizerItem to represent a spacer
228 // ----------------------------------------------------------------------------
230 class WXDLLIMPEXP_CORE wxSizerSpacer
233 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
235 void SetSize(const wxSize
& size
) { m_size
= size
; }
236 const wxSize
& GetSize() const { return m_size
; }
238 void Show(bool show
) { m_isShown
= show
; }
239 bool IsShown() const { return m_isShown
; }
242 // the size, in pixel
245 // is the spacer currently shown?
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
257 wxSizerItem( wxWindow
*window
,
261 wxObject
* userData
=NULL
);
264 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
272 wxSizerItem( wxSizer
*sizer
,
276 wxObject
* userData
=NULL
);
279 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
287 wxSizerItem( int width
,
292 wxObject
* userData
=NULL
);
295 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
299 DoSetSpacer(wxSize(width
, height
));
303 virtual ~wxSizerItem();
305 virtual void DeleteWindows();
307 // Enable deleting the SizerItem without destroying the contained sizer.
308 void DetachSizer() { m_sizer
= NULL
; }
310 virtual wxSize
GetSize() const;
311 virtual wxSize
CalcMin();
312 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
314 wxSize
GetMinSize() const
315 { return m_minSize
; }
316 wxSize
GetMinSizeWithBorder() const;
318 wxSize
GetMaxSize() const
319 { return IsWindow() ? m_window
->GetMaxSize() : wxDefaultSize
; }
320 wxSize
GetMaxSizeWithBorder() const;
322 void SetMinSize(const wxSize
& size
)
325 m_window
->SetMinSize(size
);
328 void SetMinSize( int x
, int y
)
329 { SetMinSize(wxSize(x
, y
)); }
330 void SetInitSize( int x
, int y
)
331 { SetMinSize(wxSize(x
, y
)); }
333 // if either of dimensions is zero, ratio is assumed to be 1
334 // to avoid "divide by zero" errors
335 void SetRatio(int width
, int height
)
336 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
337 void SetRatio(const wxSize
& size
)
338 { SetRatio(size
.x
, size
.y
); }
339 void SetRatio(float ratio
)
341 float GetRatio() const
344 virtual wxRect
GetRect() { return m_rect
; }
346 // set a sizer item id (different from a window id, all sizer items,
347 // including spacers, can have an associated id)
348 void SetId(int id
) { m_id
= id
; }
349 int GetId() const { return m_id
; }
351 bool IsWindow() const { return m_kind
== Item_Window
; }
352 bool IsSizer() const { return m_kind
== Item_Sizer
; }
353 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
355 #if WXWIN_COMPATIBILITY_2_6
356 // Deprecated in 2.6, use {G,S}etProportion instead.
357 wxDEPRECATED( void SetOption( int option
) );
358 wxDEPRECATED( int GetOption() const );
359 #endif // WXWIN_COMPATIBILITY_2_6
361 void SetProportion( int proportion
)
362 { m_proportion
= proportion
; }
363 int GetProportion() const
364 { return m_proportion
; }
365 void SetFlag( int flag
)
369 void SetBorder( int border
)
370 { m_border
= border
; }
371 int GetBorder() const
374 wxWindow
*GetWindow() const
375 { return m_kind
== Item_Window
? m_window
: NULL
; }
376 wxSizer
*GetSizer() const
377 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
378 wxSize
GetSpacer() const;
380 // This function behaves obviously for the windows and spacers but for the
381 // sizers it returns true if any sizer element is shown and only returns
382 // false if all of them are hidden. Also, it always returns true if
383 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
384 bool IsShown() const;
386 void Show(bool show
);
388 void SetUserData(wxObject
* userData
)
389 { delete m_userData
; m_userData
= userData
; }
390 wxObject
* GetUserData() const
391 { return m_userData
; }
392 wxPoint
GetPosition() const
395 // Called once the first component of an item has been decided. This is
396 // used in algorithms that depend on knowing the size in one direction
397 // before the min size in the other direction can be known.
398 // Returns true if it made use of the information (and min size was changed).
399 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
401 // these functions delete the current contents of the item if it's a sizer
402 // or a spacer but not if it is a window
403 void AssignWindow(wxWindow
*window
)
409 void AssignSizer(wxSizer
*sizer
)
415 void AssignSpacer(const wxSize
& size
)
421 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
423 #if WXWIN_COMPATIBILITY_2_8
424 // these functions do not free the old sizer/spacer and so can easily
425 // provoke the memory leaks and so shouldn't be used, use Assign() instead
426 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
427 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
428 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
429 wxDEPRECATED( void SetSpacer(int width
, int height
) );
430 #endif // WXWIN_COMPATIBILITY_2_8
433 // common part of several ctors
434 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
436 // common part of ctors taking wxSizerFlags
437 void Init(const wxSizerFlags
& flags
);
439 // free current contents
442 // common parts of Set/AssignXXX()
443 void DoSetWindow(wxWindow
*window
);
444 void DoSetSizer(wxSizer
*sizer
);
445 void DoSetSpacer(const wxSize
& size
);
447 // Add the border specified for this item to the given size
448 // if it's != wxDefaultSize, just return wxDefaultSize otherwise.
449 wxSize
AddBorderToSize(const wxSize
& size
) const;
451 // discriminated union: depending on m_kind one of the fields is valid
464 wxSizerSpacer
*m_spacer
;
474 // on screen rectangle of this item (not including borders)
477 // Aspect ratio can always be calculated from m_size,
478 // but this would cause precision loss when the window
479 // is shrunk. It is safer to preserve the initial value.
482 wxObject
*m_userData
;
485 DECLARE_CLASS(wxSizerItem
)
486 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
489 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
492 //---------------------------------------------------------------------------
494 //---------------------------------------------------------------------------
496 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
499 wxSizer() { m_containingWindow
= NULL
; }
502 // methods for adding elements to the sizer: there are Add/Insert/Prepend
503 // overloads for each of window/sizer/spacer/wxSizerItem
504 wxSizerItem
* Add(wxWindow
*window
,
508 wxObject
* userData
= NULL
);
509 wxSizerItem
* Add(wxSizer
*sizer
,
513 wxObject
* userData
= NULL
);
514 wxSizerItem
* Add(int width
,
519 wxObject
* userData
= NULL
);
520 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
521 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
522 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
523 wxSizerItem
* Add( wxSizerItem
*item
);
525 virtual wxSizerItem
*AddSpacer(int size
);
526 wxSizerItem
* AddStretchSpacer(int prop
= 1);
528 wxSizerItem
* Insert(size_t index
,
533 wxObject
* userData
= NULL
);
534 wxSizerItem
* Insert(size_t index
,
539 wxObject
* userData
= NULL
);
540 wxSizerItem
* Insert(size_t index
,
546 wxObject
* userData
= NULL
);
547 wxSizerItem
* Insert(size_t index
,
549 const wxSizerFlags
& flags
);
550 wxSizerItem
* Insert(size_t index
,
552 const wxSizerFlags
& flags
);
553 wxSizerItem
* Insert(size_t index
,
556 const wxSizerFlags
& flags
);
558 // NB: do _not_ override this function in the derived classes, this one is
559 // virtual for compatibility reasons only to allow old code overriding
560 // it to continue to work, override DoInsert() instead in the new code
561 virtual wxSizerItem
* Insert(size_t index
, wxSizerItem
*item
);
563 wxSizerItem
* InsertSpacer(size_t index
, int size
);
564 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
566 wxSizerItem
* Prepend(wxWindow
*window
,
570 wxObject
* userData
= NULL
);
571 wxSizerItem
* Prepend(wxSizer
*sizer
,
575 wxObject
* userData
= NULL
);
576 wxSizerItem
* Prepend(int width
,
581 wxObject
* userData
= NULL
);
582 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
583 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
584 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
585 wxSizerItem
* Prepend(wxSizerItem
*item
);
587 wxSizerItem
* PrependSpacer(int size
);
588 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
590 // set (or possibly unset if window is NULL) or get the window this sizer
592 void SetContainingWindow(wxWindow
*window
);
593 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
595 #if WXWIN_COMPATIBILITY_2_6
596 // Deprecated in 2.6 since historically it does not delete the window,
597 // use Detach instead.
598 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
599 #endif // WXWIN_COMPATIBILITY_2_6
601 virtual bool Remove( wxSizer
*sizer
);
602 virtual bool Remove( int index
);
604 virtual bool Detach( wxWindow
*window
);
605 virtual bool Detach( wxSizer
*sizer
);
606 virtual bool Detach( int index
);
608 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
609 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
610 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
612 virtual void Clear( bool delete_windows
= false );
613 virtual void DeleteWindows();
615 // Inform sizer about the first direction that has been decided (by parent item)
616 // Returns true if it made use of the information (and recalculated min size)
617 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
620 void SetMinSize( int width
, int height
)
621 { DoSetMinSize( width
, height
); }
622 void SetMinSize( const wxSize
& size
)
623 { DoSetMinSize( size
.x
, size
.y
); }
625 // Searches recursively
626 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
627 { return DoSetItemMinSize( window
, width
, height
); }
628 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
629 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
631 // Searches recursively
632 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
633 { return DoSetItemMinSize( sizer
, width
, height
); }
634 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
635 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
637 bool SetItemMinSize( size_t index
, int width
, int height
)
638 { return DoSetItemMinSize( index
, width
, height
); }
639 bool SetItemMinSize( size_t index
, const wxSize
& size
)
640 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
642 wxSize
GetSize() const
644 wxPoint
GetPosition() const
645 { return m_position
; }
647 // Calculate the minimal size or return m_minSize if bigger.
650 // These virtual functions are used by the layout algorithm: first
651 // CalcMin() is called to calculate the minimal size of the sizer and
652 // prepare for laying it out and then RecalcSizes() is called to really
653 // update all the sizer items
654 virtual wxSize
CalcMin() = 0;
655 virtual void RecalcSizes() = 0;
657 virtual void Layout();
659 wxSize
ComputeFittingClientSize(wxWindow
*window
);
660 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
662 wxSize
Fit( wxWindow
*window
);
663 void FitInside( wxWindow
*window
);
664 void SetSizeHints( wxWindow
*window
);
665 #if WXWIN_COMPATIBILITY_2_8
666 // This only calls FitInside() since 2.9
667 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
670 wxSizerItemList
& GetChildren()
671 { return m_children
; }
672 const wxSizerItemList
& GetChildren() const
673 { return m_children
; }
675 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
681 // This call is required for wxWrapSizer to be able to calculate its
682 // minimal size correctly.
683 InformFirstDirection(wxHORIZONTAL
, size
.x
, size
.y
);
685 void SetDimension(int x
, int y
, int width
, int height
)
686 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
688 size_t GetItemCount() const { return m_children
.GetCount(); }
689 bool IsEmpty() const { return m_children
.IsEmpty(); }
691 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
692 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
693 wxSizerItem
* GetItem( size_t index
);
694 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
696 // Manage whether individual scene items are considered
697 // in the layout calculations or not.
698 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
699 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
700 bool Show( size_t index
, bool show
= true );
702 bool Hide( wxSizer
*sizer
, bool recursive
= false )
703 { return Show( sizer
, false, recursive
); }
704 bool Hide( wxWindow
*window
, bool recursive
= false )
705 { return Show( window
, false, recursive
); }
706 bool Hide( size_t index
)
707 { return Show( index
, false ); }
709 bool IsShown( wxWindow
*window
) const;
710 bool IsShown( wxSizer
*sizer
) const;
711 bool IsShown( size_t index
) const;
713 // Recursively call wxWindow::Show () on all sizer items.
714 virtual void ShowItems (bool show
);
716 void Show(bool show
) { ShowItems(show
); }
718 // This is the ShowItems() counterpart and returns true if any of the sizer
720 virtual bool AreAnyItemsShown() const;
726 wxSizerItemList m_children
;
728 // the window this sizer is used in, can be NULL
729 wxWindow
*m_containingWindow
;
731 wxSize
GetMaxClientSize( wxWindow
*window
) const;
732 wxSize
GetMinClientSize( wxWindow
*window
);
733 wxSize
VirtualFitSize( wxWindow
*window
);
735 virtual void DoSetMinSize( int width
, int height
);
736 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
737 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
738 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
740 // insert a new item into m_children at given index and return the item
742 virtual wxSizerItem
* DoInsert(size_t index
, wxSizerItem
*item
);
745 DECLARE_CLASS(wxSizer
)
748 //---------------------------------------------------------------------------
750 //---------------------------------------------------------------------------
752 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
755 // ctors specifying the number of columns only: number of rows will be
756 // deduced automatically depending on the number of sizer elements
757 wxGridSizer( int cols
, int vgap
, int hgap
);
758 wxGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
760 // ctors specifying the number of rows and columns
761 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
762 wxGridSizer( int rows
, int cols
, const wxSize
& gap
);
764 virtual void RecalcSizes();
765 virtual wxSize
CalcMin();
767 void SetCols( int cols
)
769 wxASSERT_MSG( cols
>= 0, "Number of columns must be non-negative");
773 void SetRows( int rows
)
775 wxASSERT_MSG( rows
>= 0, "Number of rows must be non-negative");
779 void SetVGap( int gap
) { m_vgap
= gap
; }
780 void SetHGap( int gap
) { m_hgap
= gap
; }
781 int GetCols() const { return m_cols
; }
782 int GetRows() const { return m_rows
; }
783 int GetVGap() const { return m_vgap
; }
784 int GetHGap() const { return m_hgap
; }
786 int GetEffectiveColsCount() const { return m_cols
? m_cols
: CalcCols(); }
787 int GetEffectiveRowsCount() const { return m_rows
? m_rows
: CalcRows(); }
789 // return the number of total items and the number of columns and rows
790 // (for internal use only)
791 int CalcRowsCols(int& rows
, int& cols
) const;
794 // the number of rows/columns in the sizer, if 0 then it is determined
795 // dynamically depending on the total number of items
799 // gaps between rows and columns
803 virtual wxSizerItem
*DoInsert(size_t index
, wxSizerItem
*item
);
805 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
807 // returns the number of columns/rows needed for the current total number
808 // of children (and the fixed number of rows/columns)
814 "Can't calculate number of cols if number of rows is not specified"
817 return (m_children
.GetCount() + m_rows
- 1) / m_rows
;
825 "Can't calculate number of cols if number of rows is not specified"
828 return (m_children
.GetCount() + m_cols
- 1) / m_cols
;
832 DECLARE_CLASS(wxGridSizer
)
835 //---------------------------------------------------------------------------
837 //---------------------------------------------------------------------------
839 // values which define the behaviour for resizing wxFlexGridSizer cells in the
840 // "non-flexible" direction
841 enum wxFlexSizerGrowMode
843 // don't resize the cells in non-flexible direction at all
844 wxFLEX_GROWMODE_NONE
,
846 // uniformly resize only the specified ones (default)
847 wxFLEX_GROWMODE_SPECIFIED
,
849 // uniformly resize all cells
853 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
856 // ctors specifying the number of columns only: number of rows will be
857 // deduced automatically depending on the number of sizer elements
858 wxFlexGridSizer( int cols
, int vgap
, int hgap
);
859 wxFlexGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
861 // ctors specifying the number of rows and columns
862 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
863 wxFlexGridSizer( int rows
, int cols
, const wxSize
& gap
);
866 virtual ~wxFlexGridSizer();
868 // set the rows/columns which will grow (the others will remain of the
869 // constant initial size)
870 void AddGrowableRow( size_t idx
, int proportion
= 0 );
871 void RemoveGrowableRow( size_t idx
);
872 void AddGrowableCol( size_t idx
, int proportion
= 0 );
873 void RemoveGrowableCol( size_t idx
);
875 bool IsRowGrowable( size_t idx
);
876 bool IsColGrowable( size_t idx
);
878 // the sizer cells may grow in both directions, not grow at all or only
879 // grow in one direction but not the other
881 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
882 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
883 int GetFlexibleDirection() const { return m_flexDirection
; }
885 // note that the grow mode only applies to the direction which is not
887 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
888 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
890 // Read-only access to the row heights and col widths arrays
891 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
892 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
895 virtual void RecalcSizes();
896 virtual wxSize
CalcMin();
899 void AdjustForFlexDirection();
900 void AdjustForGrowables(const wxSize
& sz
);
901 void FindWidthsAndHeights(int nrows
, int ncols
);
903 // the heights/widths of all rows/columns
904 wxArrayInt m_rowHeights
,
907 // indices of the growable columns and rows
908 wxArrayInt m_growableRows
,
911 // proportion values of the corresponding growable rows and columns
912 wxArrayInt m_growableRowsProportions
,
913 m_growableColsProportions
;
915 // parameters describing whether the growable cells should be resized in
916 // both directions or only one
918 wxFlexSizerGrowMode m_growMode
;
920 // saves CalcMin result to optimize RecalcSizes
921 wxSize m_calculatedMinSize
;
924 DECLARE_CLASS(wxFlexGridSizer
)
925 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
928 //---------------------------------------------------------------------------
930 //---------------------------------------------------------------------------
932 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
935 wxBoxSizer(int orient
)
938 m_totalProportion
= 0;
940 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
941 wxT("invalid value for wxBoxSizer orientation") );
944 virtual wxSizerItem
*AddSpacer(int size
);
946 int GetOrientation() const { return m_orient
; }
948 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
950 void SetOrientation(int orient
) { m_orient
= orient
; }
952 // implementation of our resizing logic
953 virtual wxSize
CalcMin();
954 virtual void RecalcSizes();
957 // helpers for our code: this returns the component of the given wxSize in
958 // the direction of the sizer and in the other direction, respectively
959 int GetSizeInMajorDir(const wxSize
& sz
) const
961 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
964 int& SizeInMajorDir(wxSize
& sz
)
966 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
969 int& PosInMajorDir(wxPoint
& pt
)
971 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
974 int GetSizeInMinorDir(const wxSize
& sz
) const
976 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
979 int& SizeInMinorDir(wxSize
& sz
)
981 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
984 int& PosInMinorDir(wxPoint
& pt
)
986 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
989 // another helper: creates wxSize from major and minor components
990 wxSize
SizeFromMajorMinor(int major
, int minor
) const
992 if ( m_orient
== wxHORIZONTAL
)
994 return wxSize(major
, minor
);
998 return wxSize(minor
, major
);
1003 // either wxHORIZONTAL or wxVERTICAL
1006 // the sum of proportion of all of our elements
1007 int m_totalProportion
;
1009 // the minimal size needed for this sizer as calculated by the last call to
1014 DECLARE_CLASS(wxBoxSizer
)
1017 //---------------------------------------------------------------------------
1019 //---------------------------------------------------------------------------
1023 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
1025 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
1028 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
1029 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
1030 virtual ~wxStaticBoxSizer();
1035 wxStaticBox
*GetStaticBox() const
1036 { return m_staticBox
; }
1038 // override to hide/show the static box as well
1039 virtual void ShowItems (bool show
);
1040 virtual bool AreAnyItemsShown() const;
1042 virtual bool Detach( wxWindow
*window
);
1043 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
1044 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
1047 wxStaticBox
*m_staticBox
;
1050 DECLARE_CLASS(wxStaticBoxSizer
)
1051 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
1054 #endif // wxUSE_STATBOX
1056 //---------------------------------------------------------------------------
1057 // wxStdDialogButtonSizer
1058 //---------------------------------------------------------------------------
1062 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
1065 // Constructor just creates a new wxBoxSizer, not much else.
1066 // Box sizer orientation is automatically determined here:
1067 // vertical for PDAs, horizontal for everything else?
1068 wxStdDialogButtonSizer();
1070 // Checks button ID against system IDs and sets one of the pointers below
1071 // to this button. Does not do any sizer-related things here.
1072 void AddButton(wxButton
*button
);
1074 // Use these if no standard ID can/should be used
1075 void SetAffirmativeButton( wxButton
*button
);
1076 void SetNegativeButton( wxButton
*button
);
1077 void SetCancelButton( wxButton
*button
);
1079 // All platform-specific code here, checks which buttons exist and add
1080 // them to the sizer accordingly.
1081 // Note - one potential hack on Mac we could use here,
1082 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1083 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1084 // I wouldn't add any other hacks like that into here,
1085 // but this one I can see being useful.
1088 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1089 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1090 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1091 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1092 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1095 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1096 wxButton
*m_buttonApply
; // wxID_APPLY
1097 wxButton
*m_buttonNegative
; // wxID_NO
1098 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1099 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1102 DECLARE_CLASS(wxStdDialogButtonSizer
)
1103 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1106 #endif // wxUSE_BUTTON
1109 // ----------------------------------------------------------------------------
1110 // inline functions implementation
1111 // ----------------------------------------------------------------------------
1113 #if WXWIN_COMPATIBILITY_2_8
1115 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1117 DoSetWindow(window
);
1120 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1125 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1130 inline void wxSizerItem::SetSpacer(int width
, int height
)
1132 DoSetSpacer(wxSize(width
, height
));
1135 #endif // WXWIN_COMPATIBILITY_2_8
1138 wxSizer::Insert(size_t index
, wxSizerItem
*item
)
1140 return DoInsert(index
, item
);
1145 wxSizer::Add( wxSizerItem
*item
)
1147 return Insert( m_children
.GetCount(), item
);
1151 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1153 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1157 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1159 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1163 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1165 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1169 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1171 return Add( new wxSizerItem(window
, flags
) );
1175 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1177 return Add( new wxSizerItem(sizer
, flags
) );
1181 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1183 return Add( new wxSizerItem(width
, height
, flags
) );
1187 wxSizer::AddSpacer(int size
)
1189 return Add(size
, size
);
1193 wxSizer::AddStretchSpacer(int prop
)
1195 return Add(0, 0, prop
);
1199 wxSizer::Prepend( wxSizerItem
*item
)
1201 return Insert( 0, item
);
1205 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1207 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1211 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1213 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1217 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1219 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1223 wxSizer::PrependSpacer(int size
)
1225 return Prepend(size
, size
);
1229 wxSizer::PrependStretchSpacer(int prop
)
1231 return Prepend(0, 0, prop
);
1235 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1237 return Prepend( new wxSizerItem(window
, flags
) );
1241 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1243 return Prepend( new wxSizerItem(sizer
, flags
) );
1247 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1249 return Prepend( new wxSizerItem(width
, height
, flags
) );
1253 wxSizer::Insert( size_t index
,
1258 wxObject
* userData
)
1260 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1264 wxSizer::Insert( size_t index
,
1269 wxObject
* userData
)
1271 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1275 wxSizer::Insert( size_t index
,
1281 wxObject
* userData
)
1283 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1287 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1289 return Insert( index
, new wxSizerItem(window
, flags
) );
1293 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1295 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1299 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1301 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1305 wxSizer::InsertSpacer(size_t index
, int size
)
1307 return Insert(index
, size
, size
);
1311 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1313 return Insert(index
, 0, 0, prop
);
1316 #endif // __WXSIZER_H__