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
);
275 void wxSizer::Add( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
277 m_children
.Append( new wxSizerItem( window
, option
, flag
, border
, userData
) );
278 window
->SetContainingSizer(this);
281 void wxSizer::Add( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
283 m_children
.Append( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
286 void wxSizer::Add( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
288 m_children
.Append( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
291 void wxSizer::Prepend( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
293 m_children
.Insert( new wxSizerItem( window
, option
, flag
, border
, userData
) );
294 window
->SetContainingSizer(this);
297 void wxSizer::Prepend( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
299 m_children
.Insert( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
302 void wxSizer::Prepend( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
304 m_children
.Insert( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
307 void wxSizer::Insert( int before
, wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
309 m_children
.Insert( before
, new wxSizerItem( window
, option
, flag
, border
, userData
) );
310 window
->SetContainingSizer(this);
313 void wxSizer::Insert( int before
, wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
315 m_children
.Insert( before
, new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
318 void wxSizer::Insert( int before
, int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
320 m_children
.Insert( before
, new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
323 bool wxSizer::Remove( wxWindow
*window
)
327 wxNode
*node
= m_children
.First();
330 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
331 if (item
->GetWindow() == window
)
333 item
->GetWindow()->SetContainingSizer(NULL
);
334 m_children
.DeleteNode( node
);
343 bool wxSizer::Remove( wxSizer
*sizer
)
347 wxNode
*node
= m_children
.First();
350 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
351 if (item
->GetSizer() == sizer
)
353 m_children
.DeleteNode( node
);
362 bool wxSizer::Remove( int pos
)
364 wxNode
*node
= m_children
.Nth( pos
);
365 if (!node
) return FALSE
;
367 m_children
.DeleteNode( node
);
372 void wxSizer::Clear( bool delete_windows
)
374 // First clear the ContainingSizer pointers
375 wxNode
*node
= m_children
.First();
378 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
379 if (item
->IsWindow())
380 item
->GetWindow()->SetContainingSizer(NULL
);
384 // Destroy the windows if needed
388 // Now empty the list
392 void wxSizer::DeleteWindows()
394 wxNode
*node
= m_children
.First();
397 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
398 item
->DeleteWindows();
403 void wxSizer::Fit( wxWindow
*window
)
406 if (window
->IsTopLevel())
407 size
= FitSize( window
);
409 size
= GetMinWindowSize( window
);
411 window
->SetSize( size
);
414 void wxSizer::Layout()
420 void wxSizer::SetSizeHints( wxWindow
*window
)
422 // Preserve the window's max size hints, but set the
423 // lower bound according to the sizer calculations.
425 wxSize size
= FitSize( window
);
426 window
->SetSizeHints( size
.x
,
428 window
->GetMaxWidth(),
429 window
->GetMaxHeight() );
432 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
)
434 return window
->GetMaxSize();
437 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
439 wxSize
minSize( GetMinSize() );
440 wxSize
size( window
->GetSize() );
441 wxSize
client_size( window
->GetClientSize() );
442 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
443 minSize
.y
+size
.y
-client_size
.y
);
446 // Return a window size that will fit within the screens dimensions
447 wxSize
wxSizer::FitSize( wxWindow
*window
)
449 wxSize size
= GetMinWindowSize( window
);
450 wxSize sizeMax
= GetMaxWindowSize( window
);
452 // Limit the size if sizeMax != wxDefaultSize
454 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
456 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
462 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
472 wxSize
wxSizer::GetMinSize()
474 wxSize
ret( CalcMin() );
475 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
476 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
480 void wxSizer::DoSetMinSize( int width
, int height
)
483 m_minSize
.y
= height
;
486 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
490 wxNode
*node
= m_children
.First();
493 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
494 if (item
->GetWindow() == window
)
496 item
->SetInitSize( width
, height
);
502 node
= m_children
.First();
505 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
506 if (item
->GetSizer())
508 /* It's a sizer, so lets search recursively. */
509 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
511 /* A child sizer found the requested windw, exit. */
521 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
525 wxNode
*node
= m_children
.First();
528 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
529 if (item
->GetSizer() == sizer
)
531 item
->GetSizer()->DoSetMinSize( width
, height
);
537 node
= m_children
.First();
540 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
541 if (item
->GetSizer())
543 /* It's a sizer, so lets search recursively. */
544 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
546 /* A child sizer found the requested windw, exit. */
556 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
558 wxNode
*node
= m_children
.Nth( pos
);
559 if (!node
) return FALSE
;
561 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
562 if (item
->GetSizer())
564 /* Sizers contains the minimal size in them, if not calculated ... */
565 item
->GetSizer()->DoSetMinSize( width
, height
);
569 /* ... whereas the minimal size of spacers and windows in stored
571 item
->SetInitSize( width
, height
);
577 //---------------------------------------------------------------------------
579 //---------------------------------------------------------------------------
581 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
589 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
597 void wxGridSizer::RecalcSizes()
599 if (m_children
.GetCount() == 0)
602 int nitems
= m_children
.GetCount();
607 nrows
= (nitems
+ ncols
-1) / ncols
;
609 ncols
= (nitems
+ nrows
-1) / nrows
;
611 wxSize
sz( GetSize() );
612 wxPoint
pt( GetPosition() );
614 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
615 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
618 for (int c
= 0; c
< ncols
; c
++)
621 for (int r
= 0; r
< nrows
; r
++)
623 int i
= r
* ncols
+ c
;
626 wxNode
*node
= m_children
.Nth( i
);
629 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
637 wxSize
wxGridSizer::CalcMin()
639 if (m_children
.GetCount() == 0)
640 return wxSize(10,10);
642 int nitems
= m_children
.GetCount();
647 nrows
= (nitems
+ ncols
-1) / ncols
;
649 ncols
= (nitems
+ nrows
-1) / nrows
;
651 /* Find the max width and height for any component */
655 wxNode
*node
= m_children
.First();
658 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
659 wxSize
sz( item
->CalcMin() );
660 w
= wxMax( w
, sz
.x
);
661 h
= wxMax( h
, sz
.y
);
666 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
667 nrows
* h
+ (nrows
-1) * m_vgap
);
670 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
673 wxSize
sz( item
->CalcMin() );
674 int flag
= item
->GetFlag();
676 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
682 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
684 pt
.x
= x
+ (w
- sz
.x
) / 2;
686 else if (flag
& wxALIGN_RIGHT
)
688 pt
.x
= x
+ (w
- sz
.x
);
691 if (flag
& wxALIGN_CENTER_VERTICAL
)
693 pt
.y
= y
+ (h
- sz
.y
) / 2;
695 else if (flag
& wxALIGN_BOTTOM
)
697 pt
.y
= y
+ (h
- sz
.y
);
701 item
->SetDimension(pt
, sz
);
704 //---------------------------------------------------------------------------
706 //---------------------------------------------------------------------------
708 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
709 : wxGridSizer( rows
, cols
, vgap
, hgap
)
711 m_rowHeights
= (int*) NULL
;
712 m_colWidths
= (int*) NULL
;
715 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
716 : wxGridSizer( cols
, vgap
, hgap
)
718 m_rowHeights
= (int*) NULL
;
719 m_colWidths
= (int*) NULL
;
722 wxFlexGridSizer::~wxFlexGridSizer()
725 delete[] m_rowHeights
;
727 delete[] m_colWidths
;
730 void wxFlexGridSizer::CreateArrays()
733 delete[] m_rowHeights
;
735 delete[] m_colWidths
;
737 if (m_children
.GetCount() == 0)
740 int nitems
= m_children
.GetCount();
745 nrows
= (nitems
+ ncols
-1) / ncols
;
747 ncols
= (nitems
+ nrows
-1) / nrows
;
749 m_rowHeights
= new int[nrows
];
750 m_colWidths
= new int[ncols
];
752 for (int col
= 0; col
< ncols
; col
++)
753 m_colWidths
[ col
] = 0;
754 for (int row
= 0; row
< nrows
; row
++)
755 m_rowHeights
[ row
] = 0;
758 void wxFlexGridSizer::RecalcSizes()
760 if (m_children
.GetCount() == 0)
763 int nitems
= m_children
.GetCount();
768 nrows
= (nitems
+ ncols
-1) / ncols
;
770 ncols
= (nitems
+ nrows
-1) / nrows
;
772 wxSize
sz( GetSize() );
773 wxSize
minsz( CalcMin() );
774 wxPoint
pt( GetPosition() );
778 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
780 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
781 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
782 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
785 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
787 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
788 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
789 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
792 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
795 for (int c
= 0; c
< ncols
; c
++)
798 for (int r
= 0; r
< nrows
; r
++)
800 int i
= r
* ncols
+ c
;
803 wxNode
*node
= m_children
.Nth( i
);
806 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
807 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
809 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
811 y
= y
+ m_rowHeights
[r
] + m_vgap
;
813 x
= x
+ m_colWidths
[c
] + m_hgap
;
817 wxSize
wxFlexGridSizer::CalcMin()
819 if (m_children
.GetCount() == 0)
820 return wxSize(10,10);
822 int nitems
= m_children
.GetCount();
827 nrows
= (nitems
+ ncols
-1) / ncols
;
829 ncols
= (nitems
+ nrows
-1) / nrows
;
837 wxNode
*node
= m_children
.First();
840 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
841 wxSize
sz( item
->CalcMin() );
844 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
845 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
852 for (col
= 0; col
< ncols
; col
++)
853 width
+= m_colWidths
[ col
];
856 for (row
= 0; row
< nrows
; row
++)
857 height
+= m_rowHeights
[ row
];
859 return wxSize( width
+ (ncols
-1) * m_hgap
,
860 height
+ (nrows
-1) * m_vgap
);
863 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
865 m_growableRows
.Add( idx
);
868 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
872 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
874 m_growableCols
.Add( idx
);
877 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
881 //---------------------------------------------------------------------------
883 //---------------------------------------------------------------------------
885 wxBoxSizer::wxBoxSizer( int orient
)
890 void wxBoxSizer::RecalcSizes()
892 if (m_children
.GetCount() == 0)
899 if (m_orient
== wxHORIZONTAL
)
901 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
902 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
906 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
907 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
911 wxPoint
pt( m_position
);
913 wxNode
*node
= m_children
.GetFirst();
916 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
919 if (item
->GetOption())
920 weight
= item
->GetOption();
922 wxSize
size( item
->CalcMin() );
924 if (m_orient
== wxVERTICAL
)
926 wxCoord height
= size
.y
;
927 if (item
->GetOption())
929 height
= (delta
* weight
) + extra
;
930 extra
= 0; // only the first item will get the remainder as extra size
933 wxPoint
child_pos( pt
);
934 wxSize
child_size( wxSize( size
.x
, height
) );
936 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
937 child_size
.x
= m_size
.x
;
938 else if (item
->GetFlag() & wxALIGN_RIGHT
)
939 child_pos
.x
+= m_size
.x
- size
.x
;
940 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
941 // XXX wxCENTER is added for backward compatibility;
942 // wxALIGN_CENTER should be used in new code
943 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
945 item
->SetDimension( child_pos
, child_size
);
951 wxCoord width
= size
.x
;
952 if (item
->GetOption())
954 width
= (delta
* weight
) + extra
;
955 extra
= 0; // only the first item will get the remainder as extra size
958 wxPoint
child_pos( pt
);
959 wxSize
child_size( wxSize(width
, size
.y
) );
961 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
962 child_size
.y
= m_size
.y
;
963 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
964 child_pos
.y
+= m_size
.y
- size
.y
;
965 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
966 // XXX wxCENTER is added for backward compatibility;
967 // wxALIGN_CENTER should be used in new code
968 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
970 item
->SetDimension( child_pos
, child_size
);
979 wxSize
wxBoxSizer::CalcMin()
981 if (m_children
.GetCount() == 0)
982 return wxSize(10,10);
990 // Find how long each stretch unit needs to be
992 wxNode
*node
= m_children
.GetFirst();
995 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
996 if (item
->GetOption() != 0)
998 int stretch
= item
->GetOption();
999 wxSize
size( item
->CalcMin() );
1001 // Integer division rounded up is (a + b - 1) / b
1002 if (m_orient
== wxHORIZONTAL
)
1003 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
1005 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
1006 if (sizePerStretch
> stretchSize
)
1007 stretchSize
= sizePerStretch
;
1009 node
= node
->Next();
1011 // Calculate overall minimum size
1012 node
= m_children
.GetFirst();
1015 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1017 m_stretchable
+= item
->GetOption();
1019 wxSize
size( item
->CalcMin() );
1020 if (item
->GetOption() != 0)
1022 if (m_orient
== wxHORIZONTAL
)
1023 size
.x
= stretchSize
* item
->GetOption();
1025 size
.y
= stretchSize
* item
->GetOption();
1028 if (m_orient
== wxHORIZONTAL
)
1030 m_minWidth
+= size
.x
;
1031 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1035 m_minHeight
+= size
.y
;
1036 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1039 if (item
->GetOption() == 0)
1041 if (m_orient
== wxVERTICAL
)
1043 m_fixedHeight
+= size
.y
;
1044 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1048 m_fixedWidth
+= size
.x
;
1049 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1053 node
= node
->Next();
1056 return wxSize( m_minWidth
, m_minHeight
);
1059 //---------------------------------------------------------------------------
1061 //---------------------------------------------------------------------------
1065 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1066 : wxBoxSizer( orient
)
1068 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1073 static void GetStaticBoxBorders(wxStaticBox
*box
,
1074 int *borderTop
, int *borderOther
)
1076 // this has to be done platform by platform as there is no way to
1077 // guess the thickness of a wxStaticBox border
1079 if ( box
->GetLabel().IsEmpty() )
1088 void wxStaticBoxSizer::RecalcSizes()
1090 int top_border
, other_border
;
1091 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1093 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1095 wxPoint
old_pos( m_position
);
1096 m_position
.x
+= other_border
;
1097 m_position
.y
+= top_border
;
1098 wxSize
old_size( m_size
);
1099 m_size
.x
-= 2*other_border
;
1100 m_size
.y
-= top_border
+ other_border
;
1102 wxBoxSizer::RecalcSizes();
1104 m_position
= old_pos
;
1108 wxSize
wxStaticBoxSizer::CalcMin()
1110 int top_border
, other_border
;
1111 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1113 wxSize
ret( wxBoxSizer::CalcMin() );
1114 ret
.x
+= 2*other_border
;
1115 ret
.y
+= other_border
+ top_border
;
1120 #endif // wxUSE_STATBOX
1122 //---------------------------------------------------------------------------
1124 //---------------------------------------------------------------------------
1128 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1130 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1135 void wxNotebookSizer::RecalcSizes()
1137 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1140 wxSize
wxNotebookSizer::CalcMin()
1142 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1147 if (m_notebook
->GetChildren().GetCount() == 0)
1149 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1155 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1158 wxWindow
*item
= node
->GetData();
1159 wxSizer
*itemsizer
= item
->GetSizer();
1163 wxSize
subsize( itemsizer
->CalcMin() );
1165 if (subsize
.x
> maxX
)
1167 if (subsize
.y
> maxY
)
1171 node
= node
->GetNext();
1174 return wxSize( maxX
, maxY
) + sizeBorder
;
1177 #endif // wxUSE_NOTEBOOK