]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
Notebook, Listbox, and Checklst updates
[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 #if defined(__GNUG__) && !defined(__APPLE__)
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 // return the number of total items and the number of columns and rows
248 int CalcRowsCols(int& rows, int& cols) const;
249
250 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
251
252 private:
253 DECLARE_CLASS(wxGridSizer);
254 };
255
256 //---------------------------------------------------------------------------
257 // wxFlexGridSizer
258 //---------------------------------------------------------------------------
259
260 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
261 {
262 public:
263 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
264 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
265 ~wxFlexGridSizer();
266
267 void RecalcSizes();
268 wxSize CalcMin();
269
270 void AddGrowableRow( size_t idx );
271 void RemoveGrowableRow( size_t idx );
272 void AddGrowableCol( size_t idx );
273 void RemoveGrowableCol( size_t idx );
274
275 protected:
276 int *m_rowHeights;
277 int *m_colWidths;
278 wxArrayInt m_growableRows;
279 wxArrayInt m_growableCols;
280
281 void CreateArrays();
282
283 private:
284 DECLARE_CLASS(wxFlexGridSizer);
285 };
286
287 //---------------------------------------------------------------------------
288 // wxBoxSizer
289 //---------------------------------------------------------------------------
290
291 class WXDLLEXPORT wxBoxSizer: public wxSizer
292 {
293 public:
294 wxBoxSizer( int orient );
295
296 void RecalcSizes();
297 wxSize CalcMin();
298
299 int GetOrientation()
300 { return m_orient; }
301
302 protected:
303 int m_orient;
304 int m_stretchable;
305 int m_minWidth;
306 int m_minHeight;
307 int m_fixedWidth;
308 int m_fixedHeight;
309
310 private:
311 DECLARE_CLASS(wxBoxSizer);
312 };
313
314 //---------------------------------------------------------------------------
315 // wxStaticBoxSizer
316 //---------------------------------------------------------------------------
317
318 #if wxUSE_STATBOX
319
320 class WXDLLEXPORT wxStaticBox;
321
322 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
323 {
324 public:
325 wxStaticBoxSizer( wxStaticBox *box, int orient );
326
327 void RecalcSizes();
328 wxSize CalcMin();
329
330 wxStaticBox *GetStaticBox()
331 { return m_staticBox; }
332
333 protected:
334 wxStaticBox *m_staticBox;
335
336 private:
337 DECLARE_CLASS(wxStaticBoxSizer);
338 };
339
340 #endif // wxUSE_STATBOX
341
342 //---------------------------------------------------------------------------
343 // wxNotebookSizer
344 //---------------------------------------------------------------------------
345
346 #if wxUSE_NOTEBOOK
347
348 class WXDLLEXPORT wxNotebook;
349
350 class WXDLLEXPORT wxNotebookSizer: public wxSizer
351 {
352 public:
353 wxNotebookSizer( wxNotebook *nb );
354
355 void RecalcSizes();
356 wxSize CalcMin();
357
358 wxNotebook *GetNotebook()
359 { return m_notebook; }
360
361 protected:
362 wxNotebook *m_notebook;
363
364 private:
365 DECLARE_CLASS(wxNotebookSizer);
366 };
367
368 #endif // wxUSE_NOTEBOOK
369
370
371 #endif
372 // __WXSIZER_H__