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