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:
@@ -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& )
|
||||
|
Reference in New Issue
Block a user