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 wxSize
GetSize();
52 virtual wxSize
CalcMin();
53 virtual void SetDimension( wxPoint pos
, wxSize size
);
58 void SetRatio( int width
, int height
)
59 // if either of dimensions is zero, ratio is assumed to be 1
60 // to avoid "divide by zero" errors
61 { m_ratio
= (width
&& height
) ? ((float) width
/ (float) height
) : 1; }
62 void SetRatio( wxSize size
)
63 { m_ratio
= (size
.x
&& size
.y
) ? ((float) size
.x
/ (float) size
.y
) : 1; }
64 void SetRatio( float ratio
)
66 float GetRatio() const
73 void SetInitSize( int x
, int y
)
74 { m_minSize
.x
= x
; m_minSize
.y
= y
; }
75 void SetOption( int option
)
76 { m_option
= option
; }
77 void SetFlag( int flag
)
79 void SetBorder( int border
)
80 { m_border
= border
; }
82 wxWindow
*GetWindow() const
84 void SetWindow( wxWindow
*window
)
85 { m_window
= window
; }
86 wxSizer
*GetSizer() const
88 void SetSizer( wxSizer
*sizer
)
96 wxObject
* GetUserData()
97 { return m_userData
; }
110 // als: aspect ratio can always be calculated from m_size,
111 // but this would cause precision loss when the window
112 // is shrinked. it is safer to preserve initial value.
114 wxObject
*m_userData
;
117 DECLARE_CLASS(wxSizerItem
);
120 //---------------------------------------------------------------------------
122 //---------------------------------------------------------------------------
124 class WXDLLEXPORT wxSizer
: public wxObject
, public wxClientDataContainer
130 /* These should be called Append() really. */
131 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
132 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
133 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
135 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
136 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
137 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
139 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
140 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
141 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
143 virtual bool Remove( wxWindow
*window
);
144 virtual bool Remove( wxSizer
*sizer
);
145 virtual bool Remove( int pos
);
147 void SetMinSize( int width
, int height
)
148 { DoSetMinSize( width
, height
); }
149 void SetMinSize( wxSize size
)
150 { DoSetMinSize( size
.x
, size
.y
); }
152 /* Searches recursively */
153 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
154 { return DoSetItemMinSize( window
, width
, height
); }
155 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
156 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
158 /* Searches recursively */
159 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
160 { return DoSetItemMinSize( sizer
, width
, height
); }
161 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
162 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
164 bool SetItemMinSize( int pos
, int width
, int height
)
165 { return DoSetItemMinSize( pos
, width
, height
); }
166 bool SetItemMinSize( int pos
, wxSize size
)
167 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
171 wxPoint
GetPosition()
172 { return m_position
; }
174 /* Calculate the minimal size or return m_minSize if bigger. */
177 virtual void RecalcSizes() = 0;
178 virtual wxSize
CalcMin() = 0;
180 virtual void Layout();
182 void Fit( wxWindow
*window
);
183 void SetSizeHints( wxWindow
*window
);
185 wxList
& GetChildren()
186 { return m_children
; }
188 void SetDimension( int x
, int y
, int width
, int height
);
196 wxSize
GetMaxWindowSize( wxWindow
*window
);
197 wxSize
GetMinWindowSize( wxWindow
*window
);
198 wxSize
FitSize( wxWindow
*window
);
200 virtual void DoSetMinSize( int width
, int height
);
201 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
202 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
203 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
206 DECLARE_CLASS(wxSizer
);
209 //---------------------------------------------------------------------------
211 //---------------------------------------------------------------------------
213 class WXDLLEXPORT wxGridSizer
: public wxSizer
216 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
217 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
222 void SetCols( int cols
) { m_cols
= cols
; }
223 void SetRows( int rows
) { m_rows
= rows
; }
224 void SetVGap( int gap
) { m_vgap
= gap
; }
225 void SetHGap( int gap
) { m_hgap
= gap
; }
226 int GetCols() { return m_cols
; }
227 int GetRows() { return m_rows
; }
228 int GetVGap() { return m_vgap
; }
229 int GetHGap() { return m_hgap
; }
237 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
240 DECLARE_CLASS(wxGridSizer
);
243 //---------------------------------------------------------------------------
245 //---------------------------------------------------------------------------
247 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
250 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
251 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
257 void AddGrowableRow( size_t idx
);
258 void RemoveGrowableRow( size_t idx
);
259 void AddGrowableCol( size_t idx
);
260 void RemoveGrowableCol( size_t idx
);
265 wxArrayInt m_growableRows
;
266 wxArrayInt m_growableCols
;
271 DECLARE_CLASS(wxFlexGridSizer
);
274 //---------------------------------------------------------------------------
276 //---------------------------------------------------------------------------
278 class WXDLLEXPORT wxBoxSizer
: public wxSizer
281 wxBoxSizer( int orient
);
298 DECLARE_CLASS(wxBoxSizer
);
301 //---------------------------------------------------------------------------
303 //---------------------------------------------------------------------------
307 class WXDLLEXPORT wxStaticBox
;
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 #endif // wxUSE_STATBOX
329 //---------------------------------------------------------------------------
331 //---------------------------------------------------------------------------
335 class WXDLLEXPORT wxNotebook
;
337 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
340 wxNotebookSizer( wxNotebook
*nb
);
345 wxNotebook
*GetNotebook()
346 { return m_notebook
; }
349 wxNotebook
*m_notebook
;
352 DECLARE_CLASS(wxNotebookSizer
);
355 #endif // wxUSE_NOTEBOOK