added wxRESERVE_SPACE_EVEN_IF_HIDDEN sizer flag that prevents the sizer from changing...
[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 WXDLLIMPEXP_FWD_CORE wxButton;
24 class WXDLLIMPEXP_FWD_CORE wxBoxSizer;
25 class WXDLLIMPEXP_FWD_CORE wxSizerItem;
26 class WXDLLIMPEXP_FWD_CORE 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(wxALIGN_CENTRE); }
77 wxSizerFlags& Center() { return Centre(); }
78 wxSizerFlags& Top() { return Align(wxALIGN_TOP); }
79 wxSizerFlags& Left() { return Align(wxALIGN_LEFT); }
80 wxSizerFlags& Right() { return Align(wxALIGN_RIGHT); }
81 wxSizerFlags& Bottom() { return Align(wxALIGN_BOTTOM); }
82
83 // default border size used by Border() below
84 static int GetDefaultBorder()
85 {
86 #if wxUSE_BORDER_BY_DEFAULT
87 // FIXME: default border size shouldn't be hardcoded and at the very
88 // least they should depend on the current font size
89 return 5;
90 #else
91 return 0;
92 #endif
93 }
94
95
96 wxSizerFlags& Border(int direction, int borderInPixels)
97 {
98 m_flags &= ~wxALL;
99 m_flags |= direction;
100
101 m_borderInPixels = borderInPixels;
102
103 return *this;
104 }
105
106 wxSizerFlags& Border(int direction = wxALL)
107 {
108 #if wxUSE_BORDER_BY_DEFAULT
109 return Border(direction, GetDefaultBorder());
110 #else
111 // no borders by default on limited size screen
112 wxUnusedVar(direction);
113
114 return *this;
115 #endif
116 }
117
118 wxSizerFlags& DoubleBorder(int direction = wxALL)
119 {
120 #if wxUSE_BORDER_BY_DEFAULT
121 return Border(direction, 2*GetDefaultBorder());
122 #else
123 wxUnusedVar(direction);
124
125 return *this;
126 #endif
127 }
128
129 wxSizerFlags& TripleBorder(int direction = wxALL)
130 {
131 #if wxUSE_BORDER_BY_DEFAULT
132 return Border(direction, 3*GetDefaultBorder());
133 #else
134 wxUnusedVar(direction);
135
136 return *this;
137 #endif
138 }
139
140 wxSizerFlags& HorzBorder()
141 {
142 #if wxUSE_BORDER_BY_DEFAULT
143 return Border(wxLEFT | wxRIGHT, GetDefaultBorder());
144 #else
145 return *this;
146 #endif
147 }
148
149 wxSizerFlags& DoubleHorzBorder()
150 {
151 #if wxUSE_BORDER_BY_DEFAULT
152 return Border(wxLEFT | wxRIGHT, 2*GetDefaultBorder());
153 #else
154 return *this;
155 #endif
156 }
157
158 // setters for the others flags
159 wxSizerFlags& Shaped()
160 {
161 m_flags |= wxSHAPED;
162
163 return *this;
164 }
165
166 wxSizerFlags& FixedMinSize()
167 {
168 m_flags |= wxFIXED_MINSIZE;
169
170 return *this;
171 }
172
173 // makes the item ignore window's visibility status
174 wxSizerFlags& ReserveSpaceEvenIfHidden()
175 {
176 m_flags |= wxRESERVE_SPACE_EVEN_IF_HIDDEN;
177 return *this;
178 }
179
180 // accessors for wxSizer only
181 int GetProportion() const { return m_proportion; }
182 int GetFlags() const { return m_flags; }
183 int GetBorderInPixels() const { return m_borderInPixels; }
184
185 private:
186 int m_proportion;
187 int m_flags;
188 int m_borderInPixels;
189 };
190
191
192 // ----------------------------------------------------------------------------
193 // wxSizerSpacer: used by wxSizerItem to represent a spacer
194 // ----------------------------------------------------------------------------
195
196 class WXDLLEXPORT wxSizerSpacer
197 {
198 public:
199 wxSizerSpacer(const wxSize& size) : m_size(size), m_isShown(true) { }
200
201 void SetSize(const wxSize& size) { m_size = size; }
202 const wxSize& GetSize() const { return m_size; }
203
204 void Show(bool show) { m_isShown = show; }
205 bool IsShown() const { return m_isShown; }
206
207 private:
208 // the size, in pixel
209 wxSize m_size;
210
211 // is the spacer currently shown?
212 bool m_isShown;
213 };
214
215 // ----------------------------------------------------------------------------
216 // wxSizerItem
217 // ----------------------------------------------------------------------------
218
219 class WXDLLEXPORT wxSizerItem : public wxObject
220 {
221 public:
222 // window
223 wxSizerItem( wxWindow *window,
224 int proportion,
225 int flag,
226 int border,
227 wxObject* userData );
228
229 // window with flags
230 wxSizerItem(wxWindow *window, const wxSizerFlags& flags)
231 {
232 Init(flags);
233
234 DoSetWindow(window);
235 }
236
237 // subsizer
238 wxSizerItem( wxSizer *sizer,
239 int proportion,
240 int flag,
241 int border,
242 wxObject* userData );
243
244 // sizer with flags
245 wxSizerItem(wxSizer *sizer, const wxSizerFlags& flags)
246 {
247 Init(flags);
248
249 DoSetSizer(sizer);
250 }
251
252 // spacer
253 wxSizerItem( int width,
254 int height,
255 int proportion,
256 int flag,
257 int border,
258 wxObject* userData);
259
260 // spacer with flags
261 wxSizerItem(int width, int height, const wxSizerFlags& flags)
262 {
263 Init(flags);
264
265 DoSetSpacer(wxSize(width, height));
266 }
267
268 wxSizerItem();
269 virtual ~wxSizerItem();
270
271 virtual void DeleteWindows();
272
273 // Enable deleting the SizerItem without destroying the contained sizer.
274 void DetachSizer() { m_sizer = NULL; }
275
276 virtual wxSize GetSize() const;
277 virtual wxSize CalcMin();
278 virtual void SetDimension( const wxPoint& pos, const wxSize& size );
279
280 wxSize GetMinSize() const
281 { return m_minSize; }
282 wxSize GetMinSizeWithBorder() const;
283
284 void SetMinSize(const wxSize& size)
285 {
286 if ( IsWindow() )
287 m_window->SetMinSize(size);
288 m_minSize = size;
289 }
290 void SetMinSize( int x, int y )
291 { SetMinSize(wxSize(x, y)); }
292 void SetInitSize( int x, int y )
293 { SetMinSize(wxSize(x, y)); }
294
295 // if either of dimensions is zero, ratio is assumed to be 1
296 // to avoid "divide by zero" errors
297 void SetRatio(int width, int height)
298 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
299 void SetRatio(const wxSize& size)
300 { SetRatio(size.x, size.y); }
301 void SetRatio(float ratio)
302 { m_ratio = ratio; }
303 float GetRatio() const
304 { return m_ratio; }
305
306 virtual wxRect GetRect() { return m_rect; }
307
308 // set a sizer item id (different from a window id, all sizer items,
309 // including spacers, can have an associated id)
310 void SetId(int id) { m_id = id; }
311 int GetId() const { return m_id; }
312
313 bool IsWindow() const { return m_kind == Item_Window; }
314 bool IsSizer() const { return m_kind == Item_Sizer; }
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
323 void SetProportion( int proportion )
324 { m_proportion = proportion; }
325 int GetProportion() const
326 { return m_proportion; }
327 void SetFlag( int flag )
328 { m_flag = flag; }
329 int GetFlag() const
330 { return m_flag; }
331 void SetBorder( int border )
332 { m_border = border; }
333 int GetBorder() const
334 { return m_border; }
335
336 wxWindow *GetWindow() const
337 { return m_kind == Item_Window ? m_window : NULL; }
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. Also, it always returns true if
345 // wxRESERVE_SPACE_EVEN_IF_HIDDEN flag was used.
346 bool IsShown() const;
347
348 void Show(bool show);
349
350 void SetUserData(wxObject* userData)
351 { delete m_userData; m_userData = userData; }
352 wxObject* GetUserData() const
353 { return m_userData; }
354 wxPoint GetPosition() const
355 { return m_pos; }
356
357 // Called once the first component of an item has been decided. This is
358 // used in algorithms that depend on knowing the size in one direction
359 // before the min size in the other direction can be known.
360 // Returns true if it made use of the information (and min size was changed).
361 bool InformFirstDirection( int direction, int size, int availableOtherDir=-1 );
362
363 // these functions delete the current contents of the item if it's a sizer
364 // or a spacer but not if it is a window
365 void AssignWindow(wxWindow *window)
366 {
367 Free();
368 DoSetWindow(window);
369 }
370
371 void AssignSizer(wxSizer *sizer)
372 {
373 Free();
374 DoSetSizer(sizer);
375 }
376
377 void AssignSpacer(const wxSize& size)
378 {
379 Free();
380 DoSetSpacer(size);
381 }
382
383 void AssignSpacer(int w, int h) { AssignSpacer(wxSize(w, h)); }
384
385 #if WXWIN_COMPATIBILITY_2_8
386 // these functions do not free the old sizer/spacer and so can easily
387 // provoke the memory leaks and so shouldn't be used, use Assign() instead
388 wxDEPRECATED( void SetWindow(wxWindow *window) );
389 wxDEPRECATED( void SetSizer(wxSizer *sizer) );
390 wxDEPRECATED( void SetSpacer(const wxSize& size) );
391 wxDEPRECATED( void SetSpacer(int width, int height) );
392 #endif // WXWIN_COMPATIBILITY_2_8
393
394 protected:
395 // common part of several ctors
396 void Init() { m_userData = NULL; m_kind = Item_None; }
397
398 // common part of ctors taking wxSizerFlags
399 void Init(const wxSizerFlags& flags);
400
401 // free current contents
402 void Free();
403
404 // common parts of Set/AssignXXX()
405 void DoSetWindow(wxWindow *window);
406 void DoSetSizer(wxSizer *sizer);
407 void DoSetSpacer(const wxSize& size);
408
409 // discriminated union: depending on m_kind one of the fields is valid
410 enum
411 {
412 Item_None,
413 Item_Window,
414 Item_Sizer,
415 Item_Spacer,
416 Item_Max
417 } m_kind;
418 union
419 {
420 wxWindow *m_window;
421 wxSizer *m_sizer;
422 wxSizerSpacer *m_spacer;
423 };
424
425 wxPoint m_pos;
426 wxSize m_minSize;
427 int m_proportion;
428 int m_border;
429 int m_flag;
430 int m_id;
431
432 // on screen rectangle of this item (not including borders)
433 wxRect m_rect;
434
435 // Aspect ratio can always be calculated from m_size,
436 // but this would cause precision loss when the window
437 // is shrunk. It is safer to preserve the initial value.
438 float m_ratio;
439
440 wxObject *m_userData;
441
442 private:
443 DECLARE_CLASS(wxSizerItem)
444 DECLARE_NO_COPY_CLASS(wxSizerItem)
445 };
446
447 WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
448
449
450 //---------------------------------------------------------------------------
451 // wxSizer
452 //---------------------------------------------------------------------------
453
454 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
455 {
456 public:
457 wxSizer() { m_containingWindow = NULL; }
458 virtual ~wxSizer();
459
460 // methods for adding elements to the sizer: there are Add/Insert/Prepend
461 // overloads for each of window/sizer/spacer/wxSizerItem
462 wxSizerItem* Add(wxWindow *window,
463 int proportion = 0,
464 int flag = 0,
465 int border = 0,
466 wxObject* userData = NULL);
467 wxSizerItem* Add(wxSizer *sizer,
468 int proportion = 0,
469 int flag = 0,
470 int border = 0,
471 wxObject* userData = NULL);
472 wxSizerItem* Add(int width,
473 int height,
474 int proportion = 0,
475 int flag = 0,
476 int border = 0,
477 wxObject* userData = NULL);
478 wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags);
479 wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags);
480 wxSizerItem* Add( int width, int height, const wxSizerFlags& flags);
481 wxSizerItem* Add( wxSizerItem *item);
482
483 wxSizerItem* AddSpacer(int size);
484 wxSizerItem* AddStretchSpacer(int prop = 1);
485
486 wxSizerItem* Insert(size_t index,
487 wxWindow *window,
488 int proportion = 0,
489 int flag = 0,
490 int border = 0,
491 wxObject* userData = NULL);
492 wxSizerItem* Insert(size_t index,
493 wxSizer *sizer,
494 int proportion = 0,
495 int flag = 0,
496 int border = 0,
497 wxObject* userData = NULL);
498 wxSizerItem* Insert(size_t index,
499 int width,
500 int height,
501 int proportion = 0,
502 int flag = 0,
503 int border = 0,
504 wxObject* userData = NULL);
505 wxSizerItem* Insert(size_t index,
506 wxWindow *window,
507 const wxSizerFlags& flags);
508 wxSizerItem* Insert(size_t index,
509 wxSizer *sizer,
510 const wxSizerFlags& flags);
511 wxSizerItem* Insert(size_t index,
512 int width,
513 int height,
514 const wxSizerFlags& flags);
515 virtual wxSizerItem* Insert( size_t index, wxSizerItem *item);
516
517 wxSizerItem* InsertSpacer(size_t index, int size);
518 wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
519
520 wxSizerItem* Prepend(wxWindow *window,
521 int proportion = 0,
522 int flag = 0,
523 int border = 0,
524 wxObject* userData = NULL);
525 wxSizerItem* Prepend(wxSizer *sizer,
526 int proportion = 0,
527 int flag = 0,
528 int border = 0,
529 wxObject* userData = NULL);
530 wxSizerItem* Prepend(int width,
531 int height,
532 int proportion = 0,
533 int flag = 0,
534 int border = 0,
535 wxObject* userData = NULL);
536 wxSizerItem* Prepend(wxWindow *window, const wxSizerFlags& flags);
537 wxSizerItem* Prepend(wxSizer *sizer, const wxSizerFlags& flags);
538 wxSizerItem* Prepend(int width, int height, const wxSizerFlags& flags);
539 wxSizerItem* Prepend(wxSizerItem *item);
540
541 wxSizerItem* PrependSpacer(int size);
542 wxSizerItem* PrependStretchSpacer(int prop = 1);
543
544 // set (or possibly unset if window is NULL) or get the window this sizer
545 // is used in
546 void SetContainingWindow(wxWindow *window);
547 wxWindow *GetContainingWindow() const { return m_containingWindow; }
548
549 #if WXWIN_COMPATIBILITY_2_6
550 // Deprecated in 2.6 since historically it does not delete the window,
551 // use Detach instead.
552 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
553 #endif // WXWIN_COMPATIBILITY_2_6
554
555 virtual bool Remove( wxSizer *sizer );
556 virtual bool Remove( int index );
557
558 virtual bool Detach( wxWindow *window );
559 virtual bool Detach( wxSizer *sizer );
560 virtual bool Detach( int index );
561
562 virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false );
563 virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false );
564 virtual bool Replace( size_t index, wxSizerItem *newitem );
565
566 virtual void Clear( bool delete_windows = false );
567 virtual void DeleteWindows();
568
569 // Inform sizer about the first direction that has been decided (by parent item)
570 // Returns true if it made use of the informtion (and recalculated min size)
571 virtual bool InformFirstDirection( int WXUNUSED(direction), int WXUNUSED(size), int WXUNUSED(availableOtherDir) )
572 { return false; }
573
574 void SetMinSize( int width, int height )
575 { DoSetMinSize( width, height ); }
576 void SetMinSize( const wxSize& size )
577 { DoSetMinSize( size.x, size.y ); }
578
579 // Searches recursively
580 bool SetItemMinSize( wxWindow *window, int width, int height )
581 { return DoSetItemMinSize( window, width, height ); }
582 bool SetItemMinSize( wxWindow *window, const wxSize& size )
583 { return DoSetItemMinSize( window, size.x, size.y ); }
584
585 // Searches recursively
586 bool SetItemMinSize( wxSizer *sizer, int width, int height )
587 { return DoSetItemMinSize( sizer, width, height ); }
588 bool SetItemMinSize( wxSizer *sizer, const wxSize& size )
589 { return DoSetItemMinSize( sizer, size.x, size.y ); }
590
591 bool SetItemMinSize( size_t index, int width, int height )
592 { return DoSetItemMinSize( index, width, height ); }
593 bool SetItemMinSize( size_t index, const wxSize& size )
594 { return DoSetItemMinSize( index, size.x, size.y ); }
595
596 wxSize GetSize() const
597 { return m_size; }
598 wxPoint GetPosition() const
599 { return m_position; }
600
601 // Calculate the minimal size or return m_minSize if bigger.
602 wxSize GetMinSize();
603
604 // These virtual functions are used by the layout algorithm: first
605 // CalcMin() is called to calculate the minimal size of the sizer and
606 // prepare for laying it out and then RecalcSizes() is called to really
607 // update all the sizer items
608 virtual wxSize CalcMin() = 0;
609 virtual void RecalcSizes() = 0;
610
611 virtual void Layout();
612
613 wxSize ComputeFittingClientSize(wxWindow *window);
614 wxSize ComputeFittingWindowSize(wxWindow *window);
615
616 wxSize Fit( wxWindow *window );
617 void FitInside( wxWindow *window );
618 void SetSizeHints( wxWindow *window );
619 #if WXWIN_COMPATIBILITY_2_8
620 // This only calls FitInside() since 2.9
621 wxDEPRECATED( void SetVirtualSizeHints( wxWindow *window ) );
622 #endif
623
624 wxSizerItemList& GetChildren()
625 { return m_children; }
626 const wxSizerItemList& GetChildren() const
627 { return m_children; }
628
629 void SetDimension( int x, int y, int width, int height );
630
631 wxSizerItem* GetItem( wxWindow *window, bool recursive = false );
632 wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false );
633 wxSizerItem* GetItem( size_t index );
634 wxSizerItem* GetItemById( int id, bool recursive = false );
635
636 // Manage whether individual scene items are considered
637 // in the layout calculations or not.
638 bool Show( wxWindow *window, bool show = true, bool recursive = false );
639 bool Show( wxSizer *sizer, bool show = true, bool recursive = false );
640 bool Show( size_t index, bool show = true );
641
642 bool Hide( wxSizer *sizer, bool recursive = false )
643 { return Show( sizer, false, recursive ); }
644 bool Hide( wxWindow *window, bool recursive = false )
645 { return Show( window, false, recursive ); }
646 bool Hide( size_t index )
647 { return Show( index, false ); }
648
649 bool IsShown( wxWindow *window ) const;
650 bool IsShown( wxSizer *sizer ) const;
651 bool IsShown( size_t index ) const;
652
653 // Recursively call wxWindow::Show () on all sizer items.
654 virtual void ShowItems (bool show);
655
656 void Show(bool show) { ShowItems(show); }
657
658 protected:
659 wxSize m_size;
660 wxSize m_minSize;
661 wxPoint m_position;
662 wxSizerItemList m_children;
663
664 // the window this sizer is used in, can be NULL
665 wxWindow *m_containingWindow;
666
667 wxSize GetMaxClientSize( wxWindow *window ) const;
668 wxSize GetMinClientSize( wxWindow *window );
669 wxSize VirtualFitSize( wxWindow *window );
670
671 virtual void DoSetMinSize( int width, int height );
672 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
673 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
674 virtual bool DoSetItemMinSize( size_t index, int width, int height );
675
676 private:
677 DECLARE_CLASS(wxSizer)
678 };
679
680 //---------------------------------------------------------------------------
681 // wxGridSizer
682 //---------------------------------------------------------------------------
683
684 class WXDLLEXPORT wxGridSizer: public wxSizer
685 {
686 public:
687 wxGridSizer( int rows, int cols, int vgap, int hgap );
688 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
689
690 virtual void RecalcSizes();
691 virtual wxSize CalcMin();
692
693 void SetCols( int cols ) { m_cols = cols; }
694 void SetRows( int rows ) { m_rows = rows; }
695 void SetVGap( int gap ) { m_vgap = gap; }
696 void SetHGap( int gap ) { m_hgap = gap; }
697 int GetCols() const { return m_cols; }
698 int GetRows() const { return m_rows; }
699 int GetVGap() const { return m_vgap; }
700 int GetHGap() const { return m_hgap; }
701
702 protected:
703 int m_rows;
704 int m_cols;
705 int m_vgap;
706 int m_hgap;
707
708 // return the number of total items and the number of columns and rows
709 int CalcRowsCols(int& rows, int& cols) const;
710
711 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
712
713 private:
714 DECLARE_CLASS(wxGridSizer)
715 };
716
717 //---------------------------------------------------------------------------
718 // wxFlexGridSizer
719 //---------------------------------------------------------------------------
720
721 // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
722 // direction
723 enum wxFlexSizerGrowMode
724 {
725 // don't resize the cells in non-flexible direction at all
726 wxFLEX_GROWMODE_NONE,
727
728 // uniformly resize only the specified ones (default)
729 wxFLEX_GROWMODE_SPECIFIED,
730
731 // uniformly resize all cells
732 wxFLEX_GROWMODE_ALL
733 };
734
735 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
736 {
737 public:
738 // ctors/dtor
739 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
740 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
741 virtual ~wxFlexGridSizer();
742
743
744 // set the rows/columns which will grow (the others will remain of the
745 // constant initial size)
746 void AddGrowableRow( size_t idx, int proportion = 0 );
747 void RemoveGrowableRow( size_t idx );
748 void AddGrowableCol( size_t idx, int proportion = 0 );
749 void RemoveGrowableCol( size_t idx );
750
751
752 // the sizer cells may grow in both directions, not grow at all or only
753 // grow in one direction but not the other
754
755 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
756 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
757 int GetFlexibleDirection() const { return m_flexDirection; }
758
759 // note that the grow mode only applies to the direction which is not
760 // flexible
761 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
762 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
763
764 // Read-only access to the row heights and col widths arrays
765 const wxArrayInt& GetRowHeights() const { return m_rowHeights; }
766 const wxArrayInt& GetColWidths() const { return m_colWidths; }
767
768 // implementation
769 virtual void RecalcSizes();
770 virtual wxSize CalcMin();
771
772 protected:
773 void AdjustForFlexDirection();
774 void AdjustForGrowables(const wxSize& sz);
775 void FindWidthsAndHeights(int nrows, int ncols);
776
777 // the heights/widths of all rows/columns
778 wxArrayInt m_rowHeights,
779 m_colWidths;
780
781 // indices of the growable columns and rows
782 wxArrayInt m_growableRows,
783 m_growableCols;
784
785 // proportion values of the corresponding growable rows and columns
786 wxArrayInt m_growableRowsProportions,
787 m_growableColsProportions;
788
789 // parameters describing whether the growable cells should be resized in
790 // both directions or only one
791 int m_flexDirection;
792 wxFlexSizerGrowMode m_growMode;
793
794 // saves CalcMin result to optimize RecalcSizes
795 wxSize m_calculatedMinSize;
796
797 private:
798 DECLARE_CLASS(wxFlexGridSizer)
799 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
800 };
801
802 //---------------------------------------------------------------------------
803 // wxBoxSizer
804 //---------------------------------------------------------------------------
805
806 class WXDLLEXPORT wxBoxSizer: public wxSizer
807 {
808 public:
809 wxBoxSizer(int orient)
810 {
811 m_orient = orient;
812 m_totalProportion = 0;
813
814 wxASSERT_MSG( m_orient == wxHORIZONTAL || m_orient == wxVERTICAL,
815 _T("invalid value for wxBoxSizer orientation") );
816 }
817
818 int GetOrientation() const { return m_orient; }
819
820 bool IsVertical() const { return m_orient == wxVERTICAL; }
821
822 void SetOrientation(int orient) { m_orient = orient; }
823
824 // implementation of our resizing logic
825 virtual wxSize CalcMin();
826 virtual void RecalcSizes();
827
828 protected:
829 // helpers for our code: this returns the component of the given wxSize in
830 // the direction of the sizer and in the other direction, respectively
831 int GetSizeInMajorDir(const wxSize& sz) const
832 {
833 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
834 }
835
836 int& SizeInMajorDir(wxSize& sz)
837 {
838 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
839 }
840
841 int& PosInMajorDir(wxPoint& pt)
842 {
843 return m_orient == wxHORIZONTAL ? pt.x : pt.y;
844 }
845
846 int GetSizeInMinorDir(const wxSize& sz) const
847 {
848 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
849 }
850
851 int& SizeInMinorDir(wxSize& sz)
852 {
853 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
854 }
855
856 int& PosInMinorDir(wxPoint& pt)
857 {
858 return m_orient == wxHORIZONTAL ? pt.y : pt.x;
859 }
860
861 // another helper: creates wxSize from major and minor components
862 wxSize SizeFromMajorMinor(int major, int minor) const
863 {
864 if ( m_orient == wxHORIZONTAL )
865 {
866 return wxSize(major, minor);
867 }
868 else // wxVERTICAL
869 {
870 return wxSize(minor, major);
871 }
872 }
873
874
875 // either wxHORIZONTAL or wxVERTICAL
876 int m_orient;
877
878 // the sum of proportion of all of our elements
879 int m_totalProportion;
880
881 // the minimal size needed for this sizer as calculated by the last call to
882 // our CalcMin()
883 wxSize m_minSize;
884
885 private:
886 DECLARE_CLASS(wxBoxSizer)
887 };
888
889 //---------------------------------------------------------------------------
890 // wxWrapSizer - A box sizer that can wrap items on several lines when
891 // widths exceed available width.
892 //---------------------------------------------------------------------------
893
894 // Borrow unused flag value
895 #define wxEXTEND_LAST_ON_EACH_LINE wxFULL_REPAINT_ON_RESIZE
896
897 class WXDLLEXPORT wxWrapSizer: public wxBoxSizer
898 {
899 public:
900 wxWrapSizer( int orient=wxHORIZONTAL, int flags=wxEXTEND_LAST_ON_EACH_LINE );
901 virtual ~wxWrapSizer();
902
903 virtual void RecalcSizes();
904 virtual wxSize CalcMin();
905
906 virtual bool InformFirstDirection( int direction, int size, int availableOtherDir );
907
908 protected:
909 int m_prim_size_last; // Size in primary direction last time
910 int m_n_line; // Number of lines
911 wxBoxSizer m_rows; // Rows of items
912 int m_flags;
913
914 void AdjustPropLastItem(wxSizer *psz, wxSizerItem *itemLast);
915
916 DECLARE_DYNAMIC_CLASS(wxWrapSizer)
917 };
918
919 //---------------------------------------------------------------------------
920 // wxStaticBoxSizer
921 //---------------------------------------------------------------------------
922
923 #if wxUSE_STATBOX
924
925 class WXDLLIMPEXP_FWD_CORE wxStaticBox;
926
927 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
928 {
929 public:
930 wxStaticBoxSizer(wxStaticBox *box, int orient);
931 wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
932 virtual ~wxStaticBoxSizer();
933
934 void RecalcSizes();
935 wxSize CalcMin();
936
937 wxStaticBox *GetStaticBox() const
938 { return m_staticBox; }
939
940 // override to hide/show the static box as well
941 virtual void ShowItems (bool show);
942
943 virtual bool Detach( wxWindow *window );
944 virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); }
945 virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); }
946
947 protected:
948 wxStaticBox *m_staticBox;
949
950 private:
951 DECLARE_CLASS(wxStaticBoxSizer)
952 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
953 };
954
955 #endif // wxUSE_STATBOX
956
957 #if wxUSE_BUTTON
958
959 class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer
960 {
961 public:
962 // Constructor just creates a new wxBoxSizer, not much else.
963 // Box sizer orientation is automatically determined here:
964 // vertical for PDAs, horizontal for everything else?
965 wxStdDialogButtonSizer();
966
967 // Checks button ID against system IDs and sets one of the pointers below
968 // to this button. Does not do any sizer-related things here.
969 void AddButton(wxButton *button);
970
971 // Use these if no standard ID can/should be used
972 void SetAffirmativeButton( wxButton *button );
973 void SetNegativeButton( wxButton *button );
974 void SetCancelButton( wxButton *button );
975
976 // All platform-specific code here, checks which buttons exist and add
977 // them to the sizer accordingly.
978 // Note - one potential hack on Mac we could use here,
979 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
980 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
981 // I wouldn't add any other hacks like that into here,
982 // but this one I can see being useful.
983 void Realize();
984
985 wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; }
986 wxButton *GetApplyButton() const { return m_buttonApply; }
987 wxButton *GetNegativeButton() const { return m_buttonNegative; }
988 wxButton *GetCancelButton() const { return m_buttonCancel; }
989 wxButton *GetHelpButton() const { return m_buttonHelp; }
990
991 protected:
992 wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here
993 wxButton *m_buttonApply; // wxID_APPLY
994 wxButton *m_buttonNegative; // wxID_NO
995 wxButton *m_buttonCancel; // wxID_CANCEL, wxID_CLOSE
996 wxButton *m_buttonHelp; // wxID_HELP, wxID_CONTEXT_HELP
997
998 private:
999 DECLARE_CLASS(wxStdDialogButtonSizer)
1000 DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer)
1001 };
1002
1003 #endif // wxUSE_BUTTON
1004
1005
1006 // ----------------------------------------------------------------------------
1007 // inline functions implementation
1008 // ----------------------------------------------------------------------------
1009
1010 #if WXWIN_COMPATIBILITY_2_8
1011
1012 inline void wxSizerItem::SetWindow(wxWindow *window)
1013 {
1014 DoSetWindow(window);
1015 }
1016
1017 inline void wxSizerItem::SetSizer(wxSizer *sizer)
1018 {
1019 DoSetSizer(sizer);
1020 }
1021
1022 inline void wxSizerItem::SetSpacer(const wxSize& size)
1023 {
1024 DoSetSpacer(size);
1025 }
1026
1027 inline void wxSizerItem::SetSpacer(int width, int height)
1028 {
1029 DoSetSpacer(wxSize(width, height));
1030 }
1031
1032 #endif // WXWIN_COMPATIBILITY_2_8
1033
1034
1035 inline wxSizerItem*
1036 wxSizer::Add( wxSizerItem *item )
1037 {
1038 return Insert( m_children.GetCount(), item );
1039 }
1040
1041 inline wxSizerItem*
1042 wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
1043 {
1044 return Add( new wxSizerItem( window, proportion, flag, border, userData ) );
1045 }
1046
1047 inline wxSizerItem*
1048 wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
1049 {
1050 return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1051 }
1052
1053 inline wxSizerItem*
1054 wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData )
1055 {
1056 return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1057 }
1058
1059 inline wxSizerItem*
1060 wxSizer::Add( wxWindow *window, const wxSizerFlags& flags )
1061 {
1062 return Add( new wxSizerItem(window, flags) );
1063 }
1064
1065 inline wxSizerItem*
1066 wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
1067 {
1068 return Add( new wxSizerItem(sizer, flags) );
1069 }
1070
1071 inline wxSizerItem*
1072 wxSizer::Add( int width, int height, const wxSizerFlags& flags )
1073 {
1074 return Add( new wxSizerItem(width, height, flags) );
1075 }
1076
1077 inline wxSizerItem*
1078 wxSizer::AddSpacer(int size)
1079 {
1080 return Add(size, size);
1081 }
1082
1083 inline wxSizerItem*
1084 wxSizer::AddStretchSpacer(int prop)
1085 {
1086 return Add(0, 0, prop);
1087 }
1088
1089 inline wxSizerItem*
1090 wxSizer::Prepend( wxSizerItem *item )
1091 {
1092 return Insert( 0, item );
1093 }
1094
1095 inline wxSizerItem*
1096 wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
1097 {
1098 return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) );
1099 }
1100
1101 inline wxSizerItem*
1102 wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
1103 {
1104 return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1105 }
1106
1107 inline wxSizerItem*
1108 wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData )
1109 {
1110 return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1111 }
1112
1113 inline wxSizerItem*
1114 wxSizer::PrependSpacer(int size)
1115 {
1116 return Prepend(size, size);
1117 }
1118
1119 inline wxSizerItem*
1120 wxSizer::PrependStretchSpacer(int prop)
1121 {
1122 return Prepend(0, 0, prop);
1123 }
1124
1125 inline wxSizerItem*
1126 wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags )
1127 {
1128 return Prepend( new wxSizerItem(window, flags) );
1129 }
1130
1131 inline wxSizerItem*
1132 wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags )
1133 {
1134 return Prepend( new wxSizerItem(sizer, flags) );
1135 }
1136
1137 inline wxSizerItem*
1138 wxSizer::Prepend( int width, int height, const wxSizerFlags& flags )
1139 {
1140 return Prepend( new wxSizerItem(width, height, flags) );
1141 }
1142
1143 inline wxSizerItem*
1144 wxSizer::Insert( size_t index,
1145 wxWindow *window,
1146 int proportion,
1147 int flag,
1148 int border,
1149 wxObject* userData )
1150 {
1151 return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) );
1152 }
1153
1154 inline wxSizerItem*
1155 wxSizer::Insert( size_t index,
1156 wxSizer *sizer,
1157 int proportion,
1158 int flag,
1159 int border,
1160 wxObject* userData )
1161 {
1162 return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) );
1163 }
1164
1165 inline wxSizerItem*
1166 wxSizer::Insert( size_t index,
1167 int width,
1168 int height,
1169 int proportion,
1170 int flag,
1171 int border,
1172 wxObject* userData )
1173 {
1174 return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) );
1175 }
1176
1177 inline wxSizerItem*
1178 wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags )
1179 {
1180 return Insert( index, new wxSizerItem(window, flags) );
1181 }
1182
1183 inline wxSizerItem*
1184 wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags )
1185 {
1186 return Insert( index, new wxSizerItem(sizer, flags) );
1187 }
1188
1189 inline wxSizerItem*
1190 wxSizer::Insert( size_t index, int width, int height, const wxSizerFlags& flags )
1191 {
1192 return Insert( index, new wxSizerItem(width, height, flags) );
1193 }
1194
1195 inline wxSizerItem*
1196 wxSizer::InsertSpacer(size_t index, int size)
1197 {
1198 return Insert(index, size, size);
1199 }
1200
1201 inline wxSizerItem*
1202 wxSizer::InsertStretchSpacer(size_t index, int prop)
1203 {
1204 return Insert(index, 0, 0, prop);
1205 }
1206
1207 #endif // __WXSIZER_H__