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