]> git.saurik.com Git - wxWidgets.git/commitdiff
Ensure that size in the minor direction of box sizer doesn't exceed the total.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Mar 2010 15:07:19 +0000 (15:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Mar 2010 15:07:19 +0000 (15:07 +0000)
This is similar to the previous commit but for the transversal direction of a
box sizer: we could give an item size larger than the size of the sizer itself
making only part of its window visible (and thus potentially making the window
unusable e.g. because the scrollbar wasn't visible at all).

Fix this by always restricting the item size in the minor direction to the
total size available and add a unit test which failed previously and passes
now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/sizer.cpp
tests/sizers/boxsizer.cpp

index ad0abd60edaa85ea3f8e3c965b531194cfd0ec6b..a5a68e5c07f03930192876ad0ecb16f369e264e3 100644 (file)
@@ -2087,8 +2087,12 @@ void wxBoxSizer::RecalcSizes()
 
         wxCoord minorSize = GetSizeInMinorDir(sizeThis);
         const int flag = item->GetFlag();
-        if ( flag & (wxEXPAND | wxSHAPED) )
+        if ( (flag & (wxEXPAND | wxSHAPED)) || (minorSize > totalMinorSize) )
         {
+            // occupy all the available space if wxEXPAND was given and also if
+            // the item is too big to fit -- in this case we truncate it below
+            // its minimal size which is bad but better than not showing parts
+            // of the window at all
             minorSize = totalMinorSize;
         }
         else if ( flag & (IsVertical() ? wxALIGN_RIGHT : wxALIGN_BOTTOM) )
@@ -2097,7 +2101,8 @@ void wxBoxSizer::RecalcSizes()
         }
         // NB: wxCENTRE is used here only for backwards compatibility,
         //     wxALIGN_CENTRE should be used in new code
-        else if ( flag & (wxCENTER | (IsVertical() ? wxALIGN_CENTRE_HORIZONTAL : wxALIGN_CENTRE_VERTICAL)))
+        else if ( flag & (wxCENTER | (IsVertical() ? wxALIGN_CENTRE_HORIZONTAL
+                                                   : wxALIGN_CENTRE_VERTICAL)) )
         {
             PosInMinorDir(posChild) += (totalMinorSize - minorSize) / 2;
         }
index e7916a1841d9137144d24bfeb70e3d522949b850..c86e319549f357888cb6bc5c930090d9c158acad 100644 (file)
@@ -104,6 +104,12 @@ void BoxSizerTestCase::Size1()
     m_win->Layout();
     CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
 
+    m_sizer->Clear();
+    m_sizer->Add(child, wxSizerFlags());
+    m_sizer->SetItemMinSize(child, sizeTotal*2);
+    m_win->Layout();
+    CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
+
     m_sizer->Clear();
     m_sizer->Add(child, wxSizerFlags().Expand());
     m_sizer->SetItemMinSize(child, sizeTotal*2);