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
& Align(int alignment
) // combination of wxAlignment values
63 m_flags
&= ~wxALIGN_MASK
;
69 wxSizerFlags
& Expand()
75 // some shortcuts for Align()
76 wxSizerFlags
& Centre() { return Align(wxALIGN_CENTRE
); }
77 wxSizerFlags
& Center() { return Centre(); }
78 wxSizerFlags
& Top() { return Align(wxALIGN_TOP
); }
79 wxSizerFlags
& Left() { return Align(wxALIGN_LEFT
); }
80 wxSizerFlags
& Right() { return Align(wxALIGN_RIGHT
); }
81 wxSizerFlags
& Bottom() { return Align(wxALIGN_BOTTOM
); }
83 // default border size used by Border() below
84 static int GetDefaultBorder()
86 #if wxUSE_BORDER_BY_DEFAULT
88 // GNOME HIG says to use 6px as the base unit:
89 // http://library.gnome.org/devel/hig-book/stable/design-window.html.en
92 // FIXME: default border size shouldn't be hardcoded and at the very
93 // least they should depend on the current font size
102 wxSizerFlags
& Border(int direction
, int borderInPixels
)
105 m_flags
|= direction
;
107 m_borderInPixels
= borderInPixels
;
112 wxSizerFlags
& Border(int direction
= wxALL
)
114 #if wxUSE_BORDER_BY_DEFAULT
115 return Border(direction
, GetDefaultBorder());
117 // no borders by default on limited size screen
118 wxUnusedVar(direction
);
124 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
126 #if wxUSE_BORDER_BY_DEFAULT
127 return Border(direction
, 2*GetDefaultBorder());
129 wxUnusedVar(direction
);
135 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
137 #if wxUSE_BORDER_BY_DEFAULT
138 return Border(direction
, 3*GetDefaultBorder());
140 wxUnusedVar(direction
);
146 wxSizerFlags
& HorzBorder()
148 #if wxUSE_BORDER_BY_DEFAULT
149 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
155 wxSizerFlags
& DoubleHorzBorder()
157 #if wxUSE_BORDER_BY_DEFAULT
158 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
164 // setters for the others flags
165 wxSizerFlags
& Shaped()
172 wxSizerFlags
& FixedMinSize()
174 m_flags
|= wxFIXED_MINSIZE
;
179 // makes the item ignore window's visibility status
180 wxSizerFlags
& ReserveSpaceEvenIfHidden()
182 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
186 // accessors for wxSizer only
187 int GetProportion() const { return m_proportion
; }
188 int GetFlags() const { return m_flags
; }
189 int GetBorderInPixels() const { return m_borderInPixels
; }
194 int m_borderInPixels
;
198 // ----------------------------------------------------------------------------
199 // wxSizerSpacer: used by wxSizerItem to represent a spacer
200 // ----------------------------------------------------------------------------
202 class WXDLLIMPEXP_CORE wxSizerSpacer
205 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
207 void SetSize(const wxSize
& size
) { m_size
= size
; }
208 const wxSize
& GetSize() const { return m_size
; }
210 void Show(bool show
) { m_isShown
= show
; }
211 bool IsShown() const { return m_isShown
; }
214 // the size, in pixel
217 // is the spacer currently shown?
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
225 class WXDLLIMPEXP_CORE wxSizerItem
: public wxObject
229 wxSizerItem( wxWindow
*window
,
233 wxObject
* userData
);
236 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
244 wxSizerItem( wxSizer
*sizer
,
248 wxObject
* userData
);
251 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
259 wxSizerItem( int width
,
267 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
271 DoSetSpacer(wxSize(width
, height
));
275 virtual ~wxSizerItem();
277 virtual void DeleteWindows();
279 // Enable deleting the SizerItem without destroying the contained sizer.
280 void DetachSizer() { m_sizer
= NULL
; }
282 virtual wxSize
GetSize() const;
283 virtual wxSize
CalcMin();
284 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
286 wxSize
GetMinSize() const
287 { return m_minSize
; }
288 wxSize
GetMinSizeWithBorder() const;
290 void SetMinSize(const wxSize
& size
)
293 m_window
->SetMinSize(size
);
296 void SetMinSize( int x
, int y
)
297 { SetMinSize(wxSize(x
, y
)); }
298 void SetInitSize( int x
, int y
)
299 { SetMinSize(wxSize(x
, y
)); }
301 // if either of dimensions is zero, ratio is assumed to be 1
302 // to avoid "divide by zero" errors
303 void SetRatio(int width
, int height
)
304 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
305 void SetRatio(const wxSize
& size
)
306 { SetRatio(size
.x
, size
.y
); }
307 void SetRatio(float ratio
)
309 float GetRatio() const
312 virtual wxRect
GetRect() { return m_rect
; }
314 // set a sizer item id (different from a window id, all sizer items,
315 // including spacers, can have an associated id)
316 void SetId(int id
) { m_id
= id
; }
317 int GetId() const { return m_id
; }
319 bool IsWindow() const { return m_kind
== Item_Window
; }
320 bool IsSizer() const { return m_kind
== Item_Sizer
; }
321 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
323 #if WXWIN_COMPATIBILITY_2_6
324 // Deprecated in 2.6, use {G,S}etProportion instead.
325 wxDEPRECATED( void SetOption( int option
) );
326 wxDEPRECATED( int GetOption() const );
327 #endif // WXWIN_COMPATIBILITY_2_6
329 void SetProportion( int proportion
)
330 { m_proportion
= proportion
; }
331 int GetProportion() const
332 { return m_proportion
; }
333 void SetFlag( int flag
)
337 void SetBorder( int border
)
338 { m_border
= border
; }
339 int GetBorder() const
342 wxWindow
*GetWindow() const
343 { return m_kind
== Item_Window
? m_window
: NULL
; }
344 wxSizer
*GetSizer() const
345 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
346 wxSize
GetSpacer() const;
348 // This function behaves obviously for the windows and spacers but for the
349 // sizers it returns true if any sizer element is shown and only returns
350 // false if all of them are hidden. Also, it always returns true if
351 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
352 bool IsShown() const;
354 void Show(bool show
);
356 void SetUserData(wxObject
* userData
)
357 { delete m_userData
; m_userData
= userData
; }
358 wxObject
* GetUserData() const
359 { return m_userData
; }
360 wxPoint
GetPosition() const
363 // Called once the first component of an item has been decided. This is
364 // used in algorithms that depend on knowing the size in one direction
365 // before the min size in the other direction can be known.
366 // Returns true if it made use of the information (and min size was changed).
367 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
369 // these functions delete the current contents of the item if it's a sizer
370 // or a spacer but not if it is a window
371 void AssignWindow(wxWindow
*window
)
377 void AssignSizer(wxSizer
*sizer
)
383 void AssignSpacer(const wxSize
& size
)
389 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
391 #if WXWIN_COMPATIBILITY_2_8
392 // these functions do not free the old sizer/spacer and so can easily
393 // provoke the memory leaks and so shouldn't be used, use Assign() instead
394 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
395 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
396 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
397 wxDEPRECATED( void SetSpacer(int width
, int height
) );
398 #endif // WXWIN_COMPATIBILITY_2_8
401 // common part of several ctors
402 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
404 // common part of ctors taking wxSizerFlags
405 void Init(const wxSizerFlags
& flags
);
407 // free current contents
410 // common parts of Set/AssignXXX()
411 void DoSetWindow(wxWindow
*window
);
412 void DoSetSizer(wxSizer
*sizer
);
413 void DoSetSpacer(const wxSize
& size
);
415 // discriminated union: depending on m_kind one of the fields is valid
428 wxSizerSpacer
*m_spacer
;
438 // on screen rectangle of this item (not including borders)
441 // Aspect ratio can always be calculated from m_size,
442 // but this would cause precision loss when the window
443 // is shrunk. It is safer to preserve the initial value.
446 wxObject
*m_userData
;
449 DECLARE_CLASS(wxSizerItem
)
450 DECLARE_NO_COPY_CLASS(wxSizerItem
)
453 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
456 //---------------------------------------------------------------------------
458 //---------------------------------------------------------------------------
460 class WXDLLIMPEXP_CORE wxSizer
: public wxObject
, public wxClientDataContainer
463 wxSizer() { m_containingWindow
= NULL
; }
466 // methods for adding elements to the sizer: there are Add/Insert/Prepend
467 // overloads for each of window/sizer/spacer/wxSizerItem
468 wxSizerItem
* Add(wxWindow
*window
,
472 wxObject
* userData
= NULL
);
473 wxSizerItem
* Add(wxSizer
*sizer
,
477 wxObject
* userData
= NULL
);
478 wxSizerItem
* Add(int width
,
483 wxObject
* userData
= NULL
);
484 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
485 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
486 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
487 wxSizerItem
* Add( wxSizerItem
*item
);
489 wxSizerItem
* AddSpacer(int size
);
490 wxSizerItem
* AddStretchSpacer(int prop
= 1);
492 wxSizerItem
* Insert(size_t index
,
497 wxObject
* userData
= NULL
);
498 wxSizerItem
* Insert(size_t index
,
503 wxObject
* userData
= NULL
);
504 wxSizerItem
* Insert(size_t index
,
510 wxObject
* userData
= NULL
);
511 wxSizerItem
* Insert(size_t index
,
513 const wxSizerFlags
& flags
);
514 wxSizerItem
* Insert(size_t index
,
516 const wxSizerFlags
& flags
);
517 wxSizerItem
* Insert(size_t index
,
520 const wxSizerFlags
& flags
);
521 virtual wxSizerItem
* Insert( size_t index
, wxSizerItem
*item
);
523 wxSizerItem
* InsertSpacer(size_t index
, int size
);
524 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
526 wxSizerItem
* Prepend(wxWindow
*window
,
530 wxObject
* userData
= NULL
);
531 wxSizerItem
* Prepend(wxSizer
*sizer
,
535 wxObject
* userData
= NULL
);
536 wxSizerItem
* Prepend(int width
,
541 wxObject
* userData
= NULL
);
542 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
543 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
544 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
545 wxSizerItem
* Prepend(wxSizerItem
*item
);
547 wxSizerItem
* PrependSpacer(int size
);
548 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
550 // set (or possibly unset if window is NULL) or get the window this sizer
552 void SetContainingWindow(wxWindow
*window
);
553 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
555 #if WXWIN_COMPATIBILITY_2_6
556 // Deprecated in 2.6 since historically it does not delete the window,
557 // use Detach instead.
558 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
559 #endif // WXWIN_COMPATIBILITY_2_6
561 virtual bool Remove( wxSizer
*sizer
);
562 virtual bool Remove( int index
);
564 virtual bool Detach( wxWindow
*window
);
565 virtual bool Detach( wxSizer
*sizer
);
566 virtual bool Detach( int index
);
568 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
569 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
570 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
572 virtual void Clear( bool delete_windows
= false );
573 virtual void DeleteWindows();
575 // Inform sizer about the first direction that has been decided (by parent item)
576 // Returns true if it made use of the informtion (and recalculated min size)
577 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
580 void SetMinSize( int width
, int height
)
581 { DoSetMinSize( width
, height
); }
582 void SetMinSize( const wxSize
& size
)
583 { DoSetMinSize( size
.x
, size
.y
); }
585 // Searches recursively
586 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
587 { return DoSetItemMinSize( window
, width
, height
); }
588 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
589 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
591 // Searches recursively
592 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
593 { return DoSetItemMinSize( sizer
, width
, height
); }
594 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
595 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
597 bool SetItemMinSize( size_t index
, int width
, int height
)
598 { return DoSetItemMinSize( index
, width
, height
); }
599 bool SetItemMinSize( size_t index
, const wxSize
& size
)
600 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
602 wxSize
GetSize() const
604 wxPoint
GetPosition() const
605 { return m_position
; }
607 // Calculate the minimal size or return m_minSize if bigger.
610 // These virtual functions are used by the layout algorithm: first
611 // CalcMin() is called to calculate the minimal size of the sizer and
612 // prepare for laying it out and then RecalcSizes() is called to really
613 // update all the sizer items
614 virtual wxSize
CalcMin() = 0;
615 virtual void RecalcSizes() = 0;
617 virtual void Layout();
619 wxSize
ComputeFittingClientSize(wxWindow
*window
);
620 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
622 wxSize
Fit( wxWindow
*window
);
623 void FitInside( wxWindow
*window
);
624 void SetSizeHints( wxWindow
*window
);
625 #if WXWIN_COMPATIBILITY_2_8
626 // This only calls FitInside() since 2.9
627 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
630 wxSizerItemList
& GetChildren()
631 { return m_children
; }
632 const wxSizerItemList
& GetChildren() const
633 { return m_children
; }
635 void SetDimension( int x
, int y
, int width
, int height
);
637 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
638 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
639 wxSizerItem
* GetItem( size_t index
);
640 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
642 // Manage whether individual scene items are considered
643 // in the layout calculations or not.
644 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
645 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
646 bool Show( size_t index
, bool show
= true );
648 bool Hide( wxSizer
*sizer
, bool recursive
= false )
649 { return Show( sizer
, false, recursive
); }
650 bool Hide( wxWindow
*window
, bool recursive
= false )
651 { return Show( window
, false, recursive
); }
652 bool Hide( size_t index
)
653 { return Show( index
, false ); }
655 bool IsShown( wxWindow
*window
) const;
656 bool IsShown( wxSizer
*sizer
) const;
657 bool IsShown( size_t index
) const;
659 // Recursively call wxWindow::Show () on all sizer items.
660 virtual void ShowItems (bool show
);
662 void Show(bool show
) { ShowItems(show
); }
668 wxSizerItemList m_children
;
670 // the window this sizer is used in, can be NULL
671 wxWindow
*m_containingWindow
;
673 wxSize
GetMaxClientSize( wxWindow
*window
) const;
674 wxSize
GetMinClientSize( wxWindow
*window
);
675 wxSize
VirtualFitSize( wxWindow
*window
);
677 virtual void DoSetMinSize( int width
, int height
);
678 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
679 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
680 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
683 DECLARE_CLASS(wxSizer
)
686 //---------------------------------------------------------------------------
688 //---------------------------------------------------------------------------
690 class WXDLLIMPEXP_CORE wxGridSizer
: public wxSizer
693 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
694 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
696 virtual void RecalcSizes();
697 virtual wxSize
CalcMin();
699 void SetCols( int cols
) { m_cols
= cols
; }
700 void SetRows( int rows
) { m_rows
= rows
; }
701 void SetVGap( int gap
) { m_vgap
= gap
; }
702 void SetHGap( int gap
) { m_hgap
= gap
; }
703 int GetCols() const { return m_cols
; }
704 int GetRows() const { return m_rows
; }
705 int GetVGap() const { return m_vgap
; }
706 int GetHGap() const { return m_hgap
; }
714 // return the number of total items and the number of columns and rows
715 int CalcRowsCols(int& rows
, int& cols
) const;
717 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
720 DECLARE_CLASS(wxGridSizer
)
723 //---------------------------------------------------------------------------
725 //---------------------------------------------------------------------------
727 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
729 enum wxFlexSizerGrowMode
731 // don't resize the cells in non-flexible direction at all
732 wxFLEX_GROWMODE_NONE
,
734 // uniformly resize only the specified ones (default)
735 wxFLEX_GROWMODE_SPECIFIED
,
737 // uniformly resize all cells
741 class WXDLLIMPEXP_CORE wxFlexGridSizer
: public wxGridSizer
745 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
746 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
747 virtual ~wxFlexGridSizer();
750 // set the rows/columns which will grow (the others will remain of the
751 // constant initial size)
752 void AddGrowableRow( size_t idx
, int proportion
= 0 );
753 void RemoveGrowableRow( size_t idx
);
754 void AddGrowableCol( size_t idx
, int proportion
= 0 );
755 void RemoveGrowableCol( size_t idx
);
758 // the sizer cells may grow in both directions, not grow at all or only
759 // grow in one direction but not the other
761 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
762 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
763 int GetFlexibleDirection() const { return m_flexDirection
; }
765 // note that the grow mode only applies to the direction which is not
767 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
768 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
770 // Read-only access to the row heights and col widths arrays
771 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
772 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
775 virtual void RecalcSizes();
776 virtual wxSize
CalcMin();
779 void AdjustForFlexDirection();
780 void AdjustForGrowables(const wxSize
& sz
);
781 void FindWidthsAndHeights(int nrows
, int ncols
);
783 // the heights/widths of all rows/columns
784 wxArrayInt m_rowHeights
,
787 // indices of the growable columns and rows
788 wxArrayInt m_growableRows
,
791 // proportion values of the corresponding growable rows and columns
792 wxArrayInt m_growableRowsProportions
,
793 m_growableColsProportions
;
795 // parameters describing whether the growable cells should be resized in
796 // both directions or only one
798 wxFlexSizerGrowMode m_growMode
;
800 // saves CalcMin result to optimize RecalcSizes
801 wxSize m_calculatedMinSize
;
804 DECLARE_CLASS(wxFlexGridSizer
)
805 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
808 //---------------------------------------------------------------------------
810 //---------------------------------------------------------------------------
812 class WXDLLIMPEXP_CORE wxBoxSizer
: public wxSizer
815 wxBoxSizer(int orient
)
818 m_totalProportion
= 0;
820 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
821 _T("invalid value for wxBoxSizer orientation") );
824 int GetOrientation() const { return m_orient
; }
826 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
828 void SetOrientation(int orient
) { m_orient
= orient
; }
830 // implementation of our resizing logic
831 virtual wxSize
CalcMin();
832 virtual void RecalcSizes();
835 // helpers for our code: this returns the component of the given wxSize in
836 // the direction of the sizer and in the other direction, respectively
837 int GetSizeInMajorDir(const wxSize
& sz
) const
839 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
842 int& SizeInMajorDir(wxSize
& sz
)
844 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
847 int& PosInMajorDir(wxPoint
& pt
)
849 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
852 int GetSizeInMinorDir(const wxSize
& sz
) const
854 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
857 int& SizeInMinorDir(wxSize
& sz
)
859 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
862 int& PosInMinorDir(wxPoint
& pt
)
864 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
867 // another helper: creates wxSize from major and minor components
868 wxSize
SizeFromMajorMinor(int major
, int minor
) const
870 if ( m_orient
== wxHORIZONTAL
)
872 return wxSize(major
, minor
);
876 return wxSize(minor
, major
);
881 // either wxHORIZONTAL or wxVERTICAL
884 // the sum of proportion of all of our elements
885 int m_totalProportion
;
887 // the minimal size needed for this sizer as calculated by the last call to
892 DECLARE_CLASS(wxBoxSizer
)
895 //---------------------------------------------------------------------------
896 // wxWrapSizer - A box sizer that can wrap items on several lines when
897 // widths exceed available width.
898 //---------------------------------------------------------------------------
900 // Borrow unused flag value
901 #define wxEXTEND_LAST_ON_EACH_LINE wxFULL_REPAINT_ON_RESIZE
903 class WXDLLIMPEXP_CORE wxWrapSizer
: public wxBoxSizer
906 wxWrapSizer( int orient
=wxHORIZONTAL
, int flags
=wxEXTEND_LAST_ON_EACH_LINE
);
907 virtual ~wxWrapSizer();
909 virtual void RecalcSizes();
910 virtual wxSize
CalcMin();
912 virtual bool InformFirstDirection( int direction
, int size
, int availableOtherDir
);
915 int m_prim_size_last
; // Size in primary direction last time
916 int m_n_line
; // Number of lines
917 wxBoxSizer m_rows
; // Rows of items
920 void AdjustPropLastItem(wxSizer
*psz
, wxSizerItem
*itemLast
);
922 DECLARE_DYNAMIC_CLASS(wxWrapSizer
)
925 //---------------------------------------------------------------------------
927 //---------------------------------------------------------------------------
931 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
933 class WXDLLIMPEXP_CORE wxStaticBoxSizer
: public wxBoxSizer
936 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
937 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
938 virtual ~wxStaticBoxSizer();
943 wxStaticBox
*GetStaticBox() const
944 { return m_staticBox
; }
946 // override to hide/show the static box as well
947 virtual void ShowItems (bool show
);
949 virtual bool Detach( wxWindow
*window
);
950 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
951 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
954 wxStaticBox
*m_staticBox
;
957 DECLARE_CLASS(wxStaticBoxSizer
)
958 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
961 #endif // wxUSE_STATBOX
965 class WXDLLIMPEXP_CORE wxStdDialogButtonSizer
: public wxBoxSizer
968 // Constructor just creates a new wxBoxSizer, not much else.
969 // Box sizer orientation is automatically determined here:
970 // vertical for PDAs, horizontal for everything else?
971 wxStdDialogButtonSizer();
973 // Checks button ID against system IDs and sets one of the pointers below
974 // to this button. Does not do any sizer-related things here.
975 void AddButton(wxButton
*button
);
977 // Use these if no standard ID can/should be used
978 void SetAffirmativeButton( wxButton
*button
);
979 void SetNegativeButton( wxButton
*button
);
980 void SetCancelButton( wxButton
*button
);
982 // All platform-specific code here, checks which buttons exist and add
983 // them to the sizer accordingly.
984 // Note - one potential hack on Mac we could use here,
985 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
986 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
987 // I wouldn't add any other hacks like that into here,
988 // but this one I can see being useful.
991 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
992 wxButton
*GetApplyButton() const { return m_buttonApply
; }
993 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
994 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
995 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
998 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
999 wxButton
*m_buttonApply
; // wxID_APPLY
1000 wxButton
*m_buttonNegative
; // wxID_NO
1001 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
1002 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
1005 DECLARE_CLASS(wxStdDialogButtonSizer
)
1006 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
)
1009 #endif // wxUSE_BUTTON
1012 // ----------------------------------------------------------------------------
1013 // inline functions implementation
1014 // ----------------------------------------------------------------------------
1016 #if WXWIN_COMPATIBILITY_2_8
1018 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1020 DoSetWindow(window
);
1023 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1028 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1033 inline void wxSizerItem::SetSpacer(int width
, int height
)
1035 DoSetSpacer(wxSize(width
, height
));
1038 #endif // WXWIN_COMPATIBILITY_2_8
1042 wxSizer::Add( wxSizerItem
*item
)
1044 return Insert( m_children
.GetCount(), item
);
1048 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1050 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1054 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1056 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1060 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1062 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1066 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1068 return Add( new wxSizerItem(window
, flags
) );
1072 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1074 return Add( new wxSizerItem(sizer
, flags
) );
1078 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1080 return Add( new wxSizerItem(width
, height
, flags
) );
1084 wxSizer::AddSpacer(int size
)
1086 return Add(size
, size
);
1090 wxSizer::AddStretchSpacer(int prop
)
1092 return Add(0, 0, prop
);
1096 wxSizer::Prepend( wxSizerItem
*item
)
1098 return Insert( 0, item
);
1102 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1104 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1108 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1110 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1114 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1116 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1120 wxSizer::PrependSpacer(int size
)
1122 return Prepend(size
, size
);
1126 wxSizer::PrependStretchSpacer(int prop
)
1128 return Prepend(0, 0, prop
);
1132 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1134 return Prepend( new wxSizerItem(window
, flags
) );
1138 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1140 return Prepend( new wxSizerItem(sizer
, flags
) );
1144 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1146 return Prepend( new wxSizerItem(width
, height
, flags
) );
1150 wxSizer::Insert( size_t index
,
1155 wxObject
* userData
)
1157 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1161 wxSizer::Insert( size_t index
,
1166 wxObject
* userData
)
1168 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1172 wxSizer::Insert( size_t index
,
1178 wxObject
* userData
)
1180 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1184 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1186 return Insert( index
, new wxSizerItem(window
, flags
) );
1190 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1192 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1196 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1198 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1202 wxSizer::InsertSpacer(size_t index
, int size
)
1204 return Insert(index
, size
, size
);
1208 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1210 return Insert(index
, 0, 0, prop
);
1213 #endif // __WXSIZER_H__