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