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
=NULL
);
260 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
268 wxSizerItem( wxSizer
*sizer
,
272 wxObject
* userData
=NULL
);
275 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
283 wxSizerItem( int width
,
288 wxObject
* userData
=NULL
);
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 wxSize
GetMaxSize() const
315 { return IsWindow() ? m_window
->GetMaxSize() : wxDefaultSize
; }
316 wxSize
GetMaxSizeWithBorder() const;
318 void SetMinSize(const wxSize
& size
)
321 m_window
->SetMinSize(size
);
324 void SetMinSize( int x
, int y
)
325 { SetMinSize(wxSize(x
, y
)); }
326 void SetInitSize( int x
, int y
)
327 { SetMinSize(wxSize(x
, y
)); }
329 // if either of dimensions is zero, ratio is assumed to be 1
330 // to avoid "divide by zero" errors
331 void SetRatio(int width
, int height
)
332 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
333 void SetRatio(const wxSize
& size
)
334 { SetRatio(size
.x
, size
.y
); }
335 void SetRatio(float ratio
)
337 float GetRatio() const
340 virtual wxRect
GetRect() { return m_rect
; }
342 // set a sizer item id (different from a window id, all sizer items,
343 // including spacers, can have an associated id)
344 void SetId(int id
) { m_id
= id
; }
345 int GetId() const { return m_id
; }
347 bool IsWindow() const { return m_kind
== Item_Window
; }
348 bool IsSizer() const { return m_kind
== Item_Sizer
; }
349 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
351 #if WXWIN_COMPATIBILITY_2_6
352 // Deprecated in 2.6, use {G,S}etProportion instead.
353 wxDEPRECATED( void SetOption( int option
) );
354 wxDEPRECATED( int GetOption() const );
355 #endif // WXWIN_COMPATIBILITY_2_6
357 void SetProportion( int proportion
)
358 { m_proportion
= proportion
; }
359 int GetProportion() const
360 { return m_proportion
; }
361 void SetFlag( int flag
)
365 void SetBorder( int border
)
366 { m_border
= border
; }
367 int GetBorder() const
370 wxWindow
*GetWindow() const
371 { return m_kind
== Item_Window
? m_window
: NULL
; }
372 wxSizer
*GetSizer() const
373 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
374 wxSize
GetSpacer() const;
376 // This function behaves obviously for the windows and spacers but for the
377 // sizers it returns true if any sizer element is shown and only returns
378 // false if all of them are hidden. Also, it always returns true if
379 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
380 bool IsShown() const;
382 void Show(bool show
);
384 void SetUserData(wxObject
* userData
)
385 { delete m_userData
; m_userData
= userData
; }
386 wxObject
* GetUserData() const
387 { return m_userData
; }
388 wxPoint
GetPosition() const
391 // Called once the first component of an item has been decided. This is
392 // used in algorithms that depend on knowing the size in one direction
393 // before the min size in the other direction can be known.
394 // Returns true if it made use of the information (and min size was changed).
395 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
397 // these functions delete the current contents of the item if it's a sizer
398 // or a spacer but not if it is a window
399 void AssignWindow(wxWindow
*window
)
405 void AssignSizer(wxSizer
*sizer
)
411 void AssignSpacer(const wxSize
& size
)
417 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
419 #if WXWIN_COMPATIBILITY_2_8
420 // these functions do not free the old sizer/spacer and so can easily
421 // provoke the memory leaks and so shouldn't be used, use Assign() instead
422 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
423 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
424 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
425 wxDEPRECATED( void SetSpacer(int width
, int height
) );
426 #endif // WXWIN_COMPATIBILITY_2_8
429 // common part of several ctors
430 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
432 // common part of ctors taking wxSizerFlags
433 void Init(const wxSizerFlags
& flags
);
435 // free current contents
438 // common parts of Set/AssignXXX()
439 void DoSetWindow(wxWindow
*window
);
440 void DoSetSizer(wxSizer
*sizer
);
441 void DoSetSpacer(const wxSize
& size
);
443 // Add the border specified for this item to the given size
444 // if it's != wxDefaultSize, just return wxDefaultSize otherwise.
445 wxSize
AddBorderToSize(const wxSize
& size
) const;
447 // discriminated union: depending on m_kind one of the fields is valid
460 wxSizerSpacer
*m_spacer
;
470 // on screen rectangle of this item (not including borders)
473 // Aspect ratio can always be calculated from m_size,
474 // but this would cause precision loss when the window
475 // is shrunk. It is safer to preserve the initial value.
478 wxObject
*m_userData
;
481 DECLARE_CLASS(wxSizerItem
)
482 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
485 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
488 //---------------------------------------------------------------------------
490 //---------------------------------------------------------------------------
492 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
495 wxSizer() { m_containingWindow
= NULL
; }
498 // methods for adding elements to the sizer: there are Add/Insert/Prepend
499 // overloads for each of window/sizer/spacer/wxSizerItem
500 wxSizerItem
* Add(wxWindow
*window
,
504 wxObject
* userData
= NULL
);
505 wxSizerItem
* Add(wxSizer
*sizer
,
509 wxObject
* userData
= NULL
);
510 wxSizerItem
* Add(int width
,
515 wxObject
* userData
= NULL
);
516 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
517 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
518 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
519 wxSizerItem
* Add( wxSizerItem
*item
);
521 virtual wxSizerItem
*AddSpacer(int size
);
522 wxSizerItem
* AddStretchSpacer(int prop
= 1);
524 wxSizerItem
* Insert(size_t index
,
529 wxObject
* userData
= NULL
);
530 wxSizerItem
* Insert(size_t index
,
535 wxObject
* userData
= NULL
);
536 wxSizerItem
* Insert(size_t index
,
542 wxObject
* userData
= NULL
);
543 wxSizerItem
* Insert(size_t index
,
545 const wxSizerFlags
& flags
);
546 wxSizerItem
* Insert(size_t index
,
548 const wxSizerFlags
& flags
);
549 wxSizerItem
* Insert(size_t index
,
552 const wxSizerFlags
& flags
);
554 // NB: do _not_ override this function in the derived classes, this one is
555 // virtual for compatibility reasons only to allow old code overriding
556 // it to continue to work, override DoInsert() instead in the new code
557 virtual wxSizerItem
* Insert(size_t index
, wxSizerItem
*item
);
559 wxSizerItem
* InsertSpacer(size_t index
, int size
);
560 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
562 wxSizerItem
* Prepend(wxWindow
*window
,
566 wxObject
* userData
= NULL
);
567 wxSizerItem
* Prepend(wxSizer
*sizer
,
571 wxObject
* userData
= NULL
);
572 wxSizerItem
* Prepend(int width
,
577 wxObject
* userData
= NULL
);
578 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
579 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
580 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
581 wxSizerItem
* Prepend(wxSizerItem
*item
);
583 wxSizerItem
* PrependSpacer(int size
);
584 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
586 // set (or possibly unset if window is NULL) or get the window this sizer
588 void SetContainingWindow(wxWindow
*window
);
589 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
591 #if WXWIN_COMPATIBILITY_2_6
592 // Deprecated in 2.6 since historically it does not delete the window,
593 // use Detach instead.
594 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
595 #endif // WXWIN_COMPATIBILITY_2_6
597 virtual bool Remove( wxSizer
*sizer
);
598 virtual bool Remove( int index
);
600 virtual bool Detach( wxWindow
*window
);
601 virtual bool Detach( wxSizer
*sizer
);
602 virtual bool Detach( int index
);
604 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
605 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
606 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
608 virtual void Clear( bool delete_windows
= false );
609 virtual void DeleteWindows();
611 // Inform sizer about the first direction that has been decided (by parent item)
612 // Returns true if it made use of the information (and recalculated min size)
613 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
616 void SetMinSize( int width
, int height
)
617 { DoSetMinSize( width
, height
); }
618 void SetMinSize( const wxSize
& size
)
619 { DoSetMinSize( size
.x
, size
.y
); }
621 // Searches recursively
622 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
623 { return DoSetItemMinSize( window
, width
, height
); }
624 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
625 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
627 // Searches recursively
628 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
629 { return DoSetItemMinSize( sizer
, width
, height
); }
630 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
631 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
633 bool SetItemMinSize( size_t index
, int width
, int height
)
634 { return DoSetItemMinSize( index
, width
, height
); }
635 bool SetItemMinSize( size_t index
, const wxSize
& size
)
636 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
638 wxSize
GetSize() const
640 wxPoint
GetPosition() const
641 { return m_position
; }
643 // Calculate the minimal size or return m_minSize if bigger.
646 // These virtual functions are used by the layout algorithm: first
647 // CalcMin() is called to calculate the minimal size of the sizer and
648 // prepare for laying it out and then RecalcSizes() is called to really
649 // update all the sizer items
650 virtual wxSize
CalcMin() = 0;
651 virtual void RecalcSizes() = 0;
653 virtual void Layout();
655 wxSize
ComputeFittingClientSize(wxWindow
*window
);
656 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
658 wxSize
Fit( wxWindow
*window
);
659 void FitInside( wxWindow
*window
);
660 void SetSizeHints( wxWindow
*window
);
661 #if WXWIN_COMPATIBILITY_2_8
662 // This only calls FitInside() since 2.9
663 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
666 wxSizerItemList
& GetChildren()
667 { return m_children
; }
668 const wxSizerItemList
& GetChildren() const
669 { return m_children
; }
671 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
677 // This call is required for wxWrapSizer to be able to calculate its
678 // minimal size correctly.
679 InformFirstDirection(wxHORIZONTAL
, size
.x
, size
.y
);
681 void SetDimension(int x
, int y
, int width
, int height
)
682 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
684 size_t GetItemCount() const { return m_children
.GetCount(); }
685 bool IsEmpty() const { return m_children
.IsEmpty(); }
687 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
688 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
689 wxSizerItem
* GetItem( size_t index
);
690 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
692 // Manage whether individual scene items are considered
693 // in the layout calculations or not.
694 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
695 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
696 bool Show( size_t index
, bool show
= true );
698 bool Hide( wxSizer
*sizer
, bool recursive
= false )
699 { return Show( sizer
, false, recursive
); }
700 bool Hide( wxWindow
*window
, bool recursive
= false )
701 { return Show( window
, false, recursive
); }
702 bool Hide( size_t index
)
703 { return Show( index
, false ); }
705 bool IsShown( wxWindow
*window
) const;
706 bool IsShown( wxSizer
*sizer
) const;
707 bool IsShown( size_t index
) const;
709 // Recursively call wxWindow::Show () on all sizer items.
710 virtual void ShowItems (bool show
);
712 void Show(bool show
) { ShowItems(show
); }
718 wxSizerItemList m_children
;
720 // the window this sizer is used in, can be NULL
721 wxWindow
*m_containingWindow
;
723 wxSize
GetMaxClientSize( wxWindow
*window
) const;
724 wxSize
GetMinClientSize( wxWindow
*window
);
725 wxSize
VirtualFitSize( wxWindow
*window
);
727 virtual void DoSetMinSize( int width
, int height
);
728 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
729 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
730 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
732 // insert a new item into m_children at given index and return the item
734 virtual wxSizerItem
* DoInsert(size_t index
, wxSizerItem
*item
);
737 DECLARE_CLASS(wxSizer
)
740 //---------------------------------------------------------------------------
742 //---------------------------------------------------------------------------
744 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
747 // ctors specifying the number of columns only: number of rows will be
748 // deduced automatically depending on the number of sizer elements
749 wxGridSizer( int cols
, int vgap
, int hgap
);
750 wxGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
752 // ctors specifying the number of rows and columns
753 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
754 wxGridSizer( int rows
, int cols
, const wxSize
& gap
);
756 virtual void RecalcSizes();
757 virtual wxSize
CalcMin();
759 void SetCols( int cols
)
761 wxASSERT_MSG( cols
>= 0, "Number of columns must be non-negative");
765 void SetRows( int rows
)
767 wxASSERT_MSG( rows
>= 0, "Number of rows must be non-negative");
771 void SetVGap( int gap
) { m_vgap
= gap
; }
772 void SetHGap( int gap
) { m_hgap
= gap
; }
773 int GetCols() const { return m_cols
; }
774 int GetRows() const { return m_rows
; }
775 int GetVGap() const { return m_vgap
; }
776 int GetHGap() const { return m_hgap
; }
778 int GetEffectiveColsCount() const { return m_cols
? m_cols
: CalcCols(); }
779 int GetEffectiveRowsCount() const { return m_rows
? m_rows
: CalcRows(); }
781 // return the number of total items and the number of columns and rows
782 // (for internal use only)
783 int CalcRowsCols(int& rows
, int& cols
) const;
786 // the number of rows/columns in the sizer, if 0 then it is determined
787 // dynamically depending on the total number of items
791 // gaps between rows and columns
795 virtual wxSizerItem
*DoInsert(size_t index
, wxSizerItem
*item
);
797 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
799 // returns the number of columns/rows needed for the current total number
800 // of children (and the fixed number of rows/columns)
806 "Can't calculate number of cols if number of rows is not specified"
809 return (m_children
.GetCount() + m_rows
- 1) / m_rows
;
817 "Can't calculate number of cols if number of rows is not specified"
820 return (m_children
.GetCount() + m_cols
- 1) / m_cols
;
824 DECLARE_CLASS(wxGridSizer
)
827 //---------------------------------------------------------------------------
829 //---------------------------------------------------------------------------
831 // values which define the behaviour for resizing wxFlexGridSizer cells in the
832 // "non-flexible" direction
833 enum wxFlexSizerGrowMode
835 // don't resize the cells in non-flexible direction at all
836 wxFLEX_GROWMODE_NONE
,
838 // uniformly resize only the specified ones (default)
839 wxFLEX_GROWMODE_SPECIFIED
,
841 // uniformly resize all cells
845 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
848 // ctors specifying the number of columns only: number of rows will be
849 // deduced automatically depending on the number of sizer elements
850 wxFlexGridSizer( int cols
, int vgap
, int hgap
);
851 wxFlexGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
853 // ctors specifying the number of rows and columns
854 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
855 wxFlexGridSizer( int rows
, int cols
, const wxSize
& gap
);
858 virtual ~wxFlexGridSizer();
860 // set the rows/columns which will grow (the others will remain of the
861 // constant initial size)
862 void AddGrowableRow( size_t idx
, int proportion
= 0 );
863 void RemoveGrowableRow( size_t idx
);
864 void AddGrowableCol( size_t idx
, int proportion
= 0 );
865 void RemoveGrowableCol( size_t idx
);
867 bool IsRowGrowable( size_t idx
);
868 bool IsColGrowable( size_t idx
);
870 // the sizer cells may grow in both directions, not grow at all or only
871 // grow in one direction but not the other
873 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
874 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
875 int GetFlexibleDirection() const { return m_flexDirection
; }
877 // note that the grow mode only applies to the direction which is not
879 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
880 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
882 // Read-only access to the row heights and col widths arrays
883 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
884 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
887 virtual void RecalcSizes();
888 virtual wxSize
CalcMin();
891 void AdjustForFlexDirection();
892 void AdjustForGrowables(const wxSize
& sz
);
893 void FindWidthsAndHeights(int nrows
, int ncols
);
895 // the heights/widths of all rows/columns
896 wxArrayInt m_rowHeights
,
899 // indices of the growable columns and rows
900 wxArrayInt m_growableRows
,
903 // proportion values of the corresponding growable rows and columns
904 wxArrayInt m_growableRowsProportions
,
905 m_growableColsProportions
;
907 // parameters describing whether the growable cells should be resized in
908 // both directions or only one
910 wxFlexSizerGrowMode m_growMode
;
912 // saves CalcMin result to optimize RecalcSizes
913 wxSize m_calculatedMinSize
;
916 DECLARE_CLASS(wxFlexGridSizer
)
917 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
920 //---------------------------------------------------------------------------
922 //---------------------------------------------------------------------------
924 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
927 wxBoxSizer(int orient
)
930 m_totalProportion
= 0;
932 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
933 wxT("invalid value for wxBoxSizer orientation") );
936 virtual wxSizerItem
*AddSpacer(int size
);
938 int GetOrientation() const { return m_orient
; }
940 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
942 void SetOrientation(int orient
) { m_orient
= orient
; }
944 // implementation of our resizing logic
945 virtual wxSize
CalcMin();
946 virtual void RecalcSizes();
949 // helpers for our code: this returns the component of the given wxSize in
950 // the direction of the sizer and in the other direction, respectively
951 int GetSizeInMajorDir(const wxSize
& sz
) const
953 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
956 int& SizeInMajorDir(wxSize
& sz
)
958 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
961 int& PosInMajorDir(wxPoint
& pt
)
963 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
966 int GetSizeInMinorDir(const wxSize
& sz
) const
968 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
971 int& SizeInMinorDir(wxSize
& sz
)
973 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
976 int& PosInMinorDir(wxPoint
& pt
)
978 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
981 // another helper: creates wxSize from major and minor components
982 wxSize
SizeFromMajorMinor(int major
, int minor
) const
984 if ( m_orient
== wxHORIZONTAL
)
986 return wxSize(major
, minor
);
990 return wxSize(minor
, major
);
995 // either wxHORIZONTAL or wxVERTICAL
998 // the sum of proportion of all of our elements
999 int m_totalProportion
;
1001 // the minimal size needed for this sizer as calculated by the last call to
1006 DECLARE_CLASS(wxBoxSizer
)
1009 //---------------------------------------------------------------------------
1011 //---------------------------------------------------------------------------
1015 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
1017 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
1020 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
1021 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
1022 virtual ~wxStaticBoxSizer();
1027 wxStaticBox
*GetStaticBox() const
1028 { return m_staticBox
; }
1030 // override to hide/show the static box as well
1031 virtual void ShowItems (bool show
);
1033 virtual bool Detach( wxWindow
*window
);
1034 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
1035 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
1038 wxStaticBox
*m_staticBox
;
1041 DECLARE_CLASS(wxStaticBoxSizer
)
1042 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
1045 #endif // wxUSE_STATBOX
1047 //---------------------------------------------------------------------------
1048 // wxStdDialogButtonSizer
1049 //---------------------------------------------------------------------------
1053 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
1056 // Constructor just creates a new wxBoxSizer, not much else.
1057 // Box sizer orientation is automatically determined here:
1058 // vertical for PDAs, horizontal for everything else?
1059 wxStdDialogButtonSizer();
1061 // Checks button ID against system IDs and sets one of the pointers below
1062 // to this button. Does not do any sizer-related things here.
1063 void AddButton(wxButton
*button
);
1065 // Use these if no standard ID can/should be used
1066 void SetAffirmativeButton( wxButton
*button
);
1067 void SetNegativeButton( wxButton
*button
);
1068 void SetCancelButton( wxButton
*button
);
1070 // All platform-specific code here, checks which buttons exist and add
1071 // them to the sizer accordingly.
1072 // Note - one potential hack on Mac we could use here,
1073 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1074 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1075 // I wouldn't add any other hacks like that into here,
1076 // but this one I can see being useful.
1079 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1080 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1081 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1082 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1083 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1086 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1087 wxButton
*m_buttonApply
; // wxID_APPLY
1088 wxButton
*m_buttonNegative
; // wxID_NO
1089 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1090 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1093 DECLARE_CLASS(wxStdDialogButtonSizer
)
1094 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1097 #endif // wxUSE_BUTTON
1100 // ----------------------------------------------------------------------------
1101 // inline functions implementation
1102 // ----------------------------------------------------------------------------
1104 #if WXWIN_COMPATIBILITY_2_8
1106 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1108 DoSetWindow(window
);
1111 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1116 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1121 inline void wxSizerItem::SetSpacer(int width
, int height
)
1123 DoSetSpacer(wxSize(width
, height
));
1126 #endif // WXWIN_COMPATIBILITY_2_8
1129 wxSizer::Insert(size_t index
, wxSizerItem
*item
)
1131 return DoInsert(index
, item
);
1136 wxSizer::Add( wxSizerItem
*item
)
1138 return Insert( m_children
.GetCount(), item
);
1142 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1144 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1148 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1150 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1154 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1156 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1160 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1162 return Add( new wxSizerItem(window
, flags
) );
1166 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1168 return Add( new wxSizerItem(sizer
, flags
) );
1172 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1174 return Add( new wxSizerItem(width
, height
, flags
) );
1178 wxSizer::AddSpacer(int size
)
1180 return Add(size
, size
);
1184 wxSizer::AddStretchSpacer(int prop
)
1186 return Add(0, 0, prop
);
1190 wxSizer::Prepend( wxSizerItem
*item
)
1192 return Insert( 0, item
);
1196 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1198 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1202 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1204 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1208 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1210 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1214 wxSizer::PrependSpacer(int size
)
1216 return Prepend(size
, size
);
1220 wxSizer::PrependStretchSpacer(int prop
)
1222 return Prepend(0, 0, prop
);
1226 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1228 return Prepend( new wxSizerItem(window
, flags
) );
1232 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1234 return Prepend( new wxSizerItem(sizer
, flags
) );
1238 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1240 return Prepend( new wxSizerItem(width
, height
, flags
) );
1244 wxSizer::Insert( size_t index
,
1249 wxObject
* userData
)
1251 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1255 wxSizer::Insert( size_t index
,
1260 wxObject
* userData
)
1262 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1266 wxSizer::Insert( size_t index
,
1272 wxObject
* userData
)
1274 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1278 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1280 return Insert( index
, new wxSizerItem(window
, flags
) );
1284 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1286 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1290 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1292 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1296 wxSizer::InsertSpacer(size_t index
, int size
)
1298 return Insert(index
, size
, size
);
1302 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1304 return Insert(index
, 0, 0, prop
);
1307 #endif // __WXSIZER_H__