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
);
135 //---------------------------------------------------------------------------
137 //---------------------------------------------------------------------------
139 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
145 /* These should be called Append() really. */
146 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
147 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
148 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
150 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
151 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
152 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
154 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
155 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
156 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
158 // Remove will delete a sizer, but not a window.
159 virtual bool Remove( wxWindow
*window
);
160 virtual bool Remove( wxSizer
*sizer
);
161 virtual bool Remove( int pos
);
163 // Detach will never destroy a sizer or window.
164 virtual bool Detach( wxWindow
*window
)
165 { return Remove( window
); }
166 virtual bool Detach( wxSizer
*sizer
);
167 virtual bool Detach( int pos
);
169 virtual void Clear( bool delete_windows
=FALSE
);
170 virtual void DeleteWindows();
172 void SetMinSize( int width
, int height
)
173 { DoSetMinSize( width
, height
); }
174 void SetMinSize( wxSize size
)
175 { DoSetMinSize( size
.x
, size
.y
); }
177 /* Searches recursively */
178 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
179 { return DoSetItemMinSize( window
, width
, height
); }
180 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
181 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
183 /* Searches recursively */
184 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
185 { return DoSetItemMinSize( sizer
, width
, height
); }
186 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
187 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
189 bool SetItemMinSize( int pos
, int width
, int height
)
190 { return DoSetItemMinSize( pos
, width
, height
); }
191 bool SetItemMinSize( int pos
, wxSize size
)
192 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
196 wxPoint
GetPosition()
197 { return m_position
; }
199 /* Calculate the minimal size or return m_minSize if bigger. */
202 virtual void RecalcSizes() = 0;
203 virtual wxSize
CalcMin() = 0;
205 virtual void Layout();
207 wxSize
Fit( wxWindow
*window
);
208 void FitInside( wxWindow
*window
);
209 void SetSizeHints( wxWindow
*window
);
210 void SetVirtualSizeHints( wxWindow
*window
);
212 wxList
& GetChildren()
213 { return m_children
; }
215 void SetDimension( int x
, int y
, int width
, int height
);
217 // Manage whether individual windows or sub-sizers are considered
218 // in the layout calculations or not.
219 void Show( wxWindow
*window
, bool show
= TRUE
);
220 void Hide( wxWindow
*window
)
221 { Show (window
, FALSE
); }
222 void Show( wxSizer
*sizer
, bool show
= TRUE
);
223 void Hide( wxSizer
*sizer
)
224 { Show (sizer
, FALSE
); }
226 bool IsShown( wxWindow
*window
);
227 bool IsShown( wxSizer
*sizer
);
229 // Recursively call wxWindow::Show () on all sizer items.
230 void ShowItems (bool show
);
238 wxSize
GetMaxWindowSize( wxWindow
*window
);
239 wxSize
GetMinWindowSize( wxWindow
*window
);
240 wxSize
GetMaxClientSize( wxWindow
*window
);
241 wxSize
GetMinClientSize( wxWindow
*window
);
242 wxSize
FitSize( wxWindow
*window
);
243 wxSize
VirtualFitSize( wxWindow
*window
);
245 virtual void DoSetMinSize( int width
, int height
);
246 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
247 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
248 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
251 DECLARE_CLASS(wxSizer
);
254 //---------------------------------------------------------------------------
256 //---------------------------------------------------------------------------
258 class WXDLLEXPORT wxGridSizer
: public wxSizer
261 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
262 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
267 void SetCols( int cols
) { m_cols
= cols
; }
268 void SetRows( int rows
) { m_rows
= rows
; }
269 void SetVGap( int gap
) { m_vgap
= gap
; }
270 void SetHGap( int gap
) { m_hgap
= gap
; }
271 int GetCols() { return m_cols
; }
272 int GetRows() { return m_rows
; }
273 int GetVGap() { return m_vgap
; }
274 int GetHGap() { return m_hgap
; }
282 // return the number of total items and the number of columns and rows
283 int CalcRowsCols(int& rows
, int& cols
) const;
285 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
288 DECLARE_CLASS(wxGridSizer
);
291 //---------------------------------------------------------------------------
293 //---------------------------------------------------------------------------
295 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
298 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
299 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
305 void AddGrowableRow( size_t idx
);
306 void RemoveGrowableRow( size_t idx
);
307 void AddGrowableCol( size_t idx
);
308 void RemoveGrowableCol( size_t idx
);
313 wxArrayInt m_growableRows
;
314 wxArrayInt m_growableCols
;
319 DECLARE_CLASS(wxFlexGridSizer
);
322 //---------------------------------------------------------------------------
324 //---------------------------------------------------------------------------
326 class WXDLLEXPORT wxBoxSizer
: public wxSizer
329 wxBoxSizer( int orient
);
337 void SetOrientation(int orient
)
338 { m_orient
= orient
; }
349 DECLARE_CLASS(wxBoxSizer
);
352 //---------------------------------------------------------------------------
354 //---------------------------------------------------------------------------
358 class WXDLLEXPORT wxStaticBox
;
360 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
363 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
368 wxStaticBox
*GetStaticBox()
369 { return m_staticBox
; }
372 wxStaticBox
*m_staticBox
;
375 DECLARE_CLASS(wxStaticBoxSizer
);
378 #endif // wxUSE_STATBOX
380 //---------------------------------------------------------------------------
382 //---------------------------------------------------------------------------
386 class WXDLLEXPORT wxNotebook
;
388 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
391 wxNotebookSizer( wxNotebook
*nb
);
396 wxNotebook
*GetNotebook()
397 { return m_notebook
; }
400 wxNotebook
*m_notebook
;
403 DECLARE_CLASS(wxNotebookSizer
);
406 #endif // wxUSE_NOTEBOOK