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->SetClientSize( size );
412 window
->SetSize( size
);
415 void wxSizer::Layout()
421 void wxSizer::SetSizeHints( wxWindow
*window
)
423 // Preserve the window's max size hints, but set the
424 // lower bound according to the sizer calculations.
426 wxSize size
= FitSize( window
);
427 window
->SetSizeHints( size
.x
,
429 window
->GetMaxWidth(),
430 window
->GetMaxHeight() );
433 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
)
435 return window
->GetMaxSize();
438 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
440 wxSize
minSize( GetMinSize() );
441 wxSize
size( window
->GetSize() );
442 wxSize
client_size( window
->GetClientSize() );
443 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
444 minSize
.y
+size
.y
-client_size
.y
);
447 // Return a window size that will fit within the screens dimensions
448 wxSize
wxSizer::FitSize( wxWindow
*window
)
450 wxSize size
= GetMinWindowSize( window
);
451 wxSize sizeMax
= GetMaxWindowSize( window
);
453 // Limit the size if sizeMax != wxDefaultSize
455 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
457 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
463 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
473 wxSize
wxSizer::GetMinSize()
475 wxSize
ret( CalcMin() );
476 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
477 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
481 void wxSizer::DoSetMinSize( int width
, int height
)
484 m_minSize
.y
= height
;
487 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
491 wxNode
*node
= m_children
.First();
494 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
495 if (item
->GetWindow() == window
)
497 item
->SetInitSize( width
, height
);
503 node
= m_children
.First();
506 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
507 if (item
->GetSizer())
509 /* It's a sizer, so lets search recursively. */
510 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
512 /* A child sizer found the requested windw, exit. */
522 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
526 wxNode
*node
= m_children
.First();
529 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
530 if (item
->GetSizer() == sizer
)
532 item
->GetSizer()->DoSetMinSize( width
, height
);
538 node
= m_children
.First();
541 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
542 if (item
->GetSizer())
544 /* It's a sizer, so lets search recursively. */
545 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
547 /* A child sizer found the requested windw, exit. */
557 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
559 wxNode
*node
= m_children
.Nth( pos
);
560 if (!node
) return FALSE
;
562 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
563 if (item
->GetSizer())
565 /* Sizers contains the minimal size in them, if not calculated ... */
566 item
->GetSizer()->DoSetMinSize( width
, height
);
570 /* ... whereas the minimal size of spacers and windows in stored
572 item
->SetInitSize( width
, height
);
578 //---------------------------------------------------------------------------
580 //---------------------------------------------------------------------------
582 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
590 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
598 void wxGridSizer::RecalcSizes()
600 if (m_children
.GetCount() == 0)
603 int nitems
= m_children
.GetCount();
608 nrows
= (nitems
+ ncols
-1) / ncols
;
610 ncols
= (nitems
+ nrows
-1) / nrows
;
612 wxSize
sz( GetSize() );
613 wxPoint
pt( GetPosition() );
615 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
616 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
619 for (int c
= 0; c
< ncols
; c
++)
622 for (int r
= 0; r
< nrows
; r
++)
624 int i
= r
* ncols
+ c
;
627 wxNode
*node
= m_children
.Nth( i
);
630 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
638 wxSize
wxGridSizer::CalcMin()
640 if (m_children
.GetCount() == 0)
641 return wxSize(10,10);
643 int nitems
= m_children
.GetCount();
648 nrows
= (nitems
+ ncols
-1) / ncols
;
650 ncols
= (nitems
+ nrows
-1) / nrows
;
652 /* Find the max width and height for any component */
656 wxNode
*node
= m_children
.First();
659 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
660 wxSize
sz( item
->CalcMin() );
661 w
= wxMax( w
, sz
.x
);
662 h
= wxMax( h
, sz
.y
);
667 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
668 nrows
* h
+ (nrows
-1) * m_vgap
);
671 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
674 wxSize
sz( item
->CalcMin() );
675 int flag
= item
->GetFlag();
677 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
683 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
685 pt
.x
= x
+ (w
- sz
.x
) / 2;
687 else if (flag
& wxALIGN_RIGHT
)
689 pt
.x
= x
+ (w
- sz
.x
);
692 if (flag
& wxALIGN_CENTER_VERTICAL
)
694 pt
.y
= y
+ (h
- sz
.y
) / 2;
696 else if (flag
& wxALIGN_BOTTOM
)
698 pt
.y
= y
+ (h
- sz
.y
);
702 item
->SetDimension(pt
, sz
);
705 //---------------------------------------------------------------------------
707 //---------------------------------------------------------------------------
709 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
710 : wxGridSizer( rows
, cols
, vgap
, hgap
)
712 m_rowHeights
= (int*) NULL
;
713 m_colWidths
= (int*) NULL
;
716 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
717 : wxGridSizer( cols
, vgap
, hgap
)
719 m_rowHeights
= (int*) NULL
;
720 m_colWidths
= (int*) NULL
;
723 wxFlexGridSizer::~wxFlexGridSizer()
726 delete[] m_rowHeights
;
728 delete[] m_colWidths
;
731 void wxFlexGridSizer::CreateArrays()
734 delete[] m_rowHeights
;
736 delete[] m_colWidths
;
738 if (m_children
.GetCount() == 0)
741 int nitems
= m_children
.GetCount();
746 nrows
= (nitems
+ ncols
-1) / ncols
;
748 ncols
= (nitems
+ nrows
-1) / nrows
;
750 m_rowHeights
= new int[nrows
];
751 m_colWidths
= new int[ncols
];
753 for (int col
= 0; col
< ncols
; col
++)
754 m_colWidths
[ col
] = 0;
755 for (int row
= 0; row
< nrows
; row
++)
756 m_rowHeights
[ row
] = 0;
759 void wxFlexGridSizer::RecalcSizes()
761 if (m_children
.GetCount() == 0)
764 int nitems
= m_children
.GetCount();
769 nrows
= (nitems
+ ncols
-1) / ncols
;
771 ncols
= (nitems
+ nrows
-1) / nrows
;
773 wxSize
sz( GetSize() );
774 wxSize
minsz( CalcMin() );
775 wxPoint
pt( GetPosition() );
779 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
781 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
782 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
783 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
786 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
788 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
789 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
790 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
793 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
796 for (int c
= 0; c
< ncols
; c
++)
799 for (int r
= 0; r
< nrows
; r
++)
801 int i
= r
* ncols
+ c
;
804 wxNode
*node
= m_children
.Nth( i
);
807 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
808 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
810 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
812 y
= y
+ m_rowHeights
[r
] + m_vgap
;
814 x
= x
+ m_colWidths
[c
] + m_hgap
;
818 wxSize
wxFlexGridSizer::CalcMin()
820 if (m_children
.GetCount() == 0)
821 return wxSize(10,10);
823 int nitems
= m_children
.GetCount();
828 nrows
= (nitems
+ ncols
-1) / ncols
;
830 ncols
= (nitems
+ nrows
-1) / nrows
;
838 wxNode
*node
= m_children
.First();
841 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
842 wxSize
sz( item
->CalcMin() );
845 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
846 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
853 for (col
= 0; col
< ncols
; col
++)
854 width
+= m_colWidths
[ col
];
857 for (row
= 0; row
< nrows
; row
++)
858 height
+= m_rowHeights
[ row
];
860 return wxSize( width
+ (ncols
-1) * m_hgap
,
861 height
+ (nrows
-1) * m_vgap
);
864 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
866 m_growableRows
.Add( idx
);
869 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
873 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
875 m_growableCols
.Add( idx
);
878 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
882 //---------------------------------------------------------------------------
884 //---------------------------------------------------------------------------
886 wxBoxSizer::wxBoxSizer( int orient
)
891 void wxBoxSizer::RecalcSizes()
893 if (m_children
.GetCount() == 0)
900 if (m_orient
== wxHORIZONTAL
)
902 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
903 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
907 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
908 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
912 wxPoint
pt( m_position
);
914 wxNode
*node
= m_children
.GetFirst();
917 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
920 if (item
->GetOption())
921 weight
= item
->GetOption();
923 wxSize
size( item
->CalcMin() );
925 if (m_orient
== wxVERTICAL
)
927 wxCoord height
= size
.y
;
928 if (item
->GetOption())
930 height
= (delta
* weight
) + extra
;
931 extra
= 0; // only the first item will get the remainder as extra size
934 wxPoint
child_pos( pt
);
935 wxSize
child_size( wxSize( size
.x
, height
) );
937 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
938 child_size
.x
= m_size
.x
;
939 else if (item
->GetFlag() & wxALIGN_RIGHT
)
940 child_pos
.x
+= m_size
.x
- size
.x
;
941 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
942 // XXX wxCENTER is added for backward compatibility;
943 // wxALIGN_CENTER should be used in new code
944 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
946 item
->SetDimension( child_pos
, child_size
);
952 wxCoord width
= size
.x
;
953 if (item
->GetOption())
955 width
= (delta
* weight
) + extra
;
956 extra
= 0; // only the first item will get the remainder as extra size
959 wxPoint
child_pos( pt
);
960 wxSize
child_size( wxSize(width
, size
.y
) );
962 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
963 child_size
.y
= m_size
.y
;
964 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
965 child_pos
.y
+= m_size
.y
- size
.y
;
966 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
967 // XXX wxCENTER is added for backward compatibility;
968 // wxALIGN_CENTER should be used in new code
969 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
971 item
->SetDimension( child_pos
, child_size
);
980 wxSize
wxBoxSizer::CalcMin()
982 if (m_children
.GetCount() == 0)
983 return wxSize(10,10);
991 // Find how long each stretch unit needs to be
993 wxNode
*node
= m_children
.GetFirst();
996 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
997 if (item
->GetOption() != 0)
999 int stretch
= item
->GetOption();
1000 wxSize
size( item
->CalcMin() );
1002 // Integer division rounded up is (a + b - 1) / b
1003 if (m_orient
== wxHORIZONTAL
)
1004 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
1006 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
1007 if (sizePerStretch
> stretchSize
)
1008 stretchSize
= sizePerStretch
;
1010 node
= node
->Next();
1012 // Calculate overall minimum size
1013 node
= m_children
.GetFirst();
1016 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1018 m_stretchable
+= item
->GetOption();
1020 wxSize
size( item
->CalcMin() );
1021 if (item
->GetOption() != 0)
1023 if (m_orient
== wxHORIZONTAL
)
1024 size
.x
= stretchSize
* item
->GetOption();
1026 size
.y
= stretchSize
* item
->GetOption();
1029 if (m_orient
== wxHORIZONTAL
)
1031 m_minWidth
+= size
.x
;
1032 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1036 m_minHeight
+= size
.y
;
1037 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1040 if (item
->GetOption() == 0)
1042 if (m_orient
== wxVERTICAL
)
1044 m_fixedHeight
+= size
.y
;
1045 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1049 m_fixedWidth
+= size
.x
;
1050 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1054 node
= node
->Next();
1057 return wxSize( m_minWidth
, m_minHeight
);
1060 //---------------------------------------------------------------------------
1062 //---------------------------------------------------------------------------
1066 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1067 : wxBoxSizer( orient
)
1069 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1074 static void GetStaticBoxBorders(wxStaticBox
*box
,
1075 int *borderTop
, int *borderOther
)
1077 // this has to be done platform by platform as there is no way to
1078 // guess the thickness of a wxStaticBox border
1080 if ( box
->GetLabel().IsEmpty() )
1089 void wxStaticBoxSizer::RecalcSizes()
1091 int top_border
, other_border
;
1092 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1094 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1096 wxPoint
old_pos( m_position
);
1097 m_position
.x
+= other_border
;
1098 m_position
.y
+= top_border
;
1099 wxSize
old_size( m_size
);
1100 m_size
.x
-= 2*other_border
;
1101 m_size
.y
-= top_border
+ other_border
;
1103 wxBoxSizer::RecalcSizes();
1105 m_position
= old_pos
;
1109 wxSize
wxStaticBoxSizer::CalcMin()
1111 int top_border
, other_border
;
1112 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1114 wxSize
ret( wxBoxSizer::CalcMin() );
1115 ret
.x
+= 2*other_border
;
1116 ret
.y
+= other_border
+ top_border
;
1121 #endif // wxUSE_STATBOX
1123 //---------------------------------------------------------------------------
1125 //---------------------------------------------------------------------------
1129 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1131 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1136 void wxNotebookSizer::RecalcSizes()
1138 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1141 wxSize
wxNotebookSizer::CalcMin()
1143 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1148 if (m_notebook
->GetChildren().GetCount() == 0)
1150 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1156 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1159 wxWindow
*item
= node
->GetData();
1160 wxSizer
*itemsizer
= item
->GetSizer();
1164 wxSize
subsize( itemsizer
->CalcMin() );
1166 if (subsize
.x
> maxX
)
1168 if (subsize
.y
> maxY
)
1172 node
= node
->GetNext();
1175 return wxSize( maxX
, maxY
) + sizeBorder
;
1178 #endif // wxUSE_NOTEBOOK