]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
fixed compilation of multilib dll
[wxWidgets.git] / include / wx / sizer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sizer.h
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Robin Dunn, 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,
42 int height,
43 int proportion,
44 int flag,
45 int border,
46 wxObject* userData);
47
48 // window
49 wxSizerItem( wxWindow *window,
50 int proportion,
51 int flag,
52 int border,
53 wxObject* userData );
54
55 // subsizer
56 wxSizerItem( wxSizer *sizer,
57 int proportion,
58 int flag,
59 int border,
60 wxObject* userData );
61
62 ~wxSizerItem();
63
64 virtual void DeleteWindows();
65
66 // Enable deleting the SizerItem without destroying the contained sizer.
67 void DetachSizer()
68 { m_sizer = 0; }
69
70 virtual wxSize GetSize() const;
71 virtual wxSize CalcMin();
72 virtual void SetDimension( wxPoint pos, wxSize size );
73
74 wxSize GetMinSize() const
75 { return m_minSize; }
76 void SetInitSize( int x, int y )
77 { m_minSize.x = x; m_minSize.y = y; }
78
79 void SetRatio( int width, int height )
80 // if either of dimensions is zero, ratio is assumed to be 1
81 // to avoid "divide by zero" errors
82 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
83 void SetRatio( wxSize size )
84 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
85 void SetRatio( float ratio )
86 { m_ratio = ratio; }
87 float GetRatio() const
88 { return m_ratio; }
89
90 bool IsWindow() const;
91 bool IsSizer() const;
92 bool IsSpacer() const;
93
94 // Deprecated in 2.6, use {G,S}etProportion instead.
95 wxDEPRECATED( void SetOption( int option ) );
96 wxDEPRECATED( int GetOption() const );
97
98 void SetProportion( int proportion )
99 { m_proportion = proportion; }
100 int GetProportion() const
101 { return m_proportion; }
102 void SetFlag( int flag )
103 { m_flag = flag; }
104 int GetFlag() const
105 { return m_flag; }
106 void SetBorder( int border )
107 { m_border = border; }
108 int GetBorder() const
109 { return m_border; }
110
111 wxWindow *GetWindow() const
112 { return m_window; }
113 void SetWindow( wxWindow *window )
114 { m_window = window; }
115 wxSizer *GetSizer() const
116 { return m_sizer; }
117 void SetSizer( wxSizer *sizer )
118 { m_sizer = sizer; }
119 const wxSize &GetSpacer() const
120 { return m_size; }
121 void SetSpacer( const wxSize &size )
122 { m_size = size; m_minSize = size; }
123
124 void Show ( bool show );
125 bool IsShown() const
126 { return m_show; }
127
128 wxObject* GetUserData() const
129 { return m_userData; }
130 wxPoint GetPosition() const
131 { return m_pos; }
132
133 protected:
134 wxWindow *m_window;
135 wxSizer *m_sizer;
136 wxSize m_size;
137 wxPoint m_pos;
138 wxSize m_minSize;
139 int m_proportion;
140 int m_border;
141 int m_flag;
142
143 // If true, then this item is considered in the layout
144 // calculation. Otherwise, it is skipped over.
145 bool m_show;
146
147 // Aspect ratio can always be calculated from m_size,
148 // but this would cause precision loss when the window
149 // is shrunk. It is safer to preserve the initial value.
150 float m_ratio;
151
152 wxObject *m_userData;
153
154 private:
155 DECLARE_CLASS(wxSizerItem);
156 DECLARE_NO_COPY_CLASS(wxSizerItem)
157 };
158
159 WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
160
161
162 //---------------------------------------------------------------------------
163 // wxSizer
164 //---------------------------------------------------------------------------
165
166 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
167 {
168 public:
169 wxSizer();
170 ~wxSizer();
171
172 /* These should be called Append() really. */
173 virtual void Add( wxWindow *window,
174 int proportion = 0,
175 int flag = 0,
176 int border = 0,
177 wxObject* userData = NULL );
178 virtual void Add( wxSizer *sizer,
179 int proportion = 0,
180 int flag = 0,
181 int border = 0,
182 wxObject* userData = NULL );
183 virtual void Add( int width,
184 int height,
185 int proportion = 0,
186 int flag = 0,
187 int border = 0,
188 wxObject* userData = NULL );
189 virtual void Add( wxSizerItem *item );
190
191 virtual void Insert( size_t index,
192 wxWindow *window,
193 int proportion = 0,
194 int flag = 0,
195 int border = 0,
196 wxObject* userData = NULL );
197 virtual void Insert( size_t index,
198 wxSizer *sizer,
199 int proportion = 0,
200 int flag = 0,
201 int border = 0,
202 wxObject* userData = NULL );
203 virtual void Insert( size_t index,
204 int width,
205 int height,
206 int proportion = 0,
207 int flag = 0,
208 int border = 0,
209 wxObject* userData = NULL );
210 virtual void Insert( size_t index,
211 wxSizerItem *item );
212
213 virtual void Prepend( wxWindow *window,
214 int proportion = 0,
215 int flag = 0,
216 int border = 0,
217 wxObject* userData = NULL );
218 virtual void Prepend( wxSizer *sizer,
219 int proportion = 0,
220 int flag = 0,
221 int border = 0,
222 wxObject* userData = NULL );
223 virtual void Prepend( int width,
224 int height,
225 int proportion = 0,
226 int flag = 0,
227 int border = 0,
228 wxObject* userData = NULL );
229 virtual void Prepend( wxSizerItem *item );
230
231 // Deprecated in 2.6 since historically it does not delete the window,
232 // use Detach instead.
233 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
234 virtual bool Remove( wxSizer *sizer );
235 virtual bool Remove( int index );
236
237 virtual bool Detach( wxWindow *window );
238 virtual bool Detach( wxSizer *sizer );
239 virtual bool Detach( int index );
240
241 virtual void Clear( bool delete_windows = false );
242 virtual void DeleteWindows();
243
244 void SetMinSize( int width, int height )
245 { DoSetMinSize( width, height ); }
246 void SetMinSize( wxSize size )
247 { DoSetMinSize( size.x, size.y ); }
248
249 /* Searches recursively */
250 bool SetItemMinSize( wxWindow *window, int width, int height )
251 { return DoSetItemMinSize( window, width, height ); }
252 bool SetItemMinSize( wxWindow *window, wxSize size )
253 { return DoSetItemMinSize( window, size.x, size.y ); }
254
255 /* Searches recursively */
256 bool SetItemMinSize( wxSizer *sizer, int width, int height )
257 { return DoSetItemMinSize( sizer, width, height ); }
258 bool SetItemMinSize( wxSizer *sizer, wxSize size )
259 { return DoSetItemMinSize( sizer, size.x, size.y ); }
260
261 bool SetItemMinSize( size_t index, int width, int height )
262 { return DoSetItemMinSize( index, width, height ); }
263 bool SetItemMinSize( size_t index, wxSize size )
264 { return DoSetItemMinSize( index, size.x, size.y ); }
265
266 wxSize GetSize() const
267 { return m_size; }
268 wxPoint GetPosition() const
269 { return m_position; }
270
271 /* Calculate the minimal size or return m_minSize if bigger. */
272 wxSize GetMinSize();
273
274 virtual void RecalcSizes() = 0;
275 virtual wxSize CalcMin() = 0;
276
277 virtual void Layout();
278
279 wxSize Fit( wxWindow *window );
280 void FitInside( wxWindow *window );
281 void SetSizeHints( wxWindow *window );
282 void SetVirtualSizeHints( wxWindow *window );
283
284 wxSizerItemList& GetChildren()
285 { return m_children; }
286
287 void SetDimension( int x, int y, int width, int height );
288
289 // Manage whether individual scene items are considered
290 // in the layout calculations or not.
291 void Show( wxWindow *window, bool show = true );
292 void Show( wxSizer *sizer, bool show = true );
293 void Show( size_t index, bool show = true );
294
295 void Hide( wxSizer *sizer )
296 { Show( sizer, false ); }
297 void Hide( wxWindow *window )
298 { Show( window, false ); }
299 void Hide( size_t index )
300 { Show( index, false ); }
301
302 bool IsShown( wxWindow *window ) const;
303 bool IsShown( wxSizer *sizer ) const;
304 bool IsShown( size_t index ) const;
305
306 // Recursively call wxWindow::Show () on all sizer items.
307 void ShowItems (bool show);
308
309 protected:
310 wxSize m_size;
311 wxSize m_minSize;
312 wxPoint m_position;
313 wxSizerItemList m_children;
314
315 wxSize GetMaxWindowSize( wxWindow *window ) const;
316 wxSize GetMinWindowSize( wxWindow *window );
317 wxSize GetMaxClientSize( wxWindow *window ) const;
318 wxSize GetMinClientSize( wxWindow *window );
319 wxSize FitSize( wxWindow *window );
320 wxSize VirtualFitSize( wxWindow *window );
321
322 virtual void DoSetMinSize( int width, int height );
323 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
324 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
325 virtual bool DoSetItemMinSize( size_t index, int width, int height );
326
327 private:
328 DECLARE_CLASS(wxSizer);
329 };
330
331 //---------------------------------------------------------------------------
332 // wxGridSizer
333 //---------------------------------------------------------------------------
334
335 class WXDLLEXPORT wxGridSizer: public wxSizer
336 {
337 public:
338 wxGridSizer( int rows, int cols, int vgap, int hgap );
339 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
340
341 virtual void RecalcSizes();
342 virtual wxSize CalcMin();
343
344 void SetCols( int cols ) { m_cols = cols; }
345 void SetRows( int rows ) { m_rows = rows; }
346 void SetVGap( int gap ) { m_vgap = gap; }
347 void SetHGap( int gap ) { m_hgap = gap; }
348 int GetCols() const { return m_cols; }
349 int GetRows() const { return m_rows; }
350 int GetVGap() const { return m_vgap; }
351 int GetHGap() const { return m_hgap; }
352
353 protected:
354 int m_rows;
355 int m_cols;
356 int m_vgap;
357 int m_hgap;
358
359 // return the number of total items and the number of columns and rows
360 int CalcRowsCols(int& rows, int& cols) const;
361
362 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
363
364 private:
365 DECLARE_CLASS(wxGridSizer);
366 };
367
368 //---------------------------------------------------------------------------
369 // wxFlexGridSizer
370 //---------------------------------------------------------------------------
371
372 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
373 // direction
374 enum wxFlexSizerGrowMode
375 {
376 // don't resize the cells in non-flexible direction at all
377 wxFLEX_GROWMODE_NONE,
378
379 // uniformly resize only the specified ones (default)
380 wxFLEX_GROWMODE_SPECIFIED,
381
382 // uniformly resize all cells
383 wxFLEX_GROWMODE_ALL
384 };
385
386 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
387 {
388 public:
389 // ctors/dtor
390 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
391 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
392 virtual ~wxFlexGridSizer();
393
394
395 // set the rows/columns which will grow (the others will remain of the
396 // constant initial size)
397 void AddGrowableRow( size_t idx, int proportion = 0 );
398 void RemoveGrowableRow( size_t idx );
399 void AddGrowableCol( size_t idx, int proportion = 0 );
400 void RemoveGrowableCol( size_t idx );
401
402
403 // the sizer cells may grow in both directions, not grow at all or only
404 // grow in one direction but not the other
405
406 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
407 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
408 int GetFlexibleDirection() const { return m_flexDirection; }
409
410 // note that the grow mode only applies to the direction which is not
411 // flexible
412 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
413 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
414
415
416 // implementation
417 virtual void RecalcSizes();
418 virtual wxSize CalcMin();
419
420 protected:
421 // the heights/widths of all rows/columns
422 wxArrayInt m_rowHeights,
423 m_colWidths;
424
425 // indices of the growable columns and rows
426 wxArrayInt m_growableRows,
427 m_growableCols;
428
429 // proportion values of the corresponding growable rows and columns
430 wxArrayInt m_growableRowsProportions,
431 m_growableColsProportions;
432
433 // parameters describing whether the growable cells should be resized in
434 // both directions or only one
435 int m_flexDirection;
436 wxFlexSizerGrowMode m_growMode;
437
438 private:
439 DECLARE_CLASS(wxFlexGridSizer);
440 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
441 };
442
443 //---------------------------------------------------------------------------
444 // wxBoxSizer
445 //---------------------------------------------------------------------------
446
447 class WXDLLEXPORT wxBoxSizer: public wxSizer
448 {
449 public:
450 wxBoxSizer( int orient );
451
452 void RecalcSizes();
453 wxSize CalcMin();
454
455 int GetOrientation() const
456 { return m_orient; }
457
458 void SetOrientation(int orient)
459 { m_orient = orient; }
460
461 protected:
462 int m_orient;
463 int m_stretchable;
464 int m_minWidth;
465 int m_minHeight;
466 int m_fixedWidth;
467 int m_fixedHeight;
468
469 private:
470 DECLARE_CLASS(wxBoxSizer);
471 };
472
473 //---------------------------------------------------------------------------
474 // wxStaticBoxSizer
475 //---------------------------------------------------------------------------
476
477 #if wxUSE_STATBOX
478
479 class WXDLLEXPORT wxStaticBox;
480
481 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
482 {
483 public:
484 wxStaticBoxSizer( wxStaticBox *box, int orient );
485
486 void RecalcSizes();
487 wxSize CalcMin();
488
489 wxStaticBox *GetStaticBox() const
490 { return m_staticBox; }
491
492 protected:
493 wxStaticBox *m_staticBox;
494
495 private:
496 DECLARE_CLASS(wxStaticBoxSizer);
497 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
498 };
499
500 #endif // wxUSE_STATBOX
501
502 //---------------------------------------------------------------------------
503 // wxNotebookSizer
504 //---------------------------------------------------------------------------
505
506 #if wxUSE_NOTEBOOK
507
508 class WXDLLEXPORT wxNotebook;
509
510 class WXDLLEXPORT wxNotebookSizer: public wxSizer
511 {
512 public:
513 wxNotebookSizer( wxNotebook *nb );
514
515 void RecalcSizes();
516 wxSize CalcMin();
517
518 wxNotebook *GetNotebook() const
519 { return m_notebook; }
520
521 protected:
522 wxNotebook *m_notebook;
523
524 private:
525 DECLARE_CLASS(wxNotebookSizer);
526 DECLARE_NO_COPY_CLASS(wxNotebookSizer)
527 };
528
529 #endif // wxUSE_NOTEBOOK
530
531
532 #endif
533 // __WXSIZER_H__