1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide new wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
8 // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "sizer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/statbox.h"
26 #include "wx/notebook.h"
28 //---------------------------------------------------------------------------
30 IMPLEMENT_ABSTRACT_CLASS(wxSizerItem
, wxObject
);
31 IMPLEMENT_ABSTRACT_CLASS(wxSizer
, wxObject
);
32 IMPLEMENT_ABSTRACT_CLASS(wxGridSizer
, wxSizer
);
33 IMPLEMENT_ABSTRACT_CLASS(wxFlexGridSizer
, wxGridSizer
);
34 IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer
, wxSizer
);
35 IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer
, wxBoxSizer
);
37 IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer
, wxSizer
);
40 //---------------------------------------------------------------------------
42 //---------------------------------------------------------------------------
44 wxSizerItem::wxSizerItem( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
46 m_window
= (wxWindow
*) NULL
;
47 m_sizer
= (wxSizer
*) NULL
;
51 m_userData
= userData
;
53 // minimal size is the initial size
57 SetRatio(width
, height
);
59 // size is set directly
63 wxSizerItem::wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
66 m_sizer
= (wxSizer
*) NULL
;
70 m_userData
= userData
;
72 // minimal size is the initial size
73 m_minSize
= window
->GetSize();
75 // aspect ratio calculated from initial size
78 // size is calculated later
82 wxSizerItem::wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
84 m_window
= (wxWindow
*) NULL
;
89 m_userData
= userData
;
91 // minimal size is calculated later
95 // size is calculated later
99 wxSizerItem::~wxSizerItem()
108 wxSize
wxSizerItem::GetSize()
112 ret
= m_sizer
->GetSize();
115 ret
= m_window
->GetSize();
122 if (m_flag
& wxNORTH
)
124 if (m_flag
& wxSOUTH
)
130 wxSize
wxSizerItem::CalcMin()
135 ret
= m_sizer
->GetMinSize();
137 // if we have to preserve aspect ratio _AND_ this is
138 // the first-time calculation, consider ret to be initial size
139 if ((m_flag
& wxSHAPED
) && !m_ratio
)
144 if ( IsWindow() && (m_flag
& wxADJUST_MINSIZE
) )
146 // check if the best (minimal, in fact) window size hadn't changed
147 // by chance: this may happen for, e.g. static text if its label
149 wxSize size
= m_window
->GetBestSize();
150 if ( size
.x
> m_minSize
.x
)
151 m_minSize
.x
= size
.x
;
152 if ( size
.y
> m_minSize
.y
)
153 m_minSize
.y
= size
.y
;
163 if (m_flag
& wxNORTH
)
165 if (m_flag
& wxSOUTH
)
171 void wxSizerItem::SetDimension( wxPoint pos
, wxSize size
)
173 if (m_flag
& wxSHAPED
)
175 // adjust aspect ratio
176 int rwidth
= (int) (size
.y
* m_ratio
);
180 int rheight
= (int) (size
.x
/ m_ratio
);
181 // add vertical space
182 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
183 pos
.y
+= (size
.y
- rheight
) / 2;
184 else if (m_flag
& wxALIGN_BOTTOM
)
185 pos
.y
+= (size
.y
- rheight
);
186 // use reduced dimensions
189 else if (rwidth
< size
.x
)
191 // add horizontal space
192 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
193 pos
.x
+= (size
.x
- rwidth
) / 2;
194 else if (m_flag
& wxALIGN_RIGHT
)
195 pos
.x
+= (size
.x
- rwidth
);
200 // This is what GetPosition() returns. Since we calculate
201 // borders afterwards, GetPosition() will be the left/top
202 // corner of the surrounding border.
214 if (m_flag
& wxNORTH
)
219 if (m_flag
& wxSOUTH
)
225 m_sizer
->SetDimension( pos
.x
, pos
.y
, size
.x
, size
.y
);
228 m_window
->SetSize( pos
.x
, pos
.y
, size
.x
, size
.y
, wxSIZE_ALLOW_MINUS_ONE
);
233 bool wxSizerItem::IsWindow()
235 return (m_window
!= NULL
);
238 bool wxSizerItem::IsSizer()
240 return (m_sizer
!= NULL
);
243 bool wxSizerItem::IsSpacer()
245 return (m_window
== NULL
) && (m_sizer
== NULL
);
248 //---------------------------------------------------------------------------
250 //---------------------------------------------------------------------------
254 m_children
.DeleteContents( TRUE
);
263 void wxSizer::Add( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
265 m_children
.Append( new wxSizerItem( window
, option
, flag
, border
, userData
) );
268 void wxSizer::Add( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
270 m_children
.Append( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
273 void wxSizer::Add( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
275 m_children
.Append( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
278 void wxSizer::Prepend( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
280 m_children
.Insert( new wxSizerItem( window
, option
, flag
, border
, userData
) );
283 void wxSizer::Prepend( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
285 m_children
.Insert( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
288 void wxSizer::Prepend( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
290 m_children
.Insert( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
293 void wxSizer::Insert( int before
, wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
295 m_children
.Insert( before
, new wxSizerItem( window
, option
, flag
, border
, userData
) );
298 void wxSizer::Insert( int before
, wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
300 m_children
.Insert( before
, new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
303 void wxSizer::Insert( int before
, int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
305 m_children
.Insert( before
, new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
308 bool wxSizer::Remove( wxWindow
*window
)
312 wxNode
*node
= m_children
.First();
315 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
316 if (item
->GetWindow() == window
)
318 m_children
.DeleteNode( node
);
327 bool wxSizer::Remove( wxSizer
*sizer
)
331 wxNode
*node
= m_children
.First();
334 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
335 if (item
->GetSizer() == sizer
)
337 m_children
.DeleteNode( node
);
346 bool wxSizer::Remove( int pos
)
348 wxNode
*node
= m_children
.Nth( pos
);
349 if (!node
) return FALSE
;
351 m_children
.DeleteNode( node
);
356 void wxSizer::Fit( wxWindow
*window
)
359 if (window
->IsTopLevel())
360 size
= FitSize( window
);
362 size
= GetMinWindowSize( window
);
364 window
->SetSize( size
);
367 void wxSizer::Layout()
373 void wxSizer::SetSizeHints( wxWindow
*window
)
375 wxSize size
= FitSize( window
);
376 window
->SetSizeHints( size
.x
, size
.y
);
379 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*WXUNUSED(window
) )
381 wxRect rect
= wxGetClientDisplayRect();
382 wxSize
sizeMax (rect
.width
,rect
.height
);
384 // Make the max size a bit smaller than the visible portion of
385 // the screen. A window which takes the entire screen doesn't
386 // look very nice either
396 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
398 wxSize
minSize( GetMinSize() );
399 wxSize
size( window
->GetSize() );
400 wxSize
client_size( window
->GetClientSize() );
401 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
402 minSize
.y
+size
.y
-client_size
.y
);
405 // Return a window size that will fit within the screens dimensions
406 wxSize
wxSizer::FitSize( wxWindow
*window
)
408 wxSize size
= GetMinWindowSize( window
);
409 wxSize sizeMax
= GetMaxWindowSize( window
);
411 if ( size
.x
> sizeMax
.x
)
413 if ( size
.y
> sizeMax
.y
)
419 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
429 wxSize
wxSizer::GetMinSize()
431 wxSize
ret( CalcMin() );
432 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
433 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
437 void wxSizer::DoSetMinSize( int width
, int height
)
440 m_minSize
.y
= height
;
443 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
447 wxNode
*node
= m_children
.First();
450 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
451 if (item
->GetWindow() == window
)
453 item
->SetInitSize( width
, height
);
459 node
= m_children
.First();
462 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
463 if (item
->GetSizer())
465 /* It's a sizer, so lets search recursively. */
466 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
468 /* A child sizer found the requested windw, exit. */
478 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
482 wxNode
*node
= m_children
.First();
485 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
486 if (item
->GetSizer() == sizer
)
488 item
->GetSizer()->DoSetMinSize( width
, height
);
494 node
= m_children
.First();
497 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
498 if (item
->GetSizer())
500 /* It's a sizer, so lets search recursively. */
501 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
503 /* A child sizer found the requested windw, exit. */
513 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
515 wxNode
*node
= m_children
.Nth( pos
);
516 if (!node
) return FALSE
;
518 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
519 if (item
->GetSizer())
521 /* Sizers contains the minimal size in them, if not calculated ... */
522 item
->GetSizer()->DoSetMinSize( width
, height
);
526 /* ... whereas the minimal size of spacers and windows in stored
528 item
->SetInitSize( width
, height
);
534 //---------------------------------------------------------------------------
536 //---------------------------------------------------------------------------
538 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
546 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
554 void wxGridSizer::RecalcSizes()
556 if (m_children
.GetCount() == 0)
559 int nitems
= m_children
.GetCount();
564 nrows
= (nitems
+ ncols
-1) / ncols
;
566 ncols
= (nitems
+ nrows
-1) / nrows
;
568 wxSize
sz( GetSize() );
569 wxPoint
pt( GetPosition() );
571 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
572 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
575 for (int c
= 0; c
< ncols
; c
++)
578 for (int r
= 0; r
< nrows
; r
++)
580 int i
= r
* ncols
+ c
;
583 wxNode
*node
= m_children
.Nth( i
);
586 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
594 wxSize
wxGridSizer::CalcMin()
596 if (m_children
.GetCount() == 0)
597 return wxSize(10,10);
599 int nitems
= m_children
.GetCount();
604 nrows
= (nitems
+ ncols
-1) / ncols
;
606 ncols
= (nitems
+ nrows
-1) / nrows
;
608 /* Find the max width and height for any component */
612 wxNode
*node
= m_children
.First();
615 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
616 wxSize
sz( item
->CalcMin() );
617 w
= wxMax( w
, sz
.x
);
618 h
= wxMax( h
, sz
.y
);
623 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
624 nrows
* h
+ (nrows
-1) * m_vgap
);
627 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
630 wxSize
sz( item
->CalcMin() );
631 int flag
= item
->GetFlag();
633 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
639 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
641 pt
.x
= x
+ (w
- sz
.x
) / 2;
643 else if (flag
& wxALIGN_RIGHT
)
645 pt
.x
= x
+ (w
- sz
.x
);
648 if (flag
& wxALIGN_CENTER_VERTICAL
)
650 pt
.y
= y
+ (h
- sz
.y
) / 2;
652 else if (flag
& wxALIGN_BOTTOM
)
654 pt
.y
= y
+ (h
- sz
.y
);
658 item
->SetDimension(pt
, sz
);
661 //---------------------------------------------------------------------------
663 //---------------------------------------------------------------------------
665 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
666 : wxGridSizer( rows
, cols
, vgap
, hgap
)
668 m_rowHeights
= (int*) NULL
;
669 m_colWidths
= (int*) NULL
;
672 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
673 : wxGridSizer( cols
, vgap
, hgap
)
675 m_rowHeights
= (int*) NULL
;
676 m_colWidths
= (int*) NULL
;
679 wxFlexGridSizer::~wxFlexGridSizer()
682 delete[] m_rowHeights
;
684 delete[] m_colWidths
;
687 void wxFlexGridSizer::CreateArrays()
690 delete[] m_rowHeights
;
692 delete[] m_colWidths
;
694 if (m_children
.GetCount() == 0)
697 int nitems
= m_children
.GetCount();
702 nrows
= (nitems
+ ncols
-1) / ncols
;
704 ncols
= (nitems
+ nrows
-1) / nrows
;
706 m_rowHeights
= new int[nrows
];
707 m_colWidths
= new int[ncols
];
709 for (int col
= 0; col
< ncols
; col
++)
710 m_colWidths
[ col
] = 0;
711 for (int row
= 0; row
< nrows
; row
++)
712 m_rowHeights
[ row
] = 0;
715 void wxFlexGridSizer::RecalcSizes()
717 if (m_children
.GetCount() == 0)
720 int nitems
= m_children
.GetCount();
725 nrows
= (nitems
+ ncols
-1) / ncols
;
727 ncols
= (nitems
+ nrows
-1) / nrows
;
729 wxSize
sz( GetSize() );
730 wxSize
minsz( CalcMin() );
731 wxPoint
pt( GetPosition() );
735 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
737 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
738 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
739 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
742 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
744 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
745 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
746 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
749 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
752 for (int c
= 0; c
< ncols
; c
++)
755 for (int r
= 0; r
< nrows
; r
++)
757 int i
= r
* ncols
+ c
;
760 wxNode
*node
= m_children
.Nth( i
);
763 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
764 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
766 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
768 y
= y
+ m_rowHeights
[r
] + m_vgap
;
770 x
= x
+ m_colWidths
[c
] + m_hgap
;
774 wxSize
wxFlexGridSizer::CalcMin()
776 if (m_children
.GetCount() == 0)
777 return wxSize(10,10);
779 int nitems
= m_children
.GetCount();
784 nrows
= (nitems
+ ncols
-1) / ncols
;
786 ncols
= (nitems
+ nrows
-1) / nrows
;
794 wxNode
*node
= m_children
.First();
797 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
798 wxSize
sz( item
->CalcMin() );
801 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
802 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
809 for (col
= 0; col
< ncols
; col
++)
810 width
+= m_colWidths
[ col
];
813 for (row
= 0; row
< nrows
; row
++)
814 height
+= m_rowHeights
[ row
];
816 return wxSize( width
+ (ncols
-1) * m_hgap
,
817 height
+ (nrows
-1) * m_vgap
);
820 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
822 m_growableRows
.Add( idx
);
825 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
829 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
831 m_growableCols
.Add( idx
);
834 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
838 //---------------------------------------------------------------------------
840 //---------------------------------------------------------------------------
842 wxBoxSizer::wxBoxSizer( int orient
)
847 void wxBoxSizer::RecalcSizes()
849 if (m_children
.GetCount() == 0)
856 if (m_orient
== wxHORIZONTAL
)
858 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
859 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
863 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
864 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
868 wxPoint
pt( m_position
);
870 wxNode
*node
= m_children
.GetFirst();
873 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
876 if (item
->GetOption())
877 weight
= item
->GetOption();
879 wxSize
size( item
->CalcMin() );
881 if (m_orient
== wxVERTICAL
)
883 wxCoord height
= size
.y
;
884 if (item
->GetOption())
886 height
= (delta
* weight
) + extra
;
887 extra
= 0; // only the first item will get the remainder as extra size
890 wxPoint
child_pos( pt
);
891 wxSize
child_size( wxSize( size
.x
, height
) );
893 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
894 child_size
.x
= m_size
.x
;
895 else if (item
->GetFlag() & wxALIGN_RIGHT
)
896 child_pos
.x
+= m_size
.x
- size
.x
;
897 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
898 // XXX wxCENTER is added for backward compatibility;
899 // wxALIGN_CENTER should be used in new code
900 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
902 item
->SetDimension( child_pos
, child_size
);
908 wxCoord width
= size
.x
;
909 if (item
->GetOption())
911 width
= (delta
* weight
) + extra
;
912 extra
= 0; // only the first item will get the remainder as extra size
915 wxPoint
child_pos( pt
);
916 wxSize
child_size( wxSize(width
, size
.y
) );
918 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
919 child_size
.y
= m_size
.y
;
920 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
921 child_pos
.y
+= m_size
.y
- size
.y
;
922 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
923 // XXX wxCENTER is added for backward compatibility;
924 // wxALIGN_CENTER should be used in new code
925 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
927 item
->SetDimension( child_pos
, child_size
);
936 wxSize
wxBoxSizer::CalcMin()
938 if (m_children
.GetCount() == 0)
939 return wxSize(10,10);
947 // Find how long each stretch unit needs to be
949 wxNode
*node
= m_children
.GetFirst();
952 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
953 if (item
->GetOption() != 0)
955 int stretch
= item
->GetOption();
956 wxSize
size( item
->CalcMin() );
958 // Integer division rounded up is (a + b - 1) / b
959 if (m_orient
== wxHORIZONTAL
)
960 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
962 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
963 if (sizePerStretch
> stretchSize
)
964 stretchSize
= sizePerStretch
;
968 // Calculate overall minimum size
969 node
= m_children
.GetFirst();
972 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
974 m_stretchable
+= item
->GetOption();
976 wxSize
size( item
->CalcMin() );
977 if (item
->GetOption() != 0)
979 if (m_orient
== wxHORIZONTAL
)
980 size
.x
= stretchSize
* item
->GetOption();
982 size
.y
= stretchSize
* item
->GetOption();
985 if (m_orient
== wxHORIZONTAL
)
987 m_minWidth
+= size
.x
;
988 m_minHeight
= wxMax( m_minHeight
, size
.y
);
992 m_minHeight
+= size
.y
;
993 m_minWidth
= wxMax( m_minWidth
, size
.x
);
996 if (item
->GetOption() == 0)
998 if (m_orient
== wxVERTICAL
)
1000 m_fixedHeight
+= size
.y
;
1001 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1005 m_fixedWidth
+= size
.x
;
1006 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1010 node
= node
->Next();
1013 return wxSize( m_minWidth
, m_minHeight
);
1016 //---------------------------------------------------------------------------
1018 //---------------------------------------------------------------------------
1020 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1021 : wxBoxSizer( orient
)
1023 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1028 static void GetStaticBoxBorders(wxStaticBox
*box
,
1029 int *borderTop
, int *borderOther
)
1031 // this has to be done platform by platform as there is no way to
1032 // guess the thickness of a wxStaticBox border
1034 if ( box
->GetLabel().IsEmpty() )
1043 void wxStaticBoxSizer::RecalcSizes()
1045 int top_border
, other_border
;
1046 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1048 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1050 wxPoint
old_pos( m_position
);
1051 m_position
.x
+= other_border
;
1052 m_position
.y
+= top_border
;
1053 wxSize
old_size( m_size
);
1054 m_size
.x
-= 2*other_border
;
1055 m_size
.y
-= top_border
+ other_border
;
1057 wxBoxSizer::RecalcSizes();
1059 m_position
= old_pos
;
1063 wxSize
wxStaticBoxSizer::CalcMin()
1065 int top_border
, other_border
;
1066 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1068 wxSize
ret( wxBoxSizer::CalcMin() );
1069 ret
.x
+= 2*other_border
;
1070 ret
.y
+= other_border
+ top_border
;
1075 //---------------------------------------------------------------------------
1077 //---------------------------------------------------------------------------
1081 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1083 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1088 void wxNotebookSizer::RecalcSizes()
1090 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1093 wxSize
wxNotebookSizer::CalcMin()
1095 // This will have to be done platform by platform
1096 // as there is no way to guess the thickness of
1097 // the wxNotebook tabs and border.
1101 if ((m_notebook
->HasFlag(wxNB_RIGHT
)) ||
1102 (m_notebook
->HasFlag(wxNB_LEFT
)))
1104 borderX
+= 90; // improvements later..
1108 borderY
+= 40; // improvements later..
1111 if (m_notebook
->GetChildren().GetCount() == 0)
1112 return wxSize(borderX
+ 10, borderY
+ 10);
1117 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1120 wxWindow
*item
= node
->GetData();
1121 wxSizer
*itemsizer
= item
->GetSizer();
1125 wxSize
subsize( itemsizer
->CalcMin() );
1127 if (subsize
.x
> maxX
) maxX
= subsize
.x
;
1128 if (subsize
.y
> maxY
) maxY
= subsize
.y
;
1131 node
= node
->GetNext();
1134 return wxSize( borderX
+ maxX
, borderY
+ maxY
);
1137 #endif // wxUSE_NOTEBOOK