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()) + ); +}