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
GetMaxWindowSize( wxWindow
*window
);
201 wxSize
GetMinWindowSize( wxWindow
*window
);
202 wxSize
FitSize( wxWindow
*window
);
204 virtual void DoSetMinSize( int width
, int height
);
205 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
206 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
207 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
210 DECLARE_CLASS(wxSizer
);
213 //---------------------------------------------------------------------------
215 //---------------------------------------------------------------------------
217 class WXDLLEXPORT wxGridSizer
: public wxSizer
220 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
221 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
226 void SetCols( int cols
) { m_cols
= cols
; }
227 void SetRows( int rows
) { m_rows
= rows
; }
228 void SetVGap( int gap
) { m_vgap
= gap
; }
229 void SetHGap( int gap
) { m_hgap
= gap
; }
230 int GetCols() { return m_cols
; }
231 int GetRows() { return m_rows
; }
232 int GetVGap() { return m_vgap
; }
233 int GetHGap() { return m_hgap
; }
241 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
244 DECLARE_CLASS(wxGridSizer
);
247 //---------------------------------------------------------------------------
249 //---------------------------------------------------------------------------
251 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
254 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
255 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
261 void AddGrowableRow( size_t idx
);
262 void RemoveGrowableRow( size_t idx
);
263 void AddGrowableCol( size_t idx
);
264 void RemoveGrowableCol( size_t idx
);
269 wxArrayInt m_growableRows
;
270 wxArrayInt m_growableCols
;
275 DECLARE_CLASS(wxFlexGridSizer
);
278 //---------------------------------------------------------------------------
280 //---------------------------------------------------------------------------
282 class WXDLLEXPORT wxBoxSizer
: public wxSizer
285 wxBoxSizer( int orient
);
302 DECLARE_CLASS(wxBoxSizer
);
305 //---------------------------------------------------------------------------
307 //---------------------------------------------------------------------------
309 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
312 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
317 wxStaticBox
*GetStaticBox()
318 { return m_staticBox
; }
321 wxStaticBox
*m_staticBox
;
324 DECLARE_CLASS(wxStaticBoxSizer
);
327 //---------------------------------------------------------------------------
329 //---------------------------------------------------------------------------
333 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
336 wxNotebookSizer( wxNotebook
*nb
);
341 wxNotebook
*GetNotebook()
342 { return m_notebook
; }
345 wxNotebook
*m_notebook
;
348 DECLARE_CLASS(wxNotebookSizer
);