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 virtual wxSize
GetSize();
54 virtual wxSize
CalcMin();
55 virtual void SetDimension( wxPoint pos
, wxSize size
);
60 void SetRatio( int width
, int height
)
61 // if either of dimensions is zero, ratio is assumed to be 1
62 // to avoid "divide by zero" errors
63 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
64 void SetRatio( wxSize size
)
65 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
66 void SetRatio( float ratio
)
68 float GetRatio() const
75 void SetInitSize( int x
, int y
)
76 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
77 void SetOption( int option
)
78 { m_option
= option
; }
79 void SetFlag( int flag
)
81 void SetBorder( int border
)
82 { m_border
= border
; }
83 void Show ( bool show
)
86 wxWindow
*GetWindow() const
88 void SetWindow( wxWindow
*window
)
89 { m_window
= window
; }
90 wxSizer
*GetSizer() const
92 void SetSizer( wxSizer
*sizer
)
102 wxObject
* GetUserData()
103 { return m_userData
; }
104 wxPoint
GetPosition()
117 // If TRUE, then this item is considered in the layout
118 // calculation. Otherwise, it is skipped over.
120 // als: aspect ratio can always be calculated from m_size,
121 // but this would cause precision loss when the window
122 // is shrinked. it is safer to preserve initial value.
125 wxObject
*m_userData
;
128 DECLARE_CLASS(wxSizerItem
);
131 //---------------------------------------------------------------------------
133 //---------------------------------------------------------------------------
135 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
141 /* These should be called Append() really. */
142 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
143 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
144 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
146 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
147 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
148 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
150 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
151 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
152 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
154 virtual bool Remove( wxWindow
*window
);
155 virtual bool Remove( wxSizer
*sizer
);
156 virtual bool Remove( int pos
);
158 virtual void Clear( bool delete_windows
=FALSE
);
159 virtual void DeleteWindows();
161 void SetMinSize( int width
, int height
)
162 { DoSetMinSize( width
, height
); }
163 void SetMinSize( wxSize size
)
164 { DoSetMinSize( size
.x
, size
.y
); }
166 /* Searches recursively */
167 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
168 { return DoSetItemMinSize( window
, width
, height
); }
169 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
170 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
172 /* Searches recursively */
173 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
174 { return DoSetItemMinSize( sizer
, width
, height
); }
175 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
176 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
178 bool SetItemMinSize( int pos
, int width
, int height
)
179 { return DoSetItemMinSize( pos
, width
, height
); }
180 bool SetItemMinSize( int pos
, wxSize size
)
181 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
185 wxPoint
GetPosition()
186 { return m_position
; }
188 /* Calculate the minimal size or return m_minSize if bigger. */
191 virtual void RecalcSizes() = 0;
192 virtual wxSize
CalcMin() = 0;
194 virtual void Layout();
196 wxSize
Fit( wxWindow
*window
);
197 void FitInside( wxWindow
*window
);
198 void SetSizeHints( wxWindow
*window
);
199 void SetVirtualSizeHints( wxWindow
*window
);
201 wxList
& GetChildren()
202 { return m_children
; }
204 void SetDimension( int x
, int y
, int width
, int height
);
206 // Manage whether individual windows or sub-sizers are considered
207 // in the layout calculations or not.
208 void Show( wxWindow
*window
, bool show
= TRUE
);
209 void Hide( wxWindow
*window
)
210 { Show (window
, FALSE
); }
211 void Show( wxSizer
*sizer
, bool show
= TRUE
);
212 void Hide( wxSizer
*sizer
)
213 { Show (sizer
, FALSE
); }
215 bool IsShown( wxWindow
*window
);
216 bool IsShown( wxSizer
*sizer
);
218 // Recursively call wxWindow::Show () on all sizer items.
219 void ShowItems (bool show
);
227 wxSize
GetMaxWindowSize( wxWindow
*window
);
228 wxSize
GetMinWindowSize( wxWindow
*window
);
229 wxSize
GetMaxClientSize( wxWindow
*window
);
230 wxSize
GetMinClientSize( wxWindow
*window
);
231 wxSize
FitSize( wxWindow
*window
);
232 wxSize
VirtualFitSize( wxWindow
*window
);
234 virtual void DoSetMinSize( int width
, int height
);
235 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
236 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
237 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
240 DECLARE_CLASS(wxSizer
);
243 //---------------------------------------------------------------------------
245 //---------------------------------------------------------------------------
247 class WXDLLEXPORT wxGridSizer
: public wxSizer
250 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
251 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
256 void SetCols( int cols
) { m_cols
= cols
; }
257 void SetRows( int rows
) { m_rows
= rows
; }
258 void SetVGap( int gap
) { m_vgap
= gap
; }
259 void SetHGap( int gap
) { m_hgap
= gap
; }
260 int GetCols() { return m_cols
; }
261 int GetRows() { return m_rows
; }
262 int GetVGap() { return m_vgap
; }
263 int GetHGap() { return m_hgap
; }
271 // return the number of total items and the number of columns and rows
272 int CalcRowsCols(int& rows
, int& cols
) const;
274 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
277 DECLARE_CLASS(wxGridSizer
);
280 //---------------------------------------------------------------------------
282 //---------------------------------------------------------------------------
284 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
287 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
288 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
294 void AddGrowableRow( size_t idx
);
295 void RemoveGrowableRow( size_t idx
);
296 void AddGrowableCol( size_t idx
);
297 void RemoveGrowableCol( size_t idx
);
302 wxArrayInt m_growableRows
;
303 wxArrayInt m_growableCols
;
308 DECLARE_CLASS(wxFlexGridSizer
);
311 //---------------------------------------------------------------------------
313 //---------------------------------------------------------------------------
315 class WXDLLEXPORT wxBoxSizer
: public wxSizer
318 wxBoxSizer( int orient
);
335 DECLARE_CLASS(wxBoxSizer
);
338 //---------------------------------------------------------------------------
340 //---------------------------------------------------------------------------
344 class WXDLLEXPORT wxStaticBox
;
346 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
349 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
354 wxStaticBox
*GetStaticBox()
355 { return m_staticBox
; }
358 wxStaticBox
*m_staticBox
;
361 DECLARE_CLASS(wxStaticBoxSizer
);
364 #endif // wxUSE_STATBOX
366 //---------------------------------------------------------------------------
368 //---------------------------------------------------------------------------
372 class WXDLLEXPORT wxNotebook
;
374 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
377 wxNotebookSizer( wxNotebook
*nb
);
382 wxNotebook
*GetNotebook()
383 { return m_notebook
; }
386 wxNotebook
*m_notebook
;
389 DECLARE_CLASS(wxNotebookSizer
);
392 #endif // wxUSE_NOTEBOOK