Merge branch 'grid-align-overflow'

Fix overflow in wxGrid cells with non-default alignment.

See https://github.com/wxWidgets/wxWidgets/pull/1775
This commit is contained in:
Vadim Zeitlin
2020-04-04 18:46:18 +02:00
4 changed files with 26 additions and 10 deletions

View File

@@ -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");
@@ -1604,8 +1605,7 @@ MyGridCellAttrProvider::MyGridCellAttrProvider()
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
{
wxObjectDataPtr<wxGridCellAttr>
attr(wxGridCellAttrProvider::GetAttr(row, col, kind));
wxGridCellAttrPtr attr(wxGridCellAttrProvider::GetAttr(row, col, kind));
if ( row % 2 )
{

View File

@@ -301,7 +301,7 @@ public:
wxGridCellAttr::wxAttrKind kind) const wxOVERRIDE;
private:
wxObjectDataPtr<wxGridCellAttr> m_attrForOddRows;
wxGridCellAttrPtr m_attrForOddRows;
};
// ----------------------------------------------------------------------------

View File

@@ -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

View File

@@ -899,7 +899,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::GetNonDefaultAlignment", "[grid]")
// GetNonDefaultAlignment() is used by several renderers having their own
// preferred alignment, so check that if we don't reset the alignment
// explicitly, it doesn't override the alignment used by default.
wxGridCellAttr* attr = NULL;
wxGridCellAttrPtr attr;
int hAlign = wxALIGN_RIGHT,
vAlign = wxALIGN_INVALID;
@@ -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]")
@@ -1174,9 +1182,9 @@ TEST_CASE_METHOD(GridTestCase, "Grid::AutoSizeColumn", "[grid]")
// Hardcoded extra margin for the columns used in grid.cpp.
const int margin = m_grid->FromDIP(10);
wxGridCellAttr *attr = m_grid->GetOrCreateCellAttr(0, 0);
wxGridCellRenderer *renderer = attr->GetRenderer(m_grid, 0, 0);
REQUIRE(renderer != NULL);
wxGridCellAttrPtr attr(m_grid->GetOrCreateCellAttr(0, 0));
wxGridCellRendererPtr renderer(attr->GetRenderer(m_grid, 0, 0));
REQUIRE(renderer);
wxClientDC dcCell(m_grid->GetGridWindow());