diff --git a/interface/wx/sizer.h b/interface/wx/sizer.h index a6e694d2a0..1aea7a9dcb 100644 --- a/interface/wx/sizer.h +++ b/interface/wx/sizer.h @@ -68,7 +68,17 @@ These flags are used to specify which side(s) of the sizer item the border width will apply to.} @itemdef{wxEXPAND, - The item will be expanded to fill the space assigned to the item.} + The item will be expanded to fill the space assigned to the item. + When used for the items of wxBoxSizer, the expansion only happens + in the transversal direction of the sizer as only the item + proportion governs its behaviour in the principal sizer direction. + But when it is used for the items of wxGridSizer, this flag can be + combined with the alignment flags which override it in the + corresponding direction if specified, e.g. @c wxEXPAND | + wxALIGN_CENTRE_VERTICAL would expand the item only horizontally + but center it vertically. Notice that this doesn't work for the + default left/top alignment and @c wxEXPAND still applies in both + directions if it is combined with @c wxALIGN_LEFT or @c wxALIGN_TOP.} @itemdef{wxSHAPED, The item will be expanded as much as possible while also maintaining its aspect ratio.} diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 21d6eee3ab..78ed8d2e39 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1517,11 +1517,13 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) wxSize sz( item->GetMinSizeWithBorder() ); int flag = item->GetFlag(); - if ((flag & wxEXPAND) || (flag & wxSHAPED)) + // wxSHAPED maintains aspect ratio and so always applies to both + // directions. + if ( flag & wxSHAPED ) { - sz = wxSize(w, h); + sz = wxSize(w, h); } - else + else // Otherwise we handle each direction individually. { if (flag & wxALIGN_CENTER_HORIZONTAL) { @@ -1531,6 +1533,10 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) { pt.x = x + (w - sz.x); } + else if (flag & wxEXPAND) + { + sz.x = w; + } if (flag & wxALIGN_CENTER_VERTICAL) { @@ -1540,6 +1546,10 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) { pt.y = y + (h - sz.y); } + else if ( flag & wxEXPAND ) + { + sz.y = h; + } } item->SetDimension(pt, sz); diff --git a/tests/sizers/gridsizer.cpp b/tests/sizers/gridsizer.cpp index ba7e1262b2..f54e10567f 100644 --- a/tests/sizers/gridsizer.cpp +++ b/tests/sizers/gridsizer.cpp @@ -136,4 +136,23 @@ void GridSizerTestCase::Expand() CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), children[2]->GetSize() ); CPPUNIT_ASSERT_EQUAL( sizeRest, children[3]->GetSize() ); + + // With expand and another alignment flag, they should expand only in the + // direction in which the alignment is not given. + SetChildren(children, wxSizerFlags().Expand().CentreVertical()); + CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y), + children[1]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( sizeChild, children[2]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y), + children[3]->GetSize() ); + + // Same as above but mirrored. + SetChildren(children, wxSizerFlags().Expand().CentreHorizontal()); + CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( sizeChild, children[1]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), + children[2]->GetSize() ); + CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), + children[3]->GetSize() ); }