1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layouting
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee
8 // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(__APPLE__)
17 #pragma interface "sizer.h"
22 #include "wx/window.h"
24 #include "wx/dialog.h"
26 //---------------------------------------------------------------------------
28 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
36 //---------------------------------------------------------------------------
38 class WXDLLEXPORT wxSizerItem
: public wxObject
42 wxSizerItem( int width
,
50 wxSizerItem( wxWindow
*window
,
57 wxSizerItem( wxSizer
*sizer
,
65 virtual void DeleteWindows();
67 // Enable deleting the SizerItem without destroying the contained sizer.
71 virtual wxSize
GetSize();
72 virtual wxSize
CalcMin();
73 virtual void SetDimension( wxPoint pos
, wxSize size
);
77 void SetInitSize( int x
, int y
)
78 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
80 void SetRatio( int width
, int height
)
81 // if either of dimensions is zero, ratio is assumed to be 1
82 // to avoid "divide by zero" errors
83 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
84 void SetRatio( wxSize size
)
85 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
86 void SetRatio( float ratio
)
88 float GetRatio() const
95 // Deprecated in 2.6, use {G,S}etProportion instead.
96 wxDEPRECATED( void SetOption( int option
) );
97 wxDEPRECATED( int GetOption() const );
99 void SetProportion( int proportion
)
100 { m_proportion
= proportion
; }
101 int GetProportion() const
102 { return m_proportion
; }
103 void SetFlag( int flag
)
107 void SetBorder( int border
)
108 { m_border
= border
; }
109 int GetBorder() const
112 wxWindow
*GetWindow() const
114 void SetWindow( wxWindow
*window
)
115 { m_window
= window
; }
116 wxSizer
*GetSizer() const
118 void SetSizer( wxSizer
*sizer
)
120 const wxSize
&GetSpacer() const
122 void SetSpacer( const wxSize
&size
)
123 { m_size
= size
; m_minSize
= size
; }
125 void Show ( bool show
);
129 wxObject
* GetUserData()
130 { return m_userData
; }
131 wxPoint
GetPosition()
144 // If true, then this item is considered in the layout
145 // calculation. Otherwise, it is skipped over.
148 // Aspect ratio can always be calculated from m_size,
149 // but this would cause precision loss when the window
150 // is shrunk. It is safer to preserve the initial value.
153 wxObject
*m_userData
;
155 DECLARE_DYNAMIC_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( size_t index
);
237 virtual bool Detach( wxWindow
*window
);
238 virtual bool Detach( wxSizer
*sizer
);
239 virtual bool Detach( size_t 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
); }
268 wxPoint
GetPosition()
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
);
303 bool IsShown( wxSizer
*sizer
);
304 bool IsShown( size_t index
);
306 // Recursively call wxWindow::Show () on all sizer items.
307 void ShowItems (bool show
);
313 wxSizerItemList m_children
;
315 wxSize
GetMaxWindowSize( wxWindow
*window
);
316 wxSize
GetMinWindowSize( wxWindow
*window
);
317 wxSize
GetMaxClientSize( wxWindow
*window
);
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
);
327 DECLARE_DYNAMIC_CLASS(wxSizer
);
330 //---------------------------------------------------------------------------
332 //---------------------------------------------------------------------------
334 class WXDLLEXPORT wxGridSizer
: public wxSizer
337 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
338 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
343 void SetCols( int cols
) { m_cols
= cols
; }
344 void SetRows( int rows
) { m_rows
= rows
; }
345 void SetVGap( int gap
) { m_vgap
= gap
; }
346 void SetHGap( int gap
) { m_hgap
= gap
; }
347 int GetCols() { return m_cols
; }
348 int GetRows() { return m_rows
; }
349 int GetVGap() { return m_vgap
; }
350 int GetHGap() { return m_hgap
; }
358 // return the number of total items and the number of columns and rows
359 int CalcRowsCols(int& rows
, int& cols
) const;
361 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
363 DECLARE_DYNAMIC_CLASS(wxGridSizer
);
366 //---------------------------------------------------------------------------
368 //---------------------------------------------------------------------------
370 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
373 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
374 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
380 void AddGrowableRow( size_t idx
);
381 void RemoveGrowableRow( size_t idx
);
382 void AddGrowableCol( size_t idx
);
383 void RemoveGrowableCol( size_t idx
);
388 wxArrayInt m_growableRows
;
389 wxArrayInt m_growableCols
;
393 DECLARE_DYNAMIC_CLASS(wxFlexGridSizer
);
394 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
397 //---------------------------------------------------------------------------
399 //---------------------------------------------------------------------------
401 class WXDLLEXPORT wxBoxSizer
: public wxSizer
404 wxBoxSizer( int orient
);
412 void SetOrientation(int orient
)
413 { m_orient
= orient
; }
423 DECLARE_DYNAMIC_CLASS(wxBoxSizer
);
426 //---------------------------------------------------------------------------
428 //---------------------------------------------------------------------------
432 class WXDLLEXPORT wxStaticBox
;
434 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
437 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
442 wxStaticBox
*GetStaticBox()
443 { return m_staticBox
; }
446 wxStaticBox
*m_staticBox
;
448 DECLARE_DYNAMIC_CLASS(wxStaticBoxSizer
);
449 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
452 #endif // wxUSE_STATBOX
454 //---------------------------------------------------------------------------
456 //---------------------------------------------------------------------------
460 class WXDLLEXPORT wxNotebook
;
462 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
465 wxNotebookSizer( wxNotebook
*nb
);
470 wxNotebook
*GetNotebook()
471 { return m_notebook
; }
474 wxNotebook
*m_notebook
;
476 DECLARE_DYNAMIC_CLASS(wxNotebookSizer
);
477 DECLARE_NO_COPY_CLASS(wxNotebookSizer
)
480 #endif // wxUSE_NOTEBOOK