]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
fixed a Really Stupid Bug
[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: Ron Lee
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 wxSizerItem;
30 class wxSizer;
31 class wxBoxSizer;
32
33 //---------------------------------------------------------------------------
34 // wxSizerItem
35 //---------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxSizerItem: public wxObject
38 {
39 public:
40 // spacer
41 wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
42
43 // window
44 wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
45
46 // subsizer
47 wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
48
49 ~wxSizerItem();
50
51 virtual void DeleteWindows();
52
53 virtual wxSize GetSize();
54 virtual wxSize CalcMin();
55 virtual void SetDimension( wxPoint pos, wxSize size );
56
57 wxSize GetMinSize()
58 { return m_minSize; }
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 )
67 { m_ratio = ratio; }
68 float GetRatio() const
69 { return m_ratio; }
70
71 bool IsWindow();
72 bool IsSizer();
73 bool IsSpacer();
74
75 void SetInitSize( int x, int y )
76 { m_minSize.x = x; m_minSize.y = y; }
77 void SetOption( int option )
78 { m_option = option; }
79 void SetFlag( int flag )
80 { m_flag = flag; }
81 void SetBorder( int border )
82 { m_border = border; }
83
84 wxWindow *GetWindow() const
85 { return m_window; }
86 void SetWindow( wxWindow *window )
87 { m_window = window; }
88 wxSizer *GetSizer() const
89 { return m_sizer; }
90 void SetSizer( wxSizer *sizer )
91 { m_sizer = sizer; }
92 int GetOption() const
93 { return m_option; }
94 int GetFlag() const
95 { return m_flag; }
96 int GetBorder() const
97 { return m_border; }
98 wxObject* GetUserData()
99 { return m_userData; }
100 wxPoint GetPosition()
101 { return m_pos; }
102
103 protected:
104 wxWindow *m_window;
105 wxSizer *m_sizer;
106 wxSize m_size;
107 wxPoint m_pos;
108 wxSize m_minSize;
109 int m_option;
110 int m_border;
111 int m_flag;
112 // als: aspect ratio can always be calculated from m_size,
113 // but this would cause precision loss when the window
114 // is shrinked. it is safer to preserve initial value.
115 float m_ratio;
116 wxObject *m_userData;
117
118 private:
119 DECLARE_CLASS(wxSizerItem);
120 };
121
122 //---------------------------------------------------------------------------
123 // wxSizer
124 //---------------------------------------------------------------------------
125
126 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
127 {
128 public:
129 wxSizer();
130 ~wxSizer();
131
132 /* These should be called Append() really. */
133 virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
134 virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
135 virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
136
137 virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
138 virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
139 virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
140
141 virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
142 virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
143 virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
144
145 virtual bool Remove( wxWindow *window );
146 virtual bool Remove( wxSizer *sizer );
147 virtual bool Remove( int pos );
148
149 virtual void Clear( bool delete_windows=FALSE );
150 virtual void DeleteWindows();
151
152 void SetMinSize( int width, int height )
153 { DoSetMinSize( width, height ); }
154 void SetMinSize( wxSize size )
155 { DoSetMinSize( size.x, size.y ); }
156
157 /* Searches recursively */
158 bool SetItemMinSize( wxWindow *window, int width, int height )
159 { return DoSetItemMinSize( window, width, height ); }
160 bool SetItemMinSize( wxWindow *window, wxSize size )
161 { return DoSetItemMinSize( window, size.x, size.y ); }
162
163 /* Searches recursively */
164 bool SetItemMinSize( wxSizer *sizer, int width, int height )
165 { return DoSetItemMinSize( sizer, width, height ); }
166 bool SetItemMinSize( wxSizer *sizer, wxSize size )
167 { return DoSetItemMinSize( sizer, size.x, size.y ); }
168
169 bool SetItemMinSize( int pos, int width, int height )
170 { return DoSetItemMinSize( pos, width, height ); }
171 bool SetItemMinSize( int pos, wxSize size )
172 { return DoSetItemMinSize( pos, size.x, size.y ); }
173
174 wxSize GetSize()
175 { return m_size; }
176 wxPoint GetPosition()
177 { return m_position; }
178
179 /* Calculate the minimal size or return m_minSize if bigger. */
180 wxSize GetMinSize();
181
182 virtual void RecalcSizes() = 0;
183 virtual wxSize CalcMin() = 0;
184
185 virtual void Layout();
186
187 wxSize Fit( wxWindow *window );
188 void FitInside( wxWindow *window );
189 void SetSizeHints( wxWindow *window );
190 void SetVirtualSizeHints( wxWindow *window );
191
192 wxList& GetChildren()
193 { return m_children; }
194
195 void SetDimension( int x, int y, int width, int height );
196
197 protected:
198 wxSize m_size;
199 wxSize m_minSize;
200 wxPoint m_position;
201 wxList m_children;
202
203 wxSize GetMaxWindowSize( wxWindow *window );
204 wxSize GetMinWindowSize( wxWindow *window );
205 wxSize GetMaxClientSize( wxWindow *window );
206 wxSize GetMinClientSize( wxWindow *window );
207 wxSize FitSize( wxWindow *window );
208 wxSize VirtualFitSize( wxWindow *window );
209
210 virtual void DoSetMinSize( int width, int height );
211 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
212 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
213 virtual bool DoSetItemMinSize( int pos, int width, int height );
214
215 private:
216 DECLARE_CLASS(wxSizer);
217 };
218
219 //---------------------------------------------------------------------------
220 // wxGridSizer
221 //---------------------------------------------------------------------------
222
223 class WXDLLEXPORT wxGridSizer: public wxSizer
224 {
225 public:
226 wxGridSizer( int rows, int cols, int vgap, int hgap );
227 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
228
229 void RecalcSizes();
230 wxSize CalcMin();
231
232 void SetCols( int cols ) { m_cols = cols; }
233 void SetRows( int rows ) { m_rows = rows; }
234 void SetVGap( int gap ) { m_vgap = gap; }
235 void SetHGap( int gap ) { m_hgap = gap; }
236 int GetCols() { return m_cols; }
237 int GetRows() { return m_rows; }
238 int GetVGap() { return m_vgap; }
239 int GetHGap() { return m_hgap; }
240
241 protected:
242 int m_rows;
243 int m_cols;
244 int m_vgap;
245 int m_hgap;
246
247 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
248
249 private:
250 DECLARE_CLASS(wxGridSizer);
251 };
252
253 //---------------------------------------------------------------------------
254 // wxFlexGridSizer
255 //---------------------------------------------------------------------------
256
257 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
258 {
259 public:
260 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
261 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
262 ~wxFlexGridSizer();
263
264 void RecalcSizes();
265 wxSize CalcMin();
266
267 void AddGrowableRow( size_t idx );
268 void RemoveGrowableRow( size_t idx );
269 void AddGrowableCol( size_t idx );
270 void RemoveGrowableCol( size_t idx );
271
272 protected:
273 int *m_rowHeights;
274 int *m_colWidths;
275 wxArrayInt m_growableRows;
276 wxArrayInt m_growableCols;
277
278 void CreateArrays();
279
280 private:
281 DECLARE_CLASS(wxFlexGridSizer);
282 };
283
284 //---------------------------------------------------------------------------
285 // wxBoxSizer
286 //---------------------------------------------------------------------------
287
288 class WXDLLEXPORT wxBoxSizer: public wxSizer
289 {
290 public:
291 wxBoxSizer( int orient );
292
293 void RecalcSizes();
294 wxSize CalcMin();
295
296 int GetOrientation()
297 { return m_orient; }
298
299 protected:
300 int m_orient;
301 int m_stretchable;
302 int m_minWidth;
303 int m_minHeight;
304 int m_fixedWidth;
305 int m_fixedHeight;
306
307 private:
308 DECLARE_CLASS(wxBoxSizer);
309 };
310
311 //---------------------------------------------------------------------------
312 // wxStaticBoxSizer
313 //---------------------------------------------------------------------------
314
315 #if wxUSE_STATBOX
316
317 class WXDLLEXPORT wxStaticBox;
318
319 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
320 {
321 public:
322 wxStaticBoxSizer( wxStaticBox *box, int orient );
323
324 void RecalcSizes();
325 wxSize CalcMin();
326
327 wxStaticBox *GetStaticBox()
328 { return m_staticBox; }
329
330 protected:
331 wxStaticBox *m_staticBox;
332
333 private:
334 DECLARE_CLASS(wxStaticBoxSizer);
335 };
336
337 #endif // wxUSE_STATBOX
338
339 //---------------------------------------------------------------------------
340 // wxNotebookSizer
341 //---------------------------------------------------------------------------
342
343 #if wxUSE_NOTEBOOK
344
345 class WXDLLEXPORT wxNotebook;
346
347 class WXDLLEXPORT wxNotebookSizer: public wxSizer
348 {
349 public:
350 wxNotebookSizer( wxNotebook *nb );
351
352 void RecalcSizes();
353 wxSize CalcMin();
354
355 wxNotebook *GetNotebook()
356 { return m_notebook; }
357
358 protected:
359 wxNotebook *m_notebook;
360
361 private:
362 DECLARE_CLASS(wxNotebookSizer);
363 };
364
365 #endif // wxUSE_NOTEBOOK
366
367
368 #endif
369 // __WXSIZER_H__