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 //---------------------------------------------------------------------------
35 class wxStaticBoxSizer
;
37 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
41 class WXDLLEXPORT wxSizerItem
: public wxObject
45 wxSizerItem( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
);
48 wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
);
51 wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
);
55 virtual wxSize
GetSize();
56 virtual wxSize
CalcMin();
57 virtual void SetDimension( wxPoint pos
, wxSize size
);
62 void SetRatio( int width
, int height
)
63 // if either of dimensions is zero, ratio is assumed to be 1
64 // to avoid "divide by zero" errors
65 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
66 void SetRatio( wxSize size
)
67 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
68 void SetRatio( float ratio
)
70 float GetRatio() const
77 void SetInitSize( int x
, int y
)
78 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
79 void SetOption( int option
)
80 { m_option
= option
; }
81 void SetFlag( int flag
)
83 void SetBorder( int border
)
84 { m_border
= border
; }
86 wxWindow
*GetWindow() const
88 void SetWindow( wxWindow
*window
)
89 { m_window
= window
; }
90 wxSizer
*GetSizer() const
92 void SetSizer( wxSizer
*sizer
)
100 wxObject
* GetUserData()
101 { return m_userData
; }
102 wxPoint
GetPosition()
114 // als: aspect ratio can always be calculated from m_size,
115 // but this would cause precision loss when the window
116 // is shrinked. it is safer to preserve initial value.
118 wxObject
*m_userData
;
121 DECLARE_CLASS(wxSizerItem
);
124 //---------------------------------------------------------------------------
126 //---------------------------------------------------------------------------
128 class WXDLLEXPORT wxSizer
: public wxObject
134 /* These should be called Append() really. */
135 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
136 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
137 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
139 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
140 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
141 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
143 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
144 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
145 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
147 virtual bool Remove( wxWindow
*window
);
148 virtual bool Remove( wxSizer
*sizer
);
149 virtual bool Remove( int pos
);
151 void SetMinSize( int width
, int height
)
152 { DoSetMinSize( width
, height
); }
153 void SetMinSize( wxSize size
)
154 { DoSetMinSize( size
.x
, size
.y
); }
156 /* Searches recursively */
157 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
158 { return DoSetItemMinSize( window
, width
, height
); }
159 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
160 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
162 /* Searches recursively */
163 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
164 { return DoSetItemMinSize( sizer
, width
, height
); }
165 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
166 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
168 bool SetItemMinSize( int pos
, int width
, int height
)
169 { return DoSetItemMinSize( pos
, width
, height
); }
170 bool SetItemMinSize( int pos
, wxSize size
)
171 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
175 wxPoint
GetPosition()
176 { return m_position
; }
178 /* Calculate the minimal size or return m_minSize if bigger. */
181 virtual void RecalcSizes() = 0;
182 virtual wxSize
CalcMin() = 0;
184 virtual void Layout();
186 void Fit( wxWindow
*window
);
187 void SetSizeHints( wxWindow
*window
);
189 wxList
& GetChildren()
190 { return m_children
; }
192 void SetDimension( int x
, int y
, int width
, int height
);
200 wxSize
GetMinWindowSize( wxWindow
*window
);
202 virtual void DoSetMinSize( int width
, int height
);
203 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
204 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
205 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
208 DECLARE_CLASS(wxSizer
);
211 //---------------------------------------------------------------------------
213 //---------------------------------------------------------------------------
215 class WXDLLEXPORT wxGridSizer
: public wxSizer
218 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
219 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
224 void SetCols( int cols
) { m_cols
= cols
; }
225 void SetRows( int rows
) { m_rows
= rows
; }
226 void SetVGap( int gap
) { m_vgap
= gap
; }
227 void SetHGap( int gap
) { m_hgap
= gap
; }
228 int GetCols() { return m_cols
; }
229 int GetRows() { return m_rows
; }
230 int GetVGap() { return m_vgap
; }
231 int GetHGap() { return m_hgap
; }
239 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
242 DECLARE_CLASS(wxGridSizer
);
245 //---------------------------------------------------------------------------
247 //---------------------------------------------------------------------------
249 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
252 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
253 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
259 void AddGrowableRow( size_t idx
);
260 void RemoveGrowableRow( size_t idx
);
261 void AddGrowableCol( size_t idx
);
262 void RemoveGrowableCol( size_t idx
);
267 wxArrayInt m_growableRows
;
268 wxArrayInt m_growableCols
;
273 DECLARE_CLASS(wxFlexGridSizer
);
276 //---------------------------------------------------------------------------
278 //---------------------------------------------------------------------------
280 class WXDLLEXPORT wxBoxSizer
: public wxSizer
283 wxBoxSizer( int orient
);
300 DECLARE_CLASS(wxBoxSizer
);
303 //---------------------------------------------------------------------------
305 //---------------------------------------------------------------------------
307 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
310 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
315 wxStaticBox
*GetStaticBox()
316 { return m_staticBox
; }
319 wxStaticBox
*m_staticBox
;
322 DECLARE_CLASS(wxStaticBoxSizer
);
325 //---------------------------------------------------------------------------
327 //---------------------------------------------------------------------------
331 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
334 wxNotebookSizer( wxNotebook
*nb
);
339 wxNotebook
*GetNotebook()
340 { return m_notebook
; }
343 wxNotebook
*m_notebook
;
346 DECLARE_CLASS(wxNotebookSizer
);