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