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 /////////////////////////////////////////////////////////////////////////////
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
; }
84 wxWindow
*GetWindow() const
86 void SetWindow( wxWindow
*window
)
87 { m_window
= window
; }
88 wxSizer
*GetSizer() const
90 void SetSizer( wxSizer
*sizer
)
98 wxObject
* GetUserData()
99 { return m_userData
; }
100 wxPoint
GetPosition()
112 // als: aspect ratio can always be calculated from m_size,
113 // but this would cause precision loss when the window
114 // is shrinked. it is safer to preserve initial value.
116 wxObject
*m_userData
;
119 DECLARE_CLASS(wxSizerItem
);
122 //---------------------------------------------------------------------------
124 //---------------------------------------------------------------------------
126 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
132 /* These should be called Append() really. */
133 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
134 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
135 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
137 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
138 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
139 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
141 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
142 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
143 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
145 virtual bool Remove( wxWindow
*window
);
146 virtual bool Remove( wxSizer
*sizer
);
147 virtual bool Remove( int pos
);
149 virtual void Clear( bool delete_windows
=FALSE
);
150 virtual void DeleteWindows();
152 void SetMinSize( int width
, int height
)
153 { DoSetMinSize( width
, height
); }
154 void SetMinSize( wxSize size
)
155 { DoSetMinSize( size
.x
, size
.y
); }
157 /* Searches recursively */
158 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
159 { return DoSetItemMinSize( window
, width
, height
); }
160 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
161 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
163 /* Searches recursively */
164 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
165 { return DoSetItemMinSize( sizer
, width
, height
); }
166 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
167 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
169 bool SetItemMinSize( int pos
, int width
, int height
)
170 { return DoSetItemMinSize( pos
, width
, height
); }
171 bool SetItemMinSize( int pos
, wxSize size
)
172 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
176 wxPoint
GetPosition()
177 { return m_position
; }
179 /* Calculate the minimal size or return m_minSize if bigger. */
182 virtual void RecalcSizes() = 0;
183 virtual wxSize
CalcMin() = 0;
185 virtual void Layout();
187 wxSize
Fit( wxWindow
*window
);
188 void FitInside( wxWindow
*window
);
189 void SetSizeHints( wxWindow
*window
);
190 void SetVirtualSizeHints( wxWindow
*window
);
192 wxList
& GetChildren()
193 { return m_children
; }
195 void SetDimension( int x
, int y
, int width
, int height
);
203 wxSize
GetMaxWindowSize( wxWindow
*window
);
204 wxSize
GetMinWindowSize( wxWindow
*window
);
205 wxSize
GetMaxClientSize( wxWindow
*window
);
206 wxSize
GetMinClientSize( wxWindow
*window
);
207 wxSize
FitSize( wxWindow
*window
);
208 wxSize
VirtualFitSize( wxWindow
*window
);
210 virtual void DoSetMinSize( int width
, int height
);
211 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
212 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
213 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
216 DECLARE_CLASS(wxSizer
);
219 //---------------------------------------------------------------------------
221 //---------------------------------------------------------------------------
223 class WXDLLEXPORT wxGridSizer
: public wxSizer
226 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
227 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
232 void SetCols( int cols
) { m_cols
= cols
; }
233 void SetRows( int rows
) { m_rows
= rows
; }
234 void SetVGap( int gap
) { m_vgap
= gap
; }
235 void SetHGap( int gap
) { m_hgap
= gap
; }
236 int GetCols() { return m_cols
; }
237 int GetRows() { return m_rows
; }
238 int GetVGap() { return m_vgap
; }
239 int GetHGap() { return m_hgap
; }
247 // return the number of total items and the number of columns and rows
248 int CalcRowsCols(int& rows
, int& cols
) const;
250 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
253 DECLARE_CLASS(wxGridSizer
);
256 //---------------------------------------------------------------------------
258 //---------------------------------------------------------------------------
260 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
263 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
264 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
270 void AddGrowableRow( size_t idx
);
271 void RemoveGrowableRow( size_t idx
);
272 void AddGrowableCol( size_t idx
);
273 void RemoveGrowableCol( size_t idx
);
278 wxArrayInt m_growableRows
;
279 wxArrayInt m_growableCols
;
284 DECLARE_CLASS(wxFlexGridSizer
);
287 //---------------------------------------------------------------------------
289 //---------------------------------------------------------------------------
291 class WXDLLEXPORT wxBoxSizer
: public wxSizer
294 wxBoxSizer( int orient
);
311 DECLARE_CLASS(wxBoxSizer
);
314 //---------------------------------------------------------------------------
316 //---------------------------------------------------------------------------
320 class WXDLLEXPORT wxStaticBox
;
322 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
325 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
330 wxStaticBox
*GetStaticBox()
331 { return m_staticBox
; }
334 wxStaticBox
*m_staticBox
;
337 DECLARE_CLASS(wxStaticBoxSizer
);
340 #endif // wxUSE_STATBOX
342 //---------------------------------------------------------------------------
344 //---------------------------------------------------------------------------
348 class WXDLLEXPORT wxNotebook
;
350 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
353 wxNotebookSizer( wxNotebook
*nb
);
358 wxNotebook
*GetNotebook()
359 { return m_notebook
; }
362 wxNotebook
*m_notebook
;
365 DECLARE_CLASS(wxNotebookSizer
);
368 #endif // wxUSE_NOTEBOOK