1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide wxSizer class for layouting
4 // Author: Robert Roebling and Robin Dunn
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 void Fit( wxWindow
*window
);
188 void SetSizeHints( wxWindow
*window
);
190 wxList
& GetChildren()
191 { return m_children
; }
193 void SetDimension( int x
, int y
, int width
, int height
);
201 wxSize
GetMaxWindowSize( wxWindow
*window
);
202 wxSize
GetMinWindowSize( wxWindow
*window
);
203 wxSize
FitSize( wxWindow
*window
);
205 virtual void DoSetMinSize( int width
, int height
);
206 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
207 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
208 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
211 DECLARE_CLASS(wxSizer
);
214 //---------------------------------------------------------------------------
216 //---------------------------------------------------------------------------
218 class WXDLLEXPORT wxGridSizer
: public wxSizer
221 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
222 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
227 void SetCols( int cols
) { m_cols
= cols
; }
228 void SetRows( int rows
) { m_rows
= rows
; }
229 void SetVGap( int gap
) { m_vgap
= gap
; }
230 void SetHGap( int gap
) { m_hgap
= gap
; }
231 int GetCols() { return m_cols
; }
232 int GetRows() { return m_rows
; }
233 int GetVGap() { return m_vgap
; }
234 int GetHGap() { return m_hgap
; }
242 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
245 DECLARE_CLASS(wxGridSizer
);
248 //---------------------------------------------------------------------------
250 //---------------------------------------------------------------------------
252 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
255 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
256 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
262 void AddGrowableRow( size_t idx
);
263 void RemoveGrowableRow( size_t idx
);
264 void AddGrowableCol( size_t idx
);
265 void RemoveGrowableCol( size_t idx
);
270 wxArrayInt m_growableRows
;
271 wxArrayInt m_growableCols
;
276 DECLARE_CLASS(wxFlexGridSizer
);
279 //---------------------------------------------------------------------------
281 //---------------------------------------------------------------------------
283 class WXDLLEXPORT wxBoxSizer
: public wxSizer
286 wxBoxSizer( int orient
);
303 DECLARE_CLASS(wxBoxSizer
);
306 //---------------------------------------------------------------------------
308 //---------------------------------------------------------------------------
312 class WXDLLEXPORT wxStaticBox
;
314 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
317 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
322 wxStaticBox
*GetStaticBox()
323 { return m_staticBox
; }
326 wxStaticBox
*m_staticBox
;
329 DECLARE_CLASS(wxStaticBoxSizer
);
332 #endif // wxUSE_STATBOX
334 //---------------------------------------------------------------------------
336 //---------------------------------------------------------------------------
340 class WXDLLEXPORT wxNotebook
;
342 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
345 wxNotebookSizer( wxNotebook
*nb
);
350 wxNotebook
*GetNotebook()
351 { return m_notebook
; }
354 wxNotebook
*m_notebook
;
357 DECLARE_CLASS(wxNotebookSizer
);
360 #endif // wxUSE_NOTEBOOK