Rename wxBoxSizer::m_minSize to avoid clash with the base class

wxSizer already has m_minSize field, use m_calculatedMinSize for the field of
the derived wxBoxSizer class to avoid confusion, just as wxFlexGridSizer
already did.

Also add a new unit test checking that GetMinSize() still works after this
change.
This commit is contained in:
Vadim Zeitlin
2015-10-11 00:35:30 +02:00
parent cfb1e8adbf
commit 154ebfd1d9
4 changed files with 37 additions and 20 deletions

View File

@@ -1016,7 +1016,7 @@ protected:
// the minimal size needed for this sizer as calculated by the last call to // the minimal size needed for this sizer as calculated by the last call to
// our CalcMin() // our CalcMin()
wxSize m_minSize; wxSize m_calculatedMinSize;
private: private:
wxDECLARE_CLASS(wxBoxSizer); wxDECLARE_CLASS(wxBoxSizer);

View File

@@ -2179,7 +2179,7 @@ void wxBoxSizer::RecalcSizes()
// the amount of free space which we should redistribute among the // the amount of free space which we should redistribute among the
// stretchable items (i.e. those with non zero proportion) // stretchable items (i.e. those with non zero proportion)
int delta = totalMajorSize - GetSizeInMajorDir(m_minSize); int delta = totalMajorSize - GetSizeInMajorDir(m_calculatedMinSize);
// declare loop variables used below: // declare loop variables used below:
wxSizerItemList::const_iterator i; // iterator in m_children list wxSizerItemList::const_iterator i; // iterator in m_children list
@@ -2498,7 +2498,7 @@ void wxBoxSizer::RecalcSizes()
wxSize wxBoxSizer::CalcMin() wxSize wxBoxSizer::CalcMin()
{ {
m_totalProportion = 0; m_totalProportion = 0;
m_minSize = wxSize(0, 0); m_calculatedMinSize = wxSize(0, 0);
// The minimal size for the sizer should be big enough to allocate its // 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 // element at least its minimal size but also, and this is the non trivial
@@ -2529,19 +2529,19 @@ wxSize wxBoxSizer::CalcMin()
else // fixed size item else // fixed size item
{ {
// Just account for its size directly // Just account for its size directly
SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis); SizeInMajorDir(m_calculatedMinSize) += GetSizeInMajorDir(sizeMinThis);
} }
// In the transversal direction we just need to find the maximum. // In the transversal direction we just need to find the maximum.
if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_minSize) ) if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_calculatedMinSize) )
SizeInMinorDir(m_minSize) = GetSizeInMinorDir(sizeMinThis); SizeInMinorDir(m_calculatedMinSize) = GetSizeInMinorDir(sizeMinThis);
} }
// Using the max ratio ensures that the min size is big enough for all // 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. // items to have their min size and satisfy the proportions among them.
SizeInMajorDir(m_minSize) += (int)(maxMinSizeToProp*m_totalProportion); SizeInMajorDir(m_calculatedMinSize) += (int)(maxMinSizeToProp*m_totalProportion);
return m_minSize; return m_calculatedMinSize;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -141,8 +141,8 @@ bool wxWrapSizer::InformFirstDirection(int direction,
// Store the values for later use // Store the values for later use
m_availSize = size; m_availSize = size;
m_availableOtherDir = availableOtherDir + m_availableOtherDir = availableOtherDir +
(direction == wxHORIZONTAL ? m_minSize.y (direction == wxHORIZONTAL ? m_calculatedMinSize.y
: m_minSize.x); : m_calculatedMinSize.x);
m_dirInform = direction; m_dirInform = direction;
m_lastUsed = false; m_lastUsed = false;
return true; return true;
@@ -208,7 +208,7 @@ wxSize wxWrapSizer::CalcMin()
} }
} }
return m_minSize; return m_calculatedMinSize;
} }
void wxWrapSizer::CalcMinFittingSize(const wxSize& szBoundary) void wxWrapSizer::CalcMinFittingSize(const wxSize& szBoundary)
@@ -220,7 +220,7 @@ void wxWrapSizer::CalcMinFittingSize(const wxSize& szBoundary)
if ( m_minSizeMinor < SizeInMinorDir(m_size) && if ( m_minSizeMinor < SizeInMinorDir(m_size) &&
m_maxSizeMajor < SizeInMajorDir(m_size) ) m_maxSizeMajor < SizeInMajorDir(m_size) )
{ {
m_minSize = sizeMin; m_calculatedMinSize = sizeMin;
} }
else else
{ {
@@ -231,9 +231,9 @@ void wxWrapSizer::CalcMinFittingSize(const wxSize& szBoundary)
// We try to present a lower min value by removing an item in // We try to present a lower min value by removing an item in
// the major direction (and preserving current minor min size). // the major direction (and preserving current minor min size).
CalcMinFromMajor(m_maxSizeMajor - m_minItemMajor); CalcMinFromMajor(m_maxSizeMajor - m_minItemMajor);
if ( m_minSize.x <= szBoundary.x && m_minSize.y <= szBoundary.y ) if ( m_calculatedMinSize.x <= szBoundary.x && m_calculatedMinSize.y <= szBoundary.y )
{ {
SizeInMinorDir(m_minSize) = SizeInMinorDir(sizeMin); SizeInMinorDir(m_calculatedMinSize) = SizeInMinorDir(sizeMin);
done = true; done = true;
} }
} }
@@ -241,7 +241,7 @@ void wxWrapSizer::CalcMinFittingSize(const wxSize& szBoundary)
if ( !done ) if ( !done )
{ {
// If failed finding little smaller area, go back to what we had // If failed finding little smaller area, go back to what we had
m_minSize = sizeMin; m_calculatedMinSize = sizeMin;
} }
} }
} }
@@ -269,7 +269,7 @@ void wxWrapSizer::CalcMaxSingleItemSize()
// This is, of course, not our real minimal size but if we return more // This is, of course, not our real minimal size but if we return more
// than this it would be impossible to shrink us to one row/column so // than this it would be impossible to shrink us to one row/column so
// we have to pretend that this is all we need for now. // we have to pretend that this is all we need for now.
m_minSize = SizeFromMajorMinor(maxMajor, maxMinor); m_calculatedMinSize = SizeFromMajorMinor(maxMajor, maxMinor);
} }
void wxWrapSizer::CalcMinFromMajor(int totMajor) void wxWrapSizer::CalcMinFromMajor(int totMajor)
@@ -325,7 +325,7 @@ void wxWrapSizer::CalcMinFromMajor(int totMajor)
if ( rowTotalMajor > maxTotalMajor ) if ( rowTotalMajor > maxTotalMajor )
maxTotalMajor = rowTotalMajor; maxTotalMajor = rowTotalMajor;
m_minSize = SizeFromMajorMinor(maxTotalMajor, minorSum); m_calculatedMinSize = SizeFromMajorMinor(maxTotalMajor, minorSum);
} }
// Helper struct for CalcMinFromMinor // Helper struct for CalcMinFromMinor
@@ -370,7 +370,7 @@ void wxWrapSizer::CalcMinFromMinor(int totMinor)
// The trivial case // The trivial case
if ( !itemCount || totMajor==0 || maxMinor==0 ) if ( !itemCount || totMajor==0 || maxMinor==0 )
{ {
m_minSize = wxSize(0,0); m_calculatedMinSize = wxSize(0,0);
return; return;
} }
@@ -379,7 +379,7 @@ void wxWrapSizer::CalcMinFromMinor(int totMinor)
if ( nrLines<=1 ) if ( nrLines<=1 )
{ {
// Another simple case, everything fits on one line // Another simple case, everything fits on one line
m_minSize = SizeFromMajorMinor(totMajor,maxMinor); m_calculatedMinSize = SizeFromMajorMinor(totMajor,maxMinor);
return; return;
} }
@@ -469,7 +469,7 @@ void wxWrapSizer::CalcMinFromMinor(int totMinor)
} }
// Now have min size in the opposite direction // Now have min size in the opposite direction
m_minSize = SizeFromMajorMinor(lineSize,sumMinor); m_calculatedMinSize = SizeFromMajorMinor(lineSize,sumMinor);
} }
void wxWrapSizer::FinishRow(size_t n, void wxWrapSizer::FinishRow(size_t n,

View File

@@ -41,6 +41,7 @@ private:
CPPUNIT_TEST( Size1 ); CPPUNIT_TEST( Size1 );
CPPUNIT_TEST( Size3 ); CPPUNIT_TEST( Size3 );
CPPUNIT_TEST( CalcMin ); CPPUNIT_TEST( CalcMin );
CPPUNIT_TEST( SetMinSize );
CPPUNIT_TEST( BestSizeRespectsMaxSize ); CPPUNIT_TEST( BestSizeRespectsMaxSize );
CPPUNIT_TEST( RecalcSizesRespectsMaxSize1 ); CPPUNIT_TEST( RecalcSizesRespectsMaxSize1 );
CPPUNIT_TEST( RecalcSizesRespectsMaxSize2 ); CPPUNIT_TEST( RecalcSizesRespectsMaxSize2 );
@@ -50,6 +51,7 @@ private:
void Size1(); void Size1();
void Size3(); void Size3();
void CalcMin(); void CalcMin();
void SetMinSize();
void BestSizeRespectsMaxSize(); void BestSizeRespectsMaxSize();
void RecalcSizesRespectsMaxSize1(); void RecalcSizesRespectsMaxSize1();
void RecalcSizesRespectsMaxSize2(); void RecalcSizesRespectsMaxSize2();
@@ -307,6 +309,21 @@ void BoxSizerTestCase::CalcMin()
} }
} }
void BoxSizerTestCase::SetMinSize()
{
wxWindow* const child = new wxWindow(m_win, wxID_ANY);
child->SetInitialSize(wxSize(10, -1));
m_sizer->Add(child);
// Setting minimal size explicitly must make GetMinSize() return at least
// this size even if it needs a much smaller one.
m_sizer->SetMinSize(100, 0);
CPPUNIT_ASSERT_EQUAL( 100, m_sizer->GetMinSize().x );
m_sizer->Layout();
CPPUNIT_ASSERT_EQUAL( 100, m_sizer->GetMinSize().x );
}
void BoxSizerTestCase::BestSizeRespectsMaxSize() void BoxSizerTestCase::BestSizeRespectsMaxSize()
{ {
m_sizer->Clear(); m_sizer->Clear();