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