diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index b02ef8c0f9..013afb6045 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -614,6 +614,7 @@ GridFrame::GridFrame() grid->SetRowSize(10, 30); attr = new wxGridCellAttr; attr->SetBackgroundColour(*wxLIGHT_GREY); + attr->SetAlignment(wxALIGN_INVALID, wxALIGN_CENTRE); grid->SetRowAttr(10, attr); grid->SetCellValue(10, 0, "You can't resize this row interactively -- try it"); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index ad0f62d585..f4196a3969 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -647,9 +647,17 @@ wxGridFitMode wxGridCellAttr::GetFitMode() const bool wxGridCellAttr::CanOverflow() const { - int hAlign; - GetAlignment(&hAlign, NULL); - return GetOverflow() && (hAlign == wxALIGN_LEFT); + // If overflow is disabled anyhow, we definitely can't overflow. + if ( !GetOverflow() ) + return false; + + // But if it is enabled, we still don't use it for right-aligned or + // centered cells because it's not really clear how it should work for + // them. + int hAlign = wxALIGN_LEFT; + GetNonDefaultAlignment(&hAlign, NULL); + + return hAlign == wxALIGN_LEFT; } // GetRenderer and GetEditor use a slightly different decision path about diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 7277ab8817..23de3046a5 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -925,6 +925,14 @@ TEST_CASE_METHOD(GridTestCase, "Grid::GetNonDefaultAlignment", "[grid]") attr->GetNonDefaultAlignment(&hAlign, &vAlign); CHECK( hAlign == wxALIGN_RIGHT ); CHECK( vAlign == wxALIGN_CENTRE_VERTICAL ); + + // This is only indirectly related, but test here for CanOverflow() working + // correctly for the cells with non-default alignment, as this used to be + // broken. + m_grid->SetCellAlignment(0, 0, wxALIGN_INVALID, wxALIGN_CENTRE); + attr = m_grid->CallGetCellAttr(0, 0); + REQUIRE( attr ); + CHECK( attr->CanOverflow() ); } TEST_CASE_METHOD(GridTestCase, "Grid::Editable", "[grid]")