Remove wxGridCellWithAttr
After the previous commit the coords stored by wxGridCellWithAttr have become redundant as the coords are now also stored as part of the key used for an attributes map. With then only an attribute remaining in wxGridCellWithAttr it can be removed completely, letting the value of an attributes map point directly to a (ref-counted) attribute instead.
This commit is contained in:
@@ -24,54 +24,7 @@
|
|||||||
WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs,
|
WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs,
|
||||||
class WXDLLIMPEXP_ADV);
|
class WXDLLIMPEXP_ADV);
|
||||||
|
|
||||||
struct wxGridCellWithAttr
|
WX_DECLARE_HASH_MAP_WITH_DECL(wxLongLong_t, wxGridCellAttr*,
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
attr->DecRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxGridCellCoords coords;
|
|
||||||
wxGridCellAttr *attr;
|
|
||||||
};
|
|
||||||
|
|
||||||
WX_DECLARE_HASH_MAP_WITH_DECL(wxLongLong_t, wxGridCellWithAttr*,
|
|
||||||
wxIntegerHash, wxIntegerEqual,
|
wxIntegerHash, wxIntegerEqual,
|
||||||
wxGridCoordsToAttrMap, class WXDLLIMPEXP_CORE);
|
wxGridCoordsToAttrMap, class WXDLLIMPEXP_CORE);
|
||||||
|
|
||||||
|
@@ -788,7 +788,7 @@ wxGridCellAttrData::~wxGridCellAttrData()
|
|||||||
it != m_attrs.end();
|
it != m_attrs.end();
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
delete it->second;
|
it->second->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_attrs.clear();
|
m_attrs.clear();
|
||||||
@@ -796,33 +796,28 @@ wxGridCellAttrData::~wxGridCellAttrData()
|
|||||||
|
|
||||||
void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col)
|
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
|
|
||||||
wxGridCoordsToAttrMap::iterator it = FindIndex(row, col);
|
wxGridCoordsToAttrMap::iterator it = FindIndex(row, col);
|
||||||
if ( it == m_attrs.end() )
|
if ( it == m_attrs.end() )
|
||||||
{
|
{
|
||||||
if ( attr )
|
if ( attr )
|
||||||
{
|
{
|
||||||
// add the attribute
|
// add the attribute
|
||||||
m_attrs[CoordsToKey(row, col)] = new wxGridCellWithAttr(row, col, attr);
|
m_attrs[CoordsToKey(row, col)] = attr;
|
||||||
}
|
}
|
||||||
//else: nothing to do
|
//else: nothing to do
|
||||||
}
|
}
|
||||||
else // we already have an attribute for this cell
|
else // we already have an attribute for this cell
|
||||||
{
|
{
|
||||||
|
// See note near DecRef() in wxGridRowOrColAttrData::SetAttr for why
|
||||||
|
// this also works when old and new attribute are the same.
|
||||||
|
it->second->DecRef();
|
||||||
|
|
||||||
|
// Change or remove the attribute.
|
||||||
if ( attr )
|
if ( attr )
|
||||||
{
|
it->second = attr;
|
||||||
// change the attribute
|
|
||||||
it->second->ChangeAttr(attr);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// remove this attribute
|
|
||||||
delete it->second;
|
|
||||||
m_attrs.erase(it);
|
m_attrs.erase(it);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
|
wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
|
||||||
@@ -832,7 +827,7 @@ wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
|
|||||||
wxGridCoordsToAttrMap::iterator it = FindIndex(row, col);
|
wxGridCoordsToAttrMap::iterator it = FindIndex(row, col);
|
||||||
if ( it != m_attrs.end() )
|
if ( it != m_attrs.end() )
|
||||||
{
|
{
|
||||||
attr = it->second->attr;
|
attr = it->second;
|
||||||
attr->IncRef();
|
attr->IncRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,8 +859,7 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
const wxGridCoordsToAttrMap::key_type oldCoords = it->first;
|
const wxGridCoordsToAttrMap::key_type oldCoords = it->first;
|
||||||
wxGridCellWithAttr* cellWithAttr = it->second;
|
wxGridCellAttr* cellAttr = it->second;
|
||||||
wxGridCellAttr* cellAttr = cellWithAttr->attr;
|
|
||||||
|
|
||||||
int cellRows, cellCols;
|
int cellRows, cellCols;
|
||||||
cellAttr->GetSize(&cellRows, &cellCols);
|
cellAttr->GetSize(&cellRows, &cellCols);
|
||||||
@@ -873,9 +867,6 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
int cellRow, cellCol;
|
int cellRow, cellCol;
|
||||||
KeyToCoords(oldCoords, &cellRow, &cellCol);
|
KeyToCoords(oldCoords, &cellRow, &cellCol);
|
||||||
|
|
||||||
wxGridCellCoords& coords = cellWithAttr->coords;
|
|
||||||
wxASSERT(wxGridCellCoords(cellRow, cellCol) == coords);
|
|
||||||
|
|
||||||
const int cellPos = isEditingRows ? cellRow : cellCol;
|
const int cellPos = isEditingRows ? cellRow : cellCol;
|
||||||
|
|
||||||
if ( cellPos < editPos )
|
if ( cellPos < editPos )
|
||||||
@@ -944,7 +935,7 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set attribute at old/unmodified coords.
|
// Set attribute at old/unmodified coords.
|
||||||
newAttrs[oldCoords] = cellWithAttr;
|
newAttrs[oldCoords] = cellAttr;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -953,7 +944,7 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
{
|
{
|
||||||
// This row/col is deleted and the cell doesn't exist any longer:
|
// This row/col is deleted and the cell doesn't exist any longer:
|
||||||
// Remove the attribute.
|
// Remove the attribute.
|
||||||
delete cellWithAttr;
|
cellAttr->DecRef();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -965,8 +956,7 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
{
|
{
|
||||||
// Rows/cols inserted or deleted (and this cell still exists):
|
// Rows/cols inserted or deleted (and this cell still exists):
|
||||||
// Adjust cell coords.
|
// Adjust cell coords.
|
||||||
coords.Set(cellRow + editRowCount, cellCol + editColCount);
|
newAttrs[newCoords] = cellAttr;
|
||||||
newAttrs[newCoords] = cellWithAttr;
|
|
||||||
|
|
||||||
// Nothing more to do: cell is not an inside cell of a multicell.
|
// Nothing more to do: cell is not an inside cell of a multicell.
|
||||||
continue;
|
continue;
|
||||||
@@ -982,15 +972,14 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
// On a position that still exists after deletion but main cell
|
// On a position that still exists after deletion but main cell
|
||||||
// of multicell is within deletion range so the multicell is gone:
|
// of multicell is within deletion range so the multicell is gone:
|
||||||
// Remove the attribute.
|
// Remove the attribute.
|
||||||
delete cellWithAttr;
|
cellAttr->DecRef();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rows/cols inserted or deleted (and this inside cell still exists):
|
// Rows/cols inserted or deleted (and this inside cell still exists):
|
||||||
// Adjust (inside) cell coords.
|
// Adjust (inside) cell coords.
|
||||||
coords.Set(cellRow + editRowCount, cellCol + editColCount);
|
newAttrs[newCoords] = cellAttr;
|
||||||
newAttrs[newCoords] = cellWithAttr;
|
|
||||||
|
|
||||||
if ( mainPos >= editPos )
|
if ( mainPos >= editPos )
|
||||||
{
|
{
|
||||||
@@ -1017,7 +1006,7 @@ void UpdateCellAttrRowsOrCols(wxGridCoordsToAttrMap& attrs, int editPos,
|
|||||||
|
|
||||||
const int row = cellRow + adjustRows,
|
const int row = cellRow + adjustRows,
|
||||||
col = cellCol + adjustCols;
|
col = cellCol + adjustCols;
|
||||||
newAttrs[CoordsToKey(row, col)] = new wxGridCellWithAttr(row, col, attr);
|
newAttrs[CoordsToKey(row, col)] = attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user