]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
support for using DIBs for wxBitmap implementation (patch 649866)
[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 // Enable deleting the SizerItem without destroying the contained sizer.
54 void DetachSizer()
55 { m_sizer = 0; }
56
57 virtual wxSize GetSize();
58 virtual wxSize CalcMin();
59 virtual void SetDimension( wxPoint pos, wxSize size );
60
61 wxSize GetMinSize()
62 { return m_minSize; }
63
64 void SetRatio( int width, int height )
65 // if either of dimensions is zero, ratio is assumed to be 1
66 // to avoid "divide by zero" errors
67 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
68 void SetRatio( wxSize size )
69 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
70 void SetRatio( float ratio )
71 { m_ratio = ratio; }
72 float GetRatio() const
73 { return m_ratio; }
74
75 bool IsWindow();
76 bool IsSizer();
77 bool IsSpacer();
78
79 void SetInitSize( int x, int y )
80 { m_minSize.x = x; m_minSize.y = y; }
81 void SetOption( int option )
82 { m_option = option; }
83 void SetFlag( int flag )
84 { m_flag = flag; }
85 void SetBorder( int border )
86 { m_border = border; }
87 void Show ( bool show )
88 { m_show = show; }
89
90 wxWindow *GetWindow() const
91 { return m_window; }
92 void SetWindow( wxWindow *window )
93 { m_window = window; }
94 wxSizer *GetSizer() const
95 { return m_sizer; }
96 void SetSizer( wxSizer *sizer )
97 { m_sizer = sizer; }
98 int GetOption() const
99 { return m_option; }
100 int GetFlag() const
101 { return m_flag; }
102 int GetBorder() const
103 { return m_border; }
104 bool IsShown() const
105 { return m_show; }
106 wxObject* GetUserData()
107 { return m_userData; }
108 wxPoint GetPosition()
109 { return m_pos; }
110
111 protected:
112 wxWindow *m_window;
113 wxSizer *m_sizer;
114 wxSize m_size;
115 wxPoint m_pos;
116 wxSize m_minSize;
117 int m_option;
118 int m_border;
119 int m_flag;
120
121 // If TRUE, then this item is considered in the layout
122 // calculation. Otherwise, it is skipped over.
123 bool m_show;
124 // als: aspect ratio can always be calculated from m_size,
125 // but this would cause precision loss when the window
126 // is shrinked. it is safer to preserve initial value.
127 float m_ratio;
128
129 wxObject *m_userData;
130
131 private:
132 DECLARE_CLASS(wxSizerItem);
133 };
134
135 //---------------------------------------------------------------------------
136 // wxSizer
137 //---------------------------------------------------------------------------
138
139 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
140 {
141 public:
142 wxSizer();
143 ~wxSizer();
144
145 /* These should be called Append() really. */
146 virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
147 virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
148 virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
149
150 virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
151 virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
152 virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
153
154 virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
155 virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
156 virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
157
158 // Remove will delete a sizer, but not a window.
159 virtual bool Remove( wxWindow *window );
160 virtual bool Remove( wxSizer *sizer );
161 virtual bool Remove( int pos );
162
163 // Detach will never destroy a sizer or window.
164 virtual bool Detach( wxWindow *window )
165 { return Remove( window ); }
166 virtual bool Detach( wxSizer *sizer );
167 virtual bool Detach( int pos );
168
169 virtual void Clear( bool delete_windows=FALSE );
170 virtual void DeleteWindows();
171
172 void SetMinSize( int width, int height )
173 { DoSetMinSize( width, height ); }
174 void SetMinSize( wxSize size )
175 { DoSetMinSize( size.x, size.y ); }
176
177 /* Searches recursively */
178 bool SetItemMinSize( wxWindow *window, int width, int height )
179 { return DoSetItemMinSize( window, width, height ); }
180 bool SetItemMinSize( wxWindow *window, wxSize size )
181 { return DoSetItemMinSize( window, size.x, size.y ); }
182
183 /* Searches recursively */
184 bool SetItemMinSize( wxSizer *sizer, int width, int height )
185 { return DoSetItemMinSize( sizer, width, height ); }
186 bool SetItemMinSize( wxSizer *sizer, wxSize size )
187 { return DoSetItemMinSize( sizer, size.x, size.y ); }
188
189 bool SetItemMinSize( int pos, int width, int height )
190 { return DoSetItemMinSize( pos, width, height ); }
191 bool SetItemMinSize( int pos, wxSize size )
192 { return DoSetItemMinSize( pos, size.x, size.y ); }
193
194 wxSize GetSize()
195 { return m_size; }
196 wxPoint GetPosition()
197 { return m_position; }
198
199 /* Calculate the minimal size or return m_minSize if bigger. */
200 wxSize GetMinSize();
201
202 virtual void RecalcSizes() = 0;
203 virtual wxSize CalcMin() = 0;
204
205 virtual void Layout();
206
207 wxSize Fit( wxWindow *window );
208 void FitInside( wxWindow *window );
209 void SetSizeHints( wxWindow *window );
210 void SetVirtualSizeHints( wxWindow *window );
211
212 wxList& GetChildren()
213 { return m_children; }
214
215 void SetDimension( int x, int y, int width, int height );
216
217 // Manage whether individual windows or sub-sizers are considered
218 // in the layout calculations or not.
219 void Show( wxWindow *window, bool show = TRUE );
220 void Hide( wxWindow *window )
221 { Show (window, FALSE); }
222 void Show( wxSizer *sizer, bool show = TRUE );
223 void Hide( wxSizer *sizer )
224 { Show (sizer, FALSE); }
225
226 bool IsShown( wxWindow *window );
227 bool IsShown( wxSizer *sizer );
228
229 // Recursively call wxWindow::Show () on all sizer items.
230 void ShowItems (bool show);
231
232 protected:
233 wxSize m_size;
234 wxSize m_minSize;
235 wxPoint m_position;
236 wxList m_children;
237
238 wxSize GetMaxWindowSize( wxWindow *window );
239 wxSize GetMinWindowSize( wxWindow *window );
240 wxSize GetMaxClientSize( wxWindow *window );
241 wxSize GetMinClientSize( wxWindow *window );
242 wxSize FitSize( wxWindow *window );
243 wxSize VirtualFitSize( wxWindow *window );
244
245 virtual void DoSetMinSize( int width, int height );
246 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
247 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
248 virtual bool DoSetItemMinSize( int pos, int width, int height );
249
250 private:
251 DECLARE_CLASS(wxSizer);
252 };
253
254 //---------------------------------------------------------------------------
255 // wxGridSizer
256 //---------------------------------------------------------------------------
257
258 class WXDLLEXPORT wxGridSizer: public wxSizer
259 {
260 public:
261 wxGridSizer( int rows, int cols, int vgap, int hgap );
262 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
263
264 void RecalcSizes();
265 wxSize CalcMin();
266
267 void SetCols( int cols ) { m_cols = cols; }
268 void SetRows( int rows ) { m_rows = rows; }
269 void SetVGap( int gap ) { m_vgap = gap; }
270 void SetHGap( int gap ) { m_hgap = gap; }
271 int GetCols() { return m_cols; }
272 int GetRows() { return m_rows; }
273 int GetVGap() { return m_vgap; }
274 int GetHGap() { return m_hgap; }
275
276 protected:
277 int m_rows;
278 int m_cols;
279 int m_vgap;
280 int m_hgap;
281
282 // return the number of total items and the number of columns and rows
283 int CalcRowsCols(int& rows, int& cols) const;
284
285 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
286
287 private:
288 DECLARE_CLASS(wxGridSizer);
289 };
290
291 //---------------------------------------------------------------------------
292 // wxFlexGridSizer
293 //---------------------------------------------------------------------------
294
295 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
296 {
297 public:
298 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
299 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
300 ~wxFlexGridSizer();
301
302 void RecalcSizes();
303 wxSize CalcMin();
304
305 void AddGrowableRow( size_t idx );
306 void RemoveGrowableRow( size_t idx );
307 void AddGrowableCol( size_t idx );
308 void RemoveGrowableCol( size_t idx );
309
310 protected:
311 int *m_rowHeights;
312 int *m_colWidths;
313 wxArrayInt m_growableRows;
314 wxArrayInt m_growableCols;
315
316 void CreateArrays();
317
318 private:
319 DECLARE_CLASS(wxFlexGridSizer);
320 };
321
322 //---------------------------------------------------------------------------
323 // wxBoxSizer
324 //---------------------------------------------------------------------------
325
326 class WXDLLEXPORT wxBoxSizer: public wxSizer
327 {
328 public:
329 wxBoxSizer( int orient );
330
331 void RecalcSizes();
332 wxSize CalcMin();
333
334 int GetOrientation()
335 { return m_orient; }
336
337 void SetOrientation(int orient)
338 { m_orient = orient; }
339
340 protected:
341 int m_orient;
342 int m_stretchable;
343 int m_minWidth;
344 int m_minHeight;
345 int m_fixedWidth;
346 int m_fixedHeight;
347
348 private:
349 DECLARE_CLASS(wxBoxSizer);
350 };
351
352 //---------------------------------------------------------------------------
353 // wxStaticBoxSizer
354 //---------------------------------------------------------------------------
355
356 #if wxUSE_STATBOX
357
358 class WXDLLEXPORT wxStaticBox;
359
360 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
361 {
362 public:
363 wxStaticBoxSizer( wxStaticBox *box, int orient );
364
365 void RecalcSizes();
366 wxSize CalcMin();
367
368 wxStaticBox *GetStaticBox()
369 { return m_staticBox; }
370
371 protected:
372 wxStaticBox *m_staticBox;
373
374 private:
375 DECLARE_CLASS(wxStaticBoxSizer);
376 };
377
378 #endif // wxUSE_STATBOX
379
380 //---------------------------------------------------------------------------
381 // wxNotebookSizer
382 //---------------------------------------------------------------------------
383
384 #if wxUSE_NOTEBOOK
385
386 class WXDLLEXPORT wxNotebook;
387
388 class WXDLLEXPORT wxNotebookSizer: public wxSizer
389 {
390 public:
391 wxNotebookSizer( wxNotebook *nb );
392
393 void RecalcSizes();
394 wxSize CalcMin();
395
396 wxNotebook *GetNotebook()
397 { return m_notebook; }
398
399 protected:
400 wxNotebook *m_notebook;
401
402 private:
403 DECLARE_CLASS(wxNotebookSizer);
404 };
405
406 #endif // wxUSE_NOTEBOOK
407
408
409 #endif
410 // __WXSIZER_H__