]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
extended RemoveLast() to take size_t parameter
[wxWidgets.git] / include / wx / sizer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sizer.h
3 // Purpose: provide wxSizer class for layouting
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WXSIZER_H__
13 #define __WXSIZER_H__
14
15 #ifdef __GNUG__
16 #pragma interface "sizer.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #include "wx/window.h"
22 #include "wx/frame.h"
23 #include "wx/dialog.h"
24
25 //---------------------------------------------------------------------------
26 // classes
27 //---------------------------------------------------------------------------
28
29 class wxStaticBox;
30 class wxNotebook;
31
32 class wxSizerItem;
33 class wxSizer;
34 class wxBoxSizer;
35 class wxStaticBoxSizer;
36
37 //---------------------------------------------------------------------------
38 // wxSizerItem
39 //---------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxSizerItem: public wxObject
42 {
43 public:
44 // spacer
45 wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
46
47 // window
48 wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
49
50 // subsizer
51 wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
52
53 ~wxSizerItem();
54
55 virtual wxSize GetSize();
56 virtual wxSize CalcMin();
57 virtual void SetDimension( wxPoint pos, wxSize size );
58
59 wxSize GetMinSize()
60 { return m_minSize; }
61
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 )
69 { m_ratio = ratio; }
70 float GetRatio() const
71 { return m_ratio; }
72
73 bool IsWindow();
74 bool IsSizer();
75 bool IsSpacer();
76
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 )
82 { m_flag = flag; }
83 void SetBorder( int border )
84 { m_border = border; }
85
86 wxWindow *GetWindow() const
87 { return m_window; }
88 void SetWindow( wxWindow *window )
89 { m_window = window; }
90 wxSizer *GetSizer() const
91 { return m_sizer; }
92 void SetSizer( wxSizer *sizer )
93 { m_sizer = sizer; }
94 int GetOption() const
95 { return m_option; }
96 int GetFlag() const
97 { return m_flag; }
98 int GetBorder() const
99 { return m_border; }
100 wxObject* GetUserData()
101 { return m_userData; }
102 wxPoint GetPosition()
103 { return m_pos; }
104
105 protected:
106 wxWindow *m_window;
107 wxSizer *m_sizer;
108 wxSize m_size;
109 wxPoint m_pos;
110 wxSize m_minSize;
111 int m_option;
112 int m_border;
113 int m_flag;
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.
117 float m_ratio;
118 wxObject *m_userData;
119
120 private:
121 DECLARE_CLASS(wxSizerItem);
122 };
123
124 //---------------------------------------------------------------------------
125 // wxSizer
126 //---------------------------------------------------------------------------
127
128 class WXDLLEXPORT wxSizer: public wxObject
129 {
130 public:
131 wxSizer();
132 ~wxSizer();
133
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 );
138
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 );
142
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 );
146
147 virtual bool Remove( wxWindow *window );
148 virtual bool Remove( wxSizer *sizer );
149 virtual bool Remove( int pos );
150
151 void SetMinSize( int width, int height )
152 { DoSetMinSize( width, height ); }
153 void SetMinSize( wxSize size )
154 { DoSetMinSize( size.x, size.y ); }
155
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 ); }
161
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 ); }
167
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 ); }
172
173 wxSize GetSize()
174 { return m_size; }
175 wxPoint GetPosition()
176 { return m_position; }
177
178 /* Calculate the minimal size or return m_minSize if bigger. */
179 wxSize GetMinSize();
180
181 virtual void RecalcSizes() = 0;
182 virtual wxSize CalcMin() = 0;
183
184 virtual void Layout();
185
186 void Fit( wxWindow *window );
187 void SetSizeHints( wxWindow *window );
188
189 wxList& GetChildren()
190 { return m_children; }
191
192 void SetDimension( int x, int y, int width, int height );
193
194 protected:
195 wxSize m_size;
196 wxSize m_minSize;
197 wxPoint m_position;
198 wxList m_children;
199
200 wxSize GetMinWindowSize( wxWindow *window );
201
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 );
206
207 private:
208 DECLARE_CLASS(wxSizer);
209 };
210
211 //---------------------------------------------------------------------------
212 // wxGridSizer
213 //---------------------------------------------------------------------------
214
215 class WXDLLEXPORT wxGridSizer: public wxSizer
216 {
217 public:
218 wxGridSizer( int rows, int cols, int vgap, int hgap );
219 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
220
221 void RecalcSizes();
222 wxSize CalcMin();
223
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; }
232
233 protected:
234 int m_rows;
235 int m_cols;
236 int m_vgap;
237 int m_hgap;
238
239 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
240
241 private:
242 DECLARE_CLASS(wxGridSizer);
243 };
244
245 //---------------------------------------------------------------------------
246 // wxFlexGridSizer
247 //---------------------------------------------------------------------------
248
249 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
250 {
251 public:
252 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
253 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
254 ~wxFlexGridSizer();
255
256 void RecalcSizes();
257 wxSize CalcMin();
258
259 void AddGrowableRow( size_t idx );
260 void RemoveGrowableRow( size_t idx );
261 void AddGrowableCol( size_t idx );
262 void RemoveGrowableCol( size_t idx );
263
264 protected:
265 int *m_rowHeights;
266 int *m_colWidths;
267 wxArrayInt m_growableRows;
268 wxArrayInt m_growableCols;
269
270 void CreateArrays();
271
272 private:
273 DECLARE_CLASS(wxFlexGridSizer);
274 };
275
276 //---------------------------------------------------------------------------
277 // wxBoxSizer
278 //---------------------------------------------------------------------------
279
280 class WXDLLEXPORT wxBoxSizer: public wxSizer
281 {
282 public:
283 wxBoxSizer( int orient );
284
285 void RecalcSizes();
286 wxSize CalcMin();
287
288 int GetOrientation()
289 { return m_orient; }
290
291 protected:
292 int m_orient;
293 int m_stretchable;
294 int m_minWidth;
295 int m_minHeight;
296 int m_fixedWidth;
297 int m_fixedHeight;
298
299 private:
300 DECLARE_CLASS(wxBoxSizer);
301 };
302
303 //---------------------------------------------------------------------------
304 // wxStaticBoxSizer
305 //---------------------------------------------------------------------------
306
307 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
308 {
309 public:
310 wxStaticBoxSizer( wxStaticBox *box, int orient );
311
312 void RecalcSizes();
313 wxSize CalcMin();
314
315 wxStaticBox *GetStaticBox()
316 { return m_staticBox; }
317
318 protected:
319 wxStaticBox *m_staticBox;
320
321 private:
322 DECLARE_CLASS(wxStaticBoxSizer);
323 };
324
325 //---------------------------------------------------------------------------
326 // wxNotebookSizer
327 //---------------------------------------------------------------------------
328
329 #if wxUSE_NOTEBOOK
330
331 class WXDLLEXPORT wxNotebookSizer: public wxSizer
332 {
333 public:
334 wxNotebookSizer( wxNotebook *nb );
335
336 void RecalcSizes();
337 wxSize CalcMin();
338
339 wxNotebook *GetNotebook()
340 { return m_notebook; }
341
342 protected:
343 wxNotebook *m_notebook;
344
345 private:
346 DECLARE_CLASS(wxNotebookSizer);
347 };
348
349 #endif
350
351
352 #endif
353 // __WXSIZER_H__