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() const;
72 virtual wxSize
CalcMin();
73 virtual void SetDimension( wxPoint pos
, wxSize size
);
75 wxSize
GetMinSize() const
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
91 bool IsWindow() const;
93 bool IsSpacer() 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() const
130 { return m_userData
; }
131 wxPoint
GetPosition() const
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
;
156 DECLARE_CLASS(wxSizerItem
);
157 DECLARE_NO_COPY_CLASS(wxSizerItem
)
160 WX_DECLARE_EXPORTED_LIST( wxSizerItem
, wxSizerItemList
);
163 //---------------------------------------------------------------------------
165 //---------------------------------------------------------------------------
167 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
173 /* These should be called Append() really. */
174 virtual void Add( wxWindow
*window
,
178 wxObject
* userData
= NULL
);
179 virtual void Add( wxSizer
*sizer
,
183 wxObject
* userData
= NULL
);
184 virtual void Add( int width
,
189 wxObject
* userData
= NULL
);
190 virtual void Add( wxSizerItem
*item
);
192 virtual void Insert( size_t index
,
197 wxObject
* userData
= NULL
);
198 virtual void Insert( size_t index
,
203 wxObject
* userData
= NULL
);
204 virtual void Insert( size_t index
,
210 wxObject
* userData
= NULL
);
211 virtual void Insert( size_t index
,
214 virtual void Prepend( wxWindow
*window
,
218 wxObject
* userData
= NULL
);
219 virtual void Prepend( wxSizer
*sizer
,
223 wxObject
* userData
= NULL
);
224 virtual void Prepend( int width
,
229 wxObject
* userData
= NULL
);
230 virtual void Prepend( wxSizerItem
*item
);
232 // Deprecated in 2.6 since historically it does not delete the window,
233 // use Detach instead.
234 wxDEPRECATED( virtual bool Remove( wxWindow
*window
) );
235 virtual bool Remove( wxSizer
*sizer
);
236 virtual bool Remove( size_t index
);
238 virtual bool Detach( wxWindow
*window
);
239 virtual bool Detach( wxSizer
*sizer
);
240 virtual bool Detach( size_t index
);
242 virtual void Clear( bool delete_windows
=false );
243 virtual void DeleteWindows();
245 void SetMinSize( int width
, int height
)
246 { DoSetMinSize( width
, height
); }
247 void SetMinSize( wxSize size
)
248 { DoSetMinSize( size
.x
, size
.y
); }
250 /* Searches recursively */
251 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
252 { return DoSetItemMinSize( window
, width
, height
); }
253 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
254 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
256 /* Searches recursively */
257 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
258 { return DoSetItemMinSize( sizer
, width
, height
); }
259 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
260 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
262 bool SetItemMinSize( size_t index
, int width
, int height
)
263 { return DoSetItemMinSize( index
, width
, height
); }
264 bool SetItemMinSize( size_t index
, wxSize size
)
265 { return DoSetItemMinSize( index
, size
.x
, size
.y
); }
267 wxSize
GetSize() const
269 wxPoint
GetPosition() const
270 { return m_position
; }
272 /* Calculate the minimal size or return m_minSize if bigger. */
275 virtual void RecalcSizes() = 0;
276 virtual wxSize
CalcMin() = 0;
278 virtual void Layout();
280 wxSize
Fit( wxWindow
*window
);
281 void FitInside( wxWindow
*window
);
282 void SetSizeHints( wxWindow
*window
);
283 void SetVirtualSizeHints( wxWindow
*window
);
285 wxSizerItemList
& GetChildren()
286 { return m_children
; }
288 void SetDimension( int x
, int y
, int width
, int height
);
290 // Manage whether individual scene items are considered
291 // in the layout calculations or not.
292 void Show( wxWindow
*window
, bool show
= true );
293 void Show( wxSizer
*sizer
, bool show
= true );
294 void Show( size_t index
, bool show
= true );
296 void Hide( wxSizer
*sizer
)
297 { Show( sizer
, false ); }
298 void Hide( wxWindow
*window
)
299 { Show( window
, false ); }
300 void Hide( size_t index
)
301 { Show( index
, false ); }
303 bool IsShown( wxWindow
*window
) const;
304 bool IsShown( wxSizer
*sizer
) const;
305 bool IsShown( size_t index
) const;
307 // Recursively call wxWindow::Show () on all sizer items.
308 void ShowItems (bool show
);
314 wxSizerItemList m_children
;
316 wxSize
GetMaxWindowSize( wxWindow
*window
) const;
317 wxSize
GetMinWindowSize( wxWindow
*window
);
318 wxSize
GetMaxClientSize( wxWindow
*window
) const;
319 wxSize
GetMinClientSize( wxWindow
*window
);
320 wxSize
FitSize( wxWindow
*window
);
321 wxSize
VirtualFitSize( wxWindow
*window
);
323 virtual void DoSetMinSize( int width
, int height
);
324 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
325 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
326 virtual bool DoSetItemMinSize( size_t index
, int width
, int height
);
329 DECLARE_CLASS(wxSizer
);
332 //---------------------------------------------------------------------------
334 //---------------------------------------------------------------------------
336 class WXDLLEXPORT wxGridSizer
: public wxSizer
339 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
340 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
345 void SetCols( int cols
) { m_cols
= cols
; }
346 void SetRows( int rows
) { m_rows
= rows
; }
347 void SetVGap( int gap
) { m_vgap
= gap
; }
348 void SetHGap( int gap
) { m_hgap
= gap
; }
349 int GetCols() const { return m_cols
; }
350 int GetRows() const { return m_rows
; }
351 int GetVGap() const { return m_vgap
; }
352 int GetHGap() const { return m_hgap
; }
360 // return the number of total items and the number of columns and rows
361 int CalcRowsCols(int& rows
, int& cols
) const;
363 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
366 DECLARE_CLASS(wxGridSizer
);
369 //---------------------------------------------------------------------------
371 //---------------------------------------------------------------------------
373 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
376 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
377 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
383 void AddGrowableRow( size_t idx
);
384 void RemoveGrowableRow( size_t idx
);
385 void AddGrowableCol( size_t idx
);
386 void RemoveGrowableCol( size_t idx
);
391 wxArrayInt m_growableRows
;
392 wxArrayInt m_growableCols
;
397 DECLARE_CLASS(wxFlexGridSizer
);
398 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
401 //---------------------------------------------------------------------------
403 //---------------------------------------------------------------------------
405 class WXDLLEXPORT wxBoxSizer
: public wxSizer
408 wxBoxSizer( int orient
);
413 int GetOrientation() const
416 void SetOrientation(int orient
)
417 { m_orient
= orient
; }
428 DECLARE_CLASS(wxBoxSizer
);
431 //---------------------------------------------------------------------------
433 //---------------------------------------------------------------------------
437 class WXDLLEXPORT wxStaticBox
;
439 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
442 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
447 wxStaticBox
*GetStaticBox() const
448 { return m_staticBox
; }
451 wxStaticBox
*m_staticBox
;
454 DECLARE_CLASS(wxStaticBoxSizer
);
455 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
458 #endif // wxUSE_STATBOX
460 //---------------------------------------------------------------------------
462 //---------------------------------------------------------------------------
466 class WXDLLEXPORT wxNotebook
;
468 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
471 wxNotebookSizer( wxNotebook
*nb
);
476 wxNotebook
*GetNotebook() const
477 { return m_notebook
; }
480 wxNotebook
*m_notebook
;
483 DECLARE_CLASS(wxNotebookSizer
);
484 DECLARE_NO_COPY_CLASS(wxNotebookSizer
)
487 #endif // wxUSE_NOTEBOOK