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
43 DECLARE_CLASS(wxSizerItem
);
46 wxSizerItem( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
);
49 wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
);
52 wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
);
56 virtual wxSize
GetSize();
57 virtual wxSize
CalcMin();
58 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
) { m_ratio
= ratio
; }
67 float GetRatio() const { return m_ratio
; }
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 //---------------------------------------------------------------------------
119 //---------------------------------------------------------------------------
121 class WXDLLEXPORT wxSizer
: public wxObject
127 /* These should be called Append() really. */
128 virtual void Add( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
129 virtual void Add( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
130 virtual void Add( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
132 virtual void Insert( int before
, wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
133 virtual void Insert( int before
, wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
134 virtual void Insert( int before
, int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
136 virtual void Prepend( wxWindow
*window
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
137 virtual void Prepend( wxSizer
*sizer
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
138 virtual void Prepend( int width
, int height
, int option
= 0, int flag
= 0, int border
= 0, wxObject
* userData
= NULL
);
140 virtual bool Remove( wxWindow
*window
);
141 virtual bool Remove( wxSizer
*sizer
);
142 virtual bool Remove( int pos
);
144 void SetMinSize( int width
, int height
)
145 { DoSetMinSize( width
, height
); }
146 void SetMinSize( wxSize size
)
147 { DoSetMinSize( size
.x
, size
.y
); }
149 /* Searches recursively */
150 bool SetItemMinSize( wxWindow
*window
, int width
, int height
)
151 { return DoSetItemMinSize( window
, width
, height
); }
152 bool SetItemMinSize( wxWindow
*window
, wxSize size
)
153 { return DoSetItemMinSize( window
, size
.x
, size
.y
); }
155 /* Searches recursively */
156 bool SetItemMinSize( wxSizer
*sizer
, int width
, int height
)
157 { return DoSetItemMinSize( sizer
, width
, height
); }
158 bool SetItemMinSize( wxSizer
*sizer
, wxSize size
)
159 { return DoSetItemMinSize( sizer
, size
.x
, size
.y
); }
161 bool SetItemMinSize( int pos
, int width
, int height
)
162 { return DoSetItemMinSize( pos
, width
, height
); }
163 bool SetItemMinSize( int pos
, wxSize size
)
164 { return DoSetItemMinSize( pos
, size
.x
, size
.y
); }
168 wxPoint
GetPosition()
169 { return m_position
; }
171 /* Calculate the minimal size or return m_minSize if bigger. */
174 virtual void RecalcSizes() = 0;
175 virtual wxSize
CalcMin() = 0;
177 virtual void Layout();
179 void Fit( wxWindow
*window
);
180 void SetSizeHints( wxWindow
*window
);
182 wxList
& GetChildren()
183 { return m_children
; }
185 void SetDimension( int x
, int y
, int width
, int height
);
193 wxSize
GetMinWindowSize( wxWindow
*window
);
195 virtual void DoSetMinSize( int width
, int height
);
196 virtual bool DoSetItemMinSize( wxWindow
*window
, int width
, int height
);
197 virtual bool DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
);
198 virtual bool DoSetItemMinSize( int pos
, int width
, int height
);
201 DECLARE_CLASS(wxSizer
);
204 //---------------------------------------------------------------------------
206 //---------------------------------------------------------------------------
208 class WXDLLEXPORT wxGridSizer
: public wxSizer
211 wxGridSizer( int rows
, int cols
, int vgap
, int hgap
);
212 wxGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
217 void SetCols( int cols
) { m_cols
= cols
; }
218 void SetRows( int rows
) { m_rows
= rows
; }
219 void SetVGap( int gap
) { m_vgap
= gap
; }
220 void SetHGap( int gap
) { m_hgap
= gap
; }
221 int GetCols() { return m_cols
; }
222 int GetRows() { return m_rows
; }
223 int GetVGap() { return m_vgap
; }
224 int GetHGap() { return m_hgap
; }
232 void SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
);
235 DECLARE_CLASS(wxGridSizer
);
238 //---------------------------------------------------------------------------
240 //---------------------------------------------------------------------------
242 class WXDLLEXPORT wxFlexGridSizer
: public wxGridSizer
245 wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
);
246 wxFlexGridSizer( int cols
, int vgap
= 0, int hgap
= 0 );
252 void AddGrowableRow( size_t idx
);
253 void RemoveGrowableRow( size_t idx
);
254 void AddGrowableCol( size_t idx
);
255 void RemoveGrowableCol( size_t idx
);
260 wxArrayInt m_growableRows
;
261 wxArrayInt m_growableCols
;
266 DECLARE_CLASS(wxFlexGridSizer
);
269 //---------------------------------------------------------------------------
271 //---------------------------------------------------------------------------
273 class WXDLLEXPORT wxBoxSizer
: public wxSizer
276 wxBoxSizer( int orient
);
293 DECLARE_CLASS(wxBoxSizer
);
296 //---------------------------------------------------------------------------
298 //---------------------------------------------------------------------------
300 class WXDLLEXPORT wxStaticBoxSizer
: public wxBoxSizer
303 wxStaticBoxSizer( wxStaticBox
*box
, int orient
);
308 wxStaticBox
*GetStaticBox()
309 { return m_staticBox
; }
312 wxStaticBox
*m_staticBox
;
315 DECLARE_CLASS(wxStaticBoxSizer
);
318 //---------------------------------------------------------------------------
320 //---------------------------------------------------------------------------
324 class WXDLLEXPORT wxNotebookSizer
: public wxSizer
327 wxNotebookSizer( wxNotebook
*nb
);
332 wxNotebook
*GetNotebook()
333 { return m_notebook
; }
336 wxNotebook
*m_notebook
;
339 DECLARE_CLASS(wxNotebookSizer
);