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
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
, int height
, int option
, int flag
, int border
, wxObject
* userData
);
44 wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
);
47 wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
);
51 virtual void DeleteWindows();
53 // Enable deleting the SizerItem without destroying the contained sizer.
57 virtual wxSize
GetSize();
58 virtual wxSize
CalcMin();
59 virtual void SetDimension( wxPoint pos
, wxSize size
);
64 void SetRatio( int width
, int height
)
65 // if either of dimensions is zero, ratio is assumed to be 1
66 // to avoid "divide by zero" errors
67 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
68 void SetRatio( wxSize size
)
69 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
70 void SetRatio( float ratio
)
72 float GetRatio() const
79 void SetInitSize( int x
, int y
)
80 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
81 void SetOption( int option
)
82 { m_option
= option
; }
83 void SetFlag( int flag
)
85 void SetBorder( int border
)
86 { m_border
= border
; }
87 void Show ( bool show
)
90 wxWindow
*GetWindow() const
92 void SetWindow( wxWindow
*window
)
93 { m_window
= window
; }
94 wxSizer
*GetSizer() const
96 void SetSizer( wxSizer
*sizer
)
102 int GetBorder() const
106 wxObject
* GetUserData()
107 { return m_userData
; }
108 wxPoint
GetPosition()
121 // If TRUE, then this item is considered in the layout
122 // calculation. Otherwise, it is skipped over.
124 // als: aspect ratio can always be calculated from m_size,
125 // but this would cause precision loss when the window
126 // is shrinked. it is safer to preserve initial value.
129 wxObject
*m_userData
;
132 DECLARE_CLASS(wxSizerItem
);
133 DECLARE_NO_COPY_CLASS(wxSizerItem
)
136 //---------------------------------------------------------------------------
138 //---------------------------------------------------------------------------
140 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
146 /* These should be called Append() really. */
147 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
148 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
149 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
151 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
152 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
153 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
155 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
156 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
157 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
159 // Remove will delete a sizer, but not a window.
160 virtual bool Remove( wxWindow
*window
);
161 virtual bool Remove( wxSizer
*sizer
);
162 virtual bool Remove( int pos
);
164 // Detach will never destroy a sizer or window.
165 virtual bool Detach( wxWindow
*window
)
166 { return Remove( window
); }
167 virtual bool Detach( wxSizer
*sizer
);
168 virtual bool Detach( int pos
);
170 virtual void Clear( bool delete_windows
=FALSE
);
171 virtual void DeleteWindows();
173 void SetMinSize( int width
, int height
)
174 { DoSetMinSize( width
, height
); }
175 void SetMinSize( wxSize size
)
176 { DoSetMinSize( size
.x
, size
.y
); }
178 /* Searches recursively */
179 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
180 { return DoSetItemMinSize( window
, width
, height
); }
181 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
182 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
184 /* Searches recursively */
185 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
186 { return DoSetItemMinSize( sizer
, width
, height
); }
187 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
188 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
190 bool SetItemMinSize( int pos
, int width
, int height
)
191 { return DoSetItemMinSize( pos
, width
, height
); }
192 bool SetItemMinSize( int pos
, wxSize size
)
193 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
197 wxPoint
GetPosition()
198 { return m_position
; }
200 /* Calculate the minimal size or return m_minSize if bigger. */
203 virtual void RecalcSizes() = 0;
204 virtual wxSize
CalcMin() = 0;
206 virtual void Layout();
208 wxSize
Fit( wxWindow
*window
);
209 void FitInside( wxWindow
*window
);
210 void SetSizeHints( wxWindow
*window
);
211 void SetVirtualSizeHints( wxWindow
*window
);
213 wxList
& GetChildren()
214 { return m_children
; }
216 void SetDimension( int x
, int y
, int width
, int height
);
218 // Manage whether individual windows or sub-sizers are considered
219 // in the layout calculations or not.
220 void Show( wxWindow
*window
, bool show
= TRUE
);
221 void Hide( wxWindow
*window
)
222 { Show (window
, FALSE
); }
223 void Show( wxSizer
*sizer
, bool show
= TRUE
);
224 void Hide( wxSizer
*sizer
)
225 { Show (sizer
, FALSE
); }
227 bool IsShown( wxWindow
*window
);
228 bool IsShown( wxSizer
*sizer
);
230 // Recursively call wxWindow::Show () on all sizer items.
231 void ShowItems (bool show
);
239 wxSize
GetMaxWindowSize( wxWindow
*window
);
240 wxSize
GetMinWindowSize( wxWindow
*window
);
241 wxSize
GetMaxClientSize( wxWindow
*window
);
242 wxSize
GetMinClientSize( wxWindow
*window
);
243 wxSize
FitSize( wxWindow
*window
);
244 wxSize
VirtualFitSize( wxWindow
*window
);
246 virtual void DoSetMinSize( int width
, int height
);
247 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
248 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
249 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
252 DECLARE_CLASS(wxSizer
);
255 //---------------------------------------------------------------------------
257 //---------------------------------------------------------------------------
259 class WXDLLEXPORT wxGridSizer
: public wxSizer
262 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
263 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
268 void SetCols( int cols
) { m_cols
= cols
; }
269 void SetRows( int rows
) { m_rows
= rows
; }
270 void SetVGap( int gap
) { m_vgap
= gap
; }
271 void SetHGap( int gap
) { m_hgap
= gap
; }
272 int GetCols() { return m_cols
; }
273 int GetRows() { return m_rows
; }
274 int GetVGap() { return m_vgap
; }
275 int GetHGap() { return m_hgap
; }
283 // return the number of total items and the number of columns and rows
284 int CalcRowsCols(int& rows
, int& cols
) const;
286 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
289 DECLARE_CLASS(wxGridSizer
);
292 //---------------------------------------------------------------------------
294 //---------------------------------------------------------------------------
296 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
299 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
300 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
306 void AddGrowableRow( size_t idx
);
307 void RemoveGrowableRow( size_t idx
);
308 void AddGrowableCol( size_t idx
);
309 void RemoveGrowableCol( size_t idx
);
314 wxArrayInt m_growableRows
;
315 wxArrayInt m_growableCols
;
320 DECLARE_CLASS(wxFlexGridSizer
);
321 DECLARE_NO_COPY_CLASS(wxFlexGridSizer
)
324 //---------------------------------------------------------------------------
326 //---------------------------------------------------------------------------
328 class WXDLLEXPORT wxBoxSizer
: public wxSizer
331 wxBoxSizer( int orient
);
339 void SetOrientation(int orient
)
340 { m_orient
= orient
; }
351 DECLARE_CLASS(wxBoxSizer
);
354 //---------------------------------------------------------------------------
356 //---------------------------------------------------------------------------
360 class WXDLLEXPORT wxStaticBox
;
362 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
365 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
370 wxStaticBox
*GetStaticBox()
371 { return m_staticBox
; }
374 wxStaticBox
*m_staticBox
;
377 DECLARE_CLASS(wxStaticBoxSizer
);
378 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer
)
381 #endif // wxUSE_STATBOX
383 //---------------------------------------------------------------------------
385 //---------------------------------------------------------------------------
389 class WXDLLEXPORT wxNotebook
;
391 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
394 wxNotebookSizer( wxNotebook
*nb
);
399 wxNotebook
*GetNotebook()
400 { return m_notebook
; }
403 wxNotebook
*m_notebook
;
406 DECLARE_CLASS(wxNotebookSizer
);
407 DECLARE_NO_COPY_CLASS(wxNotebookSizer
)
410 #endif // wxUSE_NOTEBOOK