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 wxSize size
= FitSize( window
);
423 window
->SetSizeHints( size
.x
, size
.y
);
426 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*WXUNUSED(window
) )
428 wxRect rect
= wxGetClientDisplayRect();
429 wxSize
sizeMax (rect
.width
,rect
.height
);
431 // Sorry, but this bit is wrong -- it makes a window that should just be
432 // able to fit onto the screen, not fit on the screen. -- JACS
434 // Make the max size a bit smaller than the visible portion of
435 // the screen. A window which takes the entire screen doesn't
436 // look very nice either
447 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
449 wxSize
minSize( GetMinSize() );
450 wxSize
size( window
->GetSize() );
451 wxSize
client_size( window
->GetClientSize() );
452 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
453 minSize
.y
+size
.y
-client_size
.y
);
456 // Return a window size that will fit within the screens dimensions
457 wxSize
wxSizer::FitSize( wxWindow
*window
)
459 wxSize size
= GetMinWindowSize( window
);
460 wxSize sizeMax
= GetMaxWindowSize( window
);
462 if ( size
.x
> sizeMax
.x
)
464 if ( size
.y
> sizeMax
.y
)
470 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
480 wxSize
wxSizer::GetMinSize()
482 wxSize
ret( CalcMin() );
483 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
484 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
488 void wxSizer::DoSetMinSize( int width
, int height
)
491 m_minSize
.y
= height
;
494 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
498 wxNode
*node
= m_children
.First();
501 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
502 if (item
->GetWindow() == window
)
504 item
->SetInitSize( width
, height
);
510 node
= m_children
.First();
513 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
514 if (item
->GetSizer())
516 /* It's a sizer, so lets search recursively. */
517 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
519 /* A child sizer found the requested windw, exit. */
529 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
533 wxNode
*node
= m_children
.First();
536 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
537 if (item
->GetSizer() == sizer
)
539 item
->GetSizer()->DoSetMinSize( width
, height
);
545 node
= m_children
.First();
548 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
549 if (item
->GetSizer())
551 /* It's a sizer, so lets search recursively. */
552 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
554 /* A child sizer found the requested windw, exit. */
564 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
566 wxNode
*node
= m_children
.Nth( pos
);
567 if (!node
) return FALSE
;
569 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
570 if (item
->GetSizer())
572 /* Sizers contains the minimal size in them, if not calculated ... */
573 item
->GetSizer()->DoSetMinSize( width
, height
);
577 /* ... whereas the minimal size of spacers and windows in stored
579 item
->SetInitSize( width
, height
);
585 //---------------------------------------------------------------------------
587 //---------------------------------------------------------------------------
589 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
597 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
605 void wxGridSizer::RecalcSizes()
607 if (m_children
.GetCount() == 0)
610 int nitems
= m_children
.GetCount();
615 nrows
= (nitems
+ ncols
-1) / ncols
;
617 ncols
= (nitems
+ nrows
-1) / nrows
;
619 wxSize
sz( GetSize() );
620 wxPoint
pt( GetPosition() );
622 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
623 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
626 for (int c
= 0; c
< ncols
; c
++)
629 for (int r
= 0; r
< nrows
; r
++)
631 int i
= r
* ncols
+ c
;
634 wxNode
*node
= m_children
.Nth( i
);
637 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
645 wxSize
wxGridSizer::CalcMin()
647 if (m_children
.GetCount() == 0)
648 return wxSize(10,10);
650 int nitems
= m_children
.GetCount();
655 nrows
= (nitems
+ ncols
-1) / ncols
;
657 ncols
= (nitems
+ nrows
-1) / nrows
;
659 /* Find the max width and height for any component */
663 wxNode
*node
= m_children
.First();
666 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
667 wxSize
sz( item
->CalcMin() );
668 w
= wxMax( w
, sz
.x
);
669 h
= wxMax( h
, sz
.y
);
674 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
675 nrows
* h
+ (nrows
-1) * m_vgap
);
678 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
681 wxSize
sz( item
->CalcMin() );
682 int flag
= item
->GetFlag();
684 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
690 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
692 pt
.x
= x
+ (w
- sz
.x
) / 2;
694 else if (flag
& wxALIGN_RIGHT
)
696 pt
.x
= x
+ (w
- sz
.x
);
699 if (flag
& wxALIGN_CENTER_VERTICAL
)
701 pt
.y
= y
+ (h
- sz
.y
) / 2;
703 else if (flag
& wxALIGN_BOTTOM
)
705 pt
.y
= y
+ (h
- sz
.y
);
709 item
->SetDimension(pt
, sz
);
712 //---------------------------------------------------------------------------
714 //---------------------------------------------------------------------------
716 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
717 : wxGridSizer( rows
, cols
, vgap
, hgap
)
719 m_rowHeights
= (int*) NULL
;
720 m_colWidths
= (int*) NULL
;
723 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
724 : wxGridSizer( cols
, vgap
, hgap
)
726 m_rowHeights
= (int*) NULL
;
727 m_colWidths
= (int*) NULL
;
730 wxFlexGridSizer::~wxFlexGridSizer()
733 delete[] m_rowHeights
;
735 delete[] m_colWidths
;
738 void wxFlexGridSizer::CreateArrays()
741 delete[] m_rowHeights
;
743 delete[] m_colWidths
;
745 if (m_children
.GetCount() == 0)
748 int nitems
= m_children
.GetCount();
753 nrows
= (nitems
+ ncols
-1) / ncols
;
755 ncols
= (nitems
+ nrows
-1) / nrows
;
757 m_rowHeights
= new int[nrows
];
758 m_colWidths
= new int[ncols
];
760 for (int col
= 0; col
< ncols
; col
++)
761 m_colWidths
[ col
] = 0;
762 for (int row
= 0; row
< nrows
; row
++)
763 m_rowHeights
[ row
] = 0;
766 void wxFlexGridSizer::RecalcSizes()
768 if (m_children
.GetCount() == 0)
771 int nitems
= m_children
.GetCount();
776 nrows
= (nitems
+ ncols
-1) / ncols
;
778 ncols
= (nitems
+ nrows
-1) / nrows
;
780 wxSize
sz( GetSize() );
781 wxSize
minsz( CalcMin() );
782 wxPoint
pt( GetPosition() );
786 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
788 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
789 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
790 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
793 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
795 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
796 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
797 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
800 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
803 for (int c
= 0; c
< ncols
; c
++)
806 for (int r
= 0; r
< nrows
; r
++)
808 int i
= r
* ncols
+ c
;
811 wxNode
*node
= m_children
.Nth( i
);
814 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
815 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
817 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
819 y
= y
+ m_rowHeights
[r
] + m_vgap
;
821 x
= x
+ m_colWidths
[c
] + m_hgap
;
825 wxSize
wxFlexGridSizer::CalcMin()
827 if (m_children
.GetCount() == 0)
828 return wxSize(10,10);
830 int nitems
= m_children
.GetCount();
835 nrows
= (nitems
+ ncols
-1) / ncols
;
837 ncols
= (nitems
+ nrows
-1) / nrows
;
845 wxNode
*node
= m_children
.First();
848 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
849 wxSize
sz( item
->CalcMin() );
852 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
853 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
860 for (col
= 0; col
< ncols
; col
++)
861 width
+= m_colWidths
[ col
];
864 for (row
= 0; row
< nrows
; row
++)
865 height
+= m_rowHeights
[ row
];
867 return wxSize( width
+ (ncols
-1) * m_hgap
,
868 height
+ (nrows
-1) * m_vgap
);
871 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
873 m_growableRows
.Add( idx
);
876 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
880 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
882 m_growableCols
.Add( idx
);
885 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
889 //---------------------------------------------------------------------------
891 //---------------------------------------------------------------------------
893 wxBoxSizer::wxBoxSizer( int orient
)
898 void wxBoxSizer::RecalcSizes()
900 if (m_children
.GetCount() == 0)
907 if (m_orient
== wxHORIZONTAL
)
909 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
910 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
914 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
915 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
919 wxPoint
pt( m_position
);
921 wxNode
*node
= m_children
.GetFirst();
924 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
927 if (item
->GetOption())
928 weight
= item
->GetOption();
930 wxSize
size( item
->CalcMin() );
932 if (m_orient
== wxVERTICAL
)
934 wxCoord height
= size
.y
;
935 if (item
->GetOption())
937 height
= (delta
* weight
) + extra
;
938 extra
= 0; // only the first item will get the remainder as extra size
941 wxPoint
child_pos( pt
);
942 wxSize
child_size( wxSize( size
.x
, height
) );
944 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
945 child_size
.x
= m_size
.x
;
946 else if (item
->GetFlag() & wxALIGN_RIGHT
)
947 child_pos
.x
+= m_size
.x
- size
.x
;
948 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
949 // XXX wxCENTER is added for backward compatibility;
950 // wxALIGN_CENTER should be used in new code
951 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
953 item
->SetDimension( child_pos
, child_size
);
959 wxCoord width
= size
.x
;
960 if (item
->GetOption())
962 width
= (delta
* weight
) + extra
;
963 extra
= 0; // only the first item will get the remainder as extra size
966 wxPoint
child_pos( pt
);
967 wxSize
child_size( wxSize(width
, size
.y
) );
969 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
970 child_size
.y
= m_size
.y
;
971 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
972 child_pos
.y
+= m_size
.y
- size
.y
;
973 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
974 // XXX wxCENTER is added for backward compatibility;
975 // wxALIGN_CENTER should be used in new code
976 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
978 item
->SetDimension( child_pos
, child_size
);
987 wxSize
wxBoxSizer::CalcMin()
989 if (m_children
.GetCount() == 0)
990 return wxSize(10,10);
998 // Find how long each stretch unit needs to be
1000 wxNode
*node
= m_children
.GetFirst();
1003 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1004 if (item
->GetOption() != 0)
1006 int stretch
= item
->GetOption();
1007 wxSize
size( item
->CalcMin() );
1009 // Integer division rounded up is (a + b - 1) / b
1010 if (m_orient
== wxHORIZONTAL
)
1011 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
1013 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
1014 if (sizePerStretch
> stretchSize
)
1015 stretchSize
= sizePerStretch
;
1017 node
= node
->Next();
1019 // Calculate overall minimum size
1020 node
= m_children
.GetFirst();
1023 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1025 m_stretchable
+= item
->GetOption();
1027 wxSize
size( item
->CalcMin() );
1028 if (item
->GetOption() != 0)
1030 if (m_orient
== wxHORIZONTAL
)
1031 size
.x
= stretchSize
* item
->GetOption();
1033 size
.y
= stretchSize
* item
->GetOption();
1036 if (m_orient
== wxHORIZONTAL
)
1038 m_minWidth
+= size
.x
;
1039 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1043 m_minHeight
+= size
.y
;
1044 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1047 if (item
->GetOption() == 0)
1049 if (m_orient
== wxVERTICAL
)
1051 m_fixedHeight
+= size
.y
;
1052 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1056 m_fixedWidth
+= size
.x
;
1057 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1061 node
= node
->Next();
1064 return wxSize( m_minWidth
, m_minHeight
);
1067 //---------------------------------------------------------------------------
1069 //---------------------------------------------------------------------------
1073 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1074 : wxBoxSizer( orient
)
1076 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1081 static void GetStaticBoxBorders(wxStaticBox
*box
,
1082 int *borderTop
, int *borderOther
)
1084 // this has to be done platform by platform as there is no way to
1085 // guess the thickness of a wxStaticBox border
1087 if ( box
->GetLabel().IsEmpty() )
1096 void wxStaticBoxSizer::RecalcSizes()
1098 int top_border
, other_border
;
1099 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1101 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1103 wxPoint
old_pos( m_position
);
1104 m_position
.x
+= other_border
;
1105 m_position
.y
+= top_border
;
1106 wxSize
old_size( m_size
);
1107 m_size
.x
-= 2*other_border
;
1108 m_size
.y
-= top_border
+ other_border
;
1110 wxBoxSizer::RecalcSizes();
1112 m_position
= old_pos
;
1116 wxSize
wxStaticBoxSizer::CalcMin()
1118 int top_border
, other_border
;
1119 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1121 wxSize
ret( wxBoxSizer::CalcMin() );
1122 ret
.x
+= 2*other_border
;
1123 ret
.y
+= other_border
+ top_border
;
1128 #endif // wxUSE_STATBOX
1130 //---------------------------------------------------------------------------
1132 //---------------------------------------------------------------------------
1136 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1138 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1143 void wxNotebookSizer::RecalcSizes()
1145 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1148 wxSize
wxNotebookSizer::CalcMin()
1150 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1155 if (m_notebook
->GetChildren().GetCount() == 0)
1157 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1163 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1166 wxWindow
*item
= node
->GetData();
1167 wxSizer
*itemsizer
= item
->GetSizer();
1171 wxSize
subsize( itemsizer
->CalcMin() );
1173 if (subsize
.x
> maxX
)
1175 if (subsize
.y
> maxY
)
1179 node
= node
->GetNext();
1182 return wxSize( maxX
, maxY
) + sizeBorder
;
1185 #endif // wxUSE_NOTEBOOK