Add wxObjectDataPtr::release()

This makes it possible to use wxObjectDataPtr inside functions returning
raw pointers owned by the caller, such as custom GetAttr() in the grid
sample.
This commit is contained in:
Vadim Zeitlin
2020-03-31 02:43:15 +02:00
parent 15b5a1865c
commit 06af121e9c
4 changed files with 28 additions and 14 deletions

View File

@@ -1596,41 +1596,34 @@ void GridFrame::OnBugsTable(wxCommandEvent& )
// ----------------------------------------------------------------------------
MyGridCellAttrProvider::MyGridCellAttrProvider()
: m_attrForOddRows(new wxGridCellAttr)
{
m_attrForOddRows = new wxGridCellAttr;
m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
}
MyGridCellAttrProvider::~MyGridCellAttrProvider()
{
m_attrForOddRows->DecRef();
}
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
{
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
wxObjectDataPtr<wxGridCellAttr>
attr(wxGridCellAttrProvider::GetAttr(row, col, kind));
if ( row % 2 )
{
if ( !attr )
{
attr = m_attrForOddRows;
attr->IncRef();
}
else
{
if ( !attr->HasBackgroundColour() )
{
wxGridCellAttr *attrNew = attr->Clone();
attr->DecRef();
attr = attrNew;
attr = attr->Clone();
attr->SetBackgroundColour(*wxLIGHT_GREY);
}
}
}
return attr;
return attr.release();
}
void GridFrame::OnVTable(wxCommandEvent& )