wxGridCellWithAttr(int row, int col, wxGridCellAttr *attr_)
: coords(row, col), attr(attr_)
{
+ wxASSERT( attr );
+ }
+
+ wxGridCellWithAttr(const wxGridCellWithAttr& other)
+ : coords(other.coords),
+ attr(other.attr)
+ {
+ attr->IncRef();
+ }
+
+ wxGridCellWithAttr& operator=(const wxGridCellWithAttr& other)
+ {
+ coords = other.coords;
+ if (attr != other.attr)
+ {
+ attr->DecRef();
+ attr = other.attr;
+ attr->IncRef();
+ }
+ return *this;
+ }
+
+ void ChangeAttr(wxGridCellAttr* new_attr)
+ {
+ if (attr != new_attr)
+ {
+ // "Delete" (i.e. DecRef) the old attribute.
+ attr->DecRef();
+ attr = new_attr;
+ // Take ownership of the new attribute, i.e. no IncRef.
+ }
}
~wxGridCellWithAttr()
wxGridCellCoords coords;
wxGridCellAttr *attr;
-
-// Cannot do this:
-// DECLARE_NO_COPY_CLASS(wxGridCellWithAttr)
-// without rewriting the macros, which require a public copy constructor.
};
WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr, wxGridCellWithAttrArray,
void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col)
{
+ // Note: contrary to wxGridRowOrColAttrData::SetAttr, we must not
+ // touch attribute's reference counting explicitly, since this
+ // is managed by class wxGridCellWithAttr
int n = FindIndex(row, col);
if ( n == wxNOT_FOUND )
{
- // add the attribute
- m_attrs.Add(new wxGridCellWithAttr(row, col, attr));
+ if ( attr )
+ {
+ // add the attribute
+ m_attrs.Add(new wxGridCellWithAttr(row, col, attr));
+ }
+ //else: nothing to do
}
- else
+ else // we already have an attribute for this cell
{
- // free the old attribute
- m_attrs[(size_t)n].attr->DecRef();
-
if ( attr )
{
// change the attribute
- m_attrs[(size_t)n].attr = attr;
+ m_attrs[(size_t)n].ChangeAttr(attr);
}
else
{
else
{
// ...or remove the attribute
- // No need to DecRef the attribute itself since this is
- // done be wxGridCellWithAttr's destructor!
m_attrs.RemoveAt(n);
n--;
count--;
else
{
// ...or remove the attribute
- // No need to DecRef the attribute itself since this is
- // done be wxGridCellWithAttr's destructor!
m_attrs.RemoveAt(n);
n--;
count--;
{
if ( attr )
{
- // add the attribute
+ // add the attribute - no need to do anything to reference count
+ // since we take ownership of the attribute.
m_rowsOrCols.Add(rowOrCol);
m_attrs.Add(attr);
}
else
{
size_t n = (size_t)i;
+ if ( m_attrs[n] == attr )
+ // nothing to do
+ return;
if ( attr )
{
- // change the attribute
+ // change the attribute, handling reference count manually,
+ // taking ownership of the new attribute.
m_attrs[n]->DecRef();
m_attrs[n] = attr;
}
else
{
- // remove this attribute
+ // remove this attribute, handling reference count manually
m_attrs[n]->DecRef();
m_rowsOrCols.RemoveAt(n);
m_attrs.RemoveAt(n);
{
if ( m_attrProvider )
{
- attr->SetKind(wxGridCellAttr::Cell);
+ if ( attr )
+ attr->SetKind(wxGridCellAttr::Cell);
m_attrProvider->SetAttr(attr, row, col);
}
else
attr = new wxGridCellAttr;
wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName);
attr->SetRenderer(renderer);
+ wxGridCellEditor *editor = GetDefaultEditorForType(typeName);
+ attr->SetEditor(editor);
SetColAttr(col, attr);
void wxGrid::ClearSelection()
{
+ wxRect r1 = BlockToDeviceRect( m_selectingTopLeft, m_selectingBottomRight);
+ wxRect r2 = BlockToDeviceRect( m_currentCellCoords, m_selectingKeyboard );
m_selectingTopLeft =
m_selectingBottomRight =
m_selectingKeyboard = wxGridNoCellCoords;
+ Refresh( false, &r1 );
+ Refresh( false, &r2 );
if ( m_selection )
m_selection->ClearSelection();
}