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