1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee
8 // Copyright: (c) Robin Dunn, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "sizer.h"
21 #include "wx/window.h"
23 #include "wx/dialog.h"
25 //---------------------------------------------------------------------------
27 //---------------------------------------------------------------------------
33 //---------------------------------------------------------------------------
35 //---------------------------------------------------------------------------
37 class WXDLLEXPORT wxSizerItem
: public wxObject
41 wxSizerItem( int width
,
49 wxSizerItem( wxWindow
*window
,
56 wxSizerItem( wxSizer
*sizer
,
63 virtual ~wxSizerItem();
65 virtual void DeleteWindows();
67 // Enable deleting the SizerItem without destroying the contained sizer.
71 virtual wxSize
GetSize() const;
72 virtual wxSize
CalcMin();
73 virtual void SetDimension( wxPoint pos
, wxSize size
);
75 wxSize
GetMinSize() const
77 void SetMinSize(const wxSize
& size
)
79 if (IsWindow() && !(m_flag
& wxFIXED_MINSIZE
))
80 m_window
->SetSizeHints(size
);
83 void SetMinSize( int x
, int y
)
84 { SetMinSize(wxSize(x
, y
)); }
85 void SetInitSize( int x
, int y
)
86 { SetMinSize(wxSize(x
, y
)); }
88 void SetRatio( int width
, int height
)
89 // if either of dimensions is zero, ratio is assumed to be 1
90 // to avoid "divide by zero" errors
91 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
92 void SetRatio( wxSize size
)
93 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
94 void SetRatio( float ratio
)
96 float GetRatio() const
99 bool IsWindow() const;
100 bool IsSizer() const;
101 bool IsSpacer() const;
103 // Deprecated in 2.6, use {G,S}etProportion instead.
104 wxDEPRECATED( void SetOption( int option
) );
105 wxDEPRECATED( int GetOption() const );
107 void SetProportion( int proportion
)
108 { m_proportion
= proportion
; }
109 int GetProportion() const
110 { return m_proportion
; }
111 void SetFlag( int flag
)
115 void SetBorder( int border
)
116 { m_border
= border
; }
117 int GetBorder() const
120 wxWindow
*GetWindow() const
122 void SetWindow( wxWindow
*window
)
123 { m_window
= window
; m_minSize
= window
->GetSize(); }
124 wxSizer
*GetSizer() const
126 void SetSizer( wxSizer
*sizer
)
128 const wxSize
&GetSpacer() const
130 void SetSpacer( const wxSize
&size
)
131 { m_size
= size
; m_minSize
= size
; }
133 void Show ( bool show
);
137 wxObject
* GetUserData() const
138 { return m_userData
; }
139 wxPoint
GetPosition() const
152 // If true, then this item is considered in the layout
153 // calculation. Otherwise, it is skipped over.
156 // Aspect ratio can always be calculated from m_size,
157 // but this would cause precision loss when the window
158 // is shrunk. It is safer to preserve the initial value.
161 wxObject
*m_userData
;
164 DECLARE_CLASS(wxSizerItem
)
165 DECLARE_NO_COPY_CLASS(wxSizerItem
)
168 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
171 //---------------------------------------------------------------------------
173 //---------------------------------------------------------------------------
175 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
181 /* These should be called Append() really. */
182 virtual void Add( wxWindow
*window
,
186 wxObject
* userData
= NULL
);
187 virtual void Add( wxSizer
*sizer
,
191 wxObject
* userData
= NULL
);
192 virtual void Add( int width
,
197 wxObject
* userData
= NULL
);
198 virtual void Add( wxSizerItem
*item
);
200 virtual void Insert( size_t index
,
205 wxObject
* userData
= NULL
);
206 virtual void Insert( size_t index
,
211 wxObject
* userData
= NULL
);
212 virtual void Insert( size_t index
,
218 wxObject
* userData
= NULL
);
219 virtual void Insert( size_t index
,
222 virtual void Prepend( wxWindow
*window
,
226 wxObject
* userData
= NULL
);
227 virtual void Prepend( wxSizer
*sizer
,
231 wxObject
* userData
= NULL
);
232 virtual void Prepend( int width
,
237 wxObject
* userData
= NULL
);
238 virtual void Prepend( wxSizerItem
*item
);
240 // Deprecated in 2.6 since historically it does not delete the window,
241 // use Detach instead.
242 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
243 virtual bool Remove( wxSizer
*sizer
);
244 virtual bool Remove( int index
);
246 virtual bool Detach( wxWindow
*window
);
247 virtual bool Detach( wxSizer
*sizer
);
248 virtual bool Detach( int index
);
250 virtual void Clear( bool delete_windows
= false );
251 virtual void DeleteWindows();
253 void SetMinSize( int width
, int height
)
254 { DoSetMinSize( width
, height
); }
255 void SetMinSize( wxSize size
)
256 { DoSetMinSize( size
.x
, size
.y
); }
258 /* Searches recursively */
259 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
260 { return DoSetItemMinSize( window
, width
, height
); }
261 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
262 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
264 /* Searches recursively */
265 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
266 { return DoSetItemMinSize( sizer
, width
, height
); }
267 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
268 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
270 bool SetItemMinSize( size_t index
, int width
, int height
)
271 { return DoSetItemMinSize( index
, width
, height
); }
272 bool SetItemMinSize( size_t index
, wxSize size
)
273 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
275 wxSize
GetSize() const
277 wxPoint
GetPosition() const
278 { return m_position
; }
280 /* Calculate the minimal size or return m_minSize if bigger. */
283 virtual void RecalcSizes() = 0;
284 virtual wxSize
CalcMin() = 0;
286 virtual void Layout();
288 wxSize
Fit( wxWindow
*window
);
289 void FitInside( wxWindow
*window
);
290 void SetSizeHints( wxWindow
*window
);
291 void SetVirtualSizeHints( wxWindow
*window
);
293 wxSizerItemList
& GetChildren()
294 { return m_children
; }
296 void SetDimension( int x
, int y
, int width
, int height
);
298 // Manage whether individual scene items are considered
299 // in the layout calculations or not.
300 void Show( wxWindow
*window
, bool show
= true );
301 void Show( wxSizer
*sizer
, bool show
= true );
302 void Show( size_t index
, bool show
= true );
304 void Hide( wxSizer
*sizer
)
305 { Show( sizer
, false ); }
306 void Hide( wxWindow
*window
)
307 { Show( window
, false ); }
308 void Hide( size_t index
)
309 { Show( index
, false ); }
311 bool IsShown( wxWindow
*window
) const;
312 bool IsShown( wxSizer
*sizer
) const;
313 bool IsShown( size_t index
) const;
315 // Recursively call wxWindow::Show () on all sizer items.
316 virtual void ShowItems (bool show
);
322 wxSizerItemList m_children
;
324 wxSize
GetMaxWindowSize( wxWindow
*window
) const;
325 wxSize
GetMinWindowSize( wxWindow
*window
);
326 wxSize
GetMaxClientSize( wxWindow
*window
) const;
327 wxSize
GetMinClientSize( wxWindow
*window
);
328 wxSize
FitSize( wxWindow
*window
);
329 wxSize
VirtualFitSize( wxWindow
*window
);
331 virtual void DoSetMinSize( int width
, int height
);
332 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
333 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
334 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
337 DECLARE_CLASS(wxSizer
)
340 //---------------------------------------------------------------------------
342 //---------------------------------------------------------------------------
344 class WXDLLEXPORT wxGridSizer
: public wxSizer
347 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
348 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
350 virtual void RecalcSizes();
351 virtual wxSize
CalcMin();
353 void SetCols( int cols
) { m_cols
= cols
; }
354 void SetRows( int rows
) { m_rows
= rows
; }
355 void SetVGap( int gap
) { m_vgap
= gap
; }
356 void SetHGap( int gap
) { m_hgap
= gap
; }
357 int GetCols() const { return m_cols
; }
358 int GetRows() const { return m_rows
; }
359 int GetVGap() const { return m_vgap
; }
360 int GetHGap() const { return m_hgap
; }
368 // return the number of total items and the number of columns and rows
369 int CalcRowsCols(int& rows
, int& cols
) const;
371 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
374 DECLARE_CLASS(wxGridSizer
)
377 //---------------------------------------------------------------------------
379 //---------------------------------------------------------------------------
381 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
383 enum wxFlexSizerGrowMode
385 // don't resize the cells in non-flexible direction at all
386 wxFLEX_GROWMODE_NONE
,
388 // uniformly resize only the specified ones (default)
389 wxFLEX_GROWMODE_SPECIFIED
,
391 // uniformly resize all cells
395 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
399 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
400 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
401 virtual ~wxFlexGridSizer();
404 // set the rows/columns which will grow (the others will remain of the
405 // constant initial size)
406 void AddGrowableRow( size_t idx
, int proportion
= 0 );
407 void RemoveGrowableRow( size_t idx
);
408 void AddGrowableCol( size_t idx
, int proportion
= 0 );
409 void RemoveGrowableCol( size_t idx
);
412 // the sizer cells may grow in both directions, not grow at all or only
413 // grow in one direction but not the other
415 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
416 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
417 int GetFlexibleDirection() const { return m_flexDirection
; }
419 // note that the grow mode only applies to the direction which is not
421 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
422 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
424 // Read-only access to the row heights and col widths arrays
425 const wxArrayInt
& GetRowHeights() const { return m_rowHeights
; }
426 const wxArrayInt
& GetColWidths() const { return m_colWidths
; }
429 virtual void RecalcSizes();
430 virtual wxSize
CalcMin();
433 void AdjustForFlexDirection();
434 void AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
435 int nrows
, int ncols
);
437 // the heights/widths of all rows/columns
438 wxArrayInt m_rowHeights
,
441 // indices of the growable columns and rows
442 wxArrayInt m_growableRows
,
445 // proportion values of the corresponding growable rows and columns
446 wxArrayInt m_growableRowsProportions
,
447 m_growableColsProportions
;
449 // parameters describing whether the growable cells should be resized in
450 // both directions or only one
452 wxFlexSizerGrowMode m_growMode
;
455 DECLARE_CLASS(wxFlexGridSizer
)
456 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
459 //---------------------------------------------------------------------------
461 //---------------------------------------------------------------------------
463 class WXDLLEXPORT wxBoxSizer
: public wxSizer
466 wxBoxSizer( int orient
);
471 int GetOrientation() const
474 void SetOrientation(int orient
)
475 { m_orient
= orient
; }
486 DECLARE_CLASS(wxBoxSizer
)
489 //---------------------------------------------------------------------------
491 //---------------------------------------------------------------------------
495 class WXDLLEXPORT wxStaticBox
;
497 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
500 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
505 wxStaticBox
*GetStaticBox() const
506 { return m_staticBox
; }
508 // override to hide/show the static box as well
509 virtual void ShowItems (bool show
);
512 wxStaticBox
*m_staticBox
;
515 DECLARE_CLASS(wxStaticBoxSizer
)
516 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
519 #endif // wxUSE_STATBOX
521 // ----------------------------------------------------------------------------
523 // ----------------------------------------------------------------------------
527 // this sizer works with wxNotebook/wxListbook/... and sizes the control to
529 class WXDLLEXPORT wxBookCtrl
;
531 class WXDLLEXPORT wxBookCtrlSizer
: public wxSizer
534 wxBookCtrlSizer(wxBookCtrl
*bookctrl
);
536 virtual void RecalcSizes();
537 virtual wxSize
CalcMin();
539 wxBookCtrl
*GetControl() const { return m_bookctrl
; }
542 wxBookCtrl
*m_bookctrl
;
545 DECLARE_CLASS(wxBookCtrlSizer
)
546 DECLARE_NO_COPY_CLASS(wxBookCtrlSizer
)
552 // before wxBookCtrl we only had wxNotebookSizer, keep it for backwards
554 class WXDLLEXPORT wxNotebook
;
556 class WXDLLEXPORT wxNotebookSizer
: public wxBookCtrlSizer
559 wxNotebookSizer(wxNotebook
*nb
);
561 wxNotebook
*GetNotebook() const { return (wxNotebook
*)m_bookctrl
; }
564 DECLARE_CLASS(wxNotebookSizer
)
565 DECLARE_NO_COPY_CLASS(wxNotebookSizer
)
568 #endif // wxUSE_NOTEBOOK
570 #endif // wxUSE_BOOKCTRL
572 #endif // __WXSIZER_H__