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 WXDLLEXPORT 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
87 // FIXME: default border size shouldn't be hardcoded and at the very
88 // least they should depend on the current font size
96 wxSizerFlags
& Border(int direction
, int borderInPixels
)
101 m_borderInPixels
= borderInPixels
;
106 wxSizerFlags
& Border(int direction
= wxALL
)
108 #if wxUSE_BORDER_BY_DEFAULT
109 return Border(direction
, GetDefaultBorder());
111 // no borders by default on limited size screen
112 wxUnusedVar(direction
);
118 wxSizerFlags
& DoubleBorder(int direction
= wxALL
)
120 #if wxUSE_BORDER_BY_DEFAULT
121 return Border(direction
, 2*GetDefaultBorder());
123 wxUnusedVar(direction
);
129 wxSizerFlags
& TripleBorder(int direction
= wxALL
)
131 #if wxUSE_BORDER_BY_DEFAULT
132 return Border(direction
, 3*GetDefaultBorder());
134 wxUnusedVar(direction
);
140 wxSizerFlags
& HorzBorder()
142 #if wxUSE_BORDER_BY_DEFAULT
143 return Border(wxLEFT
| wxRIGHT
, GetDefaultBorder());
149 wxSizerFlags
& DoubleHorzBorder()
151 #if wxUSE_BORDER_BY_DEFAULT
152 return Border(wxLEFT
| wxRIGHT
, 2*GetDefaultBorder());
158 // setters for the others flags
159 wxSizerFlags
& Shaped()
166 wxSizerFlags
& FixedMinSize()
168 m_flags
|= wxFIXED_MINSIZE
;
173 // makes the item ignore window's visibility status
174 wxSizerFlags
& ReserveSpaceEvenIfHidden()
176 m_flags
|= wxRESERVE_SPACE_EVEN_IF_HIDDEN
;
180 // accessors for wxSizer only
181 int GetProportion() const { return m_proportion
; }
182 int GetFlags() const { return m_flags
; }
183 int GetBorderInPixels() const { return m_borderInPixels
; }
188 int m_borderInPixels
;
192 // ----------------------------------------------------------------------------
193 // wxSizerSpacer: used by wxSizerItem to represent a spacer
194 // ----------------------------------------------------------------------------
196 class WXDLLEXPORT wxSizerSpacer
199 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
201 void SetSize(const wxSize
& size
) { m_size
= size
; }
202 const wxSize
& GetSize() const { return m_size
; }
204 void Show(bool show
) { m_isShown
= show
; }
205 bool IsShown() const { return m_isShown
; }
208 // the size, in pixel
211 // is the spacer currently shown?
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 class WXDLLEXPORT wxSizerItem
: public wxObject
223 wxSizerItem( wxWindow
*window
,
227 wxObject
* userData
);
230 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
238 wxSizerItem( wxSizer
*sizer
,
242 wxObject
* userData
);
245 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
253 wxSizerItem( int width
,
261 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
265 DoSetSpacer(wxSize(width
, height
));
269 virtual ~wxSizerItem();
271 virtual void DeleteWindows();
273 // Enable deleting the SizerItem without destroying the contained sizer.
274 void DetachSizer() { m_sizer
= NULL
; }
276 virtual wxSize
GetSize() const;
277 virtual wxSize
CalcMin();
278 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
280 wxSize
GetMinSize() const
281 { return m_minSize
; }
282 wxSize
GetMinSizeWithBorder() const;
284 void SetMinSize(const wxSize
& size
)
287 m_window
->SetMinSize(size
);
290 void SetMinSize( int x
, int y
)
291 { SetMinSize(wxSize(x
, y
)); }
292 void SetInitSize( int x
, int y
)
293 { SetMinSize(wxSize(x
, y
)); }
295 // if either of dimensions is zero, ratio is assumed to be 1
296 // to avoid "divide by zero" errors
297 void SetRatio(int width
, int height
)
298 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
299 void SetRatio(const wxSize
& size
)
300 { SetRatio(size
.x
, size
.y
); }
301 void SetRatio(float ratio
)
303 float GetRatio() const
306 virtual wxRect
GetRect() { return m_rect
; }
308 // set a sizer item id (different from a window id, all sizer items,
309 // including spacers, can have an associated id)
310 void SetId(int id
) { m_id
= id
; }
311 int GetId() const { return m_id
; }
313 bool IsWindow() const { return m_kind
== Item_Window
; }
314 bool IsSizer() const { return m_kind
== Item_Sizer
; }
315 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
317 #if WXWIN_COMPATIBILITY_2_6
318 // Deprecated in 2.6, use {G,S}etProportion instead.
319 wxDEPRECATED( void SetOption( int option
) );
320 wxDEPRECATED( int GetOption() const );
321 #endif // WXWIN_COMPATIBILITY_2_6
323 void SetProportion( int proportion
)
324 { m_proportion
= proportion
; }
325 int GetProportion() const
326 { return m_proportion
; }
327 void SetFlag( int flag
)
331 void SetBorder( int border
)
332 { m_border
= border
; }
333 int GetBorder() const
336 wxWindow
*GetWindow() const
337 { return m_kind
== Item_Window
? m_window
: NULL
; }
338 wxSizer
*GetSizer() const
339 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
340 wxSize
GetSpacer() const;
342 // This function behaves obviously for the windows and spacers but for the
343 // sizers it returns true if any sizer element is shown and only returns
344 // false if all of them are hidden. Also, it always returns true if
345 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
346 bool IsShown() const;
348 void Show(bool show
);
350 void SetUserData(wxObject
* userData
)
351 { delete m_userData
; m_userData
= userData
; }
352 wxObject
* GetUserData() const
353 { return m_userData
; }
354 wxPoint
GetPosition() const
357 // Called once the first component of an item has been decided. This is
358 // used in algorithms that depend on knowing the size in one direction
359 // before the min size in the other direction can be known.
360 // Returns true if it made use of the information (and min size was changed).
361 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
363 // these functions delete the current contents of the item if it's a sizer
364 // or a spacer but not if it is a window
365 void AssignWindow(wxWindow
*window
)
371 void AssignSizer(wxSizer
*sizer
)
377 void AssignSpacer(const wxSize
& size
)
383 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
385 #if WXWIN_COMPATIBILITY_2_8
386 // these functions do not free the old sizer/spacer and so can easily
387 // provoke the memory leaks and so shouldn't be used, use Assign() instead
388 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
389 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
390 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
391 wxDEPRECATED( void SetSpacer(int width
, int height
) );
392 #endif // WXWIN_COMPATIBILITY_2_8
395 // common part of several ctors
396 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
398 // common part of ctors taking wxSizerFlags
399 void Init(const wxSizerFlags
& flags
);
401 // free current contents
404 // common parts of Set/AssignXXX()
405 void DoSetWindow(wxWindow
*window
);
406 void DoSetSizer(wxSizer
*sizer
);
407 void DoSetSpacer(const wxSize
& size
);
409 // discriminated union: depending on m_kind one of the fields is valid
422 wxSizerSpacer
*m_spacer
;
432 // on screen rectangle of this item (not including borders)
435 // Aspect ratio can always be calculated from m_size,
436 // but this would cause precision loss when the window
437 // is shrunk. It is safer to preserve the initial value.
440 wxObject
*m_userData
;
443 DECLARE_CLASS(wxSizerItem
)
444 DECLARE_NO_COPY_CLASS(wxSizerItem
)
447 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
450 //---------------------------------------------------------------------------
452 //---------------------------------------------------------------------------
454 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
457 wxSizer() { m_containingWindow
= NULL
; }
460 // methods for adding elements to the sizer: there are Add/Insert/Prepend
461 // overloads for each of window/sizer/spacer/wxSizerItem
462 wxSizerItem
* Add(wxWindow
*window
,
466 wxObject
* userData
= NULL
);
467 wxSizerItem
* Add(wxSizer
*sizer
,
471 wxObject
* userData
= NULL
);
472 wxSizerItem
* Add(int width
,
477 wxObject
* userData
= NULL
);
478 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
479 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
480 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
481 wxSizerItem
* Add( wxSizerItem
*item
);
483 wxSizerItem
* AddSpacer(int size
);
484 wxSizerItem
* AddStretchSpacer(int prop
= 1);
486 wxSizerItem
* Insert(size_t index
,
491 wxObject
* userData
= NULL
);
492 wxSizerItem
* Insert(size_t index
,
497 wxObject
* userData
= NULL
);
498 wxSizerItem
* Insert(size_t index
,
504 wxObject
* userData
= NULL
);
505 wxSizerItem
* Insert(size_t index
,
507 const wxSizerFlags
& flags
);
508 wxSizerItem
* Insert(size_t index
,
510 const wxSizerFlags
& flags
);
511 wxSizerItem
* Insert(size_t index
,
514 const wxSizerFlags
& flags
);
515 virtual wxSizerItem
* Insert( size_t index
, wxSizerItem
*item
);
517 wxSizerItem
* InsertSpacer(size_t index
, int size
);
518 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
520 wxSizerItem
* Prepend(wxWindow
*window
,
524 wxObject
* userData
= NULL
);
525 wxSizerItem
* Prepend(wxSizer
*sizer
,
529 wxObject
* userData
= NULL
);
530 wxSizerItem
* Prepend(int width
,
535 wxObject
* userData
= NULL
);
536 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
537 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
538 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
539 wxSizerItem
* Prepend(wxSizerItem
*item
);
541 wxSizerItem
* PrependSpacer(int size
);
542 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
544 // set (or possibly unset if window is NULL) or get the window this sizer
546 void SetContainingWindow(wxWindow
*window
);
547 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
549 #if WXWIN_COMPATIBILITY_2_6
550 // Deprecated in 2.6 since historically it does not delete the window,
551 // use Detach instead.
552 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
553 #endif // WXWIN_COMPATIBILITY_2_6
555 virtual bool Remove( wxSizer
*sizer
);
556 virtual bool Remove( int index
);
558 virtual bool Detach( wxWindow
*window
);
559 virtual bool Detach( wxSizer
*sizer
);
560 virtual bool Detach( int index
);
562 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
563 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
564 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
566 virtual void Clear( bool delete_windows
= false );
567 virtual void DeleteWindows();
569 // Inform sizer about the first direction that has been decided (by parent item)
570 // Returns true if it made use of the informtion (and recalculated min size)
571 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
574 void SetMinSize( int width
, int height
)
575 { DoSetMinSize( width
, height
); }
576 void SetMinSize( const wxSize
& size
)
577 { DoSetMinSize( size
.x
, size
.y
); }
579 // Searches recursively
580 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
581 { return DoSetItemMinSize( window
, width
, height
); }
582 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
583 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
585 // Searches recursively
586 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
587 { return DoSetItemMinSize( sizer
, width
, height
); }
588 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
589 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
591 bool SetItemMinSize( size_t index
, int width
, int height
)
592 { return DoSetItemMinSize( index
, width
, height
); }
593 bool SetItemMinSize( size_t index
, const wxSize
& size
)
594 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
596 wxSize
GetSize() const
598 wxPoint
GetPosition() const
599 { return m_position
; }
601 // Calculate the minimal size or return m_minSize if bigger.
604 // These virtual functions are used by the layout algorithm: first
605 // CalcMin() is called to calculate the minimal size of the sizer and
606 // prepare for laying it out and then RecalcSizes() is called to really
607 // update all the sizer items
608 virtual wxSize
CalcMin() = 0;
609 virtual void RecalcSizes() = 0;
611 virtual void Layout();
613 wxSize
ComputeFittingClientSize(wxWindow
*window
);
614 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
616 wxSize
Fit( wxWindow
*window
);
617 void FitInside( wxWindow
*window
);
618 void SetSizeHints( wxWindow
*window
);
619 #if WXWIN_COMPATIBILITY_2_8
620 // This only calls FitInside() since 2.9
621 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
624 wxSizerItemList
& GetChildren()
625 { return m_children
; }
626 const wxSizerItemList
& GetChildren() const
627 { return m_children
; }
629 void SetDimension( int x
, int y
, int width
, int height
);
631 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
632 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
633 wxSizerItem
* GetItem( size_t index
);
634 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
636 // Manage whether individual scene items are considered
637 // in the layout calculations or not.
638 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
639 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
640 bool Show( size_t index
, bool show
= true );
642 bool Hide( wxSizer
*sizer
, bool recursive
= false )
643 { return Show( sizer
, false, recursive
); }
644 bool Hide( wxWindow
*window
, bool recursive
= false )
645 { return Show( window
, false, recursive
); }
646 bool Hide( size_t index
)
647 { return Show( index
, false ); }
649 bool IsShown( wxWindow
*window
) const;
650 bool IsShown( wxSizer
*sizer
) const;
651 bool IsShown( size_t index
) const;
653 // Recursively call wxWindow::Show () on all sizer items.
654 virtual void ShowItems (bool show
);
656 void Show(bool show
) { ShowItems(show
); }
662 wxSizerItemList m_children
;
664 // the window this sizer is used in, can be NULL
665 wxWindow
*m_containingWindow
;
667 wxSize
GetMaxClientSize( wxWindow
*window
) const;
668 wxSize
GetMinClientSize( wxWindow
*window
);
669 wxSize
VirtualFitSize( wxWindow
*window
);
671 virtual void DoSetMinSize( int width
, int height
);
672 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
673 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
674 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
677 DECLARE_CLASS(wxSizer
)
680 //---------------------------------------------------------------------------
682 //---------------------------------------------------------------------------
684 class WXDLLEXPORT wxGridSizer
: public wxSizer
687 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
688 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
690 virtual void RecalcSizes();
691 virtual wxSize
CalcMin();
693 void SetCols( int cols
) { m_cols
= cols
; }
694 void SetRows( int rows
) { m_rows
= rows
; }
695 void SetVGap( int gap
) { m_vgap
= gap
; }
696 void SetHGap( int gap
) { m_hgap
= gap
; }
697 int GetCols() const { return m_cols
; }
698 int GetRows() const { return m_rows
; }
699 int GetVGap() const { return m_vgap
; }
700 int GetHGap() const { return m_hgap
; }
708 // return the number of total items and the number of columns and rows
709 int CalcRowsCols(int& rows
, int& cols
) const;
711 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
714 DECLARE_CLASS(wxGridSizer
)
717 //---------------------------------------------------------------------------
719 //---------------------------------------------------------------------------
721 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
723 enum wxFlexSizerGrowMode
725 // don't resize the cells in non-flexible direction at all
726 wxFLEX_GROWMODE_NONE
,
728 // uniformly resize only the specified ones (default)
729 wxFLEX_GROWMODE_SPECIFIED
,
731 // uniformly resize all cells
735 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
739 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
740 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
741 virtual ~wxFlexGridSizer();
744 // set the rows/columns which will grow (the others will remain of the
745 // constant initial size)
746 void AddGrowableRow( size_t idx
, int proportion
= 0 );
747 void RemoveGrowableRow( size_t idx
);
748 void AddGrowableCol( size_t idx
, int proportion
= 0 );
749 void RemoveGrowableCol( size_t idx
);
752 // the sizer cells may grow in both directions, not grow at all or only
753 // grow in one direction but not the other
755 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
756 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
757 int GetFlexibleDirection() const { return m_flexDirection
; }
759 // note that the grow mode only applies to the direction which is not
761 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
762 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
764 // Read-only access to the row heights and col widths arrays
765 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
766 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
769 virtual void RecalcSizes();
770 virtual wxSize
CalcMin();
773 void AdjustForFlexDirection();
774 void AdjustForGrowables(const wxSize
& sz
);
775 void FindWidthsAndHeights(int nrows
, int ncols
);
777 // the heights/widths of all rows/columns
778 wxArrayInt m_rowHeights
,
781 // indices of the growable columns and rows
782 wxArrayInt m_growableRows
,
785 // proportion values of the corresponding growable rows and columns
786 wxArrayInt m_growableRowsProportions
,
787 m_growableColsProportions
;
789 // parameters describing whether the growable cells should be resized in
790 // both directions or only one
792 wxFlexSizerGrowMode m_growMode
;
794 // saves CalcMin result to optimize RecalcSizes
795 wxSize m_calculatedMinSize
;
798 DECLARE_CLASS(wxFlexGridSizer
)
799 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
802 //---------------------------------------------------------------------------
804 //---------------------------------------------------------------------------
806 class WXDLLEXPORT wxBoxSizer
: public wxSizer
809 wxBoxSizer(int orient
)
812 m_totalProportion
= 0;
814 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
815 _T("invalid value for wxBoxSizer orientation") );
818 int GetOrientation() const { return m_orient
; }
820 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
822 void SetOrientation(int orient
) { m_orient
= orient
; }
824 // implementation of our resizing logic
825 virtual wxSize
CalcMin();
826 virtual void RecalcSizes();
829 // helpers for our code: this returns the component of the given wxSize in
830 // the direction of the sizer and in the other direction, respectively
831 int GetSizeInMajorDir(const wxSize
& sz
) const
833 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
836 int& SizeInMajorDir(wxSize
& sz
)
838 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
841 int& PosInMajorDir(wxPoint
& pt
)
843 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
846 int GetSizeInMinorDir(const wxSize
& sz
) const
848 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
851 int& SizeInMinorDir(wxSize
& sz
)
853 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
856 int& PosInMinorDir(wxPoint
& pt
)
858 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
861 // another helper: creates wxSize from major and minor components
862 wxSize
SizeFromMajorMinor(int major
, int minor
) const
864 if ( m_orient
== wxHORIZONTAL
)
866 return wxSize(major
, minor
);
870 return wxSize(minor
, major
);
875 // either wxHORIZONTAL or wxVERTICAL
878 // the sum of proportion of all of our elements
879 int m_totalProportion
;
881 // the minimal size needed for this sizer as calculated by the last call to
886 DECLARE_CLASS(wxBoxSizer
)
889 //---------------------------------------------------------------------------
890 // wxWrapSizer - A box sizer that can wrap items on several lines when
891 // widths exceed available width.
892 //---------------------------------------------------------------------------
894 // Borrow unused flag value
895 #define wxEXTEND_LAST_ON_EACH_LINE wxFULL_REPAINT_ON_RESIZE
897 class WXDLLEXPORT wxWrapSizer
: public wxBoxSizer
900 wxWrapSizer( int orient
=wxHORIZONTAL
, int flags
=wxEXTEND_LAST_ON_EACH_LINE
);
901 virtual ~wxWrapSizer();
903 virtual void RecalcSizes();
904 virtual wxSize
CalcMin();
906 virtual bool InformFirstDirection( int direction
, int size
, int availableOtherDir
);
909 int m_prim_size_last
; // Size in primary direction last time
910 int m_n_line
; // Number of lines
911 wxBoxSizer m_rows
; // Rows of items
914 void AdjustPropLastItem(wxSizer
*psz
, wxSizerItem
*itemLast
);
916 DECLARE_DYNAMIC_CLASS(wxWrapSizer
)
919 //---------------------------------------------------------------------------
921 //---------------------------------------------------------------------------
925 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
927 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
930 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
931 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
932 virtual ~wxStaticBoxSizer();
937 wxStaticBox
*GetStaticBox() const
938 { return m_staticBox
; }
940 // override to hide/show the static box as well
941 virtual void ShowItems (bool show
);
943 virtual bool Detach( wxWindow
*window
);
944 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
945 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
948 wxStaticBox
*m_staticBox
;
951 DECLARE_CLASS(wxStaticBoxSizer
)
952 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
955 #endif // wxUSE_STATBOX
959 class WXDLLEXPORT wxStdDialogButtonSizer
: public wxBoxSizer
962 // Constructor just creates a new wxBoxSizer, not much else.
963 // Box sizer orientation is automatically determined here:
964 // vertical for PDAs, horizontal for everything else?
965 wxStdDialogButtonSizer();
967 // Checks button ID against system IDs and sets one of the pointers below
968 // to this button. Does not do any sizer-related things here.
969 void AddButton(wxButton
*button
);
971 // Use these if no standard ID can/should be used
972 void SetAffirmativeButton( wxButton
*button
);
973 void SetNegativeButton( wxButton
*button
);
974 void SetCancelButton( wxButton
*button
);
976 // All platform-specific code here, checks which buttons exist and add
977 // them to the sizer accordingly.
978 // Note - one potential hack on Mac we could use here,
979 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
980 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
981 // I wouldn't add any other hacks like that into here,
982 // but this one I can see being useful.
985 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
986 wxButton
*GetApplyButton() const { return m_buttonApply
; }
987 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
988 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
989 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
992 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
993 wxButton
*m_buttonApply
; // wxID_APPLY
994 wxButton
*m_buttonNegative
; // wxID_NO
995 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
996 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
999 DECLARE_CLASS(wxStdDialogButtonSizer
)
1000 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
)
1003 #endif // wxUSE_BUTTON
1006 // ----------------------------------------------------------------------------
1007 // inline functions implementation
1008 // ----------------------------------------------------------------------------
1010 #if WXWIN_COMPATIBILITY_2_8
1012 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1014 DoSetWindow(window
);
1017 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1022 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1027 inline void wxSizerItem::SetSpacer(int width
, int height
)
1029 DoSetSpacer(wxSize(width
, height
));
1032 #endif // WXWIN_COMPATIBILITY_2_8
1036 wxSizer::Add( wxSizerItem
*item
)
1038 return Insert( m_children
.GetCount(), item
);
1042 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1044 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1048 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1050 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1054 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1056 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1060 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1062 return Add( new wxSizerItem(window
, flags
) );
1066 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1068 return Add( new wxSizerItem(sizer
, flags
) );
1072 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1074 return Add( new wxSizerItem(width
, height
, flags
) );
1078 wxSizer::AddSpacer(int size
)
1080 return Add(size
, size
);
1084 wxSizer::AddStretchSpacer(int prop
)
1086 return Add(0, 0, prop
);
1090 wxSizer::Prepend( wxSizerItem
*item
)
1092 return Insert( 0, item
);
1096 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1098 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1102 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1104 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1108 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1110 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1114 wxSizer::PrependSpacer(int size
)
1116 return Prepend(size
, size
);
1120 wxSizer::PrependStretchSpacer(int prop
)
1122 return Prepend(0, 0, prop
);
1126 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1128 return Prepend( new wxSizerItem(window
, flags
) );
1132 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1134 return Prepend( new wxSizerItem(sizer
, flags
) );
1138 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1140 return Prepend( new wxSizerItem(width
, height
, flags
) );
1144 wxSizer::Insert( size_t index
,
1149 wxObject
* userData
)
1151 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1155 wxSizer::Insert( size_t index
,
1160 wxObject
* userData
)
1162 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1166 wxSizer::Insert( size_t index
,
1172 wxObject
* userData
)
1174 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1178 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1180 return Insert( index
, new wxSizerItem(window
, flags
) );
1184 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1186 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1190 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1192 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1196 wxSizer::InsertSpacer(size_t index
, int size
)
1198 return Insert(index
, size
, size
);
1202 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1204 return Insert(index
, 0, 0, prop
);
1207 #endif // __WXSIZER_H__