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