1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
8 // Copyright: (c) Robin Dunn, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/window.h"
19 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
23 class WXDLLIMPEXP_FWD_CORE wxButton
;
24 class WXDLLIMPEXP_FWD_CORE wxBoxSizer
;
25 class WXDLLIMPEXP_FWD_CORE wxSizerItem
;
26 class WXDLLIMPEXP_FWD_CORE wxSizer
;
28 #ifndef wxUSE_BORDER_BY_DEFAULT
30 // no borders by default on limited size screen
31 #define wxUSE_BORDER_BY_DEFAULT 0
33 #define wxUSE_BORDER_BY_DEFAULT 1
37 // ----------------------------------------------------------------------------
38 // wxSizerFlags: flags used for an item in the sizer
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxSizerFlags
44 // construct the flags object initialized with the given proportion (0 by
46 wxSizerFlags(int proportion
= 0) : m_proportion(proportion
)
52 // setters for all sizer flags, they all return the object itself so that
53 // calls to them can be chained
55 wxSizerFlags
& Proportion(int proportion
)
57 m_proportion
= proportion
;
61 wxSizerFlags
& Expand()
67 // notice that Align() replaces the current alignment flags, use specific
68 // methods below such as Top(), Left() &c if you want to set just the
69 // vertical or horizontal alignment
70 wxSizerFlags
& Align(int alignment
) // combination of wxAlignment values
72 m_flags
&= ~wxALIGN_MASK
;
78 // some shortcuts for Align()
79 wxSizerFlags
& Centre() { return Align(wxALIGN_CENTRE
); }
80 wxSizerFlags
& Center() { return Centre(); }
84 m_flags
&= ~(wxALIGN_BOTTOM
| wxALIGN_CENTRE_VERTICAL
);
90 m_flags
&= ~(wxALIGN_RIGHT
| wxALIGN_CENTRE_HORIZONTAL
);
96 m_flags
= (m_flags
& ~wxALIGN_CENTRE_HORIZONTAL
) | wxALIGN_RIGHT
;
100 wxSizerFlags
& Bottom()
102 m_flags
= (m_flags
& ~wxALIGN_CENTRE_VERTICAL
) | wxALIGN_BOTTOM
;
107 // default border size used by Border() below
108 static int GetDefaultBorder()
110 #if wxUSE_BORDER_BY_DEFAULT
112 // GNOME HIG says to use 6px as the base unit:
113 // http://library.gnome.org/devel/hig-book/stable/design-window.html.en
116 // FIXME: default border size shouldn't be hardcoded and at the very
117 // least they should depend on the current font size
126 wxSizerFlags
& Border(int direction
, int borderInPixels
)
129 m_flags
|= direction
;
131 m_borderInPixels
= borderInPixels
;
136 wxSizerFlags
& Border(int direction
= wxALL
)
138 #if wxUSE_BORDER_BY_DEFAULT
139 return Border(direction
, GetDefaultBorder());
141 // no borders by default on limited size screen
142 wxUnusedVar(direction
);
148 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
150 #if wxUSE_BORDER_BY_DEFAULT
151 return Border(direction
, 2*GetDefaultBorder());
153 wxUnusedVar(direction
);
159 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
161 #if wxUSE_BORDER_BY_DEFAULT
162 return Border(direction
, 3*GetDefaultBorder());
164 wxUnusedVar(direction
);
170 wxSizerFlags
& HorzBorder()
172 #if wxUSE_BORDER_BY_DEFAULT
173 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
179 wxSizerFlags
& DoubleHorzBorder()
181 #if wxUSE_BORDER_BY_DEFAULT
182 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
188 // setters for the others flags
189 wxSizerFlags
& Shaped()
196 wxSizerFlags
& FixedMinSize()
198 m_flags
|= wxFIXED_MINSIZE
;
203 // makes the item ignore window's visibility status
204 wxSizerFlags
& ReserveSpaceEvenIfHidden()
206 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
210 // accessors for wxSizer only
211 int GetProportion() const { return m_proportion
; }
212 int GetFlags() const { return m_flags
; }
213 int GetBorderInPixels() const { return m_borderInPixels
; }
218 int m_borderInPixels
;
222 // ----------------------------------------------------------------------------
223 // wxSizerSpacer: used by wxSizerItem to represent a spacer
224 // ----------------------------------------------------------------------------
226 class WXDLLIMPEXP_CORE wxSizerSpacer
229 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
231 void SetSize(const wxSize
& size
) { m_size
= size
; }
232 const wxSize
& GetSize() const { return m_size
; }
234 void Show(bool show
) { m_isShown
= show
; }
235 bool IsShown() const { return m_isShown
; }
238 // the size, in pixel
241 // is the spacer currently shown?
245 // ----------------------------------------------------------------------------
247 // ----------------------------------------------------------------------------
249 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
253 wxSizerItem( wxWindow
*window
,
257 wxObject
* userData
);
260 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
268 wxSizerItem( wxSizer
*sizer
,
272 wxObject
* userData
);
275 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
283 wxSizerItem( int width
,
291 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
295 DoSetSpacer(wxSize(width
, height
));
299 virtual ~wxSizerItem();
301 virtual void DeleteWindows();
303 // Enable deleting the SizerItem without destroying the contained sizer.
304 void DetachSizer() { m_sizer
= NULL
; }
306 virtual wxSize
GetSize() const;
307 virtual wxSize
CalcMin();
308 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
310 wxSize
GetMinSize() const
311 { return m_minSize
; }
312 wxSize
GetMinSizeWithBorder() const;
314 void SetMinSize(const wxSize
& size
)
317 m_window
->SetMinSize(size
);
320 void SetMinSize( int x
, int y
)
321 { SetMinSize(wxSize(x
, y
)); }
322 void SetInitSize( int x
, int y
)
323 { SetMinSize(wxSize(x
, y
)); }
325 // if either of dimensions is zero, ratio is assumed to be 1
326 // to avoid "divide by zero" errors
327 void SetRatio(int width
, int height
)
328 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
329 void SetRatio(const wxSize
& size
)
330 { SetRatio(size
.x
, size
.y
); }
331 void SetRatio(float ratio
)
333 float GetRatio() const
336 virtual wxRect
GetRect() { return m_rect
; }
338 // set a sizer item id (different from a window id, all sizer items,
339 // including spacers, can have an associated id)
340 void SetId(int id
) { m_id
= id
; }
341 int GetId() const { return m_id
; }
343 bool IsWindow() const { return m_kind
== Item_Window
; }
344 bool IsSizer() const { return m_kind
== Item_Sizer
; }
345 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
347 #if WXWIN_COMPATIBILITY_2_6
348 // Deprecated in 2.6, use {G,S}etProportion instead.
349 wxDEPRECATED( void SetOption( int option
) );
350 wxDEPRECATED( int GetOption() const );
351 #endif // WXWIN_COMPATIBILITY_2_6
353 void SetProportion( int proportion
)
354 { m_proportion
= proportion
; }
355 int GetProportion() const
356 { return m_proportion
; }
357 void SetFlag( int flag
)
361 void SetBorder( int border
)
362 { m_border
= border
; }
363 int GetBorder() const
366 wxWindow
*GetWindow() const
367 { return m_kind
== Item_Window
? m_window
: NULL
; }
368 wxSizer
*GetSizer() const
369 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
370 wxSize
GetSpacer() const;
372 // This function behaves obviously for the windows and spacers but for the
373 // sizers it returns true if any sizer element is shown and only returns
374 // false if all of them are hidden. Also, it always returns true if
375 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
376 bool IsShown() const;
378 void Show(bool show
);
380 void SetUserData(wxObject
* userData
)
381 { delete m_userData
; m_userData
= userData
; }
382 wxObject
* GetUserData() const
383 { return m_userData
; }
384 wxPoint
GetPosition() const
387 // Called once the first component of an item has been decided. This is
388 // used in algorithms that depend on knowing the size in one direction
389 // before the min size in the other direction can be known.
390 // Returns true if it made use of the information (and min size was changed).
391 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
393 // these functions delete the current contents of the item if it's a sizer
394 // or a spacer but not if it is a window
395 void AssignWindow(wxWindow
*window
)
401 void AssignSizer(wxSizer
*sizer
)
407 void AssignSpacer(const wxSize
& size
)
413 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
415 #if WXWIN_COMPATIBILITY_2_8
416 // these functions do not free the old sizer/spacer and so can easily
417 // provoke the memory leaks and so shouldn't be used, use Assign() instead
418 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
419 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
420 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
421 wxDEPRECATED( void SetSpacer(int width
, int height
) );
422 #endif // WXWIN_COMPATIBILITY_2_8
425 // common part of several ctors
426 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
428 // common part of ctors taking wxSizerFlags
429 void Init(const wxSizerFlags
& flags
);
431 // free current contents
434 // common parts of Set/AssignXXX()
435 void DoSetWindow(wxWindow
*window
);
436 void DoSetSizer(wxSizer
*sizer
);
437 void DoSetSpacer(const wxSize
& size
);
439 // discriminated union: depending on m_kind one of the fields is valid
452 wxSizerSpacer
*m_spacer
;
462 // on screen rectangle of this item (not including borders)
465 // Aspect ratio can always be calculated from m_size,
466 // but this would cause precision loss when the window
467 // is shrunk. It is safer to preserve the initial value.
470 wxObject
*m_userData
;
473 DECLARE_CLASS(wxSizerItem
)
474 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
477 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
480 //---------------------------------------------------------------------------
482 //---------------------------------------------------------------------------
484 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
487 wxSizer() { m_containingWindow
= NULL
; }
490 // methods for adding elements to the sizer: there are Add/Insert/Prepend
491 // overloads for each of window/sizer/spacer/wxSizerItem
492 wxSizerItem
* Add(wxWindow
*window
,
496 wxObject
* userData
= NULL
);
497 wxSizerItem
* Add(wxSizer
*sizer
,
501 wxObject
* userData
= NULL
);
502 wxSizerItem
* Add(int width
,
507 wxObject
* userData
= NULL
);
508 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
509 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
510 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
511 wxSizerItem
* Add( wxSizerItem
*item
);
513 virtual wxSizerItem
*AddSpacer(int size
);
514 wxSizerItem
* AddStretchSpacer(int prop
= 1);
516 wxSizerItem
* Insert(size_t index
,
521 wxObject
* userData
= NULL
);
522 wxSizerItem
* Insert(size_t index
,
527 wxObject
* userData
= NULL
);
528 wxSizerItem
* Insert(size_t index
,
534 wxObject
* userData
= NULL
);
535 wxSizerItem
* Insert(size_t index
,
537 const wxSizerFlags
& flags
);
538 wxSizerItem
* Insert(size_t index
,
540 const wxSizerFlags
& flags
);
541 wxSizerItem
* Insert(size_t index
,
544 const wxSizerFlags
& flags
);
546 // NB: do _not_ override this function in the derived classes, this one is
547 // virtual for compatibility reasons only to allow old code overriding
548 // it to continue to work, override DoInsert() instead in the new code
549 virtual wxSizerItem
* Insert(size_t index
, wxSizerItem
*item
);
551 wxSizerItem
* InsertSpacer(size_t index
, int size
);
552 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
554 wxSizerItem
* Prepend(wxWindow
*window
,
558 wxObject
* userData
= NULL
);
559 wxSizerItem
* Prepend(wxSizer
*sizer
,
563 wxObject
* userData
= NULL
);
564 wxSizerItem
* Prepend(int width
,
569 wxObject
* userData
= NULL
);
570 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
571 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
572 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
573 wxSizerItem
* Prepend(wxSizerItem
*item
);
575 wxSizerItem
* PrependSpacer(int size
);
576 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
578 // set (or possibly unset if window is NULL) or get the window this sizer
580 void SetContainingWindow(wxWindow
*window
);
581 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
583 #if WXWIN_COMPATIBILITY_2_6
584 // Deprecated in 2.6 since historically it does not delete the window,
585 // use Detach instead.
586 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
587 #endif // WXWIN_COMPATIBILITY_2_6
589 virtual bool Remove( wxSizer
*sizer
);
590 virtual bool Remove( int index
);
592 virtual bool Detach( wxWindow
*window
);
593 virtual bool Detach( wxSizer
*sizer
);
594 virtual bool Detach( int index
);
596 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
597 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
598 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
600 virtual void Clear( bool delete_windows
= false );
601 virtual void DeleteWindows();
603 // Inform sizer about the first direction that has been decided (by parent item)
604 // Returns true if it made use of the informtion (and recalculated min size)
605 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
608 void SetMinSize( int width
, int height
)
609 { DoSetMinSize( width
, height
); }
610 void SetMinSize( const wxSize
& size
)
611 { DoSetMinSize( size
.x
, size
.y
); }
613 // Searches recursively
614 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
615 { return DoSetItemMinSize( window
, width
, height
); }
616 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
617 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
619 // Searches recursively
620 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
621 { return DoSetItemMinSize( sizer
, width
, height
); }
622 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
623 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
625 bool SetItemMinSize( size_t index
, int width
, int height
)
626 { return DoSetItemMinSize( index
, width
, height
); }
627 bool SetItemMinSize( size_t index
, const wxSize
& size
)
628 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
630 wxSize
GetSize() const
632 wxPoint
GetPosition() const
633 { return m_position
; }
635 // Calculate the minimal size or return m_minSize if bigger.
638 // These virtual functions are used by the layout algorithm: first
639 // CalcMin() is called to calculate the minimal size of the sizer and
640 // prepare for laying it out and then RecalcSizes() is called to really
641 // update all the sizer items
642 virtual wxSize
CalcMin() = 0;
643 virtual void RecalcSizes() = 0;
645 virtual void Layout();
647 wxSize
ComputeFittingClientSize(wxWindow
*window
);
648 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
650 wxSize
Fit( wxWindow
*window
);
651 void FitInside( wxWindow
*window
);
652 void SetSizeHints( wxWindow
*window
);
653 #if WXWIN_COMPATIBILITY_2_8
654 // This only calls FitInside() since 2.9
655 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
658 wxSizerItemList
& GetChildren()
659 { return m_children
; }
660 const wxSizerItemList
& GetChildren() const
661 { return m_children
; }
663 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
669 void SetDimension(int x
, int y
, int width
, int height
)
670 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
672 size_t GetItemCount() const { return m_children
.GetCount(); }
673 bool IsEmpty() const { return m_children
.IsEmpty(); }
675 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
676 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
677 wxSizerItem
* GetItem( size_t index
);
678 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
680 // Manage whether individual scene items are considered
681 // in the layout calculations or not.
682 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
683 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
684 bool Show( size_t index
, bool show
= true );
686 bool Hide( wxSizer
*sizer
, bool recursive
= false )
687 { return Show( sizer
, false, recursive
); }
688 bool Hide( wxWindow
*window
, bool recursive
= false )
689 { return Show( window
, false, recursive
); }
690 bool Hide( size_t index
)
691 { return Show( index
, false ); }
693 bool IsShown( wxWindow
*window
) const;
694 bool IsShown( wxSizer
*sizer
) const;
695 bool IsShown( size_t index
) const;
697 // Recursively call wxWindow::Show () on all sizer items.
698 virtual void ShowItems (bool show
);
700 void Show(bool show
) { ShowItems(show
); }
706 wxSizerItemList m_children
;
708 // the window this sizer is used in, can be NULL
709 wxWindow
*m_containingWindow
;
711 wxSize
GetMaxClientSize( wxWindow
*window
) const;
712 wxSize
GetMinClientSize( wxWindow
*window
);
713 wxSize
VirtualFitSize( wxWindow
*window
);
715 virtual void DoSetMinSize( int width
, int height
);
716 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
717 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
718 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
720 // insert a new item into m_children at given index and return the item
722 virtual wxSizerItem
* DoInsert(size_t index
, wxSizerItem
*item
);
725 DECLARE_CLASS(wxSizer
)
728 //---------------------------------------------------------------------------
730 //---------------------------------------------------------------------------
732 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
735 // ctors specifying the number of columns only: number of rows will be
736 // deduced automatically depending on the number of sizer elements
737 wxGridSizer( int cols
, int vgap
, int hgap
);
738 wxGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
740 // ctors specifying the number of rows and columns
741 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
742 wxGridSizer( int rows
, int cols
, const wxSize
& gap
);
744 virtual void RecalcSizes();
745 virtual wxSize
CalcMin();
747 void SetCols( int cols
)
749 wxASSERT_MSG( cols
>= 0, "Number of columns must be non-negative");
753 void SetRows( int rows
)
755 wxASSERT_MSG( rows
>= 0, "Number of rows must be non-negative");
759 void SetVGap( int gap
) { m_vgap
= gap
; }
760 void SetHGap( int gap
) { m_hgap
= gap
; }
761 int GetCols() const { return m_cols
; }
762 int GetRows() const { return m_rows
; }
763 int GetVGap() const { return m_vgap
; }
764 int GetHGap() const { return m_hgap
; }
766 int GetEffectiveColsCount() const { return m_cols
? m_cols
: CalcCols(); }
767 int GetEffectiveRowsCount() const { return m_rows
? m_rows
: CalcRows(); }
769 // return the number of total items and the number of columns and rows
770 // (for internal use only)
771 int CalcRowsCols(int& rows
, int& cols
) const;
774 // the number of rows/columns in the sizer, if 0 then it is determined
775 // dynamically depending on the total number of items
779 // gaps between rows and columns
783 virtual wxSizerItem
*DoInsert(size_t index
, wxSizerItem
*item
);
785 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
787 // returns the number of columns/rows needed for the current total number
788 // of children (and the fixed number of rows/columns)
794 "Can't calculate number of cols if number of rows is not specified"
797 return (m_children
.GetCount() + m_rows
- 1) / m_rows
;
805 "Can't calculate number of cols if number of rows is not specified"
808 return (m_children
.GetCount() + m_cols
- 1) / m_cols
;
812 DECLARE_CLASS(wxGridSizer
)
815 //---------------------------------------------------------------------------
817 //---------------------------------------------------------------------------
819 // values which define the behaviour for resizing wxFlexGridSizer cells in the
820 // "non-flexible" direction
821 enum wxFlexSizerGrowMode
823 // don't resize the cells in non-flexible direction at all
824 wxFLEX_GROWMODE_NONE
,
826 // uniformly resize only the specified ones (default)
827 wxFLEX_GROWMODE_SPECIFIED
,
829 // uniformly resize all cells
833 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
836 // ctors specifying the number of columns only: number of rows will be
837 // deduced automatically depending on the number of sizer elements
838 wxFlexGridSizer( int cols
, int vgap
, int hgap
);
839 wxFlexGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
841 // ctors specifying the number of rows and columns
842 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
843 wxFlexGridSizer( int rows
, int cols
, const wxSize
& gap
);
846 virtual ~wxFlexGridSizer();
848 // set the rows/columns which will grow (the others will remain of the
849 // constant initial size)
850 void AddGrowableRow( size_t idx
, int proportion
= 0 );
851 void RemoveGrowableRow( size_t idx
);
852 void AddGrowableCol( size_t idx
, int proportion
= 0 );
853 void RemoveGrowableCol( size_t idx
);
855 bool IsRowGrowable( size_t idx
);
856 bool IsColGrowable( size_t idx
);
858 // the sizer cells may grow in both directions, not grow at all or only
859 // grow in one direction but not the other
861 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
862 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
863 int GetFlexibleDirection() const { return m_flexDirection
; }
865 // note that the grow mode only applies to the direction which is not
867 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
868 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
870 // Read-only access to the row heights and col widths arrays
871 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
872 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
875 virtual void RecalcSizes();
876 virtual wxSize
CalcMin();
879 void AdjustForFlexDirection();
880 void AdjustForGrowables(const wxSize
& sz
);
881 void FindWidthsAndHeights(int nrows
, int ncols
);
883 // the heights/widths of all rows/columns
884 wxArrayInt m_rowHeights
,
887 // indices of the growable columns and rows
888 wxArrayInt m_growableRows
,
891 // proportion values of the corresponding growable rows and columns
892 wxArrayInt m_growableRowsProportions
,
893 m_growableColsProportions
;
895 // parameters describing whether the growable cells should be resized in
896 // both directions or only one
898 wxFlexSizerGrowMode m_growMode
;
900 // saves CalcMin result to optimize RecalcSizes
901 wxSize m_calculatedMinSize
;
904 DECLARE_CLASS(wxFlexGridSizer
)
905 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
908 //---------------------------------------------------------------------------
910 //---------------------------------------------------------------------------
912 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
915 wxBoxSizer(int orient
)
918 m_totalProportion
= 0;
920 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
921 wxT("invalid value for wxBoxSizer orientation") );
924 virtual wxSizerItem
*AddSpacer(int size
);
926 int GetOrientation() const { return m_orient
; }
928 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
930 void SetOrientation(int orient
) { m_orient
= orient
; }
932 // implementation of our resizing logic
933 virtual wxSize
CalcMin();
934 virtual void RecalcSizes();
937 // helpers for our code: this returns the component of the given wxSize in
938 // the direction of the sizer and in the other direction, respectively
939 int GetSizeInMajorDir(const wxSize
& sz
) const
941 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
944 int& SizeInMajorDir(wxSize
& sz
)
946 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
949 int& PosInMajorDir(wxPoint
& pt
)
951 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
954 int GetSizeInMinorDir(const wxSize
& sz
) const
956 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
959 int& SizeInMinorDir(wxSize
& sz
)
961 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
964 int& PosInMinorDir(wxPoint
& pt
)
966 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
969 // another helper: creates wxSize from major and minor components
970 wxSize
SizeFromMajorMinor(int major
, int minor
) const
972 if ( m_orient
== wxHORIZONTAL
)
974 return wxSize(major
, minor
);
978 return wxSize(minor
, major
);
983 // either wxHORIZONTAL or wxVERTICAL
986 // the sum of proportion of all of our elements
987 int m_totalProportion
;
989 // the minimal size needed for this sizer as calculated by the last call to
994 DECLARE_CLASS(wxBoxSizer
)
997 //---------------------------------------------------------------------------
999 //---------------------------------------------------------------------------
1003 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
1005 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
1008 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
1009 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
1010 virtual ~wxStaticBoxSizer();
1015 wxStaticBox
*GetStaticBox() const
1016 { return m_staticBox
; }
1018 // override to hide/show the static box as well
1019 virtual void ShowItems (bool show
);
1021 virtual bool Detach( wxWindow
*window
);
1022 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
1023 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
1026 wxStaticBox
*m_staticBox
;
1029 DECLARE_CLASS(wxStaticBoxSizer
)
1030 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
1033 #endif // wxUSE_STATBOX
1035 //---------------------------------------------------------------------------
1036 // wxStdDialogButtonSizer
1037 //---------------------------------------------------------------------------
1041 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
1044 // Constructor just creates a new wxBoxSizer, not much else.
1045 // Box sizer orientation is automatically determined here:
1046 // vertical for PDAs, horizontal for everything else?
1047 wxStdDialogButtonSizer();
1049 // Checks button ID against system IDs and sets one of the pointers below
1050 // to this button. Does not do any sizer-related things here.
1051 void AddButton(wxButton
*button
);
1053 // Use these if no standard ID can/should be used
1054 void SetAffirmativeButton( wxButton
*button
);
1055 void SetNegativeButton( wxButton
*button
);
1056 void SetCancelButton( wxButton
*button
);
1058 // All platform-specific code here, checks which buttons exist and add
1059 // them to the sizer accordingly.
1060 // Note - one potential hack on Mac we could use here,
1061 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1062 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1063 // I wouldn't add any other hacks like that into here,
1064 // but this one I can see being useful.
1067 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1068 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1069 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1070 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1071 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1074 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1075 wxButton
*m_buttonApply
; // wxID_APPLY
1076 wxButton
*m_buttonNegative
; // wxID_NO
1077 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1078 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1081 DECLARE_CLASS(wxStdDialogButtonSizer
)
1082 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1085 #endif // wxUSE_BUTTON
1088 // ----------------------------------------------------------------------------
1089 // inline functions implementation
1090 // ----------------------------------------------------------------------------
1092 #if WXWIN_COMPATIBILITY_2_8
1094 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1096 DoSetWindow(window
);
1099 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1104 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1109 inline void wxSizerItem::SetSpacer(int width
, int height
)
1111 DoSetSpacer(wxSize(width
, height
));
1114 #endif // WXWIN_COMPATIBILITY_2_8
1117 wxSizer::Insert(size_t index
, wxSizerItem
*item
)
1119 return DoInsert(index
, item
);
1124 wxSizer::Add( wxSizerItem
*item
)
1126 return Insert( m_children
.GetCount(), item
);
1130 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1132 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1136 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1138 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1142 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1144 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1148 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1150 return Add( new wxSizerItem(window
, flags
) );
1154 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1156 return Add( new wxSizerItem(sizer
, flags
) );
1160 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1162 return Add( new wxSizerItem(width
, height
, flags
) );
1166 wxSizer::AddSpacer(int size
)
1168 return Add(size
, size
);
1172 wxSizer::AddStretchSpacer(int prop
)
1174 return Add(0, 0, prop
);
1178 wxSizer::Prepend( wxSizerItem
*item
)
1180 return Insert( 0, item
);
1184 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1186 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1190 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1192 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1196 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1198 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1202 wxSizer::PrependSpacer(int size
)
1204 return Prepend(size
, size
);
1208 wxSizer::PrependStretchSpacer(int prop
)
1210 return Prepend(0, 0, prop
);
1214 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1216 return Prepend( new wxSizerItem(window
, flags
) );
1220 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1222 return Prepend( new wxSizerItem(sizer
, flags
) );
1226 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1228 return Prepend( new wxSizerItem(width
, height
, flags
) );
1232 wxSizer::Insert( size_t index
,
1237 wxObject
* userData
)
1239 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1243 wxSizer::Insert( size_t index
,
1248 wxObject
* userData
)
1250 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1254 wxSizer::Insert( size_t index
,
1260 wxObject
* userData
)
1262 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1266 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1268 return Insert( index
, new wxSizerItem(window
, flags
) );
1272 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1274 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1278 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1280 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1284 wxSizer::InsertSpacer(size_t index
, int size
)
1286 return Insert(index
, size
, size
);
1290 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1292 return Insert(index
, 0, 0, prop
);
1295 #endif // __WXSIZER_H__