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(__APPLE__)
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
,
64 virtual void DeleteWindows();
66 // Enable deleting the SizerItem without destroying the contained sizer.
70 virtual wxSize
GetSize() const;
71 virtual wxSize
CalcMin();
72 virtual void SetDimension( wxPoint pos
, wxSize size
);
74 wxSize
GetMinSize() const
76 void SetInitSize( int x
, int y
)
77 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
79 void SetRatio( int width
, int height
)
80 // if either of dimensions is zero, ratio is assumed to be 1
81 // to avoid "divide by zero" errors
82 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
83 void SetRatio( wxSize size
)
84 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
85 void SetRatio( float ratio
)
87 float GetRatio() const
90 bool IsWindow() const;
92 bool IsSpacer() const;
94 // Deprecated in 2.6, use {G,S}etProportion instead.
95 wxDEPRECATED( void SetOption( int option
) );
96 wxDEPRECATED( int GetOption() const );
98 void SetProportion( int proportion
)
99 { m_proportion
= proportion
; }
100 int GetProportion() const
101 { return m_proportion
; }
102 void SetFlag( int flag
)
106 void SetBorder( int border
)
107 { m_border
= border
; }
108 int GetBorder() const
111 wxWindow
*GetWindow() const
113 void SetWindow( wxWindow
*window
)
114 { m_window
= window
; }
115 wxSizer
*GetSizer() const
117 void SetSizer( wxSizer
*sizer
)
119 const wxSize
&GetSpacer() const
121 void SetSpacer( const wxSize
&size
)
122 { m_size
= size
; m_minSize
= size
; }
124 void Show ( bool show
);
128 wxObject
* GetUserData() const
129 { return m_userData
; }
130 wxPoint
GetPosition() const
143 // If true, then this item is considered in the layout
144 // calculation. Otherwise, it is skipped over.
147 // Aspect ratio can always be calculated from m_size,
148 // but this would cause precision loss when the window
149 // is shrunk. It is safer to preserve the initial value.
152 wxObject
*m_userData
;
155 DECLARE_CLASS(wxSizerItem
);
156 DECLARE_NO_COPY_CLASS(wxSizerItem
)
159 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
162 //---------------------------------------------------------------------------
164 //---------------------------------------------------------------------------
166 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
172 /* These should be called Append() really. */
173 virtual void Add( wxWindow
*window
,
177 wxObject
* userData
= NULL
);
178 virtual void Add( wxSizer
*sizer
,
182 wxObject
* userData
= NULL
);
183 virtual void Add( int width
,
188 wxObject
* userData
= NULL
);
189 virtual void Add( wxSizerItem
*item
);
191 virtual void Insert( size_t index
,
196 wxObject
* userData
= NULL
);
197 virtual void Insert( size_t index
,
202 wxObject
* userData
= NULL
);
203 virtual void Insert( size_t index
,
209 wxObject
* userData
= NULL
);
210 virtual void Insert( size_t index
,
213 virtual void Prepend( wxWindow
*window
,
217 wxObject
* userData
= NULL
);
218 virtual void Prepend( wxSizer
*sizer
,
222 wxObject
* userData
= NULL
);
223 virtual void Prepend( int width
,
228 wxObject
* userData
= NULL
);
229 virtual void Prepend( wxSizerItem
*item
);
231 // Deprecated in 2.6 since historically it does not delete the window,
232 // use Detach instead.
233 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
234 virtual bool Remove( wxSizer
*sizer
);
235 virtual bool Remove( int index
);
237 virtual bool Detach( wxWindow
*window
);
238 virtual bool Detach( wxSizer
*sizer
);
239 virtual bool Detach( int index
);
241 virtual void Clear( bool delete_windows
= false );
242 virtual void DeleteWindows();
244 void SetMinSize( int width
, int height
)
245 { DoSetMinSize( width
, height
); }
246 void SetMinSize( wxSize size
)
247 { DoSetMinSize( size
.x
, size
.y
); }
249 /* Searches recursively */
250 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
251 { return DoSetItemMinSize( window
, width
, height
); }
252 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
253 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
255 /* Searches recursively */
256 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
257 { return DoSetItemMinSize( sizer
, width
, height
); }
258 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
259 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
261 bool SetItemMinSize( size_t index
, int width
, int height
)
262 { return DoSetItemMinSize( index
, width
, height
); }
263 bool SetItemMinSize( size_t index
, wxSize size
)
264 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
266 wxSize
GetSize() const
268 wxPoint
GetPosition() const
269 { return m_position
; }
271 /* Calculate the minimal size or return m_minSize if bigger. */
274 virtual void RecalcSizes() = 0;
275 virtual wxSize
CalcMin() = 0;
277 virtual void Layout();
279 wxSize
Fit( wxWindow
*window
);
280 void FitInside( wxWindow
*window
);
281 void SetSizeHints( wxWindow
*window
);
282 void SetVirtualSizeHints( wxWindow
*window
);
284 wxSizerItemList
& GetChildren()
285 { return m_children
; }
287 void SetDimension( int x
, int y
, int width
, int height
);
289 // Manage whether individual scene items are considered
290 // in the layout calculations or not.
291 void Show( wxWindow
*window
, bool show
= true );
292 void Show( wxSizer
*sizer
, bool show
= true );
293 void Show( size_t index
, bool show
= true );
295 void Hide( wxSizer
*sizer
)
296 { Show( sizer
, false ); }
297 void Hide( wxWindow
*window
)
298 { Show( window
, false ); }
299 void Hide( size_t index
)
300 { Show( index
, false ); }
302 bool IsShown( wxWindow
*window
) const;
303 bool IsShown( wxSizer
*sizer
) const;
304 bool IsShown( size_t index
) const;
306 // Recursively call wxWindow::Show () on all sizer items.
307 void ShowItems (bool show
);
313 wxSizerItemList m_children
;
315 wxSize
GetMaxWindowSize( wxWindow
*window
) const;
316 wxSize
GetMinWindowSize( wxWindow
*window
);
317 wxSize
GetMaxClientSize( wxWindow
*window
) const;
318 wxSize
GetMinClientSize( wxWindow
*window
);
319 wxSize
FitSize( wxWindow
*window
);
320 wxSize
VirtualFitSize( wxWindow
*window
);
322 virtual void DoSetMinSize( int width
, int height
);
323 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
324 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
325 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
328 DECLARE_CLASS(wxSizer
);
331 //---------------------------------------------------------------------------
333 //---------------------------------------------------------------------------
335 class WXDLLEXPORT wxGridSizer
: public wxSizer
338 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
339 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
341 virtual void RecalcSizes();
342 virtual wxSize
CalcMin();
344 void SetCols( int cols
) { m_cols
= cols
; }
345 void SetRows( int rows
) { m_rows
= rows
; }
346 void SetVGap( int gap
) { m_vgap
= gap
; }
347 void SetHGap( int gap
) { m_hgap
= gap
; }
348 int GetCols() const { return m_cols
; }
349 int GetRows() const { return m_rows
; }
350 int GetVGap() const { return m_vgap
; }
351 int GetHGap() const { return m_hgap
; }
359 // return the number of total items and the number of columns and rows
360 int CalcRowsCols(int& rows
, int& cols
) const;
362 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
365 DECLARE_CLASS(wxGridSizer
);
368 //---------------------------------------------------------------------------
370 //---------------------------------------------------------------------------
372 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
374 enum wxFlexSizerGrowMode
376 // don't resize the cells in non-flexible direction at all
377 wxFLEX_GROWMODE_NONE
,
379 // uniformly resize only the specified ones (default)
380 wxFLEX_GROWMODE_SPECIFIED
,
382 // uniformly resize all cells
386 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
390 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
391 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
392 virtual ~wxFlexGridSizer();
395 // set the rows/columns which will grow (the others will remain of the
396 // constant initial size)
397 void AddGrowableRow( size_t idx
, int proportion
= 0 );
398 void RemoveGrowableRow( size_t idx
);
399 void AddGrowableCol( size_t idx
, int proportion
= 0 );
400 void RemoveGrowableCol( size_t idx
);
403 // the sizer cells may grow in both directions, not grow at all or only
404 // grow in one direction but not the other
406 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
407 void SetFlexibleDirection(int direction
) { m_flexDirection
= direction
; }
408 int GetFlexibleDirection() const { return m_flexDirection
; }
410 // note that the grow mode only applies to the direction which is not
412 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode
) { m_growMode
= mode
; }
413 wxFlexSizerGrowMode
GetNonFlexibleGrowMode() const { return m_growMode
; }
417 virtual void RecalcSizes();
418 virtual wxSize
CalcMin();
421 // the heights/widths of all rows/columns
422 wxArrayInt m_rowHeights
,
425 // indices of the growable columns and rows
426 wxArrayInt m_growableRows
,
429 // proportion values of the corresponding growable rows and columns
430 wxArrayInt m_growableRowsProportions
,
431 m_growableColsProportions
;
433 // parameters describing whether the growable cells should be resized in
434 // both directions or only one
436 wxFlexSizerGrowMode m_growMode
;
439 DECLARE_CLASS(wxFlexGridSizer
);
440 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
443 //---------------------------------------------------------------------------
445 //---------------------------------------------------------------------------
447 class WXDLLEXPORT wxBoxSizer
: public wxSizer
450 wxBoxSizer( int orient
);
455 int GetOrientation() const
458 void SetOrientation(int orient
)
459 { m_orient
= orient
; }
470 DECLARE_CLASS(wxBoxSizer
);
473 //---------------------------------------------------------------------------
475 //---------------------------------------------------------------------------
479 class WXDLLEXPORT wxStaticBox
;
481 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
484 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
489 wxStaticBox
*GetStaticBox() const
490 { return m_staticBox
; }
493 wxStaticBox
*m_staticBox
;
496 DECLARE_CLASS(wxStaticBoxSizer
);
497 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
500 #endif // wxUSE_STATBOX
502 //---------------------------------------------------------------------------
504 //---------------------------------------------------------------------------
508 class WXDLLEXPORT wxNotebook
;
510 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
513 wxNotebookSizer( wxNotebook
*nb
);
518 wxNotebook
*GetNotebook() const
519 { return m_notebook
; }
522 wxNotebook
*m_notebook
;
525 DECLARE_CLASS(wxNotebookSizer
);
526 DECLARE_NO_COPY_CLASS(wxNotebookSizer
)
529 #endif // wxUSE_NOTEBOOK