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 // accessors for wxSizer only
174 int GetProportion() const { return m_proportion
; }
175 int GetFlags() const { return m_flags
; }
176 int GetBorderInPixels() const { return m_borderInPixels
; }
181 int m_borderInPixels
;
185 // ----------------------------------------------------------------------------
186 // wxSizerSpacer: used by wxSizerItem to represent a spacer
187 // ----------------------------------------------------------------------------
189 class WXDLLEXPORT wxSizerSpacer
192 wxSizerSpacer(const wxSize
& size
) : m_size(size
), m_isShown(true) { }
194 void SetSize(const wxSize
& size
) { m_size
= size
; }
195 const wxSize
& GetSize() const { return m_size
; }
197 void Show(bool show
) { m_isShown
= show
; }
198 bool IsShown() const { return m_isShown
; }
201 // the size, in pixel
204 // is the spacer currently shown?
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 class WXDLLEXPORT wxSizerItem
: public wxObject
216 wxSizerItem( wxWindow
*window
,
220 wxObject
* userData
);
223 wxSizerItem(wxWindow
*window
, const wxSizerFlags
& flags
)
231 wxSizerItem( wxSizer
*sizer
,
235 wxObject
* userData
);
238 wxSizerItem(wxSizer
*sizer
, const wxSizerFlags
& flags
)
246 wxSizerItem( int width
,
254 wxSizerItem(int width
, int height
, const wxSizerFlags
& flags
)
258 DoSetSpacer(wxSize(width
, height
));
262 virtual ~wxSizerItem();
264 virtual void DeleteWindows();
266 // Enable deleting the SizerItem without destroying the contained sizer.
267 void DetachSizer() { m_sizer
= NULL
; }
269 virtual wxSize
GetSize() const;
270 virtual wxSize
CalcMin();
271 virtual void SetDimension( const wxPoint
& pos
, const wxSize
& size
);
273 wxSize
GetMinSize() const
274 { return m_minSize
; }
275 wxSize
GetMinSizeWithBorder() const;
277 void SetMinSize(const wxSize
& size
)
280 m_window
->SetMinSize(size
);
283 void SetMinSize( int x
, int y
)
284 { SetMinSize(wxSize(x
, y
)); }
285 void SetInitSize( int x
, int y
)
286 { SetMinSize(wxSize(x
, y
)); }
288 // if either of dimensions is zero, ratio is assumed to be 1
289 // to avoid "divide by zero" errors
290 void SetRatio(int width
, int height
)
291 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
292 void SetRatio(const wxSize
& size
)
293 { SetRatio(size
.x
, size
.y
); }
294 void SetRatio(float ratio
)
296 float GetRatio() const
299 virtual wxRect
GetRect() { return m_rect
; }
301 // set a sizer item id (different from a window id, all sizer items,
302 // including spacers, can have an associated id)
303 void SetId(int id
) { m_id
= id
; }
304 int GetId() const { return m_id
; }
306 bool IsWindow() const { return m_kind
== Item_Window
; }
307 bool IsSizer() const { return m_kind
== Item_Sizer
; }
308 bool IsSpacer() const { return m_kind
== Item_Spacer
; }
310 #if WXWIN_COMPATIBILITY_2_6
311 // Deprecated in 2.6, use {G,S}etProportion instead.
312 wxDEPRECATED( void SetOption( int option
) );
313 wxDEPRECATED( int GetOption() const );
314 #endif // WXWIN_COMPATIBILITY_2_6
316 void SetProportion( int proportion
)
317 { m_proportion
= proportion
; }
318 int GetProportion() const
319 { return m_proportion
; }
320 void SetFlag( int flag
)
324 void SetBorder( int border
)
325 { m_border
= border
; }
326 int GetBorder() const
329 wxWindow
*GetWindow() const
330 { return m_kind
== Item_Window
? m_window
: NULL
; }
331 wxSizer
*GetSizer() const
332 { return m_kind
== Item_Sizer
? m_sizer
: NULL
; }
333 wxSize
GetSpacer() const;
335 // this function behaves obviously for the windows and spacers but for the
336 // sizers it returns true if any sizer element is shown and only returns
337 // false if all of them are hidden
338 bool IsShown() const;
339 void Show(bool show
);
341 void SetUserData(wxObject
* userData
)
342 { delete m_userData
; m_userData
= userData
; }
343 wxObject
* GetUserData() const
344 { return m_userData
; }
345 wxPoint
GetPosition() const
348 // Called once the first component of an item has been decided. This is
349 // used in algorithms that depend on knowing the size in one direction
350 // before the min size in the other direction can be known.
351 // Returns true if it made use of the information (and min size was changed).
352 bool InformFirstDirection( int direction
, int size
, int availableOtherDir
=-1 );
354 // these functions delete the current contents of the item if it's a sizer
355 // or a spacer but not if it is a window
356 void AssignWindow(wxWindow
*window
)
362 void AssignSizer(wxSizer
*sizer
)
368 void AssignSpacer(const wxSize
& size
)
374 void AssignSpacer(int w
, int h
) { AssignSpacer(wxSize(w
, h
)); }
376 #if WXWIN_COMPATIBILITY_2_8
377 // these functions do not free the old sizer/spacer and so can easily
378 // provoke the memory leaks and so shouldn't be used, use Assign() instead
379 wxDEPRECATED( void SetWindow(wxWindow
*window
) );
380 wxDEPRECATED( void SetSizer(wxSizer
*sizer
) );
381 wxDEPRECATED( void SetSpacer(const wxSize
& size
) );
382 wxDEPRECATED( void SetSpacer(int width
, int height
) );
383 #endif // WXWIN_COMPATIBILITY_2_8
386 // common part of several ctors
387 void Init() { m_userData
= NULL
; m_kind
= Item_None
; }
389 // common part of ctors taking wxSizerFlags
390 void Init(const wxSizerFlags
& flags
);
392 // free current contents
395 // common parts of Set/AssignXXX()
396 void DoSetWindow(wxWindow
*window
);
397 void DoSetSizer(wxSizer
*sizer
);
398 void DoSetSpacer(const wxSize
& size
);
400 // discriminated union: depending on m_kind one of the fields is valid
413 wxSizerSpacer
*m_spacer
;
423 // on screen rectangle of this item (not including borders)
426 // Aspect ratio can always be calculated from m_size,
427 // but this would cause precision loss when the window
428 // is shrunk. It is safer to preserve the initial value.
431 wxObject
*m_userData
;
434 DECLARE_CLASS(wxSizerItem
)
435 DECLARE_NO_COPY_CLASS(wxSizerItem
)
438 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
441 //---------------------------------------------------------------------------
443 //---------------------------------------------------------------------------
445 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
448 wxSizer() { m_containingWindow
= NULL
; }
451 // methods for adding elements to the sizer: there are Add/Insert/Prepend
452 // overloads for each of window/sizer/spacer/wxSizerItem
453 wxSizerItem
* Add(wxWindow
*window
,
457 wxObject
* userData
= NULL
);
458 wxSizerItem
* Add(wxSizer
*sizer
,
462 wxObject
* userData
= NULL
);
463 wxSizerItem
* Add(int width
,
468 wxObject
* userData
= NULL
);
469 wxSizerItem
* Add( wxWindow
*window
, const wxSizerFlags
& flags
);
470 wxSizerItem
* Add( wxSizer
*sizer
, const wxSizerFlags
& flags
);
471 wxSizerItem
* Add( int width
, int height
, const wxSizerFlags
& flags
);
472 wxSizerItem
* Add( wxSizerItem
*item
);
474 wxSizerItem
* AddSpacer(int size
);
475 wxSizerItem
* AddStretchSpacer(int prop
= 1);
477 wxSizerItem
* Insert(size_t index
,
482 wxObject
* userData
= NULL
);
483 wxSizerItem
* Insert(size_t index
,
488 wxObject
* userData
= NULL
);
489 wxSizerItem
* Insert(size_t index
,
495 wxObject
* userData
= NULL
);
496 wxSizerItem
* Insert(size_t index
,
498 const wxSizerFlags
& flags
);
499 wxSizerItem
* Insert(size_t index
,
501 const wxSizerFlags
& flags
);
502 wxSizerItem
* Insert(size_t index
,
505 const wxSizerFlags
& flags
);
506 virtual wxSizerItem
* Insert( size_t index
, wxSizerItem
*item
);
508 wxSizerItem
* InsertSpacer(size_t index
, int size
);
509 wxSizerItem
* InsertStretchSpacer(size_t index
, int prop
= 1);
511 wxSizerItem
* Prepend(wxWindow
*window
,
515 wxObject
* userData
= NULL
);
516 wxSizerItem
* Prepend(wxSizer
*sizer
,
520 wxObject
* userData
= NULL
);
521 wxSizerItem
* Prepend(int width
,
526 wxObject
* userData
= NULL
);
527 wxSizerItem
* Prepend(wxWindow
*window
, const wxSizerFlags
& flags
);
528 wxSizerItem
* Prepend(wxSizer
*sizer
, const wxSizerFlags
& flags
);
529 wxSizerItem
* Prepend(int width
, int height
, const wxSizerFlags
& flags
);
530 wxSizerItem
* Prepend(wxSizerItem
*item
);
532 wxSizerItem
* PrependSpacer(int size
);
533 wxSizerItem
* PrependStretchSpacer(int prop
= 1);
535 // set (or possibly unset if window is NULL) or get the window this sizer
537 void SetContainingWindow(wxWindow
*window
);
538 wxWindow
*GetContainingWindow() const { return m_containingWindow
; }
540 #if WXWIN_COMPATIBILITY_2_6
541 // Deprecated in 2.6 since historically it does not delete the window,
542 // use Detach instead.
543 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
544 #endif // WXWIN_COMPATIBILITY_2_6
546 virtual bool Remove( wxSizer
*sizer
);
547 virtual bool Remove( int index
);
549 virtual bool Detach( wxWindow
*window
);
550 virtual bool Detach( wxSizer
*sizer
);
551 virtual bool Detach( int index
);
553 virtual bool Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
= false );
554 virtual bool Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
= false );
555 virtual bool Replace( size_t index
, wxSizerItem
*newitem
);
557 virtual void Clear( bool delete_windows
= false );
558 virtual void DeleteWindows();
560 // Inform sizer about the first direction that has been decided (by parent item)
561 // Returns true if it made use of the informtion (and recalculated min size)
562 virtual bool InformFirstDirection( int WXUNUSED(direction
), int WXUNUSED(size
), int WXUNUSED(availableOtherDir
) )
565 void SetMinSize( int width
, int height
)
566 { DoSetMinSize( width
, height
); }
567 void SetMinSize( const wxSize
& size
)
568 { DoSetMinSize( size
.x
, size
.y
); }
570 // Searches recursively
571 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
572 { return DoSetItemMinSize( window
, width
, height
); }
573 bool SetItemMinSize( wxWindow
*window
, const wxSize
& size
)
574 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
576 // Searches recursively
577 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
578 { return DoSetItemMinSize( sizer
, width
, height
); }
579 bool SetItemMinSize( wxSizer
*sizer
, const wxSize
& size
)
580 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
582 bool SetItemMinSize( size_t index
, int width
, int height
)
583 { return DoSetItemMinSize( index
, width
, height
); }
584 bool SetItemMinSize( size_t index
, const wxSize
& size
)
585 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
587 wxSize
GetSize() const
589 wxPoint
GetPosition() const
590 { return m_position
; }
592 // Calculate the minimal size or return m_minSize if bigger.
595 // These virtual functions are used by the layout algorithm: first
596 // CalcMin() is called to calculate the minimal size of the sizer and
597 // prepare for laying it out and then RecalcSizes() is called to really
598 // update all the sizer items
599 virtual wxSize
CalcMin() = 0;
600 virtual void RecalcSizes() = 0;
602 virtual void Layout();
604 wxSize
ComputeFittingClientSize(wxWindow
*window
);
605 wxSize
ComputeFittingWindowSize(wxWindow
*window
);
607 wxSize
Fit( wxWindow
*window
);
608 void FitInside( wxWindow
*window
);
609 void SetSizeHints( wxWindow
*window
);
610 #if WXWIN_COMPATIBILITY_2_8
611 // This only calls FitInside() since 2.9
612 wxDEPRECATED( void SetVirtualSizeHints( wxWindow
*window
) );
615 wxSizerItemList
& GetChildren()
616 { return m_children
; }
617 const wxSizerItemList
& GetChildren() const
618 { return m_children
; }
620 void SetDimension( int x
, int y
, int width
, int height
);
622 wxSizerItem
* GetItem( wxWindow
*window
, bool recursive
= false );
623 wxSizerItem
* GetItem( wxSizer
*sizer
, bool recursive
= false );
624 wxSizerItem
* GetItem( size_t index
);
625 wxSizerItem
* GetItemById( int id
, bool recursive
= false );
627 // Manage whether individual scene items are considered
628 // in the layout calculations or not.
629 bool Show( wxWindow
*window
, bool show
= true, bool recursive
= false );
630 bool Show( wxSizer
*sizer
, bool show
= true, bool recursive
= false );
631 bool Show( size_t index
, bool show
= true );
633 bool Hide( wxSizer
*sizer
, bool recursive
= false )
634 { return Show( sizer
, false, recursive
); }
635 bool Hide( wxWindow
*window
, bool recursive
= false )
636 { return Show( window
, false, recursive
); }
637 bool Hide( size_t index
)
638 { return Show( index
, false ); }
640 bool IsShown( wxWindow
*window
) const;
641 bool IsShown( wxSizer
*sizer
) const;
642 bool IsShown( size_t index
) const;
644 // Recursively call wxWindow::Show () on all sizer items.
645 virtual void ShowItems (bool show
);
647 void Show(bool show
) { ShowItems(show
); }
653 wxSizerItemList m_children
;
655 // the window this sizer is used in, can be NULL
656 wxWindow
*m_containingWindow
;
658 wxSize
GetMaxClientSize( wxWindow
*window
) const;
659 wxSize
GetMinClientSize( wxWindow
*window
);
660 wxSize
VirtualFitSize( wxWindow
*window
);
662 virtual void DoSetMinSize( int width
, int height
);
663 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
664 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
665 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
668 DECLARE_CLASS(wxSizer
)
671 //---------------------------------------------------------------------------
673 //---------------------------------------------------------------------------
675 class WXDLLEXPORT wxGridSizer
: public wxSizer
678 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
679 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
681 virtual void RecalcSizes();
682 virtual wxSize
CalcMin();
684 void SetCols( int cols
) { m_cols
= cols
; }
685 void SetRows( int rows
) { m_rows
= rows
; }
686 void SetVGap( int gap
) { m_vgap
= gap
; }
687 void SetHGap( int gap
) { m_hgap
= gap
; }
688 int GetCols() const { return m_cols
; }
689 int GetRows() const { return m_rows
; }
690 int GetVGap() const { return m_vgap
; }
691 int GetHGap() const { return m_hgap
; }
699 // return the number of total items and the number of columns and rows
700 int CalcRowsCols(int& rows
, int& cols
) const;
702 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
705 DECLARE_CLASS(wxGridSizer
)
708 //---------------------------------------------------------------------------
710 //---------------------------------------------------------------------------
712 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
714 enum wxFlexSizerGrowMode
716 // don't resize the cells in non-flexible direction at all
717 wxFLEX_GROWMODE_NONE
,
719 // uniformly resize only the specified ones (default)
720 wxFLEX_GROWMODE_SPECIFIED
,
722 // uniformly resize all cells
726 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
730 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
731 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
732 virtual ~wxFlexGridSizer();
735 // set the rows/columns which will grow (the others will remain of the
736 // constant initial size)
737 void AddGrowableRow( size_t idx
, int proportion
= 0 );
738 void RemoveGrowableRow( size_t idx
);
739 void AddGrowableCol( size_t idx
, int proportion
= 0 );
740 void RemoveGrowableCol( size_t idx
);
743 // the sizer cells may grow in both directions, not grow at all or only
744 // grow in one direction but not the other
746 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
747 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
748 int GetFlexibleDirection() const { return m_flexDirection
; }
750 // note that the grow mode only applies to the direction which is not
752 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
753 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
755 // Read-only access to the row heights and col widths arrays
756 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
757 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
760 virtual void RecalcSizes();
761 virtual wxSize
CalcMin();
764 void AdjustForFlexDirection();
765 void AdjustForGrowables(const wxSize
& sz
);
766 void FindWidthsAndHeights(int nrows
, int ncols
);
768 // the heights/widths of all rows/columns
769 wxArrayInt m_rowHeights
,
772 // indices of the growable columns and rows
773 wxArrayInt m_growableRows
,
776 // proportion values of the corresponding growable rows and columns
777 wxArrayInt m_growableRowsProportions
,
778 m_growableColsProportions
;
780 // parameters describing whether the growable cells should be resized in
781 // both directions or only one
783 wxFlexSizerGrowMode m_growMode
;
785 // saves CalcMin result to optimize RecalcSizes
786 wxSize m_calculatedMinSize
;
789 DECLARE_CLASS(wxFlexGridSizer
)
790 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
793 //---------------------------------------------------------------------------
795 //---------------------------------------------------------------------------
797 class WXDLLEXPORT wxBoxSizer
: public wxSizer
800 wxBoxSizer(int orient
)
803 m_totalProportion
= 0;
805 wxASSERT_MSG( m_orient
== wxHORIZONTAL
|| m_orient
== wxVERTICAL
,
806 _T("invalid value for wxBoxSizer orientation") );
809 int GetOrientation() const { return m_orient
; }
811 bool IsVertical() const { return m_orient
== wxVERTICAL
; }
813 void SetOrientation(int orient
) { m_orient
= orient
; }
815 // implementation of our resizing logic
816 virtual wxSize
CalcMin();
817 virtual void RecalcSizes();
820 // helpers for our code: this returns the component of the given wxSize in
821 // the direction of the sizer and in the other direction, respectively
822 int GetSizeInMajorDir(const wxSize
& sz
) const
824 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
827 int& SizeInMajorDir(wxSize
& sz
)
829 return m_orient
== wxHORIZONTAL
? sz
.x
: sz
.y
;
832 int& PosInMajorDir(wxPoint
& pt
)
834 return m_orient
== wxHORIZONTAL
? pt
.x
: pt
.y
;
837 int GetSizeInMinorDir(const wxSize
& sz
) const
839 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
842 int& SizeInMinorDir(wxSize
& sz
)
844 return m_orient
== wxHORIZONTAL
? sz
.y
: sz
.x
;
847 int& PosInMinorDir(wxPoint
& pt
)
849 return m_orient
== wxHORIZONTAL
? pt
.y
: pt
.x
;
852 // another helper: creates wxSize from major and minor components
853 wxSize
SizeFromMajorMinor(int major
, int minor
) const
855 if ( m_orient
== wxHORIZONTAL
)
857 return wxSize(major
, minor
);
861 return wxSize(minor
, major
);
866 // either wxHORIZONTAL or wxVERTICAL
869 // the sum of proportion of all of our elements
870 int m_totalProportion
;
872 // the minimal size needed for this sizer as calculated by the last call to
877 DECLARE_CLASS(wxBoxSizer
)
880 //---------------------------------------------------------------------------
881 // wxWrapSizer - A box sizer that can wrap items on several lines when
882 // widths exceed available width.
883 //---------------------------------------------------------------------------
885 // Borrow unused flag value
886 #define wxEXTEND_LAST_ON_EACH_LINE wxFULL_REPAINT_ON_RESIZE
888 class WXDLLEXPORT wxWrapSizer
: public wxBoxSizer
891 wxWrapSizer( int orient
=wxHORIZONTAL
, int flags
=wxEXTEND_LAST_ON_EACH_LINE
);
892 virtual ~wxWrapSizer();
894 virtual void RecalcSizes();
895 virtual wxSize
CalcMin();
897 virtual bool InformFirstDirection( int direction
, int size
, int availableOtherDir
);
900 int m_prim_size_last
; // Size in primary direction last time
901 int m_n_line
; // Number of lines
902 wxBoxSizer m_rows
; // Rows of items
905 void AdjustPropLastItem(wxSizer
*psz
, wxSizerItem
*itemLast
);
907 DECLARE_DYNAMIC_CLASS(wxWrapSizer
)
910 //---------------------------------------------------------------------------
912 //---------------------------------------------------------------------------
916 class WXDLLIMPEXP_FWD_CORE wxStaticBox
;
918 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
921 wxStaticBoxSizer(wxStaticBox
*box
, int orient
);
922 wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& label
= wxEmptyString
);
923 virtual ~wxStaticBoxSizer();
928 wxStaticBox
*GetStaticBox() const
929 { return m_staticBox
; }
931 // override to hide/show the static box as well
932 virtual void ShowItems (bool show
);
934 virtual bool Detach( wxWindow
*window
);
935 virtual bool Detach( wxSizer
*sizer
) { return wxBoxSizer::Detach(sizer
); }
936 virtual bool Detach( int index
) { return wxBoxSizer::Detach(index
); }
939 wxStaticBox
*m_staticBox
;
942 DECLARE_CLASS(wxStaticBoxSizer
)
943 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
946 #endif // wxUSE_STATBOX
950 class WXDLLEXPORT wxStdDialogButtonSizer
: public wxBoxSizer
953 // Constructor just creates a new wxBoxSizer, not much else.
954 // Box sizer orientation is automatically determined here:
955 // vertical for PDAs, horizontal for everything else?
956 wxStdDialogButtonSizer();
958 // Checks button ID against system IDs and sets one of the pointers below
959 // to this button. Does not do any sizer-related things here.
960 void AddButton(wxButton
*button
);
962 // Use these if no standard ID can/should be used
963 void SetAffirmativeButton( wxButton
*button
);
964 void SetNegativeButton( wxButton
*button
);
965 void SetCancelButton( wxButton
*button
);
967 // All platform-specific code here, checks which buttons exist and add
968 // them to the sizer accordingly.
969 // Note - one potential hack on Mac we could use here,
970 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
971 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
972 // I wouldn't add any other hacks like that into here,
973 // but this one I can see being useful.
976 wxButton
*GetAffirmativeButton() const { return m_buttonAffirmative
; }
977 wxButton
*GetApplyButton() const { return m_buttonApply
; }
978 wxButton
*GetNegativeButton() const { return m_buttonNegative
; }
979 wxButton
*GetCancelButton() const { return m_buttonCancel
; }
980 wxButton
*GetHelpButton() const { return m_buttonHelp
; }
983 wxButton
*m_buttonAffirmative
; // wxID_OK, wxID_YES, wxID_SAVE go here
984 wxButton
*m_buttonApply
; // wxID_APPLY
985 wxButton
*m_buttonNegative
; // wxID_NO
986 wxButton
*m_buttonCancel
; // wxID_CANCEL, wxID_CLOSE
987 wxButton
*m_buttonHelp
; // wxID_HELP, wxID_CONTEXT_HELP
990 DECLARE_CLASS(wxStdDialogButtonSizer
)
991 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer
)
994 #endif // wxUSE_BUTTON
997 // ----------------------------------------------------------------------------
998 // inline functions implementation
999 // ----------------------------------------------------------------------------
1001 #if WXWIN_COMPATIBILITY_2_8
1003 inline void wxSizerItem::SetWindow(wxWindow
*window
)
1005 DoSetWindow(window
);
1008 inline void wxSizerItem::SetSizer(wxSizer
*sizer
)
1013 inline void wxSizerItem::SetSpacer(const wxSize
& size
)
1018 inline void wxSizerItem::SetSpacer(int width
, int height
)
1020 DoSetSpacer(wxSize(width
, height
));
1023 #endif // WXWIN_COMPATIBILITY_2_8
1027 wxSizer::Add( wxSizerItem
*item
)
1029 return Insert( m_children
.GetCount(), item
);
1033 wxSizer::Add( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1035 return Add( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1039 wxSizer::Add( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1041 return Add( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1045 wxSizer::Add( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1047 return Add( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1051 wxSizer::Add( wxWindow
*window
, const wxSizerFlags
& flags
)
1053 return Add( new wxSizerItem(window
, flags
) );
1057 wxSizer::Add( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1059 return Add( new wxSizerItem(sizer
, flags
) );
1063 wxSizer::Add( int width
, int height
, const wxSizerFlags
& flags
)
1065 return Add( new wxSizerItem(width
, height
, flags
) );
1069 wxSizer::AddSpacer(int size
)
1071 return Add(size
, size
);
1075 wxSizer::AddStretchSpacer(int prop
)
1077 return Add(0, 0, prop
);
1081 wxSizer::Prepend( wxSizerItem
*item
)
1083 return Insert( 0, item
);
1087 wxSizer::Prepend( wxWindow
*window
, int proportion
, int flag
, int border
, wxObject
* userData
)
1089 return Prepend( new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1093 wxSizer::Prepend( wxSizer
*sizer
, int proportion
, int flag
, int border
, wxObject
* userData
)
1095 return Prepend( new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1099 wxSizer::Prepend( int width
, int height
, int proportion
, int flag
, int border
, wxObject
* userData
)
1101 return Prepend( new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1105 wxSizer::PrependSpacer(int size
)
1107 return Prepend(size
, size
);
1111 wxSizer::PrependStretchSpacer(int prop
)
1113 return Prepend(0, 0, prop
);
1117 wxSizer::Prepend( wxWindow
*window
, const wxSizerFlags
& flags
)
1119 return Prepend( new wxSizerItem(window
, flags
) );
1123 wxSizer::Prepend( wxSizer
*sizer
, const wxSizerFlags
& flags
)
1125 return Prepend( new wxSizerItem(sizer
, flags
) );
1129 wxSizer::Prepend( int width
, int height
, const wxSizerFlags
& flags
)
1131 return Prepend( new wxSizerItem(width
, height
, flags
) );
1135 wxSizer::Insert( size_t index
,
1140 wxObject
* userData
)
1142 return Insert( index
, new wxSizerItem( window
, proportion
, flag
, border
, userData
) );
1146 wxSizer::Insert( size_t index
,
1151 wxObject
* userData
)
1153 return Insert( index
, new wxSizerItem( sizer
, proportion
, flag
, border
, userData
) );
1157 wxSizer::Insert( size_t index
,
1163 wxObject
* userData
)
1165 return Insert( index
, new wxSizerItem( width
, height
, proportion
, flag
, border
, userData
) );
1169 wxSizer::Insert( size_t index
, wxWindow
*window
, const wxSizerFlags
& flags
)
1171 return Insert( index
, new wxSizerItem(window
, flags
) );
1175 wxSizer::Insert( size_t index
, wxSizer
*sizer
, const wxSizerFlags
& flags
)
1177 return Insert( index
, new wxSizerItem(sizer
, flags
) );
1181 wxSizer::Insert( size_t index
, int width
, int height
, const wxSizerFlags
& flags
)
1183 return Insert( index
, new wxSizerItem(width
, height
, flags
) );
1187 wxSizer::InsertSpacer(size_t index
, int size
)
1189 return Insert(index
, size
, size
);
1193 wxSizer::InsertStretchSpacer(size_t index
, int prop
)
1195 return Insert(index
, 0, 0, prop
);
1198 #endif // __WXSIZER_H__