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
)
36 IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
39 IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer
, wxSizer
)
42 //---------------------------------------------------------------------------
44 //---------------------------------------------------------------------------
46 wxSizerItem::wxSizerItem( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
48 m_window
= (wxWindow
*) NULL
;
49 m_sizer
= (wxSizer
*) NULL
;
53 m_userData
= userData
;
55 // minimal size is the initial size
59 SetRatio(width
, height
);
61 // size is set directly
65 wxSizerItem::wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
68 m_sizer
= (wxSizer
*) NULL
;
72 m_userData
= userData
;
74 // minimal size is the initial size
75 m_minSize
= window
->GetSize();
77 // aspect ratio calculated from initial size
80 // size is calculated later
84 wxSizerItem::wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
86 m_window
= (wxWindow
*) NULL
;
91 m_userData
= userData
;
93 // minimal size is calculated later
97 // size is calculated later
101 wxSizerItem::~wxSizerItem()
110 wxSize
wxSizerItem::GetSize()
114 ret
= m_sizer
->GetSize();
117 ret
= m_window
->GetSize();
124 if (m_flag
& wxNORTH
)
126 if (m_flag
& wxSOUTH
)
132 wxSize
wxSizerItem::CalcMin()
137 ret
= m_sizer
->GetMinSize();
139 // if we have to preserve aspect ratio _AND_ this is
140 // the first-time calculation, consider ret to be initial size
141 if ((m_flag
& wxSHAPED
) && !m_ratio
)
146 if ( IsWindow() && (m_flag
& wxADJUST_MINSIZE
) )
148 // check if the best (minimal, in fact) window size hadn't changed
149 // by chance: this may happen for, e.g. static text if its label
151 wxSize size
= m_window
->GetBestSize();
152 if ( size
.x
> m_minSize
.x
)
153 m_minSize
.x
= size
.x
;
154 if ( size
.y
> m_minSize
.y
)
155 m_minSize
.y
= size
.y
;
165 if (m_flag
& wxNORTH
)
167 if (m_flag
& wxSOUTH
)
173 void wxSizerItem::SetDimension( wxPoint pos
, wxSize size
)
175 if (m_flag
& wxSHAPED
)
177 // adjust aspect ratio
178 int rwidth
= (int) (size
.y
* m_ratio
);
182 int rheight
= (int) (size
.x
/ m_ratio
);
183 // add vertical space
184 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
185 pos
.y
+= (size
.y
- rheight
) / 2;
186 else if (m_flag
& wxALIGN_BOTTOM
)
187 pos
.y
+= (size
.y
- rheight
);
188 // use reduced dimensions
191 else if (rwidth
< size
.x
)
193 // add horizontal space
194 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
195 pos
.x
+= (size
.x
- rwidth
) / 2;
196 else if (m_flag
& wxALIGN_RIGHT
)
197 pos
.x
+= (size
.x
- rwidth
);
202 // This is what GetPosition() returns. Since we calculate
203 // borders afterwards, GetPosition() will be the left/top
204 // corner of the surrounding border.
216 if (m_flag
& wxNORTH
)
221 if (m_flag
& wxSOUTH
)
227 m_sizer
->SetDimension( pos
.x
, pos
.y
, size
.x
, size
.y
);
230 m_window
->SetSize( pos
.x
, pos
.y
, size
.x
, size
.y
, wxSIZE_ALLOW_MINUS_ONE
);
235 void wxSizerItem::DeleteWindows()
241 m_sizer
->DeleteWindows();
244 bool wxSizerItem::IsWindow()
246 return (m_window
!= NULL
);
249 bool wxSizerItem::IsSizer()
251 return (m_sizer
!= NULL
);
254 bool wxSizerItem::IsSpacer()
256 return (m_window
== NULL
) && (m_sizer
== NULL
);
259 //---------------------------------------------------------------------------
261 //---------------------------------------------------------------------------
265 m_children
.DeleteContents( TRUE
);
274 void wxSizer::Add( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
276 m_children
.Append( new wxSizerItem( window
, option
, flag
, border
, userData
) );
279 void wxSizer::Add( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
281 m_children
.Append( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
284 void wxSizer::Add( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
286 m_children
.Append( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
289 void wxSizer::Prepend( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
291 m_children
.Insert( new wxSizerItem( window
, option
, flag
, border
, userData
) );
294 void wxSizer::Prepend( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
296 m_children
.Insert( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
299 void wxSizer::Prepend( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
301 m_children
.Insert( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
304 void wxSizer::Insert( int before
, wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
306 m_children
.Insert( before
, new wxSizerItem( window
, option
, flag
, border
, userData
) );
309 void wxSizer::Insert( int before
, wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
311 m_children
.Insert( before
, new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
314 void wxSizer::Insert( int before
, int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
316 m_children
.Insert( before
, new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
319 bool wxSizer::Remove( wxWindow
*window
)
323 wxNode
*node
= m_children
.First();
326 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
327 if (item
->GetWindow() == window
)
329 m_children
.DeleteNode( node
);
338 bool wxSizer::Remove( wxSizer
*sizer
)
342 wxNode
*node
= m_children
.First();
345 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
346 if (item
->GetSizer() == sizer
)
348 m_children
.DeleteNode( node
);
357 bool wxSizer::Remove( int pos
)
359 wxNode
*node
= m_children
.Nth( pos
);
360 if (!node
) return FALSE
;
362 m_children
.DeleteNode( node
);
367 void wxSizer::Clear( bool delete_windows
)
375 void wxSizer::DeleteWindows()
377 wxNode
*node
= m_children
.First();
380 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
381 item
->DeleteWindows();
386 void wxSizer::Fit( wxWindow
*window
)
389 if (window
->IsTopLevel())
390 size
= FitSize( window
);
392 size
= GetMinWindowSize( window
);
394 window
->SetSize( size
);
397 void wxSizer::Layout()
403 void wxSizer::SetSizeHints( wxWindow
*window
)
405 wxSize size
= FitSize( window
);
406 window
->SetSizeHints( size
.x
, size
.y
);
409 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*WXUNUSED(window
) )
411 wxRect rect
= wxGetClientDisplayRect();
412 wxSize
sizeMax (rect
.width
,rect
.height
);
414 // Sorry, but this bit is wrong -- it makes a window that should just be
415 // able to fit onto the screen, not fit on the screen. -- JACS
417 // Make the max size a bit smaller than the visible portion of
418 // the screen. A window which takes the entire screen doesn't
419 // look very nice either
430 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
432 wxSize
minSize( GetMinSize() );
433 wxSize
size( window
->GetSize() );
434 wxSize
client_size( window
->GetClientSize() );
435 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
436 minSize
.y
+size
.y
-client_size
.y
);
439 // Return a window size that will fit within the screens dimensions
440 wxSize
wxSizer::FitSize( wxWindow
*window
)
442 wxSize size
= GetMinWindowSize( window
);
443 wxSize sizeMax
= GetMaxWindowSize( window
);
445 if ( size
.x
> sizeMax
.x
)
447 if ( size
.y
> sizeMax
.y
)
453 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
463 wxSize
wxSizer::GetMinSize()
465 wxSize
ret( CalcMin() );
466 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
467 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
471 void wxSizer::DoSetMinSize( int width
, int height
)
474 m_minSize
.y
= height
;
477 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
481 wxNode
*node
= m_children
.First();
484 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
485 if (item
->GetWindow() == window
)
487 item
->SetInitSize( width
, height
);
493 node
= m_children
.First();
496 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
497 if (item
->GetSizer())
499 /* It's a sizer, so lets search recursively. */
500 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
502 /* A child sizer found the requested windw, exit. */
512 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
516 wxNode
*node
= m_children
.First();
519 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
520 if (item
->GetSizer() == sizer
)
522 item
->GetSizer()->DoSetMinSize( width
, height
);
528 node
= m_children
.First();
531 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
532 if (item
->GetSizer())
534 /* It's a sizer, so lets search recursively. */
535 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
537 /* A child sizer found the requested windw, exit. */
547 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
549 wxNode
*node
= m_children
.Nth( pos
);
550 if (!node
) return FALSE
;
552 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
553 if (item
->GetSizer())
555 /* Sizers contains the minimal size in them, if not calculated ... */
556 item
->GetSizer()->DoSetMinSize( width
, height
);
560 /* ... whereas the minimal size of spacers and windows in stored
562 item
->SetInitSize( width
, height
);
568 //---------------------------------------------------------------------------
570 //---------------------------------------------------------------------------
572 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
580 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
588 void wxGridSizer::RecalcSizes()
590 if (m_children
.GetCount() == 0)
593 int nitems
= m_children
.GetCount();
598 nrows
= (nitems
+ ncols
-1) / ncols
;
600 ncols
= (nitems
+ nrows
-1) / nrows
;
602 wxSize
sz( GetSize() );
603 wxPoint
pt( GetPosition() );
605 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
606 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
609 for (int c
= 0; c
< ncols
; c
++)
612 for (int r
= 0; r
< nrows
; r
++)
614 int i
= r
* ncols
+ c
;
617 wxNode
*node
= m_children
.Nth( i
);
620 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
628 wxSize
wxGridSizer::CalcMin()
630 if (m_children
.GetCount() == 0)
631 return wxSize(10,10);
633 int nitems
= m_children
.GetCount();
638 nrows
= (nitems
+ ncols
-1) / ncols
;
640 ncols
= (nitems
+ nrows
-1) / nrows
;
642 /* Find the max width and height for any component */
646 wxNode
*node
= m_children
.First();
649 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
650 wxSize
sz( item
->CalcMin() );
651 w
= wxMax( w
, sz
.x
);
652 h
= wxMax( h
, sz
.y
);
657 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
658 nrows
* h
+ (nrows
-1) * m_vgap
);
661 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
664 wxSize
sz( item
->CalcMin() );
665 int flag
= item
->GetFlag();
667 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
673 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
675 pt
.x
= x
+ (w
- sz
.x
) / 2;
677 else if (flag
& wxALIGN_RIGHT
)
679 pt
.x
= x
+ (w
- sz
.x
);
682 if (flag
& wxALIGN_CENTER_VERTICAL
)
684 pt
.y
= y
+ (h
- sz
.y
) / 2;
686 else if (flag
& wxALIGN_BOTTOM
)
688 pt
.y
= y
+ (h
- sz
.y
);
692 item
->SetDimension(pt
, sz
);
695 //---------------------------------------------------------------------------
697 //---------------------------------------------------------------------------
699 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
700 : wxGridSizer( rows
, cols
, vgap
, hgap
)
702 m_rowHeights
= (int*) NULL
;
703 m_colWidths
= (int*) NULL
;
706 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
707 : wxGridSizer( cols
, vgap
, hgap
)
709 m_rowHeights
= (int*) NULL
;
710 m_colWidths
= (int*) NULL
;
713 wxFlexGridSizer::~wxFlexGridSizer()
716 delete[] m_rowHeights
;
718 delete[] m_colWidths
;
721 void wxFlexGridSizer::CreateArrays()
724 delete[] m_rowHeights
;
726 delete[] m_colWidths
;
728 if (m_children
.GetCount() == 0)
731 int nitems
= m_children
.GetCount();
736 nrows
= (nitems
+ ncols
-1) / ncols
;
738 ncols
= (nitems
+ nrows
-1) / nrows
;
740 m_rowHeights
= new int[nrows
];
741 m_colWidths
= new int[ncols
];
743 for (int col
= 0; col
< ncols
; col
++)
744 m_colWidths
[ col
] = 0;
745 for (int row
= 0; row
< nrows
; row
++)
746 m_rowHeights
[ row
] = 0;
749 void wxFlexGridSizer::RecalcSizes()
751 if (m_children
.GetCount() == 0)
754 int nitems
= m_children
.GetCount();
759 nrows
= (nitems
+ ncols
-1) / ncols
;
761 ncols
= (nitems
+ nrows
-1) / nrows
;
763 wxSize
sz( GetSize() );
764 wxSize
minsz( CalcMin() );
765 wxPoint
pt( GetPosition() );
769 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
771 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
772 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
773 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
776 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
778 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
779 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
780 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
783 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
786 for (int c
= 0; c
< ncols
; c
++)
789 for (int r
= 0; r
< nrows
; r
++)
791 int i
= r
* ncols
+ c
;
794 wxNode
*node
= m_children
.Nth( i
);
797 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
798 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
800 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
802 y
= y
+ m_rowHeights
[r
] + m_vgap
;
804 x
= x
+ m_colWidths
[c
] + m_hgap
;
808 wxSize
wxFlexGridSizer::CalcMin()
810 if (m_children
.GetCount() == 0)
811 return wxSize(10,10);
813 int nitems
= m_children
.GetCount();
818 nrows
= (nitems
+ ncols
-1) / ncols
;
820 ncols
= (nitems
+ nrows
-1) / nrows
;
828 wxNode
*node
= m_children
.First();
831 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
832 wxSize
sz( item
->CalcMin() );
835 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
836 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
843 for (col
= 0; col
< ncols
; col
++)
844 width
+= m_colWidths
[ col
];
847 for (row
= 0; row
< nrows
; row
++)
848 height
+= m_rowHeights
[ row
];
850 return wxSize( width
+ (ncols
-1) * m_hgap
,
851 height
+ (nrows
-1) * m_vgap
);
854 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
856 m_growableRows
.Add( idx
);
859 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
863 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
865 m_growableCols
.Add( idx
);
868 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
872 //---------------------------------------------------------------------------
874 //---------------------------------------------------------------------------
876 wxBoxSizer::wxBoxSizer( int orient
)
881 void wxBoxSizer::RecalcSizes()
883 if (m_children
.GetCount() == 0)
890 if (m_orient
== wxHORIZONTAL
)
892 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
893 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
897 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
898 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
902 wxPoint
pt( m_position
);
904 wxNode
*node
= m_children
.GetFirst();
907 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
910 if (item
->GetOption())
911 weight
= item
->GetOption();
913 wxSize
size( item
->CalcMin() );
915 if (m_orient
== wxVERTICAL
)
917 wxCoord height
= size
.y
;
918 if (item
->GetOption())
920 height
= (delta
* weight
) + extra
;
921 extra
= 0; // only the first item will get the remainder as extra size
924 wxPoint
child_pos( pt
);
925 wxSize
child_size( wxSize( size
.x
, height
) );
927 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
928 child_size
.x
= m_size
.x
;
929 else if (item
->GetFlag() & wxALIGN_RIGHT
)
930 child_pos
.x
+= m_size
.x
- size
.x
;
931 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
932 // XXX wxCENTER is added for backward compatibility;
933 // wxALIGN_CENTER should be used in new code
934 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
936 item
->SetDimension( child_pos
, child_size
);
942 wxCoord width
= size
.x
;
943 if (item
->GetOption())
945 width
= (delta
* weight
) + extra
;
946 extra
= 0; // only the first item will get the remainder as extra size
949 wxPoint
child_pos( pt
);
950 wxSize
child_size( wxSize(width
, size
.y
) );
952 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
953 child_size
.y
= m_size
.y
;
954 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
955 child_pos
.y
+= m_size
.y
- size
.y
;
956 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
957 // XXX wxCENTER is added for backward compatibility;
958 // wxALIGN_CENTER should be used in new code
959 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
961 item
->SetDimension( child_pos
, child_size
);
970 wxSize
wxBoxSizer::CalcMin()
972 if (m_children
.GetCount() == 0)
973 return wxSize(10,10);
981 // Find how long each stretch unit needs to be
983 wxNode
*node
= m_children
.GetFirst();
986 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
987 if (item
->GetOption() != 0)
989 int stretch
= item
->GetOption();
990 wxSize
size( item
->CalcMin() );
992 // Integer division rounded up is (a + b - 1) / b
993 if (m_orient
== wxHORIZONTAL
)
994 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
996 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
997 if (sizePerStretch
> stretchSize
)
998 stretchSize
= sizePerStretch
;
1000 node
= node
->Next();
1002 // Calculate overall minimum size
1003 node
= m_children
.GetFirst();
1006 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1008 m_stretchable
+= item
->GetOption();
1010 wxSize
size( item
->CalcMin() );
1011 if (item
->GetOption() != 0)
1013 if (m_orient
== wxHORIZONTAL
)
1014 size
.x
= stretchSize
* item
->GetOption();
1016 size
.y
= stretchSize
* item
->GetOption();
1019 if (m_orient
== wxHORIZONTAL
)
1021 m_minWidth
+= size
.x
;
1022 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1026 m_minHeight
+= size
.y
;
1027 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1030 if (item
->GetOption() == 0)
1032 if (m_orient
== wxVERTICAL
)
1034 m_fixedHeight
+= size
.y
;
1035 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1039 m_fixedWidth
+= size
.x
;
1040 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1044 node
= node
->Next();
1047 return wxSize( m_minWidth
, m_minHeight
);
1050 //---------------------------------------------------------------------------
1052 //---------------------------------------------------------------------------
1056 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1057 : wxBoxSizer( orient
)
1059 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1064 static void GetStaticBoxBorders(wxStaticBox
*box
,
1065 int *borderTop
, int *borderOther
)
1067 // this has to be done platform by platform as there is no way to
1068 // guess the thickness of a wxStaticBox border
1070 if ( box
->GetLabel().IsEmpty() )
1079 void wxStaticBoxSizer::RecalcSizes()
1081 int top_border
, other_border
;
1082 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1084 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1086 wxPoint
old_pos( m_position
);
1087 m_position
.x
+= other_border
;
1088 m_position
.y
+= top_border
;
1089 wxSize
old_size( m_size
);
1090 m_size
.x
-= 2*other_border
;
1091 m_size
.y
-= top_border
+ other_border
;
1093 wxBoxSizer::RecalcSizes();
1095 m_position
= old_pos
;
1099 wxSize
wxStaticBoxSizer::CalcMin()
1101 int top_border
, other_border
;
1102 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1104 wxSize
ret( wxBoxSizer::CalcMin() );
1105 ret
.x
+= 2*other_border
;
1106 ret
.y
+= other_border
+ top_border
;
1111 #endif // wxUSE_STATBOX
1113 //---------------------------------------------------------------------------
1115 //---------------------------------------------------------------------------
1119 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1121 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1126 void wxNotebookSizer::RecalcSizes()
1128 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1131 wxSize
wxNotebookSizer::CalcMin()
1133 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1138 if (m_notebook
->GetChildren().GetCount() == 0)
1140 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1146 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1149 wxWindow
*item
= node
->GetData();
1150 wxSizer
*itemsizer
= item
->GetSizer();
1154 wxSize
subsize( itemsizer
->CalcMin() );
1156 if (subsize
.x
> maxX
)
1158 if (subsize
.y
> maxY
)
1162 node
= node
->GetNext();
1165 return wxSize( maxX
, maxY
) + sizeBorder
;
1168 #endif // wxUSE_NOTEBOOK