1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
7 // Copyright: (c) Robin Dunn, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/window.h"
18 //---------------------------------------------------------------------------
20 //---------------------------------------------------------------------------
22 class WXDLLIMPEXP_FWD_CORE wxButton
;
23 class WXDLLIMPEXP_FWD_CORE wxBoxSizer
;
24 class WXDLLIMPEXP_FWD_CORE wxSizerItem
;
25 class WXDLLIMPEXP_FWD_CORE wxSizer
;
27 #ifndef wxUSE_BORDER_BY_DEFAULT
29 // no borders by default on limited size screen
30 #define wxUSE_BORDER_BY_DEFAULT 0
32 #define wxUSE_BORDER_BY_DEFAULT 1
36 // ----------------------------------------------------------------------------
37 // wxSizerFlags: flags used for an item in the sizer
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_CORE wxSizerFlags
43 // construct the flags object initialized with the given proportion (0 by
45 wxSizerFlags(int proportion
= 0) : m_proportion(proportion
)
51 // setters for all sizer flags, they all return the object itself so that
52 // calls to them can be chained
54 wxSizerFlags
& Proportion(int proportion
)
56 m_proportion
= proportion
;
60 wxSizerFlags
& Expand()
66 // notice that Align() replaces the current alignment flags, use specific
67 // methods below such as Top(), Left() &c if you want to set just the
68 // vertical or horizontal alignment
69 wxSizerFlags
& Align(int alignment
) // combination of wxAlignment values
71 m_flags
&= ~wxALIGN_MASK
;
77 // some shortcuts for Align()
78 wxSizerFlags
& Centre() { return Align(wxALIGN_CENTRE
); }
79 wxSizerFlags
& Center() { return Centre(); }
83 m_flags
&= ~(wxALIGN_BOTTOM
| wxALIGN_CENTRE_VERTICAL
);
89 m_flags
&= ~(wxALIGN_RIGHT
| wxALIGN_CENTRE_HORIZONTAL
);
95 m_flags
= (m_flags
& ~wxALIGN_CENTRE_HORIZONTAL
) | wxALIGN_RIGHT
;
99 wxSizerFlags
& Bottom()
101 m_flags
= (m_flags
& ~wxALIGN_CENTRE_VERTICAL
) | wxALIGN_BOTTOM
;
106 // default border size used by Border() below
107 static int GetDefaultBorder()
109 #if wxUSE_BORDER_BY_DEFAULT
111 // GNOME HIG says to use 6px as the base unit:
112 // http://library.gnome.org/devel/hig-book/stable/design-window.html.en
115 // FIXME: default border size shouldn't be hardcoded and at the very
116 // least they should depend on the current font size
125 wxSizerFlags
& Border(int direction
, int borderInPixels
)
127 wxCHECK_MSG( !(direction
& ~wxALL
), *this,
128 wxS("direction must be a combination of wxDirection ")
129 wxS("enum values.") );
132 m_flags
|= direction
;
134 m_borderInPixels
= borderInPixels
;
139 wxSizerFlags
& Border(int direction
= wxALL
)
141 #if wxUSE_BORDER_BY_DEFAULT
142 return Border(direction
, GetDefaultBorder());
144 // no borders by default on limited size screen
145 wxUnusedVar(direction
);
151 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
153 #if wxUSE_BORDER_BY_DEFAULT
154 return Border(direction
, 2*GetDefaultBorder());
156 wxUnusedVar(direction
);
162 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
164 #if wxUSE_BORDER_BY_DEFAULT
165 return Border(direction
, 3*GetDefaultBorder());
167 wxUnusedVar(direction
);
173 wxSizerFlags
& HorzBorder()
175 #if wxUSE_BORDER_BY_DEFAULT
176 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
182 wxSizerFlags
& DoubleHorzBorder()
184 #if wxUSE_BORDER_BY_DEFAULT
185 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
191 // setters for the others flags
192 wxSizerFlags
& Shaped()
199 wxSizerFlags
& FixedMinSize()
201 m_flags
|= wxFIXED_MINSIZE
;
206 // makes the item ignore window's visibility status
207 wxSizerFlags
& ReserveSpaceEvenIfHidden()
209 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
213 // accessors for wxSizer only
214 int GetProportion() const { return m_proportion
; }
215 int GetFlags() const { return m_flags
; }
216 int GetBorderInPixels() const { return m_borderInPixels
; }
221 int m_borderInPixels
;
225 // ----------------------------------------------------------------------------
226 // wxSizerSpacer: used by wxSizerItem to represent a spacer
227 // ----------------------------------------------------------------------------
229 class WXDLLIMPEXP_CORE wxSizerSpacer
232 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
234 void SetSize(const wxSize
& size
) { m_size
= size
; }
235 const wxSize
& GetSize() const { return m_size
; }
237 void Show(bool show
) { m_isShown
= show
; }
238 bool IsShown() const { return m_isShown
; }
241 // the size, in pixel
244 // is the spacer currently shown?
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
252 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
256 wxSizerItem( wxWindow
*window
,
260 wxObject
* userData
=NULL
);
263 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
271 wxSizerItem( wxSizer
*sizer
,
275 wxObject
* userData
=NULL
);
278 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
286 wxSizerItem( int width
,
291 wxObject
* userData
=NULL
);
294 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
298 DoSetSpacer(wxSize(width
, height
));
302 virtual ~wxSizerItem();
304 virtual void DeleteWindows();
306 // Enable deleting the SizerItem without destroying the contained sizer.
307 void DetachSizer() { m_sizer
= NULL
; }
309 virtual wxSize
GetSize() const;
310 virtual wxSize
CalcMin();
311 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
313 wxSize
GetMinSize() const
314 { return m_minSize
; }
315 wxSize
GetMinSizeWithBorder() const;
317 wxSize
GetMaxSize() const
318 { return IsWindow() ? m_window
->GetMaxSize() : wxDefaultSize
; }
319 wxSize
GetMaxSizeWithBorder() const;
321 void SetMinSize(const wxSize
& size
)
324 m_window
->SetMinSize(size
);
327 void SetMinSize( int x
, int y
)
328 { SetMinSize(wxSize(x
, y
)); }
329 void SetInitSize( int x
, int y
)
330 { SetMinSize(wxSize(x
, y
)); }
332 // if either of dimensions is zero, ratio is assumed to be 1
333 // to avoid "divide by zero" errors
334 void SetRatio(int width
, int height
)
335 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
336 void SetRatio(const wxSize
& size
)
337 { SetRatio(size
.x
, size
.y
); }
338 void SetRatio(float ratio
)
340 float GetRatio() const
343 virtual wxRect
GetRect() { return m_rect
; }
345 // set a sizer item id (different from a window id, all sizer items,
346 // including spacers, can have an associated id)
347 void SetId(int id
) { m_id
= id
; }
348 int GetId() const { return m_id
; }
350 bool IsWindow() const { return m_kind
== Item_Window
; }
351 bool IsSizer() const { return m_kind
== Item_Sizer
; }
352 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
354 #if WXWIN_COMPATIBILITY_2_6
355 // Deprecated in 2.6, use {G,S}etProportion instead.
356 wxDEPRECATED( void SetOption( int option
) );
357 wxDEPRECATED( int GetOption() const );
358 #endif // WXWIN_COMPATIBILITY_2_6
360 void SetProportion( int proportion
)
361 { m_proportion
= proportion
; }
362 int GetProportion() const
363 { return m_proportion
; }
364 void SetFlag( int flag
)
368 void SetBorder( int border
)
369 { m_border
= border
; }
370 int GetBorder() const
373 wxWindow
*GetWindow() const
374 { return m_kind
== Item_Window
? m_window
: NULL
; }
375 wxSizer
*GetSizer() const
376 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
377 wxSize
GetSpacer() const;
379 // This function behaves obviously for the windows and spacers but for the
380 // sizers it returns true if any sizer element is shown and only returns
381 // false if all of them are hidden. Also, it always returns true if
382 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
383 bool IsShown() const;
385 void Show(bool show
);
387 void SetUserData(wxObject
* userData
)
388 { delete m_userData
; m_userData
= userData
; }
389 wxObject
* GetUserData() const
390 { return m_userData
; }
391 wxPoint
GetPosition() const
394 // Called once the first component of an item has been decided. This is
395 // used in algorithms that depend on knowing the size in one direction
396 // before the min size in the other direction can be known.
397 // Returns true if it made use of the information (and min size was changed).
398 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
400 // these functions delete the current contents of the item if it's a sizer
401 // or a spacer but not if it is a window
402 void AssignWindow(wxWindow
*window
)
408 void AssignSizer(wxSizer
*sizer
)
414 void AssignSpacer(const wxSize
& size
)
420 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
422 #if WXWIN_COMPATIBILITY_2_8
423 // these functions do not free the old sizer/spacer and so can easily
424 // provoke the memory leaks and so shouldn't be used, use Assign() instead
425 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
426 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
427 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
428 wxDEPRECATED( void SetSpacer(int width
, int height
) );
429 #endif // WXWIN_COMPATIBILITY_2_8
432 // common part of several ctors
433 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
435 // common part of ctors taking wxSizerFlags
436 void Init(const wxSizerFlags
& flags
);
438 // free current contents
441 // common parts of Set/AssignXXX()
442 void DoSetWindow(wxWindow
*window
);
443 void DoSetSizer(wxSizer
*sizer
);
444 void DoSetSpacer(const wxSize
& size
);
446 // Add the border specified for this item to the given size
447 // if it's != wxDefaultSize, just return wxDefaultSize otherwise.
448 wxSize
AddBorderToSize(const wxSize
& size
) const;
450 // discriminated union: depending on m_kind one of the fields is valid
463 wxSizerSpacer
*m_spacer
;
473 // on screen rectangle of this item (not including borders)
476 // Aspect ratio can always be calculated from m_size,
477 // but this would cause precision loss when the window
478 // is shrunk. It is safer to preserve the initial value.
481 wxObject
*m_userData
;
484 DECLARE_CLASS(wxSizerItem
)
485 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
488 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
491 //---------------------------------------------------------------------------
493 //---------------------------------------------------------------------------
495 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
498 wxSizer() { m_containingWindow
= NULL
; }
501 // methods for adding elements to the sizer: there are Add/Insert/Prepend
502 // overloads for each of window/sizer/spacer/wxSizerItem
503 wxSizerItem
* Add(wxWindow
*window
,
507 wxObject
* userData
= NULL
);
508 wxSizerItem
* Add(wxSizer
*sizer
,
512 wxObject
* userData
= NULL
);
513 wxSizerItem
* Add(int width
,
518 wxObject
* userData
= NULL
);
519 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
520 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
521 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
522 wxSizerItem
* Add( wxSizerItem
*item
);
524 virtual wxSizerItem
*AddSpacer(int size
);
525 wxSizerItem
* AddStretchSpacer(int prop
= 1);
527 wxSizerItem
* Insert(size_t index
,
532 wxObject
* userData
= NULL
);
533 wxSizerItem
* Insert(size_t index
,
538 wxObject
* userData
= NULL
);
539 wxSizerItem
* Insert(size_t index
,
545 wxObject
* userData
= NULL
);
546 wxSizerItem
* Insert(size_t index
,
548 const wxSizerFlags
& flags
);
549 wxSizerItem
* Insert(size_t index
,
551 const wxSizerFlags
& flags
);
552 wxSizerItem
* Insert(size_t index
,
555 const wxSizerFlags
& flags
);
557 // NB: do _not_ override this function in the derived classes, this one is
558 // virtual for compatibility reasons only to allow old code overriding
559 // it to continue to work, override DoInsert() instead in the new code
560 virtual wxSizerItem
* Insert(size_t index
, wxSizerItem
*item
);
562 wxSizerItem
* InsertSpacer(size_t index
, int size
);
563 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
565 wxSizerItem
* Prepend(wxWindow
*window
,
569 wxObject
* userData
= NULL
);
570 wxSizerItem
* Prepend(wxSizer
*sizer
,
574 wxObject
* userData
= NULL
);
575 wxSizerItem
* Prepend(int width
,
580 wxObject
* userData
= NULL
);
581 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
582 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
583 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
584 wxSizerItem
* Prepend(wxSizerItem
*item
);
586 wxSizerItem
* PrependSpacer(int size
);
587 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
589 // set (or possibly unset if window is NULL) or get the window this sizer
591 void SetContainingWindow(wxWindow
*window
);
592 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
594 #if WXWIN_COMPATIBILITY_2_6
595 // Deprecated in 2.6 since historically it does not delete the window,
596 // use Detach instead.
597 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
598 #endif // WXWIN_COMPATIBILITY_2_6
600 virtual bool Remove( wxSizer
*sizer
);
601 virtual bool Remove( int index
);
603 virtual bool Detach( wxWindow
*window
);
604 virtual bool Detach( wxSizer
*sizer
);
605 virtual bool Detach( int index
);
607 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
608 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
609 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
611 virtual void Clear( bool delete_windows
= false );
612 virtual void DeleteWindows();
614 // Inform sizer about the first direction that has been decided (by parent item)
615 // Returns true if it made use of the information (and recalculated min size)
616 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
619 void SetMinSize( int width
, int height
)
620 { DoSetMinSize( width
, height
); }
621 void SetMinSize( const wxSize
& size
)
622 { DoSetMinSize( size
.x
, size
.y
); }
624 // Searches recursively
625 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
626 { return DoSetItemMinSize( window
, width
, height
); }
627 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
628 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
630 // Searches recursively
631 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
632 { return DoSetItemMinSize( sizer
, width
, height
); }
633 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
634 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
636 bool SetItemMinSize( size_t index
, int width
, int height
)
637 { return DoSetItemMinSize( index
, width
, height
); }
638 bool SetItemMinSize( size_t index
, const wxSize
& size
)
639 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
641 wxSize
GetSize() const
643 wxPoint
GetPosition() const
644 { return m_position
; }
646 // Calculate the minimal size or return m_minSize if bigger.
649 // These virtual functions are used by the layout algorithm: first
650 // CalcMin() is called to calculate the minimal size of the sizer and
651 // prepare for laying it out and then RecalcSizes() is called to really
652 // update all the sizer items
653 virtual wxSize
CalcMin() = 0;
654 virtual void RecalcSizes() = 0;
656 virtual void Layout();
658 wxSize
ComputeFittingClientSize(wxWindow
*window
);
659 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
661 wxSize
Fit( wxWindow
*window
);
662 void FitInside( wxWindow
*window
);
663 void SetSizeHints( wxWindow
*window
);
664 #if WXWIN_COMPATIBILITY_2_8
665 // This only calls FitInside() since 2.9
666 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
669 wxSizerItemList
& GetChildren()
670 { return m_children
; }
671 const wxSizerItemList
& GetChildren() const
672 { return m_children
; }
674 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
680 // This call is required for wxWrapSizer to be able to calculate its
681 // minimal size correctly.
682 InformFirstDirection(wxHORIZONTAL
, size
.x
, size
.y
);
684 void SetDimension(int x
, int y
, int width
, int height
)
685 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
687 size_t GetItemCount() const { return m_children
.GetCount(); }
688 bool IsEmpty() const { return m_children
.IsEmpty(); }
690 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
691 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
692 wxSizerItem
* GetItem( size_t index
);
693 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
695 // Manage whether individual scene items are considered
696 // in the layout calculations or not.
697 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
698 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
699 bool Show( size_t index
, bool show
= true );
701 bool Hide( wxSizer
*sizer
, bool recursive
= false )
702 { return Show( sizer
, false, recursive
); }
703 bool Hide( wxWindow
*window
, bool recursive
= false )
704 { return Show( window
, false, recursive
); }
705 bool Hide( size_t index
)
706 { return Show( index
, false ); }
708 bool IsShown( wxWindow
*window
) const;
709 bool IsShown( wxSizer
*sizer
) const;
710 bool IsShown( size_t index
) const;
712 // Recursively call wxWindow::Show () on all sizer items.
713 virtual void ShowItems (bool show
);
715 void Show(bool show
) { ShowItems(show
); }
717 // This is the ShowItems() counterpart and returns true if any of the sizer
719 virtual bool AreAnyItemsShown() const;
725 wxSizerItemList m_children
;
727 // the window this sizer is used in, can be NULL
728 wxWindow
*m_containingWindow
;
730 wxSize
GetMaxClientSize( wxWindow
*window
) const;
731 wxSize
GetMinClientSize( wxWindow
*window
);
732 wxSize
VirtualFitSize( wxWindow
*window
);
734 virtual void DoSetMinSize( int width
, int height
);
735 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
736 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
737 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
739 // insert a new item into m_children at given index and return the item
741 virtual wxSizerItem
* DoInsert(size_t index
, wxSizerItem
*item
);
744 DECLARE_CLASS(wxSizer
)
747 //---------------------------------------------------------------------------
749 //---------------------------------------------------------------------------
751 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
754 // ctors specifying the number of columns only: number of rows will be
755 // deduced automatically depending on the number of sizer elements
756 wxGridSizer( int cols
, int vgap
, int hgap
);
757 wxGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
759 // ctors specifying the number of rows and columns
760 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
761 wxGridSizer( int rows
, int cols
, const wxSize
& gap
);
763 virtual void RecalcSizes();
764 virtual wxSize
CalcMin();
766 void SetCols( int cols
)
768 wxASSERT_MSG( cols
>= 0, "Number of columns must be non-negative");
772 void SetRows( int rows
)
774 wxASSERT_MSG( rows
>= 0, "Number of rows must be non-negative");
778 void SetVGap( int gap
) { m_vgap
= gap
; }
779 void SetHGap( int gap
) { m_hgap
= gap
; }
780 int GetCols() const { return m_cols
; }
781 int GetRows() const { return m_rows
; }
782 int GetVGap() const { return m_vgap
; }
783 int GetHGap() const { return m_hgap
; }
785 int GetEffectiveColsCount() const { return m_cols
? m_cols
: CalcCols(); }
786 int GetEffectiveRowsCount() const { return m_rows
? m_rows
: CalcRows(); }
788 // return the number of total items and the number of columns and rows
789 // (for internal use only)
790 int CalcRowsCols(int& rows
, int& cols
) const;
793 // the number of rows/columns in the sizer, if 0 then it is determined
794 // dynamically depending on the total number of items
798 // gaps between rows and columns
802 virtual wxSizerItem
*DoInsert(size_t index
, wxSizerItem
*item
);
804 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
806 // returns the number of columns/rows needed for the current total number
807 // of children (and the fixed number of rows/columns)
813 "Can't calculate number of cols if number of rows is not specified"
816 return int(m_children
.GetCount() + m_rows
- 1) / m_rows
;
824 "Can't calculate number of cols if number of rows is not specified"
827 return int(m_children
.GetCount() + m_cols
- 1) / m_cols
;
831 DECLARE_CLASS(wxGridSizer
)
834 //---------------------------------------------------------------------------
836 //---------------------------------------------------------------------------
838 // values which define the behaviour for resizing wxFlexGridSizer cells in the
839 // "non-flexible" direction
840 enum wxFlexSizerGrowMode
842 // don't resize the cells in non-flexible direction at all
843 wxFLEX_GROWMODE_NONE
,
845 // uniformly resize only the specified ones (default)
846 wxFLEX_GROWMODE_SPECIFIED
,
848 // uniformly resize all cells
852 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
855 // ctors specifying the number of columns only: number of rows will be
856 // deduced automatically depending on the number of sizer elements
857 wxFlexGridSizer( int cols
, int vgap
, int hgap
);
858 wxFlexGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
860 // ctors specifying the number of rows and columns
861 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
862 wxFlexGridSizer( int rows
, int cols
, const wxSize
& gap
);
865 virtual ~wxFlexGridSizer();
867 // set the rows/columns which will grow (the others will remain of the
868 // constant initial size)
869 void AddGrowableRow( size_t idx
, int proportion
= 0 );
870 void RemoveGrowableRow( size_t idx
);
871 void AddGrowableCol( size_t idx
, int proportion
= 0 );
872 void RemoveGrowableCol( size_t idx
);
874 bool IsRowGrowable( size_t idx
);
875 bool IsColGrowable( size_t idx
);
877 // the sizer cells may grow in both directions, not grow at all or only
878 // grow in one direction but not the other
880 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
881 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
882 int GetFlexibleDirection() const { return m_flexDirection
; }
884 // note that the grow mode only applies to the direction which is not
886 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
887 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
889 // Read-only access to the row heights and col widths arrays
890 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
891 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
894 virtual void RecalcSizes();
895 virtual wxSize
CalcMin();
898 void AdjustForFlexDirection();
899 void AdjustForGrowables(const wxSize
& sz
);
900 void FindWidthsAndHeights(int nrows
, int ncols
);
902 // the heights/widths of all rows/columns
903 wxArrayInt m_rowHeights
,
906 // indices of the growable columns and rows
907 wxArrayInt m_growableRows
,
910 // proportion values of the corresponding growable rows and columns
911 wxArrayInt m_growableRowsProportions
,
912 m_growableColsProportions
;
914 // parameters describing whether the growable cells should be resized in
915 // both directions or only one
917 wxFlexSizerGrowMode m_growMode
;
919 // saves CalcMin result to optimize RecalcSizes
920 wxSize m_calculatedMinSize
;
923 DECLARE_CLASS(wxFlexGridSizer
)
924 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
927 //---------------------------------------------------------------------------
929 //---------------------------------------------------------------------------
931 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
934 wxBoxSizer(int orient
)
937 m_totalProportion
= 0;
939 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
940 wxT("invalid value for wxBoxSizer orientation") );
943 virtual wxSizerItem
*AddSpacer(int size
);
945 int GetOrientation() const { return m_orient
; }
947 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
949 void SetOrientation(int orient
) { m_orient
= orient
; }
951 // implementation of our resizing logic
952 virtual wxSize
CalcMin();
953 virtual void RecalcSizes();
956 // helpers for our code: this returns the component of the given wxSize in
957 // the direction of the sizer and in the other direction, respectively
958 int GetSizeInMajorDir(const wxSize
& sz
) const
960 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
963 int& SizeInMajorDir(wxSize
& sz
)
965 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
968 int& PosInMajorDir(wxPoint
& pt
)
970 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
973 int GetSizeInMinorDir(const wxSize
& sz
) const
975 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
978 int& SizeInMinorDir(wxSize
& sz
)
980 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
983 int& PosInMinorDir(wxPoint
& pt
)
985 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
988 // another helper: creates wxSize from major and minor components
989 wxSize
SizeFromMajorMinor(int major
, int minor
) const
991 if ( m_orient
== wxHORIZONTAL
)
993 return wxSize(major
, minor
);
997 return wxSize(minor
, major
);
1002 // either wxHORIZONTAL or wxVERTICAL
1005 // the sum of proportion of all of our elements
1006 int m_totalProportion
;
1008 // the minimal size needed for this sizer as calculated by the last call to
1013 DECLARE_CLASS(wxBoxSizer
)
1016 //---------------------------------------------------------------------------
1018 //---------------------------------------------------------------------------
1022 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
1024 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
1027 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
1028 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
1029 virtual ~wxStaticBoxSizer();
1034 wxStaticBox
*GetStaticBox() const
1035 { return m_staticBox
; }
1037 // override to hide/show the static box as well
1038 virtual void ShowItems (bool show
);
1039 virtual bool AreAnyItemsShown() const;
1041 virtual bool Detach( wxWindow
*window
);
1042 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
1043 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
1046 wxStaticBox
*m_staticBox
;
1049 DECLARE_CLASS(wxStaticBoxSizer
)
1050 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
1053 #endif // wxUSE_STATBOX
1055 //---------------------------------------------------------------------------
1056 // wxStdDialogButtonSizer
1057 //---------------------------------------------------------------------------
1061 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
1064 // Constructor just creates a new wxBoxSizer, not much else.
1065 // Box sizer orientation is automatically determined here:
1066 // vertical for PDAs, horizontal for everything else?
1067 wxStdDialogButtonSizer();
1069 // Checks button ID against system IDs and sets one of the pointers below
1070 // to this button. Does not do any sizer-related things here.
1071 void AddButton(wxButton
*button
);
1073 // Use these if no standard ID can/should be used
1074 void SetAffirmativeButton( wxButton
*button
);
1075 void SetNegativeButton( wxButton
*button
);
1076 void SetCancelButton( wxButton
*button
);
1078 // All platform-specific code here, checks which buttons exist and add
1079 // them to the sizer accordingly.
1080 // Note - one potential hack on Mac we could use here,
1081 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1082 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1083 // I wouldn't add any other hacks like that into here,
1084 // but this one I can see being useful.
1087 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1088 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1089 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1090 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1091 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1094 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1095 wxButton
*m_buttonApply
; // wxID_APPLY
1096 wxButton
*m_buttonNegative
; // wxID_NO
1097 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1098 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1101 DECLARE_CLASS(wxStdDialogButtonSizer
)
1102 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1105 #endif // wxUSE_BUTTON
1108 // ----------------------------------------------------------------------------
1109 // inline functions implementation
1110 // ----------------------------------------------------------------------------
1112 #if WXWIN_COMPATIBILITY_2_8
1114 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1116 DoSetWindow(window
);
1119 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1124 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1129 inline void wxSizerItem::SetSpacer(int width
, int height
)
1131 DoSetSpacer(wxSize(width
, height
));
1134 #endif // WXWIN_COMPATIBILITY_2_8
1137 wxSizer::Insert(size_t index
, wxSizerItem
*item
)
1139 return DoInsert(index
, item
);
1144 wxSizer::Add( wxSizerItem
*item
)
1146 return Insert( m_children
.GetCount(), item
);
1150 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1152 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1156 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1158 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1162 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1164 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1168 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1170 return Add( new wxSizerItem(window
, flags
) );
1174 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1176 return Add( new wxSizerItem(sizer
, flags
) );
1180 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1182 return Add( new wxSizerItem(width
, height
, flags
) );
1186 wxSizer::AddSpacer(int size
)
1188 return Add(size
, size
);
1192 wxSizer::AddStretchSpacer(int prop
)
1194 return Add(0, 0, prop
);
1198 wxSizer::Prepend( wxSizerItem
*item
)
1200 return Insert( 0, item
);
1204 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1206 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1210 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1212 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1216 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1218 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1222 wxSizer::PrependSpacer(int size
)
1224 return Prepend(size
, size
);
1228 wxSizer::PrependStretchSpacer(int prop
)
1230 return Prepend(0, 0, prop
);
1234 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1236 return Prepend( new wxSizerItem(window
, flags
) );
1240 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1242 return Prepend( new wxSizerItem(sizer
, flags
) );
1246 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1248 return Prepend( new wxSizerItem(width
, height
, flags
) );
1252 wxSizer::Insert( size_t index
,
1257 wxObject
* userData
)
1259 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1263 wxSizer::Insert( size_t index
,
1268 wxObject
* userData
)
1270 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1274 wxSizer::Insert( size_t index
,
1280 wxObject
* userData
)
1282 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1286 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1288 return Insert( index
, new wxSizerItem(window
, flags
) );
1292 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1294 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1298 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1300 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1304 wxSizer::InsertSpacer(size_t index
, int size
)
1306 return Insert(index
, size
, size
);
1310 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1312 return Insert(index
, 0, 0, prop
);
1315 #endif // __WXSIZER_H__