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.
This commit is contained in:
Vadim Zeitlin 2015-04-04 19:07:56 +02:00
parent 9aaa38c7c8
commit 58114f22c3
2 changed files with 23 additions and 0 deletions

View File

@ -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); return wxSizer::DoInsert(index, item);
} }

View File

@ -39,9 +39,11 @@ public:
private: private:
CPPUNIT_TEST_SUITE( GridSizerTestCase ); CPPUNIT_TEST_SUITE( GridSizerTestCase );
CPPUNIT_TEST( Expand ); CPPUNIT_TEST( Expand );
CPPUNIT_TEST( IncompatibleFlags );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
void Expand(); void Expand();
void IncompatibleFlags();
// Clear the current sizer contents and add the specified windows to it, // Clear the current sizer contents and add the specified windows to it,
// using the same flags for all of them. // using the same flags for all of them.
@ -156,3 +158,12 @@ void GridSizerTestCase::Expand()
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y),
children[3]->GetSize() ); 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())
);
}