1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/sizer.h
3 // Purpose: provide wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
6 // Created:
7 // RCS-ID: $Id: sizer.h 52331 2008-03-05 15:02:22Z VS $
8 // Copyright: (c) Robin Dunn, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WXSIZER_H__
13 #define __WXSIZER_H__
14
15 #include "wx/defs.h"
16
17 #include "wx/window.h"
18
19 //---------------------------------------------------------------------------
20 // classes
21 //---------------------------------------------------------------------------
22
23 class WXDLLIMPEXP_FWD_CORE wxButton;
24 class WXDLLIMPEXP_FWD_CORE wxBoxSizer;
25 class WXDLLIMPEXP_FWD_CORE wxSizerItem;
26 class WXDLLIMPEXP_FWD_CORE wxSizer;
27 class WXDLLIMPEXP_FWD_CORE wxFlexGridSizer;
28 class WXDLLIMPEXP_FWD_CORE wxGridBagSizer;
29
30 #ifndef wxUSE_BORDER_BY_DEFAULT
31 #ifdef __SMARTPHONE__
32 // no borders by default on limited size screen
33 #define wxUSE_BORDER_BY_DEFAULT 0
34 #else
35 #define wxUSE_BORDER_BY_DEFAULT 1
36 #endif
37 #endif
38
39 // ----------------------------------------------------------------------------
40 // wxSizerFlags: flags used for an item in the sizer
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxSizerFlags
44 {
45 public:
46 // construct the flags object initialized with the given proportion (0 by
47 // default)
m_proportion(proportion)48 wxSizerFlags(int proportion = 0) : m_proportion(proportion)
49 {
50 m_flags = 0;
51 m_borderInPixels = 0;
52 }
53
54 // setters for all sizer flags, they all return the object itself so that
55 // calls to them can be chained
56
Proportion(int proportion)57 wxSizerFlags& Proportion(int proportion)
58 {
59 m_proportion = proportion;
60 return *this;
61 }
62
Align(int alignment)63 wxSizerFlags& Align(int alignment) // combination of wxAlignment values
64 {
65 m_flags &= ~wxALIGN_MASK;
66 m_flags |= alignment;
67
68 return *this;
69 }
70
Expand()71 wxSizerFlags& Expand()
72 {
73 m_flags |= wxEXPAND;
74 return *this;
75 }
76
77 // some shortcuts for Align()
Centre()78 wxSizerFlags& Centre() { return Align(wxCENTRE); }
Center()79 wxSizerFlags& Center() { return Centre(); }
Left()80 wxSizerFlags& Left() { return Align(wxALIGN_LEFT); }
Right()81 wxSizerFlags& Right() { return Align(wxALIGN_RIGHT); }
82
83 #if wxABI_VERSION >= 20802
Top()84 wxSizerFlags& Top() { return Align(wxALIGN_TOP); }
Bottom()85 wxSizerFlags& Bottom() { return Align(wxALIGN_BOTTOM); }
86 #endif // wxABI 2.8.2+
87
88 // default border size used by Border() below
GetDefaultBorder()89 static int GetDefaultBorder()
90 {
91 #if wxUSE_BORDER_BY_DEFAULT
92 // FIXME: default border size shouldn't be hardcoded and at the very
93 // least they should depend on the current font size
94 return 5;
95 #else
96 return 0;
97 #endif
98 }
99
100
Border(int direction,int borderInPixels)101 wxSizerFlags& Border(int direction, int borderInPixels)
102 {
103 m_flags &= ~wxALL;
104 m_flags |= direction;
105
106 m_borderInPixels = borderInPixels;
107
108 return *this;
109 }
110
111 wxSizerFlags& Border(int direction = wxALL)
112 {
113 #if wxUSE_BORDER_BY_DEFAULT
114 return Border(direction, GetDefaultBorder());
115 #else
116 // no borders by default on limited size screen
117 wxUnusedVar(direction);
118
119 return *this;
120 #endif
121 }
122
123 wxSizerFlags& DoubleBorder(int direction = wxALL)
124 {
125 #if wxUSE_BORDER_BY_DEFAULT
126 return Border(direction, 2*GetDefaultBorder());
127 #else
128 wxUnusedVar(direction);
129
130 return *this;
131 #endif
132 }
133
134 wxSizerFlags& TripleBorder(int direction = wxALL)
135 {
136 #if wxUSE_BORDER_BY_DEFAULT
137 return Border(direction, 3*GetDefaultBorder());
138 #else
139 wxUnusedVar(direction);
140
141 return *this;
142 #endif
143 }
144
HorzBorder()145 wxSizerFlags& HorzBorder()
146 {
147 #if wxUSE_BORDER_BY_DEFAULT
148 return Border(wxLEFT | wxRIGHT, GetDefaultBorder());
149 #else
150 return *this;
151 #endif
152 }
153
DoubleHorzBorder()154 wxSizerFlags& DoubleHorzBorder()
155 {
156 #if wxUSE_BORDER_BY_DEFAULT
157 return Border(wxLEFT | wxRIGHT, 2*GetDefaultBorder());
158 #else
159 return *this;
160 #endif
161 }
162
163 #if wxABI_VERSION >= 20802
164 // setters for the others flags
Shaped()165 wxSizerFlags& Shaped()
166 {
167 m_flags |= wxSHAPED;
168
169 return *this;
170 }
171
FixedMinSize()172 wxSizerFlags& FixedMinSize()
173 {
174 m_flags |= wxFIXED_MINSIZE;
175
176 return *this;
177 }
178 #endif // wx 2.8.2+
179
180 #if wxABI_VERSION >= 20808
181 // makes the item ignore window's visibility status
182 wxSizerFlags& ReserveSpaceEvenIfHidden();
183 #endif
184
185 // accessors for wxSizer only
GetProportion()186 int GetProportion() const { return m_proportion; }
GetFlags()187 int GetFlags() const { return m_flags; }
GetBorderInPixels()188 int GetBorderInPixels() const { return m_borderInPixels; }
189
190 private:
191 int m_proportion;
192 int m_flags;
193 int m_borderInPixels;
194 };
195
196
197 // ----------------------------------------------------------------------------
198 // wxSizerSpacer: used by wxSizerItem to represent a spacer
199 // ----------------------------------------------------------------------------
200
201 class WXDLLEXPORT wxSizerSpacer
202 {
203 public:
wxSizerSpacer(const wxSize & size)204 wxSizerSpacer(const wxSize& size) : m_size(size), m_isShown(true) { }
205
SetSize(const wxSize & size)206 void SetSize(const wxSize& size) { m_size = size; }
GetSize()207 const wxSize& GetSize() const { return m_size; }
208
Show(bool show)209 void Show(bool show) { m_isShown = show; }
IsShown()210 bool IsShown() const { return m_isShown; }
211
212 private:
213 // the size, in pixel
214 wxSize m_size;
215
216 // is the spacer currently shown?
217 bool m_isShown;
218 };
219
220 // ----------------------------------------------------------------------------
221 // wxSizerItem
222 // ----------------------------------------------------------------------------
223
224 class WXDLLEXPORT wxSizerItem : public wxObject
225 {
226 public:
227 // window
228 wxSizerItem( wxWindow *window,
229 int proportion,
230 int flag,
231 int border,
232 wxObject* userData );
233
234 // window with flags
wxSizerItem(wxWindow * window,const wxSizerFlags & flags)235 wxSizerItem(wxWindow *window, const wxSizerFlags& flags)
236 {
237 Init(flags);
238
239 SetWindow(window);
240 }
241
242 // subsizer
243 wxSizerItem( wxSizer *sizer,
244 int proportion,
245 int flag,
246 int border,
247 wxObject* userData );
248
249 // sizer with flags
wxSizerItem(wxSizer * sizer,const wxSizerFlags & flags)250 wxSizerItem(wxSizer *sizer, const wxSizerFlags& flags)
251 {
252 Init(flags);
253
254 SetSizer(sizer);
255 }
256
257 // spacer
258 wxSizerItem( int width,
259 int height,
260 int proportion,
261 int flag,
262 int border,
263 wxObject* userData);
264
265 // spacer with flags
wxSizerItem(int width,int height,const wxSizerFlags & flags)266 wxSizerItem(int width, int height, const wxSizerFlags& flags)
267 {
268 Init(flags);
269
270 SetSpacer(width, height);
271 }
272
273 wxSizerItem();
274 virtual ~wxSizerItem();
275
276 virtual void DeleteWindows();
277
278 // Enable deleting the SizerItem without destroying the contained sizer.
DetachSizer()279 void DetachSizer() { m_sizer = NULL; }
280
281 virtual wxSize GetSize() const;
282 virtual wxSize CalcMin();
283 virtual void SetDimension( const wxPoint& pos, const wxSize& size );
284
GetMinSize()285 wxSize GetMinSize() const
286 { return m_minSize; }
287 wxSize GetMinSizeWithBorder() const;
288
SetMinSize(const wxSize & size)289 void SetMinSize(const wxSize& size)
290 {
291 if ( IsWindow() )
292 m_window->SetMinSize(size);
293 m_minSize = size;
294 }
SetMinSize(int x,int y)295 void SetMinSize( int x, int y )
296 { SetMinSize(wxSize(x, y)); }
SetInitSize(int x,int y)297 void SetInitSize( int x, int y )
298 { SetMinSize(wxSize(x, y)); }
299
300 // if either of dimensions is zero, ratio is assumed to be 1
301 // to avoid "divide by zero" errors
SetRatio(int width,int height)302 void SetRatio(int width, int height)
303 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
SetRatio(const wxSize & size)304 void SetRatio(const wxSize& size)
305 { SetRatio(size.x, size.y); }
SetRatio(float ratio)306 void SetRatio(float ratio)
307 { m_ratio = ratio; }
GetRatio()308 float GetRatio() const
309 { return m_ratio; }
310
GetRect()311 virtual wxRect GetRect() { return m_rect; }
312
IsWindow()313 bool IsWindow() const { return m_kind == Item_Window; }
IsSizer()314 bool IsSizer() const { return m_kind == Item_Sizer; }
IsSpacer()315 bool IsSpacer() const { return m_kind == Item_Spacer; }
316
317 #if WXWIN_COMPATIBILITY_2_6
318 // Deprecated in 2.6, use {G,S}etProportion instead.
319 wxDEPRECATED( void SetOption( int option ) );
320 wxDEPRECATED( int GetOption() const );
321 #endif // WXWIN_COMPATIBILITY_2_6
322
SetProportion(int proportion)323 void SetProportion( int proportion )
324 { m_proportion = proportion; }
GetProportion()325 int GetProportion() const
326 { return m_proportion; }
SetFlag(int flag)327 void SetFlag( int flag )
328 { m_flag = flag; }
GetFlag()329 int GetFlag() const
330 { return m_flag; }
SetBorder(int border)331 void SetBorder( int border )
332 { m_border = border; }
GetBorder()333 int GetBorder() const
334 { return m_border; }
335
GetWindow()336 wxWindow *GetWindow() const
337 { return m_kind == Item_Window ? m_window : NULL; }
GetSizer()338 wxSizer *GetSizer() const
339 { return m_kind == Item_Sizer ? m_sizer : NULL; }
340 wxSize GetSpacer() const;
341
342 // this function behaves obviously for the windows and spacers but for the
343 // sizers it returns true if any sizer element is shown and only returns
344 // false if all of them are hidden
345 bool IsShown() const;
346 void Show(bool show);
347
SetUserData(wxObject * userData)348 void SetUserData(wxObject* userData)
349 { delete m_userData; m_userData = userData; }
GetUserData()350 wxObject* GetUserData() const
351 { return m_userData; }
GetPosition()352 wxPoint GetPosition() const
353 { return m_pos; }
354
355
356 // these functions do not free old sizer/spacer
357 void SetWindow(wxWindow *window);
358 void SetSizer(wxSizer *sizer);
359 void SetSpacer(const wxSize& size);
SetSpacer(int width,int height)360 void SetSpacer(int width, int height) { SetSpacer(wxSize(width, height)); }
361
362 protected:
363 // common part of several ctors
Init()364 void Init() { m_userData = NULL; }
365
366 // common part of ctors taking wxSizerFlags
367 void Init(const wxSizerFlags& flags);
368
369
370 // discriminated union: depending on m_kind one of the fields is valid
371 enum
372 {
373 Item_None,
374 Item_Window,
375 Item_Sizer,
376 Item_Spacer,
377 Item_Max
378 } m_kind;
379 union
380 {
381 wxWindow *m_window;
382 wxSizer *m_sizer;
383 wxSizerSpacer *m_spacer;
384 };
385
386 wxPoint m_pos;
387 wxSize m_minSize;
388 int m_proportion;
389 int m_border;
390 int m_flag;
391
392 // on screen rectangle of this item (not including borders)
393 wxRect m_rect;
394
395 // Aspect ratio can always be calculated from m_size,
396 // but this would cause precision loss when the window
397 // is shrunk. It is safer to preserve the initial value.
398 float m_ratio;
399
400 wxObject *m_userData;
401
402 private:
403 // 2.8-only implementation detail for wxRESERVE_SPACE_EVEN_IF_HIDDEN
404 bool ShouldAccountFor() const;
405
406 DECLARE_CLASS(wxSizerItem)
407 DECLARE_NO_COPY_CLASS(wxSizerItem)
408
409 friend class wxBoxSizer;
410 friend class wxFlexGridSizer;
411 friend class wxGridBagSizer;
412 };
413
414 WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
415
416
417 //---------------------------------------------------------------------------
418 // wxSizer
419 //---------------------------------------------------------------------------
420
421 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
422 {
423 public:
wxSizer()424 wxSizer() { m_containingWindow = NULL; }
425 virtual ~wxSizer();
426
427 // methods for adding elements to the sizer: there are Add/Insert/Prepend
428 // overloads for each of window/sizer/spacer/wxSizerItem
429 wxSizerItem* Add(wxWindow *window,
430 int proportion = 0,
431 int flag = 0,
432 int border = 0,
433 wxObject* userData = NULL);
434 wxSizerItem* Add(wxSizer *sizer,
435 int proportion = 0,
436 int flag = 0,
437 int border = 0,
438 wxObject* userData = NULL);
439 wxSizerItem* Add(int width,
440 int height,
441 int proportion = 0,
442 int flag = 0,
443 int border = 0,
444 wxObject* userData = NULL);
445 wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags);
446 wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags);
447 wxSizerItem* Add( wxSizerItem *item);
448
449 wxSizerItem* AddSpacer(int size);
450 wxSizerItem* AddStretchSpacer(int prop = 1);
451
452 wxSizerItem* Insert(size_t index,
453 wxWindow *window,
454 int proportion = 0,
455 int flag = 0,
456 int border = 0,
457 wxObject* userData = NULL);
458 wxSizerItem* Insert(size_t index,
459 wxSizer *sizer,
460 int proportion = 0,
461 int flag = 0,
462 int border = 0,
463 wxObject* userData = NULL);
464 wxSizerItem* Insert(size_t index,
465 int width,
466 int height,
467 int proportion = 0,
468 int flag = 0,
469 int border = 0,
470 wxObject* userData = NULL);
471 wxSizerItem* Insert(size_t index,
472 wxWindow *window,
473 const wxSizerFlags& flags);
474 wxSizerItem* Insert(size_t index,
475 wxSizer *sizer,
476 const wxSizerFlags& flags);
477 virtual wxSizerItem* Insert( size_t index, wxSizerItem *item);
478
479 wxSizerItem* InsertSpacer(size_t index, int size);
480 wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
481
482 wxSizerItem* Prepend(wxWindow *window,
483 int proportion = 0,
484 int flag = 0,
485 int border = 0,
486 wxObject* userData = NULL);
487 wxSizerItem* Prepend(wxSizer *sizer,
488 int proportion = 0,
489 int flag = 0,
490 int border = 0,
491 wxObject* userData = NULL);
492 wxSizerItem* Prepend(int width,
493 int height,
494 int proportion = 0,
495 int flag = 0,
496 int border = 0,
497 wxObject* userData = NULL);
498 wxSizerItem* Prepend(wxWindow *window, const wxSizerFlags& flags);
499 wxSizerItem* Prepend(wxSizer *sizer, const wxSizerFlags& flags);
500 wxSizerItem* Prepend(wxSizerItem *item);
501
502 wxSizerItem* PrependSpacer(int size);
503 wxSizerItem* PrependStretchSpacer(int prop = 1);
504
505 // set (or possibly unset if window is NULL) or get the window this sizer
506 // is used in
507 void SetContainingWindow(wxWindow *window);
GetContainingWindow()508 wxWindow *GetContainingWindow() const { return m_containingWindow; }
509
510 #if WXWIN_COMPATIBILITY_2_6
511 // Deprecated in 2.6 since historically it does not delete the window,
512 // use Detach instead.
513 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
514 #endif // WXWIN_COMPATIBILITY_2_6
515
516 virtual bool Remove( wxSizer *sizer );
517 virtual bool Remove( int index );
518
519 virtual bool Detach( wxWindow *window );
520 virtual bool Detach( wxSizer *sizer );
521 virtual bool Detach( int index );
522
523 virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false );
524 virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false );
525 virtual bool Replace( size_t index, wxSizerItem *newitem );
526
527 virtual void Clear( bool delete_windows = false );
528 virtual void DeleteWindows();
529
SetMinSize(int width,int height)530 void SetMinSize( int width, int height )
531 { DoSetMinSize( width, height ); }
SetMinSize(const wxSize & size)532 void SetMinSize( const wxSize& size )
533 { DoSetMinSize( size.x, size.y ); }
534
535 // Searches recursively
SetItemMinSize(wxWindow * window,int width,int height)536 bool SetItemMinSize( wxWindow *window, int width, int height )
537 { return DoSetItemMinSize( window, width, height ); }
SetItemMinSize(wxWindow * window,const wxSize & size)538 bool SetItemMinSize( wxWindow *window, const wxSize& size )
539 { return DoSetItemMinSize( window, size.x, size.y ); }
540
541 // Searches recursively
SetItemMinSize(wxSizer * sizer,int width,int height)542 bool SetItemMinSize( wxSizer *sizer, int width, int height )
543 { return DoSetItemMinSize( sizer, width, height ); }
SetItemMinSize(wxSizer * sizer,const wxSize & size)544 bool SetItemMinSize( wxSizer *sizer, const wxSize& size )
545 { return DoSetItemMinSize( sizer, size.x, size.y ); }
546
SetItemMinSize(size_t index,int width,int height)547 bool SetItemMinSize( size_t index, int width, int height )
548 { return DoSetItemMinSize( index, width, height ); }
SetItemMinSize(size_t index,const wxSize & size)549 bool SetItemMinSize( size_t index, const wxSize& size )
550 { return DoSetItemMinSize( index, size.x, size.y ); }
551
GetSize()552 wxSize GetSize() const
553 { return m_size; }
GetPosition()554 wxPoint GetPosition() const
555 { return m_position; }
556
557 // Calculate the minimal size or return m_minSize if bigger.
558 wxSize GetMinSize();
559
560 virtual void RecalcSizes() = 0;
561 virtual wxSize CalcMin() = 0;
562
563 virtual void Layout();
564
565 #if wxABI_VERSION >= 20808
566 wxSize ComputeFittingClientSize(wxWindow *window);
567 wxSize ComputeFittingWindowSize(wxWindow *window);
568 #endif
569
570 wxSize Fit( wxWindow *window );
571 void FitInside( wxWindow *window );
572 void SetSizeHints( wxWindow *window );
573 void SetVirtualSizeHints( wxWindow *window );
574
GetChildren()575 wxSizerItemList& GetChildren()
576 { return m_children; }
577
578 void SetDimension( int x, int y, int width, int height );
579
580 wxSizerItem* GetItem( wxWindow *window, bool recursive = false );
581 wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false );
582 wxSizerItem* GetItem( size_t index );
583
584 // Manage whether individual scene items are considered
585 // in the layout calculations or not.
586 bool Show( wxWindow *window, bool show = true, bool recursive = false );
587 bool Show( wxSizer *sizer, bool show = true, bool recursive = false );
588 bool Show( size_t index, bool show = true );
589
590 bool Hide( wxSizer *sizer, bool recursive = false )
591 { return Show( sizer, false, recursive ); }
592 bool Hide( wxWindow *window, bool recursive = false )
593 { return Show( window, false, recursive ); }
Hide(size_t index)594 bool Hide( size_t index )
595 { return Show( index, false ); }
596
597 bool IsShown( wxWindow *window ) const;
598 bool IsShown( wxSizer *sizer ) const;
599 bool IsShown( size_t index ) const;
600
601 // Recursively call wxWindow::Show () on all sizer items.
602 virtual void ShowItems (bool show);
603
Show(bool show)604 void Show(bool show) { ShowItems(show); }
605
606 protected:
607 wxSize m_size;
608 wxSize m_minSize;
609 wxPoint m_position;
610 wxSizerItemList m_children;
611
612 // the window this sizer is used in, can be NULL
613 wxWindow *m_containingWindow;
614
615 wxSize GetMaxWindowSize( wxWindow *window ) const;
616 wxSize GetMinWindowSize( wxWindow *window );
617 wxSize GetMaxClientSize( wxWindow *window ) const;
618 wxSize GetMinClientSize( wxWindow *window );
619 wxSize VirtualFitSize( wxWindow *window );
620
621 virtual void DoSetMinSize( int width, int height );
622 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
623 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
624 virtual bool DoSetItemMinSize( size_t index, int width, int height );
625
626 private:
627 DECLARE_CLASS(wxSizer)
628 };
629
630 //---------------------------------------------------------------------------
631 // wxGridSizer
632 //---------------------------------------------------------------------------
633
634 class WXDLLEXPORT wxGridSizer: public wxSizer
635 {
636 public:
637 wxGridSizer( int rows, int cols, int vgap, int hgap );
638 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
639
640 virtual void RecalcSizes();
641 virtual wxSize CalcMin();
642
SetCols(int cols)643 void SetCols( int cols ) { m_cols = cols; }
SetRows(int rows)644 void SetRows( int rows ) { m_rows = rows; }
SetVGap(int gap)645 void SetVGap( int gap ) { m_vgap = gap; }
SetHGap(int gap)646 void SetHGap( int gap ) { m_hgap = gap; }
GetCols()647 int GetCols() const { return m_cols; }
GetRows()648 int GetRows() const { return m_rows; }
GetVGap()649 int GetVGap() const { return m_vgap; }
GetHGap()650 int GetHGap() const { return m_hgap; }
651
652 protected:
653 int m_rows;
654 int m_cols;
655 int m_vgap;
656 int m_hgap;
657
658 // return the number of total items and the number of columns and rows
659 int CalcRowsCols(int& rows, int& cols) const;
660
661 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
662
663 private:
664 DECLARE_CLASS(wxGridSizer)
665 };
666
667 //---------------------------------------------------------------------------
668 // wxFlexGridSizer
669 //---------------------------------------------------------------------------
670
671 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
672 // direction
673 enum wxFlexSizerGrowMode
674 {
675 // don't resize the cells in non-flexible direction at all
676 wxFLEX_GROWMODE_NONE,
677
678 // uniformly resize only the specified ones (default)
679 wxFLEX_GROWMODE_SPECIFIED,
680
681 // uniformly resize all cells
682 wxFLEX_GROWMODE_ALL
683 };
684
685 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
686 {
687 public:
688 // ctors/dtor
689 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
690 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
691 virtual ~wxFlexGridSizer();
692
693
694 // set the rows/columns which will grow (the others will remain of the
695 // constant initial size)
696 void AddGrowableRow( size_t idx, int proportion = 0 );
697 void RemoveGrowableRow( size_t idx );
698 void AddGrowableCol( size_t idx, int proportion = 0 );
699 void RemoveGrowableCol( size_t idx );
700
701
702 // the sizer cells may grow in both directions, not grow at all or only
703 // grow in one direction but not the other
704
705 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
SetFlexibleDirection(int direction)706 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
GetFlexibleDirection()707 int GetFlexibleDirection() const { return m_flexDirection; }
708
709 // note that the grow mode only applies to the direction which is not
710 // flexible
SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode)711 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
GetNonFlexibleGrowMode()712 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
713
714 // Read-only access to the row heights and col widths arrays
GetRowHeights()715 const wxArrayInt& GetRowHeights() const { return m_rowHeights; }
GetColWidths()716 const wxArrayInt& GetColWidths() const { return m_colWidths; }
717
718 // implementation
719 virtual void RecalcSizes();
720 virtual wxSize CalcMin();
721
722 protected:
723 void AdjustForFlexDirection();
724 void AdjustForGrowables(const wxSize& sz, const wxSize& minsz,
725 int nrows, int ncols);
726
727 // the heights/widths of all rows/columns
728 wxArrayInt m_rowHeights,
729 m_colWidths;
730
731 // indices of the growable columns and rows
732 wxArrayInt m_growableRows,
733 m_growableCols;
734
735 // proportion values of the corresponding growable rows and columns
736 wxArrayInt m_growableRowsProportions,
737 m_growableColsProportions;
738
739 // parameters describing whether the growable cells should be resized in
740 // both directions or only one
741 int m_flexDirection;
742 wxFlexSizerGrowMode m_growMode;
743
744 // saves CalcMin result to optimize RecalcSizes
745 wxSize m_calculatedMinSize;
746
747 private:
748 DECLARE_CLASS(wxFlexGridSizer)
749 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
750 };
751
752 //---------------------------------------------------------------------------
753 // wxBoxSizer
754 //---------------------------------------------------------------------------
755
756 class WXDLLEXPORT wxBoxSizer: public wxSizer
757 {
758 public:
759 wxBoxSizer( int orient );
760
761 void RecalcSizes();
762 wxSize CalcMin();
763
GetOrientation()764 int GetOrientation() const
765 { return m_orient; }
766
SetOrientation(int orient)767 void SetOrientation(int orient)
768 { m_orient = orient; }
769
770 protected:
771 int m_orient;
772 int m_stretchable;
773 int m_minWidth;
774 int m_minHeight;
775 int m_fixedWidth;
776 int m_fixedHeight;
777
778 private:
779 DECLARE_CLASS(wxBoxSizer)
780 };
781
782 //---------------------------------------------------------------------------
783 // wxStaticBoxSizer
784 //---------------------------------------------------------------------------
785
786 #if wxUSE_STATBOX
787
788 class WXDLLIMPEXP_FWD_CORE wxStaticBox;
789
790 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
791 {
792 public:
793 wxStaticBoxSizer(wxStaticBox *box, int orient);
794 wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
795 virtual ~wxStaticBoxSizer();
796
797 void RecalcSizes();
798 wxSize CalcMin();
799
GetStaticBox()800 wxStaticBox *GetStaticBox() const
801 { return m_staticBox; }
802
803 // override to hide/show the static box as well
804 virtual void ShowItems (bool show);
805
806 virtual bool Detach( wxWindow *window );
Detach(wxSizer * sizer)807 virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); }
Detach(int index)808 virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); }
809
810 protected:
811 wxStaticBox *m_staticBox;
812
813 private:
814 DECLARE_CLASS(wxStaticBoxSizer)
815 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
816 };
817
818 #endif // wxUSE_STATBOX
819
820 #if wxUSE_BUTTON
821
822 class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer
823 {
824 public:
825 // Constructor just creates a new wxBoxSizer, not much else.
826 // Box sizer orientation is automatically determined here:
827 // vertical for PDAs, horizontal for everything else?
828 wxStdDialogButtonSizer();
829
830 // Checks button ID against system IDs and sets one of the pointers below
831 // to this button. Does not do any sizer-related things here.
832 void AddButton(wxButton *button);
833
834 // Use these if no standard ID can/should be used
835 void SetAffirmativeButton( wxButton *button );
836 void SetNegativeButton( wxButton *button );
837 void SetCancelButton( wxButton *button );
838
839 // All platform-specific code here, checks which buttons exist and add
840 // them to the sizer accordingly.
841 // Note - one potential hack on Mac we could use here,
842 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
843 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
844 // I wouldn't add any other hacks like that into here,
845 // but this one I can see being useful.
846 void Realize();
847
GetAffirmativeButton()848 wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; }
GetApplyButton()849 wxButton *GetApplyButton() const { return m_buttonApply; }
GetNegativeButton()850 wxButton *GetNegativeButton() const { return m_buttonNegative; }
GetCancelButton()851 wxButton *GetCancelButton() const { return m_buttonCancel; }
GetHelpButton()852 wxButton *GetHelpButton() const { return m_buttonHelp; }
853
854 protected:
855 wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here
856 wxButton *m_buttonApply;
857 wxButton *m_buttonNegative; // wxID_NO
858 wxButton *m_buttonCancel;
859 wxButton *m_buttonHelp;
860
861 private:
862 DECLARE_CLASS(wxStdDialogButtonSizer)
863 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer)
864 };
865
866 #endif // wxUSE_BUTTON
867
868 #if WXWIN_COMPATIBILITY_2_4
869 // NB: wxBookCtrlSizer and wxNotebookSizer are deprecated, they
870 // don't do anything. wxBookCtrlBase::DoGetBestSize does the job now.
871
872 // ----------------------------------------------------------------------------
873 // wxBookCtrlSizer
874 // ----------------------------------------------------------------------------
875
876 #if wxUSE_BOOKCTRL
877
878 // this sizer works with wxNotebook/wxListbook/... and sizes the control to
879 // fit its pages
880 class WXDLLIMPEXP_FWD_CORE wxBookCtrlBase;
881
882 class WXDLLEXPORT wxBookCtrlSizer : public wxSizer
883 {
884 public:
885 #if WXWIN_COMPATIBILITY_2_6
886 wxDEPRECATED( wxBookCtrlSizer(wxBookCtrlBase *bookctrl) );
887 #endif // WXWIN_COMPATIBILITY_2_6
888
GetControl()889 wxBookCtrlBase *GetControl() const { return m_bookctrl; }
890
891 virtual void RecalcSizes();
892 virtual wxSize CalcMin();
893
894 protected:
895 // this protected ctor lets us mark the real one above as deprecated
896 // and still have warning-free build of the library itself:
wxBookCtrlSizer()897 wxBookCtrlSizer() {}
898
899 wxBookCtrlBase *m_bookctrl;
900
901 private:
902 DECLARE_CLASS(wxBookCtrlSizer)
903 DECLARE_NO_COPY_CLASS(wxBookCtrlSizer)
904 };
905
906
907 #if wxUSE_NOTEBOOK
908
909 // before wxBookCtrlBase we only had wxNotebookSizer, keep it for backwards
910 // compatibility
911 class WXDLLIMPEXP_FWD_CORE wxNotebook;
912
913 class WXDLLEXPORT wxNotebookSizer : public wxBookCtrlSizer
914 {
915 public:
916 #if WXWIN_COMPATIBILITY_2_6
917 wxDEPRECATED( wxNotebookSizer(wxNotebook *nb) );
918 #endif // WXWIN_COMPATIBILITY_2_6
919
GetNotebook()920 wxNotebook *GetNotebook() const { return (wxNotebook *)m_bookctrl; }
921
922 private:
923 DECLARE_CLASS(wxNotebookSizer)
924 DECLARE_NO_COPY_CLASS(wxNotebookSizer)
925 };
926
927 #endif // wxUSE_NOTEBOOK
928
929 #endif // wxUSE_BOOKCTRL
930
931 #endif // WXWIN_COMPATIBILITY_2_4
932
933 // ----------------------------------------------------------------------------
934 // inline functions implementation
935 // ----------------------------------------------------------------------------
936
937 inline wxSizerItem*
Add(wxSizerItem * item)938 wxSizer::Add( wxSizerItem *item )
939 {
940 return Insert( m_children.GetCount(), item );
941 }
942
943 inline wxSizerItem*
Add(wxWindow * window,int proportion,int flag,int border,wxObject * userData)944 wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
945 {
946 return Add( new wxSizerItem( window, proportion, flag, border, userData ) );
947 }
948
949 inline wxSizerItem*
Add(wxSizer * sizer,int proportion,int flag,int border,wxObject * userData)950 wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
951 {
952 return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) );
953 }
954
955 inline wxSizerItem*
Add(int width,int height,int proportion,int flag,int border,wxObject * userData)956 wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData )
957 {
958 return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) );
959 }
960
961 inline wxSizerItem*
Add(wxWindow * window,const wxSizerFlags & flags)962 wxSizer::Add( wxWindow *window, const wxSizerFlags& flags )
963 {
964 return Add( new wxSizerItem(window, flags) );
965 }
966
967 inline wxSizerItem*
Add(wxSizer * sizer,const wxSizerFlags & flags)968 wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
969 {
970 return Add( new wxSizerItem(sizer, flags) );
971 }
972
973 inline wxSizerItem*
AddSpacer(int size)974 wxSizer::AddSpacer(int size)
975 {
976 return Add(size, size);
977 }
978
979 inline wxSizerItem*
AddStretchSpacer(int prop)980 wxSizer::AddStretchSpacer(int prop)
981 {
982 return Add(0, 0, prop);
983 }
984
985 inline wxSizerItem*
Prepend(wxSizerItem * item)986 wxSizer::Prepend( wxSizerItem *item )
987 {
988 return Insert( 0, item );
989 }
990
991 inline wxSizerItem*
Prepend(wxWindow * window,int proportion,int flag,int border,wxObject * userData)992 wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
993 {
994 return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) );
995 }
996
997 inline wxSizerItem*
Prepend(wxSizer * sizer,int proportion,int flag,int border,wxObject * userData)998 wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
999 {
1000 return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1001 }
1002
1003 inline wxSizerItem*
Prepend(int width,int height,int proportion,int flag,int border,wxObject * userData)1004 wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData )
1005 {
1006 return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1007 }
1008
1009 inline wxSizerItem*
PrependSpacer(int size)1010 wxSizer::PrependSpacer(int size)
1011 {
1012 return Prepend(size, size);
1013 }
1014
1015 inline wxSizerItem*
PrependStretchSpacer(int prop)1016 wxSizer::PrependStretchSpacer(int prop)
1017 {
1018 return Prepend(0, 0, prop);
1019 }
1020
1021 inline wxSizerItem*
Prepend(wxWindow * window,const wxSizerFlags & flags)1022 wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags )
1023 {
1024 return Prepend( new wxSizerItem(window, flags) );
1025 }
1026
1027 inline wxSizerItem*
Prepend(wxSizer * sizer,const wxSizerFlags & flags)1028 wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags )
1029 {
1030 return Prepend( new wxSizerItem(sizer, flags) );
1031 }
1032
1033 inline wxSizerItem*
Insert(size_t index,wxWindow * window,int proportion,int flag,int border,wxObject * userData)1034 wxSizer::Insert( size_t index,
1035 wxWindow *window,
1036 int proportion,
1037 int flag,
1038 int border,
1039 wxObject* userData )
1040 {
1041 return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) );
1042 }
1043
1044 inline wxSizerItem*
Insert(size_t index,wxSizer * sizer,int proportion,int flag,int border,wxObject * userData)1045 wxSizer::Insert( size_t index,
1046 wxSizer *sizer,
1047 int proportion,
1048 int flag,
1049 int border,
1050 wxObject* userData )
1051 {
1052 return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) );
1053 }
1054
1055 inline wxSizerItem*
Insert(size_t index,int width,int height,int proportion,int flag,int border,wxObject * userData)1056 wxSizer::Insert( size_t index,
1057 int width,
1058 int height,
1059 int proportion,
1060 int flag,
1061 int border,
1062 wxObject* userData )
1063 {
1064 return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) );
1065 }
1066
1067 inline wxSizerItem*
Insert(size_t index,wxWindow * window,const wxSizerFlags & flags)1068 wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags )
1069 {
1070 return Insert( index, new wxSizerItem(window, flags) );
1071 }
1072
1073 inline wxSizerItem*
Insert(size_t index,wxSizer * sizer,const wxSizerFlags & flags)1074 wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags )
1075 {
1076 return Insert( index, new wxSizerItem(sizer, flags) );
1077 }
1078
1079 inline wxSizerItem*
InsertSpacer(size_t index,int size)1080 wxSizer::InsertSpacer(size_t index, int size)
1081 {
1082 return Insert(index, size, size);
1083 }
1084
1085 inline wxSizerItem*
InsertStretchSpacer(size_t index,int prop)1086 wxSizer::InsertStretchSpacer(size_t index, int prop)
1087 {
1088 return Insert(index, 0, 0, prop);
1089 }
1090
1091
1092 #endif // __WXSIZER_H__
1093