]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/sizer.cpp
Use mouse position to find the item for selection events in wxMSW listbox.
[wxWidgets.git] / src / common / sizer.cpp
index 872145da95d120f3fbaa1c743f369e4c38b93320..badc6724abbe1dc33b52c1b435c9935328767ec2 100644 (file)
@@ -2171,8 +2171,19 @@ void wxBoxSizer::RecalcSizes()
             if ( majorSizes[n] != wxDefaultCoord )
                 continue;
 
-            const wxCoord
-                minMajor = GetSizeInMajorDir(item->GetMinSizeWithBorder());
+            wxCoord minMajor = GetSizeInMajorDir(item->GetMinSizeWithBorder());
+
+            // it doesn't make sense for min size to be negative but right now
+            // it's possible to create e.g. a spacer with (-1, 10) as size and
+            // people do it in their code apparently (see #11842) so ensure
+            // that we don't use this -1 as real min size as it conflicts with
+            // the meaning we use for it here and negative min sizes just don't
+            // make sense anyhow (which is why it might be a better idea to
+            // deal with them at wxSizerItem level in the future but for now
+            // this is the minimal fix for the bug)
+            if ( minMajor < 0 )
+                minMajor = 0;
+
             const int propItem = item->GetProportion();
             if ( propItem )
             {
@@ -2289,7 +2300,12 @@ wxSize wxBoxSizer::CalcMin()
     m_totalProportion = 0;
     m_minSize = wxSize(0, 0);
 
-    // calculate the minimal sizes for all items and count sum of proportions
+    // The minimal size for the sizer should be big enough to allocate its
+    // element at least its minimal size but also, and this is the non trivial
+    // part, to respect the children proportion. To satisfy the latter
+    // condition we must find the greatest min-size-to-proportion ratio for all
+    // elements with non-zero proportion.
+    float maxMinSizeToProp = 0.;
     for ( wxSizerItemList::const_iterator i = m_children.begin();
           i != m_children.end();
           ++i )
@@ -2300,13 +2316,31 @@ wxSize wxBoxSizer::CalcMin()
             continue;
 
         const wxSize sizeMinThis = item->CalcMin();
-        SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis);
+        if ( const int propThis = item->GetProportion() )
+        {
+            float minSizeToProp = GetSizeInMajorDir(sizeMinThis);
+            minSizeToProp /= propThis;
+
+            if ( minSizeToProp > maxMinSizeToProp )
+                maxMinSizeToProp = minSizeToProp;
+
+            m_totalProportion += item->GetProportion();
+        }
+        else // fixed size item
+        {
+            // Just account for its size directly
+            SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis);
+        }
+
+        // In the transversal direction we just need to find the maximum.
         if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_minSize) )
             SizeInMinorDir(m_minSize) = GetSizeInMinorDir(sizeMinThis);
-
-        m_totalProportion += item->GetProportion();
     }
 
+    // Using the max ratio ensures that the min size is big enough for all
+    // items to have their min size and satisfy the proportions among them.
+    SizeInMajorDir(m_minSize) += maxMinSizeToProp*m_totalProportion;
+
     return m_minSize;
 }