From 58114f22c3ee697d4e7337e0ba041ef233cff44b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 4 Apr 2015 19:07:56 +0200 Subject: [PATCH] Detect the use of incompatible flags for wxGridSizer too. Complain if wxEXPAND is combined with both horizontal and vertical alignment flags, as this doesn't make sense and, moreover, the behaviour has changed since the last commit: now wxEXPAND is ignored instead of overriding the alignment flags if they are combined. --- src/common/sizer.cpp | 12 ++++++++++++ tests/sizers/gridsizer.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 78ed8d2e39..380191d4e1 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1406,6 +1406,18 @@ wxSizerItem *wxGridSizer::DoInsert(size_t index, wxSizerItem *item) } } + const int flags = item->GetFlag(); + if ( flags & wxEXPAND ) + { + // Check that expansion will happen in at least one of the directions. + wxASSERT_MSG + ( + !(flags & (wxALIGN_BOTTOM | wxALIGN_CENTRE_VERTICAL)) || + !(flags & (wxALIGN_RIGHT | wxALIGN_CENTRE_HORIZONTAL)), + wxS("wxEXPAND flag will be overridden by alignment flags") + ); + } + return wxSizer::DoInsert(index, item); } diff --git a/tests/sizers/gridsizer.cpp b/tests/sizers/gridsizer.cpp index f54e10567f..dd7b42fb01 100644 --- a/tests/sizers/gridsizer.cpp +++ b/tests/sizers/gridsizer.cpp @@ -39,9 +39,11 @@ public: private: CPPUNIT_TEST_SUITE( GridSizerTestCase ); CPPUNIT_TEST( Expand ); + CPPUNIT_TEST( IncompatibleFlags ); CPPUNIT_TEST_SUITE_END(); void Expand(); + void IncompatibleFlags(); // Clear the current sizer contents and add the specified windows to it, // using the same flags for all of them. @@ -156,3 +158,12 @@ void GridSizerTestCase::Expand() CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), children[3]->GetSize() ); } + +void GridSizerTestCase::IncompatibleFlags() +{ + WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE + ( + "Combining wxEXPAND and wxCENTRE should assert", + m_sizer->Add(10, 10, wxSizerFlags().Expand().Centre()) + ); +}