1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
8 // Copyright: (c) Robin Dunn, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/window.h"
19 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
23 class WXDLLIMPEXP_FWD_CORE wxButton
;
24 class WXDLLIMPEXP_FWD_CORE wxBoxSizer
;
25 class WXDLLIMPEXP_FWD_CORE wxSizerItem
;
26 class WXDLLIMPEXP_FWD_CORE wxSizer
;
28 #ifndef wxUSE_BORDER_BY_DEFAULT
30 // no borders by default on limited size screen
31 #define wxUSE_BORDER_BY_DEFAULT 0
33 #define wxUSE_BORDER_BY_DEFAULT 1
37 // ----------------------------------------------------------------------------
38 // wxSizerFlags: flags used for an item in the sizer
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxSizerFlags
44 // construct the flags object initialized with the given proportion (0 by
46 wxSizerFlags(int proportion
= 0) : m_proportion(proportion
)
52 // setters for all sizer flags, they all return the object itself so that
53 // calls to them can be chained
55 wxSizerFlags
& Proportion(int proportion
)
57 m_proportion
= proportion
;
61 wxSizerFlags
& Expand()
67 // notice that Align() replaces the current alignment flags, use specific
68 // methods below such as Top(), Left() &c if you want to set just the
69 // vertical or horizontal alignment
70 wxSizerFlags
& Align(int alignment
) // combination of wxAlignment values
72 m_flags
&= ~wxALIGN_MASK
;
78 // some shortcuts for Align()
79 wxSizerFlags
& Centre() { return Align(wxALIGN_CENTRE
); }
80 wxSizerFlags
& Center() { return Centre(); }
84 m_flags
&= ~(wxALIGN_BOTTOM
| wxALIGN_CENTRE_VERTICAL
);
90 m_flags
&= ~(wxALIGN_RIGHT
| wxALIGN_CENTRE_HORIZONTAL
);
96 m_flags
= (m_flags
& ~wxALIGN_CENTRE_HORIZONTAL
) | wxALIGN_RIGHT
;
100 wxSizerFlags
& Bottom()
102 m_flags
= (m_flags
& ~wxALIGN_CENTRE_VERTICAL
) | wxALIGN_BOTTOM
;
107 // default border size used by Border() below
108 static int GetDefaultBorder()
110 #if wxUSE_BORDER_BY_DEFAULT
112 // GNOME HIG says to use 6px as the base unit:
113 // http://library.gnome.org/devel/hig-book/stable/design-window.html.en
116 // FIXME: default border size shouldn't be hardcoded and at the very
117 // least they should depend on the current font size
126 wxSizerFlags
& Border(int direction
, int borderInPixels
)
128 wxCHECK_MSG( !(direction
& ~wxALL
), *this,
129 wxS("direction must be a combination of wxDirection ")
130 wxS("enum values.") );
133 m_flags
|= direction
;
135 m_borderInPixels
= borderInPixels
;
140 wxSizerFlags
& Border(int direction
= wxALL
)
142 #if wxUSE_BORDER_BY_DEFAULT
143 return Border(direction
, GetDefaultBorder());
145 // no borders by default on limited size screen
146 wxUnusedVar(direction
);
152 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
154 #if wxUSE_BORDER_BY_DEFAULT
155 return Border(direction
, 2*GetDefaultBorder());
157 wxUnusedVar(direction
);
163 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
165 #if wxUSE_BORDER_BY_DEFAULT
166 return Border(direction
, 3*GetDefaultBorder());
168 wxUnusedVar(direction
);
174 wxSizerFlags
& HorzBorder()
176 #if wxUSE_BORDER_BY_DEFAULT
177 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
183 wxSizerFlags
& DoubleHorzBorder()
185 #if wxUSE_BORDER_BY_DEFAULT
186 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
192 // setters for the others flags
193 wxSizerFlags
& Shaped()
200 wxSizerFlags
& FixedMinSize()
202 m_flags
|= wxFIXED_MINSIZE
;
207 // makes the item ignore window's visibility status
208 wxSizerFlags
& ReserveSpaceEvenIfHidden()
210 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
214 // accessors for wxSizer only
215 int GetProportion() const { return m_proportion
; }
216 int GetFlags() const { return m_flags
; }
217 int GetBorderInPixels() const { return m_borderInPixels
; }
222 int m_borderInPixels
;
226 // ----------------------------------------------------------------------------
227 // wxSizerSpacer: used by wxSizerItem to represent a spacer
228 // ----------------------------------------------------------------------------
230 class WXDLLIMPEXP_CORE wxSizerSpacer
233 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
235 void SetSize(const wxSize
& size
) { m_size
= size
; }
236 const wxSize
& GetSize() const { return m_size
; }
238 void Show(bool show
) { m_isShown
= show
; }
239 bool IsShown() const { return m_isShown
; }
242 // the size, in pixel
245 // is the spacer currently shown?
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
257 wxSizerItem( wxWindow
*window
,
261 wxObject
* userData
=NULL
);
264 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
272 wxSizerItem( wxSizer
*sizer
,
276 wxObject
* userData
=NULL
);
279 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
287 wxSizerItem( int width
,
292 wxObject
* userData
=NULL
);
295 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
299 DoSetSpacer(wxSize(width
, height
));
303 virtual ~wxSizerItem();
305 virtual void DeleteWindows();
307 // Enable deleting the SizerItem without destroying the contained sizer.
308 void DetachSizer() { m_sizer
= NULL
; }
310 virtual wxSize
GetSize() const;
311 virtual wxSize
CalcMin();
312 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
314 wxSize
GetMinSize() const
315 { return m_minSize
; }
316 wxSize
GetMinSizeWithBorder() const;
318 wxSize
GetMaxSize() const
319 { return IsWindow() ? m_window
->GetMaxSize() : wxDefaultSize
; }
320 wxSize
GetMaxSizeWithBorder() const;
322 void SetMinSize(const wxSize
& size
)
325 m_window
->SetMinSize(size
);
328 void SetMinSize( int x
, int y
)
329 { SetMinSize(wxSize(x
, y
)); }
330 void SetInitSize( int x
, int y
)
331 { SetMinSize(wxSize(x
, y
)); }
333 // if either of dimensions is zero, ratio is assumed to be 1
334 // to avoid "divide by zero" errors
335 void SetRatio(int width
, int height
)
336 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
337 void SetRatio(const wxSize
& size
)
338 { SetRatio(size
.x
, size
.y
); }
339 void SetRatio(float ratio
)
341 float GetRatio() const
344 virtual wxRect
GetRect() { return m_rect
; }
346 // set a sizer item id (different from a window id, all sizer items,
347 // including spacers, can have an associated id)
348 void SetId(int id
) { m_id
= id
; }
349 int GetId() const { return m_id
; }
351 bool IsWindow() const { return m_kind
== Item_Window
; }
352 bool IsSizer() const { return m_kind
== Item_Sizer
; }
353 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
355 #if WXWIN_COMPATIBILITY_2_6
356 // Deprecated in 2.6, use {G,S}etProportion instead.
357 wxDEPRECATED( void SetOption( int option
) );
358 wxDEPRECATED( int GetOption() const );
359 #endif // WXWIN_COMPATIBILITY_2_6
361 void SetProportion( int proportion
)
362 { m_proportion
= proportion
; }
363 int GetProportion() const
364 { return m_proportion
; }
365 void SetFlag( int flag
)
369 void SetBorder( int border
)
370 { m_border
= border
; }
371 int GetBorder() const
374 wxWindow
*GetWindow() const
375 { return m_kind
== Item_Window
? m_window
: NULL
; }
376 wxSizer
*GetSizer() const
377 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
378 wxSize
GetSpacer() const;
380 // This function behaves obviously for the windows and spacers but for the
381 // sizers it returns true if any sizer element is shown and only returns
382 // false if all of them are hidden. Also, it always returns true if
383 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
384 bool IsShown() const;
386 void Show(bool show
);
388 void SetUserData(wxObject
* userData
)
389 { delete m_userData
; m_userData
= userData
; }
390 wxObject
* GetUserData() const
391 { return m_userData
; }
392 wxPoint
GetPosition() const
395 // Called once the first component of an item has been decided. This is
396 // used in algorithms that depend on knowing the size in one direction
397 // before the min size in the other direction can be known.
398 // Returns true if it made use of the information (and min size was changed).
399 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
401 // these functions delete the current contents of the item if it's a sizer
402 // or a spacer but not if it is a window
403 void AssignWindow(wxWindow
*window
)
409 void AssignSizer(wxSizer
*sizer
)
415 void AssignSpacer(const wxSize
& size
)
421 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
423 #if WXWIN_COMPATIBILITY_2_8
424 // these functions do not free the old sizer/spacer and so can easily
425 // provoke the memory leaks and so shouldn't be used, use Assign() instead
426 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
427 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
428 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
429 wxDEPRECATED( void SetSpacer(int width
, int height
) );
430 #endif // WXWIN_COMPATIBILITY_2_8
433 // common part of several ctors
434 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
436 // common part of ctors taking wxSizerFlags
437 void Init(const wxSizerFlags
& flags
);
439 // free current contents
442 // common parts of Set/AssignXXX()
443 void DoSetWindow(wxWindow
*window
);
444 void DoSetSizer(wxSizer
*sizer
);
445 void DoSetSpacer(const wxSize
& size
);
447 // Add the border specified for this item to the given size
448 // if it's != wxDefaultSize, just return wxDefaultSize otherwise.
449 wxSize
AddBorderToSize(const wxSize
& size
) const;
451 // discriminated union: depending on m_kind one of the fields is valid
464 wxSizerSpacer
*m_spacer
;
474 // on screen rectangle of this item (not including borders)
477 // Aspect ratio can always be calculated from m_size,
478 // but this would cause precision loss when the window
479 // is shrunk. It is safer to preserve the initial value.
482 wxObject
*m_userData
;
485 DECLARE_CLASS(wxSizerItem
)
486 wxDECLARE_NO_COPY_CLASS(wxSizerItem
);
489 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
492 //---------------------------------------------------------------------------
494 //---------------------------------------------------------------------------
496 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
499 wxSizer() { m_containingWindow
= NULL
; }
502 // methods for adding elements to the sizer: there are Add/Insert/Prepend
503 // overloads for each of window/sizer/spacer/wxSizerItem
504 wxSizerItem
* Add(wxWindow
*window
,
508 wxObject
* userData
= NULL
);
509 wxSizerItem
* Add(wxSizer
*sizer
,
513 wxObject
* userData
= NULL
);
514 wxSizerItem
* Add(int width
,
519 wxObject
* userData
= NULL
);
520 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
521 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
522 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
523 wxSizerItem
* Add( wxSizerItem
*item
);
525 virtual wxSizerItem
*AddSpacer(int size
);
526 wxSizerItem
* AddStretchSpacer(int prop
= 1);
528 wxSizerItem
* Insert(size_t index
,
533 wxObject
* userData
= NULL
);
534 wxSizerItem
* Insert(size_t index
,
539 wxObject
* userData
= NULL
);
540 wxSizerItem
* Insert(size_t index
,
546 wxObject
* userData
= NULL
);
547 wxSizerItem
* Insert(size_t index
,
549 const wxSizerFlags
& flags
);
550 wxSizerItem
* Insert(size_t index
,
552 const wxSizerFlags
& flags
);
553 wxSizerItem
* Insert(size_t index
,
556 const wxSizerFlags
& flags
);
558 // NB: do _not_ override this function in the derived classes, this one is
559 // virtual for compatibility reasons only to allow old code overriding
560 // it to continue to work, override DoInsert() instead in the new code
561 virtual wxSizerItem
* Insert(size_t index
, wxSizerItem
*item
);
563 wxSizerItem
* InsertSpacer(size_t index
, int size
);
564 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
566 wxSizerItem
* Prepend(wxWindow
*window
,
570 wxObject
* userData
= NULL
);
571 wxSizerItem
* Prepend(wxSizer
*sizer
,
575 wxObject
* userData
= NULL
);
576 wxSizerItem
* Prepend(int width
,
581 wxObject
* userData
= NULL
);
582 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
583 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
584 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
585 wxSizerItem
* Prepend(wxSizerItem
*item
);
587 wxSizerItem
* PrependSpacer(int size
);
588 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
590 // set (or possibly unset if window is NULL) or get the window this sizer
592 void SetContainingWindow(wxWindow
*window
);
593 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
595 #if WXWIN_COMPATIBILITY_2_6
596 // Deprecated in 2.6 since historically it does not delete the window,
597 // use Detach instead.
598 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
599 #endif // WXWIN_COMPATIBILITY_2_6
601 virtual bool Remove( wxSizer
*sizer
);
602 virtual bool Remove( int index
);
604 virtual bool Detach( wxWindow
*window
);
605 virtual bool Detach( wxSizer
*sizer
);
606 virtual bool Detach( int index
);
608 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
609 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
610 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
612 virtual void Clear( bool delete_windows
= false );
613 virtual void DeleteWindows();
615 // Inform sizer about the first direction that has been decided (by parent item)
616 // Returns true if it made use of the information (and recalculated min size)
617 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
620 void SetMinSize( int width
, int height
)
621 { DoSetMinSize( width
, height
); }
622 void SetMinSize( const wxSize
& size
)
623 { DoSetMinSize( size
.x
, size
.y
); }
625 // Searches recursively
626 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
627 { return DoSetItemMinSize( window
, width
, height
); }
628 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
629 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
631 // Searches recursively
632 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
633 { return DoSetItemMinSize( sizer
, width
, height
); }
634 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
635 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
637 bool SetItemMinSize( size_t index
, int width
, int height
)
638 { return DoSetItemMinSize( index
, width
, height
); }
639 bool SetItemMinSize( size_t index
, const wxSize
& size
)
640 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
642 wxSize
GetSize() const
644 wxPoint
GetPosition() const
645 { return m_position
; }
647 // Calculate the minimal size or return m_minSize if bigger.
650 // These virtual functions are used by the layout algorithm: first
651 // CalcMin() is called to calculate the minimal size of the sizer and
652 // prepare for laying it out and then RecalcSizes() is called to really
653 // update all the sizer items
654 virtual wxSize
CalcMin() = 0;
655 virtual void RecalcSizes() = 0;
657 virtual void Layout();
659 wxSize
ComputeFittingClientSize(wxWindow
*window
);
660 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
662 wxSize
Fit( wxWindow
*window
);
663 void FitInside( wxWindow
*window
);
664 void SetSizeHints( wxWindow
*window
);
665 #if WXWIN_COMPATIBILITY_2_8
666 // This only calls FitInside() since 2.9
667 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
670 wxSizerItemList
& GetChildren()
671 { return m_children
; }
672 const wxSizerItemList
& GetChildren() const
673 { return m_children
; }
675 void SetDimension(const wxPoint
& pos
, const wxSize
& size
)
681 // This call is required for wxWrapSizer to be able to calculate its
682 // minimal size correctly.
683 InformFirstDirection(wxHORIZONTAL
, size
.x
, size
.y
);
685 void SetDimension(int x
, int y
, int width
, int height
)
686 { SetDimension(wxPoint(x
, y
), wxSize(width
, height
)); }
688 size_t GetItemCount() const { return m_children
.GetCount(); }
689 bool IsEmpty() const { return m_children
.IsEmpty(); }
691 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
692 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
693 wxSizerItem
* GetItem( size_t index
);
694 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
696 // Manage whether individual scene items are considered
697 // in the layout calculations or not.
698 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
699 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
700 bool Show( size_t index
, bool show
= true );
702 bool Hide( wxSizer
*sizer
, bool recursive
= false )
703 { return Show( sizer
, false, recursive
); }
704 bool Hide( wxWindow
*window
, bool recursive
= false )
705 { return Show( window
, false, recursive
); }
706 bool Hide( size_t index
)
707 { return Show( index
, false ); }
709 bool IsShown( wxWindow
*window
) const;
710 bool IsShown( wxSizer
*sizer
) const;
711 bool IsShown( size_t index
) const;
713 // Recursively call wxWindow::Show () on all sizer items.
714 virtual void ShowItems (bool show
);
716 void Show(bool show
) { ShowItems(show
); }
722 wxSizerItemList m_children
;
724 // the window this sizer is used in, can be NULL
725 wxWindow
*m_containingWindow
;
727 wxSize
GetMaxClientSize( wxWindow
*window
) const;
728 wxSize
GetMinClientSize( wxWindow
*window
);
729 wxSize
VirtualFitSize( wxWindow
*window
);
731 virtual void DoSetMinSize( int width
, int height
);
732 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
733 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
734 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
736 // insert a new item into m_children at given index and return the item
738 virtual wxSizerItem
* DoInsert(size_t index
, wxSizerItem
*item
);
741 DECLARE_CLASS(wxSizer
)
744 //---------------------------------------------------------------------------
746 //---------------------------------------------------------------------------
748 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
751 // ctors specifying the number of columns only: number of rows will be
752 // deduced automatically depending on the number of sizer elements
753 wxGridSizer( int cols
, int vgap
, int hgap
);
754 wxGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
756 // ctors specifying the number of rows and columns
757 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
758 wxGridSizer( int rows
, int cols
, const wxSize
& gap
);
760 virtual void RecalcSizes();
761 virtual wxSize
CalcMin();
763 void SetCols( int cols
)
765 wxASSERT_MSG( cols
>= 0, "Number of columns must be non-negative");
769 void SetRows( int rows
)
771 wxASSERT_MSG( rows
>= 0, "Number of rows must be non-negative");
775 void SetVGap( int gap
) { m_vgap
= gap
; }
776 void SetHGap( int gap
) { m_hgap
= gap
; }
777 int GetCols() const { return m_cols
; }
778 int GetRows() const { return m_rows
; }
779 int GetVGap() const { return m_vgap
; }
780 int GetHGap() const { return m_hgap
; }
782 int GetEffectiveColsCount() const { return m_cols
? m_cols
: CalcCols(); }
783 int GetEffectiveRowsCount() const { return m_rows
? m_rows
: CalcRows(); }
785 // return the number of total items and the number of columns and rows
786 // (for internal use only)
787 int CalcRowsCols(int& rows
, int& cols
) const;
790 // the number of rows/columns in the sizer, if 0 then it is determined
791 // dynamically depending on the total number of items
795 // gaps between rows and columns
799 virtual wxSizerItem
*DoInsert(size_t index
, wxSizerItem
*item
);
801 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
803 // returns the number of columns/rows needed for the current total number
804 // of children (and the fixed number of rows/columns)
810 "Can't calculate number of cols if number of rows is not specified"
813 return (m_children
.GetCount() + m_rows
- 1) / m_rows
;
821 "Can't calculate number of cols if number of rows is not specified"
824 return (m_children
.GetCount() + m_cols
- 1) / m_cols
;
828 DECLARE_CLASS(wxGridSizer
)
831 //---------------------------------------------------------------------------
833 //---------------------------------------------------------------------------
835 // values which define the behaviour for resizing wxFlexGridSizer cells in the
836 // "non-flexible" direction
837 enum wxFlexSizerGrowMode
839 // don't resize the cells in non-flexible direction at all
840 wxFLEX_GROWMODE_NONE
,
842 // uniformly resize only the specified ones (default)
843 wxFLEX_GROWMODE_SPECIFIED
,
845 // uniformly resize all cells
849 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
852 // ctors specifying the number of columns only: number of rows will be
853 // deduced automatically depending on the number of sizer elements
854 wxFlexGridSizer( int cols
, int vgap
, int hgap
);
855 wxFlexGridSizer( int cols
, const wxSize
& gap
= wxSize(0, 0) );
857 // ctors specifying the number of rows and columns
858 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
859 wxFlexGridSizer( int rows
, int cols
, const wxSize
& gap
);
862 virtual ~wxFlexGridSizer();
864 // set the rows/columns which will grow (the others will remain of the
865 // constant initial size)
866 void AddGrowableRow( size_t idx
, int proportion
= 0 );
867 void RemoveGrowableRow( size_t idx
);
868 void AddGrowableCol( size_t idx
, int proportion
= 0 );
869 void RemoveGrowableCol( size_t idx
);
871 bool IsRowGrowable( size_t idx
);
872 bool IsColGrowable( size_t idx
);
874 // the sizer cells may grow in both directions, not grow at all or only
875 // grow in one direction but not the other
877 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
878 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
879 int GetFlexibleDirection() const { return m_flexDirection
; }
881 // note that the grow mode only applies to the direction which is not
883 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
884 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
886 // Read-only access to the row heights and col widths arrays
887 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
888 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
891 virtual void RecalcSizes();
892 virtual wxSize
CalcMin();
895 void AdjustForFlexDirection();
896 void AdjustForGrowables(const wxSize
& sz
);
897 void FindWidthsAndHeights(int nrows
, int ncols
);
899 // the heights/widths of all rows/columns
900 wxArrayInt m_rowHeights
,
903 // indices of the growable columns and rows
904 wxArrayInt m_growableRows
,
907 // proportion values of the corresponding growable rows and columns
908 wxArrayInt m_growableRowsProportions
,
909 m_growableColsProportions
;
911 // parameters describing whether the growable cells should be resized in
912 // both directions or only one
914 wxFlexSizerGrowMode m_growMode
;
916 // saves CalcMin result to optimize RecalcSizes
917 wxSize m_calculatedMinSize
;
920 DECLARE_CLASS(wxFlexGridSizer
)
921 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer
);
924 //---------------------------------------------------------------------------
926 //---------------------------------------------------------------------------
928 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
931 wxBoxSizer(int orient
)
934 m_totalProportion
= 0;
936 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
937 wxT("invalid value for wxBoxSizer orientation") );
940 virtual wxSizerItem
*AddSpacer(int size
);
942 int GetOrientation() const { return m_orient
; }
944 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
946 void SetOrientation(int orient
) { m_orient
= orient
; }
948 // implementation of our resizing logic
949 virtual wxSize
CalcMin();
950 virtual void RecalcSizes();
953 // helpers for our code: this returns the component of the given wxSize in
954 // the direction of the sizer and in the other direction, respectively
955 int GetSizeInMajorDir(const wxSize
& sz
) const
957 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
960 int& SizeInMajorDir(wxSize
& sz
)
962 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
965 int& PosInMajorDir(wxPoint
& pt
)
967 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
970 int GetSizeInMinorDir(const wxSize
& sz
) const
972 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
975 int& SizeInMinorDir(wxSize
& sz
)
977 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
980 int& PosInMinorDir(wxPoint
& pt
)
982 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
985 // another helper: creates wxSize from major and minor components
986 wxSize
SizeFromMajorMinor(int major
, int minor
) const
988 if ( m_orient
== wxHORIZONTAL
)
990 return wxSize(major
, minor
);
994 return wxSize(minor
, major
);
999 // either wxHORIZONTAL or wxVERTICAL
1002 // the sum of proportion of all of our elements
1003 int m_totalProportion
;
1005 // the minimal size needed for this sizer as calculated by the last call to
1010 DECLARE_CLASS(wxBoxSizer
)
1013 //---------------------------------------------------------------------------
1015 //---------------------------------------------------------------------------
1019 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
1021 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
1024 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
1025 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
1026 virtual ~wxStaticBoxSizer();
1031 wxStaticBox
*GetStaticBox() const
1032 { return m_staticBox
; }
1034 // override to hide/show the static box as well
1035 virtual void ShowItems (bool show
);
1037 virtual bool Detach( wxWindow
*window
);
1038 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
1039 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
1042 wxStaticBox
*m_staticBox
;
1045 DECLARE_CLASS(wxStaticBoxSizer
)
1046 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer
);
1049 #endif // wxUSE_STATBOX
1051 //---------------------------------------------------------------------------
1052 // wxStdDialogButtonSizer
1053 //---------------------------------------------------------------------------
1057 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
1060 // Constructor just creates a new wxBoxSizer, not much else.
1061 // Box sizer orientation is automatically determined here:
1062 // vertical for PDAs, horizontal for everything else?
1063 wxStdDialogButtonSizer();
1065 // Checks button ID against system IDs and sets one of the pointers below
1066 // to this button. Does not do any sizer-related things here.
1067 void AddButton(wxButton
*button
);
1069 // Use these if no standard ID can/should be used
1070 void SetAffirmativeButton( wxButton
*button
);
1071 void SetNegativeButton( wxButton
*button
);
1072 void SetCancelButton( wxButton
*button
);
1074 // All platform-specific code here, checks which buttons exist and add
1075 // them to the sizer accordingly.
1076 // Note - one potential hack on Mac we could use here,
1077 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1078 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1079 // I wouldn't add any other hacks like that into here,
1080 // but this one I can see being useful.
1083 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
1084 wxButton
*GetApplyButton() const { return m_buttonApply
; }
1085 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
1086 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
1087 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
1090 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
1091 wxButton
*m_buttonApply
; // wxID_APPLY
1092 wxButton
*m_buttonNegative
; // wxID_NO
1093 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1094 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1097 DECLARE_CLASS(wxStdDialogButtonSizer
)
1098 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
);
1101 #endif // wxUSE_BUTTON
1104 // ----------------------------------------------------------------------------
1105 // inline functions implementation
1106 // ----------------------------------------------------------------------------
1108 #if WXWIN_COMPATIBILITY_2_8
1110 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1112 DoSetWindow(window
);
1115 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1120 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1125 inline void wxSizerItem::SetSpacer(int width
, int height
)
1127 DoSetSpacer(wxSize(width
, height
));
1130 #endif // WXWIN_COMPATIBILITY_2_8
1133 wxSizer::Insert(size_t index
, wxSizerItem
*item
)
1135 return DoInsert(index
, item
);
1140 wxSizer::Add( wxSizerItem
*item
)
1142 return Insert( m_children
.GetCount(), item
);
1146 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1148 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1152 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1154 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1158 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1160 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1164 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1166 return Add( new wxSizerItem(window
, flags
) );
1170 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1172 return Add( new wxSizerItem(sizer
, flags
) );
1176 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1178 return Add( new wxSizerItem(width
, height
, flags
) );
1182 wxSizer::AddSpacer(int size
)
1184 return Add(size
, size
);
1188 wxSizer::AddStretchSpacer(int prop
)
1190 return Add(0, 0, prop
);
1194 wxSizer::Prepend( wxSizerItem
*item
)
1196 return Insert( 0, item
);
1200 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1202 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1206 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1208 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1212 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1214 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1218 wxSizer::PrependSpacer(int size
)
1220 return Prepend(size
, size
);
1224 wxSizer::PrependStretchSpacer(int prop
)
1226 return Prepend(0, 0, prop
);
1230 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1232 return Prepend( new wxSizerItem(window
, flags
) );
1236 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1238 return Prepend( new wxSizerItem(sizer
, flags
) );
1242 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1244 return Prepend( new wxSizerItem(width
, height
, flags
) );
1248 wxSizer::Insert( size_t index
,
1253 wxObject
* userData
)
1255 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1259 wxSizer::Insert( size_t index
,
1264 wxObject
* userData
)
1266 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1270 wxSizer::Insert( size_t index
,
1276 wxObject
* userData
)
1278 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1282 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1284 return Insert( index
, new wxSizerItem(window
, flags
) );
1288 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1290 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1294 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1296 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1300 wxSizer::InsertSpacer(size_t index
, int size
)
1302 return Insert(index
, size
, size
);
1306 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1308 return Insert(index
, 0, 0, prop
);
1311 #endif // __WXSIZER_H__