]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
Added From(), OrderBy() and Where() functions that correspons to the Set/GetWhereClau...
[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 DECLARE_CLASS(wxSizerItem);
44 public:
45 // spacer
46 wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
47
48 // window
49 wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
50
51 // subsizer
52 wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
53
54 ~wxSizerItem();
55
56 virtual wxSize GetSize();
57 virtual wxSize CalcMin();
58 virtual void SetDimension( wxPoint pos, wxSize size );
59
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; }
68
69 bool IsWindow();
70 bool IsSizer();
71 bool IsSpacer();
72
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 )
78 { m_flag = flag; }
79 void SetBorder( int border )
80 { m_border = border; }
81
82 wxWindow *GetWindow() const
83 { return m_window; }
84 void SetWindow( wxWindow *window )
85 { m_window = window; }
86 wxSizer *GetSizer() const
87 { return m_sizer; }
88 void SetSizer( wxSizer *sizer )
89 { m_sizer = sizer; }
90 int GetOption() const
91 { return m_option; }
92 int GetFlag() const
93 { return m_flag; }
94 int GetBorder() const
95 { return m_border; }
96 wxObject* GetUserData()
97 { return m_userData; }
98 wxPoint GetPosition()
99 { return m_pos; }
100
101 protected:
102 wxWindow *m_window;
103 wxSizer *m_sizer;
104 wxSize m_size;
105 wxPoint m_pos;
106 wxSize m_minSize;
107 int m_option;
108 int m_border;
109 int m_flag;
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.
113 float m_ratio;
114 wxObject *m_userData;
115 };
116
117 //---------------------------------------------------------------------------
118 // wxSizer
119 //---------------------------------------------------------------------------
120
121 class WXDLLEXPORT wxSizer: public wxObject
122 {
123 public:
124 wxSizer();
125 ~wxSizer();
126
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 );
131
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 );
135
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 );
139
140 virtual bool Remove( wxWindow *window );
141 virtual bool Remove( wxSizer *sizer );
142 virtual bool Remove( int pos );
143
144 void SetMinSize( int width, int height )
145 { DoSetMinSize( width, height ); }
146 void SetMinSize( wxSize size )
147 { DoSetMinSize( size.x, size.y ); }
148
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 ); }
154
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 ); }
160
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 ); }
165
166 wxSize GetSize()
167 { return m_size; }
168 wxPoint GetPosition()
169 { return m_position; }
170
171 /* Calculate the minimal size or return m_minSize if bigger. */
172 wxSize GetMinSize();
173
174 virtual void RecalcSizes() = 0;
175 virtual wxSize CalcMin() = 0;
176
177 virtual void Layout();
178
179 void Fit( wxWindow *window );
180 void SetSizeHints( wxWindow *window );
181
182 wxList& GetChildren()
183 { return m_children; }
184
185 void SetDimension( int x, int y, int width, int height );
186
187 protected:
188 wxSize m_size;
189 wxSize m_minSize;
190 wxPoint m_position;
191 wxList m_children;
192
193 wxSize GetMinWindowSize( wxWindow *window );
194
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 );
199
200 private:
201 DECLARE_CLASS(wxSizer);
202 };
203
204 //---------------------------------------------------------------------------
205 // wxGridSizer
206 //---------------------------------------------------------------------------
207
208 class WXDLLEXPORT wxGridSizer: public wxSizer
209 {
210 public:
211 wxGridSizer( int rows, int cols, int vgap, int hgap );
212 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
213
214 void RecalcSizes();
215 wxSize CalcMin();
216
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; }
225
226 protected:
227 int m_rows;
228 int m_cols;
229 int m_vgap;
230 int m_hgap;
231
232 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
233
234 private:
235 DECLARE_CLASS(wxGridSizer);
236 };
237
238 //---------------------------------------------------------------------------
239 // wxFlexGridSizer
240 //---------------------------------------------------------------------------
241
242 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
243 {
244 public:
245 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
246 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
247 ~wxFlexGridSizer();
248
249 void RecalcSizes();
250 wxSize CalcMin();
251
252 void AddGrowableRow( size_t idx );
253 void RemoveGrowableRow( size_t idx );
254 void AddGrowableCol( size_t idx );
255 void RemoveGrowableCol( size_t idx );
256
257 protected:
258 int *m_rowHeights;
259 int *m_colWidths;
260 wxArrayInt m_growableRows;
261 wxArrayInt m_growableCols;
262
263 void CreateArrays();
264
265 private:
266 DECLARE_CLASS(wxFlexGridSizer);
267 };
268
269 //---------------------------------------------------------------------------
270 // wxBoxSizer
271 //---------------------------------------------------------------------------
272
273 class WXDLLEXPORT wxBoxSizer: public wxSizer
274 {
275 public:
276 wxBoxSizer( int orient );
277
278 void RecalcSizes();
279 wxSize CalcMin();
280
281 int GetOrientation()
282 { return m_orient; }
283
284 protected:
285 int m_orient;
286 int m_stretchable;
287 int m_minWidth;
288 int m_minHeight;
289 int m_fixedWidth;
290 int m_fixedHeight;
291
292 private:
293 DECLARE_CLASS(wxBoxSizer);
294 };
295
296 //---------------------------------------------------------------------------
297 // wxStaticBoxSizer
298 //---------------------------------------------------------------------------
299
300 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
301 {
302 public:
303 wxStaticBoxSizer( wxStaticBox *box, int orient );
304
305 void RecalcSizes();
306 wxSize CalcMin();
307
308 wxStaticBox *GetStaticBox()
309 { return m_staticBox; }
310
311 protected:
312 wxStaticBox *m_staticBox;
313
314 private:
315 DECLARE_CLASS(wxStaticBoxSizer);
316 };
317
318 //---------------------------------------------------------------------------
319 // wxNotebookSizer
320 //---------------------------------------------------------------------------
321
322 #if wxUSE_NOTEBOOK
323
324 class WXDLLEXPORT wxNotebookSizer: public wxSizer
325 {
326 public:
327 wxNotebookSizer( wxNotebook *nb );
328
329 void RecalcSizes();
330 wxSize CalcMin();
331
332 wxNotebook *GetNotebook()
333 { return m_notebook; }
334
335 protected:
336 wxNotebook *m_notebook;
337
338 private:
339 DECLARE_CLASS(wxNotebookSizer);
340 };
341
342 #endif
343
344
345 #endif
346 // __WXSIZER_H__