]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/sizer.h
fix wxBitmapComboBox Gtk-CRITICAL assertion `GTK_IS_ENTRY (entry)' failed
[wxWidgets.git] / include / wx / sizer.h
... / ...
CommitLineData
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
23class WXDLLIMPEXP_FWD_CORE wxButton;
24class WXDLLIMPEXP_FWD_CORE wxBoxSizer;
25class WXDLLIMPEXP_FWD_CORE wxSizerItem;
26class 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
41class WXDLLIMPEXP_CORE wxSizerFlags
42{
43public:
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
219private:
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
230class WXDLLIMPEXP_CORE wxSizerSpacer
231{
232public:
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
241private:
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
253class WXDLLIMPEXP_CORE wxSizerItem : public wxObject
254{
255public:
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
432protected:
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
484private:
485 DECLARE_CLASS(wxSizerItem)
486 wxDECLARE_NO_COPY_CLASS(wxSizerItem);
487};
488
489WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
490
491
492//---------------------------------------------------------------------------
493// wxSizer
494//---------------------------------------------------------------------------
495
496class WXDLLIMPEXP_CORE wxSizer: public wxObject, public wxClientDataContainer
497{
498public:
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
718protected:
719 wxSize m_size;
720 wxSize m_minSize;
721 wxPoint m_position;
722 wxSizerItemList m_children;
723
724 // the window this sizer is used in, can be NULL
725 wxWindow *m_containingWindow;
726
727 wxSize GetMaxClientSize( wxWindow *window ) const;
728 wxSize GetMinClientSize( wxWindow *window );
729 wxSize VirtualFitSize( wxWindow *window );
730
731 virtual void DoSetMinSize( int width, int height );
732 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
733 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
734 virtual bool DoSetItemMinSize( size_t index, int width, int height );
735
736 // insert a new item into m_children at given index and return the item
737 // itself
738 virtual wxSizerItem* DoInsert(size_t index, wxSizerItem *item);
739
740private:
741 DECLARE_CLASS(wxSizer)
742};
743
744//---------------------------------------------------------------------------
745// wxGridSizer
746//---------------------------------------------------------------------------
747
748class WXDLLIMPEXP_CORE wxGridSizer: public wxSizer
749{
750public:
751 // ctors specifying the number of columns only: number of rows will be
752 // deduced automatically depending on the number of sizer elements
753 wxGridSizer( int cols, int vgap, int hgap );
754 wxGridSizer( int cols, const wxSize& gap = wxSize(0, 0) );
755
756 // ctors specifying the number of rows and columns
757 wxGridSizer( int rows, int cols, int vgap, int hgap );
758 wxGridSizer( int rows, int cols, const wxSize& gap );
759
760 virtual void RecalcSizes();
761 virtual wxSize CalcMin();
762
763 void SetCols( int cols )
764 {
765 wxASSERT_MSG( cols >= 0, "Number of columns must be non-negative");
766 m_cols = cols;
767 }
768
769 void SetRows( int rows )
770 {
771 wxASSERT_MSG( rows >= 0, "Number of rows must be non-negative");
772 m_rows = rows;
773 }
774
775 void SetVGap( int gap ) { m_vgap = gap; }
776 void SetHGap( int gap ) { m_hgap = gap; }
777 int GetCols() const { return m_cols; }
778 int GetRows() const { return m_rows; }
779 int GetVGap() const { return m_vgap; }
780 int GetHGap() const { return m_hgap; }
781
782 int GetEffectiveColsCount() const { return m_cols ? m_cols : CalcCols(); }
783 int GetEffectiveRowsCount() const { return m_rows ? m_rows : CalcRows(); }
784
785 // return the number of total items and the number of columns and rows
786 // (for internal use only)
787 int CalcRowsCols(int& rows, int& cols) const;
788
789protected:
790 // the number of rows/columns in the sizer, if 0 then it is determined
791 // dynamically depending on the total number of items
792 int m_rows;
793 int m_cols;
794
795 // gaps between rows and columns
796 int m_vgap;
797 int m_hgap;
798
799 virtual wxSizerItem *DoInsert(size_t index, wxSizerItem *item);
800
801 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
802
803 // returns the number of columns/rows needed for the current total number
804 // of children (and the fixed number of rows/columns)
805 int CalcCols() const
806 {
807 wxCHECK_MSG
808 (
809 m_rows, 0,
810 "Can't calculate number of cols if number of rows is not specified"
811 );
812
813 return (m_children.GetCount() + m_rows - 1) / m_rows;
814 }
815
816 int CalcRows() const
817 {
818 wxCHECK_MSG
819 (
820 m_cols, 0,
821 "Can't calculate number of cols if number of rows is not specified"
822 );
823
824 return (m_children.GetCount() + m_cols - 1) / m_cols;
825 }
826
827private:
828 DECLARE_CLASS(wxGridSizer)
829};
830
831//---------------------------------------------------------------------------
832// wxFlexGridSizer
833//---------------------------------------------------------------------------
834
835// values which define the behaviour for resizing wxFlexGridSizer cells in the
836// "non-flexible" direction
837enum wxFlexSizerGrowMode
838{
839 // don't resize the cells in non-flexible direction at all
840 wxFLEX_GROWMODE_NONE,
841
842 // uniformly resize only the specified ones (default)
843 wxFLEX_GROWMODE_SPECIFIED,
844
845 // uniformly resize all cells
846 wxFLEX_GROWMODE_ALL
847};
848
849class WXDLLIMPEXP_CORE wxFlexGridSizer: public wxGridSizer
850{
851public:
852 // ctors specifying the number of columns only: number of rows will be
853 // deduced automatically depending on the number of sizer elements
854 wxFlexGridSizer( int cols, int vgap, int hgap );
855 wxFlexGridSizer( int cols, const wxSize& gap = wxSize(0, 0) );
856
857 // ctors specifying the number of rows and columns
858 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
859 wxFlexGridSizer( int rows, int cols, const wxSize& gap );
860
861 // dtor
862 virtual ~wxFlexGridSizer();
863
864 // set the rows/columns which will grow (the others will remain of the
865 // constant initial size)
866 void AddGrowableRow( size_t idx, int proportion = 0 );
867 void RemoveGrowableRow( size_t idx );
868 void AddGrowableCol( size_t idx, int proportion = 0 );
869 void RemoveGrowableCol( size_t idx );
870
871 bool IsRowGrowable( size_t idx );
872 bool IsColGrowable( size_t idx );
873
874 // the sizer cells may grow in both directions, not grow at all or only
875 // grow in one direction but not the other
876
877 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
878 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
879 int GetFlexibleDirection() const { return m_flexDirection; }
880
881 // note that the grow mode only applies to the direction which is not
882 // flexible
883 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
884 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
885
886 // Read-only access to the row heights and col widths arrays
887 const wxArrayInt& GetRowHeights() const { return m_rowHeights; }
888 const wxArrayInt& GetColWidths() const { return m_colWidths; }
889
890 // implementation
891 virtual void RecalcSizes();
892 virtual wxSize CalcMin();
893
894protected:
895 void AdjustForFlexDirection();
896 void AdjustForGrowables(const wxSize& sz);
897 void FindWidthsAndHeights(int nrows, int ncols);
898
899 // the heights/widths of all rows/columns
900 wxArrayInt m_rowHeights,
901 m_colWidths;
902
903 // indices of the growable columns and rows
904 wxArrayInt m_growableRows,
905 m_growableCols;
906
907 // proportion values of the corresponding growable rows and columns
908 wxArrayInt m_growableRowsProportions,
909 m_growableColsProportions;
910
911 // parameters describing whether the growable cells should be resized in
912 // both directions or only one
913 int m_flexDirection;
914 wxFlexSizerGrowMode m_growMode;
915
916 // saves CalcMin result to optimize RecalcSizes
917 wxSize m_calculatedMinSize;
918
919private:
920 DECLARE_CLASS(wxFlexGridSizer)
921 wxDECLARE_NO_COPY_CLASS(wxFlexGridSizer);
922};
923
924//---------------------------------------------------------------------------
925// wxBoxSizer
926//---------------------------------------------------------------------------
927
928class WXDLLIMPEXP_CORE wxBoxSizer: public wxSizer
929{
930public:
931 wxBoxSizer(int orient)
932 {
933 m_orient = orient;
934 m_totalProportion = 0;
935
936 wxASSERT_MSG( m_orient == wxHORIZONTAL || m_orient == wxVERTICAL,
937 wxT("invalid value for wxBoxSizer orientation") );
938 }
939
940 virtual wxSizerItem *AddSpacer(int size);
941
942 int GetOrientation() const { return m_orient; }
943
944 bool IsVertical() const { return m_orient == wxVERTICAL; }
945
946 void SetOrientation(int orient) { m_orient = orient; }
947
948 // implementation of our resizing logic
949 virtual wxSize CalcMin();
950 virtual void RecalcSizes();
951
952protected:
953 // helpers for our code: this returns the component of the given wxSize in
954 // the direction of the sizer and in the other direction, respectively
955 int GetSizeInMajorDir(const wxSize& sz) const
956 {
957 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
958 }
959
960 int& SizeInMajorDir(wxSize& sz)
961 {
962 return m_orient == wxHORIZONTAL ? sz.x : sz.y;
963 }
964
965 int& PosInMajorDir(wxPoint& pt)
966 {
967 return m_orient == wxHORIZONTAL ? pt.x : pt.y;
968 }
969
970 int GetSizeInMinorDir(const wxSize& sz) const
971 {
972 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
973 }
974
975 int& SizeInMinorDir(wxSize& sz)
976 {
977 return m_orient == wxHORIZONTAL ? sz.y : sz.x;
978 }
979
980 int& PosInMinorDir(wxPoint& pt)
981 {
982 return m_orient == wxHORIZONTAL ? pt.y : pt.x;
983 }
984
985 // another helper: creates wxSize from major and minor components
986 wxSize SizeFromMajorMinor(int major, int minor) const
987 {
988 if ( m_orient == wxHORIZONTAL )
989 {
990 return wxSize(major, minor);
991 }
992 else // wxVERTICAL
993 {
994 return wxSize(minor, major);
995 }
996 }
997
998
999 // either wxHORIZONTAL or wxVERTICAL
1000 int m_orient;
1001
1002 // the sum of proportion of all of our elements
1003 int m_totalProportion;
1004
1005 // the minimal size needed for this sizer as calculated by the last call to
1006 // our CalcMin()
1007 wxSize m_minSize;
1008
1009private:
1010 DECLARE_CLASS(wxBoxSizer)
1011};
1012
1013//---------------------------------------------------------------------------
1014// wxStaticBoxSizer
1015//---------------------------------------------------------------------------
1016
1017#if wxUSE_STATBOX
1018
1019class WXDLLIMPEXP_FWD_CORE wxStaticBox;
1020
1021class WXDLLIMPEXP_CORE wxStaticBoxSizer: public wxBoxSizer
1022{
1023public:
1024 wxStaticBoxSizer(wxStaticBox *box, int orient);
1025 wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
1026 virtual ~wxStaticBoxSizer();
1027
1028 void RecalcSizes();
1029 wxSize CalcMin();
1030
1031 wxStaticBox *GetStaticBox() const
1032 { return m_staticBox; }
1033
1034 // override to hide/show the static box as well
1035 virtual void ShowItems (bool show);
1036
1037 virtual bool Detach( wxWindow *window );
1038 virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); }
1039 virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); }
1040
1041protected:
1042 wxStaticBox *m_staticBox;
1043
1044private:
1045 DECLARE_CLASS(wxStaticBoxSizer)
1046 wxDECLARE_NO_COPY_CLASS(wxStaticBoxSizer);
1047};
1048
1049#endif // wxUSE_STATBOX
1050
1051//---------------------------------------------------------------------------
1052// wxStdDialogButtonSizer
1053//---------------------------------------------------------------------------
1054
1055#if wxUSE_BUTTON
1056
1057class WXDLLIMPEXP_CORE wxStdDialogButtonSizer: public wxBoxSizer
1058{
1059public:
1060 // Constructor just creates a new wxBoxSizer, not much else.
1061 // Box sizer orientation is automatically determined here:
1062 // vertical for PDAs, horizontal for everything else?
1063 wxStdDialogButtonSizer();
1064
1065 // Checks button ID against system IDs and sets one of the pointers below
1066 // to this button. Does not do any sizer-related things here.
1067 void AddButton(wxButton *button);
1068
1069 // Use these if no standard ID can/should be used
1070 void SetAffirmativeButton( wxButton *button );
1071 void SetNegativeButton( wxButton *button );
1072 void SetCancelButton( wxButton *button );
1073
1074 // All platform-specific code here, checks which buttons exist and add
1075 // them to the sizer accordingly.
1076 // Note - one potential hack on Mac we could use here,
1077 // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE
1078 // is set to _("Save") and m_buttonNegative is set to _("Don't Save")
1079 // I wouldn't add any other hacks like that into here,
1080 // but this one I can see being useful.
1081 void Realize();
1082
1083 wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; }
1084 wxButton *GetApplyButton() const { return m_buttonApply; }
1085 wxButton *GetNegativeButton() const { return m_buttonNegative; }
1086 wxButton *GetCancelButton() const { return m_buttonCancel; }
1087 wxButton *GetHelpButton() const { return m_buttonHelp; }
1088
1089protected:
1090 wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here
1091 wxButton *m_buttonApply; // wxID_APPLY
1092 wxButton *m_buttonNegative; // wxID_NO
1093 wxButton *m_buttonCancel; // wxID_CANCEL, wxID_CLOSE
1094 wxButton *m_buttonHelp; // wxID_HELP, wxID_CONTEXT_HELP
1095
1096private:
1097 DECLARE_CLASS(wxStdDialogButtonSizer)
1098 wxDECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer);
1099};
1100
1101#endif // wxUSE_BUTTON
1102
1103
1104// ----------------------------------------------------------------------------
1105// inline functions implementation
1106// ----------------------------------------------------------------------------
1107
1108#if WXWIN_COMPATIBILITY_2_8
1109
1110inline void wxSizerItem::SetWindow(wxWindow *window)
1111{
1112 DoSetWindow(window);
1113}
1114
1115inline void wxSizerItem::SetSizer(wxSizer *sizer)
1116{
1117 DoSetSizer(sizer);
1118}
1119
1120inline void wxSizerItem::SetSpacer(const wxSize& size)
1121{
1122 DoSetSpacer(size);
1123}
1124
1125inline void wxSizerItem::SetSpacer(int width, int height)
1126{
1127 DoSetSpacer(wxSize(width, height));
1128}
1129
1130#endif // WXWIN_COMPATIBILITY_2_8
1131
1132inline wxSizerItem*
1133wxSizer::Insert(size_t index, wxSizerItem *item)
1134{
1135 return DoInsert(index, item);
1136}
1137
1138
1139inline wxSizerItem*
1140wxSizer::Add( wxSizerItem *item )
1141{
1142 return Insert( m_children.GetCount(), item );
1143}
1144
1145inline wxSizerItem*
1146wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
1147{
1148 return Add( new wxSizerItem( window, proportion, flag, border, userData ) );
1149}
1150
1151inline wxSizerItem*
1152wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
1153{
1154 return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1155}
1156
1157inline wxSizerItem*
1158wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData )
1159{
1160 return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1161}
1162
1163inline wxSizerItem*
1164wxSizer::Add( wxWindow *window, const wxSizerFlags& flags )
1165{
1166 return Add( new wxSizerItem(window, flags) );
1167}
1168
1169inline wxSizerItem*
1170wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
1171{
1172 return Add( new wxSizerItem(sizer, flags) );
1173}
1174
1175inline wxSizerItem*
1176wxSizer::Add( int width, int height, const wxSizerFlags& flags )
1177{
1178 return Add( new wxSizerItem(width, height, flags) );
1179}
1180
1181inline wxSizerItem*
1182wxSizer::AddSpacer(int size)
1183{
1184 return Add(size, size);
1185}
1186
1187inline wxSizerItem*
1188wxSizer::AddStretchSpacer(int prop)
1189{
1190 return Add(0, 0, prop);
1191}
1192
1193inline wxSizerItem*
1194wxSizer::Prepend( wxSizerItem *item )
1195{
1196 return Insert( 0, item );
1197}
1198
1199inline wxSizerItem*
1200wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
1201{
1202 return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) );
1203}
1204
1205inline wxSizerItem*
1206wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
1207{
1208 return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) );
1209}
1210
1211inline wxSizerItem*
1212wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData )
1213{
1214 return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) );
1215}
1216
1217inline wxSizerItem*
1218wxSizer::PrependSpacer(int size)
1219{
1220 return Prepend(size, size);
1221}
1222
1223inline wxSizerItem*
1224wxSizer::PrependStretchSpacer(int prop)
1225{
1226 return Prepend(0, 0, prop);
1227}
1228
1229inline wxSizerItem*
1230wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags )
1231{
1232 return Prepend( new wxSizerItem(window, flags) );
1233}
1234
1235inline wxSizerItem*
1236wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags )
1237{
1238 return Prepend( new wxSizerItem(sizer, flags) );
1239}
1240
1241inline wxSizerItem*
1242wxSizer::Prepend( int width, int height, const wxSizerFlags& flags )
1243{
1244 return Prepend( new wxSizerItem(width, height, flags) );
1245}
1246
1247inline wxSizerItem*
1248wxSizer::Insert( size_t index,
1249 wxWindow *window,
1250 int proportion,
1251 int flag,
1252 int border,
1253 wxObject* userData )
1254{
1255 return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) );
1256}
1257
1258inline wxSizerItem*
1259wxSizer::Insert( size_t index,
1260 wxSizer *sizer,
1261 int proportion,
1262 int flag,
1263 int border,
1264 wxObject* userData )
1265{
1266 return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) );
1267}
1268
1269inline wxSizerItem*
1270wxSizer::Insert( size_t index,
1271 int width,
1272 int height,
1273 int proportion,
1274 int flag,
1275 int border,
1276 wxObject* userData )
1277{
1278 return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) );
1279}
1280
1281inline wxSizerItem*
1282wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags )
1283{
1284 return Insert( index, new wxSizerItem(window, flags) );
1285}
1286
1287inline wxSizerItem*
1288wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags )
1289{
1290 return Insert( index, new wxSizerItem(sizer, flags) );
1291}
1292
1293inline wxSizerItem*
1294wxSizer::Insert( size_t index, int width, int height, const wxSizerFlags& flags )
1295{
1296 return Insert( index, new wxSizerItem(width, height, flags) );
1297}
1298
1299inline wxSizerItem*
1300wxSizer::InsertSpacer(size_t index, int size)
1301{
1302 return Insert(index, size, size);
1303}
1304
1305inline wxSizerItem*
1306wxSizer::InsertStretchSpacer(size_t index, int prop)
1307{
1308 return Insert(index, 0, 0, prop);
1309}
1310
1311#endif // __WXSIZER_H__