Added UpdateAttrRows/Cols to change the row/column info in attributes as

needed when Deleting/Inserting rows/columns.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6080 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2000-02-16 16:08:16 +00:00
parent c3cb82e122
commit 4d60017aa5
2 changed files with 144 additions and 4 deletions

View File

@@ -311,6 +311,8 @@ public:
virtual void SetAttr(wxGridCellAttr *attr, int row, int col); virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
virtual void SetRowAttr(wxGridCellAttr *attr, int row); virtual void SetRowAttr(wxGridCellAttr *attr, int row);
virtual void SetColAttr(wxGridCellAttr *attr, int col); virtual void SetColAttr(wxGridCellAttr *attr, int col);
void UpdateAttrRows( size_t pos, int numRows );
void UpdateAttrCols( size_t pos, int numCols );
private: private:
void InitData(); void InitData();
@@ -366,6 +368,10 @@ public:
// get the currently used attr provider (may be NULL) // get the currently used attr provider (may be NULL)
wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
// change row/col number in attribute if needed
void UpdateAttrRows( size_t pos, int numRows );
void UpdateAttrCols( size_t pos, int numCols );
// by default forwarded to wxGridCellAttrProvider if any. May be // by default forwarded to wxGridCellAttrProvider if any. May be
// overridden to handle attributes directly in this class. // overridden to handle attributes directly in this class.
virtual wxGridCellAttr *GetAttr( int row, int col ); virtual wxGridCellAttr *GetAttr( int row, int col );

View File

@@ -208,6 +208,8 @@ class WXDLLEXPORT wxGridCellAttrData
public: public:
void SetAttr(wxGridCellAttr *attr, int row, int col); void SetAttr(wxGridCellAttr *attr, int row, int col);
wxGridCellAttr *GetAttr(int row, int col) const; wxGridCellAttr *GetAttr(int row, int col) const;
void UpdateAttrRows( size_t pos, int numRows );
void UpdateAttrCols( size_t pos, int numCols );
private: private:
// searches for the attr for given cell, returns wxNOT_FOUND if not found // searches for the attr for given cell, returns wxNOT_FOUND if not found
@@ -224,6 +226,7 @@ public:
void SetAttr(wxGridCellAttr *attr, int rowOrCol); void SetAttr(wxGridCellAttr *attr, int rowOrCol);
wxGridCellAttr *GetAttr(int rowOrCol) const; wxGridCellAttr *GetAttr(int rowOrCol) const;
void UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols );
private: private:
wxArrayInt m_rowsOrCols; wxArrayInt m_rowsOrCols;
@@ -640,6 +643,72 @@ wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
return attr; return attr;
} }
void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows )
{
size_t count = m_attrs.GetCount();
for ( size_t n = 0; n < count; n++ )
{
wxGridCellCoords& coords = m_attrs[n].coords;
wxCoord row = coords.GetRow();
if ((size_t)row >= pos)
{
if (numRows > 0)
{
// If rows inserted, include row counter where necessary
coords.SetRow(row + numRows);
}
else if (numRows < 0)
{
// If rows deleted ...
if ((size_t)row >= pos - numRows)
{
// ...either decrement row counter (if row still exists)...
coords.SetRow(row + numRows);
}
else
{
// ...or remove the attribute
m_attrs.RemoveAt((size_t)n);
n--; count--;
}
}
}
}
}
void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols )
{
size_t count = m_attrs.GetCount();
for ( size_t n = 0; n < count; n++ )
{
wxGridCellCoords& coords = m_attrs[n].coords;
wxCoord col = coords.GetCol();
if ( (size_t)col >= pos )
{
if ( numCols > 0 )
{
// If rows inserted, include row counter where necessary
coords.SetCol(col + numCols);
}
else if (numCols < 0)
{
// If rows deleted ...
if ((size_t)col >= pos - numCols)
{
// ...either decrement row counter (if row still exists)...
coords.SetCol(col + numCols);
}
else
{
// ...or remove the attribute
m_attrs.RemoveAt((size_t)n);
n--; count--;
}
}
}
}
}
int wxGridCellAttrData::FindIndex(int row, int col) const int wxGridCellAttrData::FindIndex(int row, int col) const
{ {
size_t count = m_attrs.GetCount(); size_t count = m_attrs.GetCount();
@@ -708,6 +777,35 @@ void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol)
} }
} }
void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols )
{
size_t count = m_attrs.GetCount();
for ( size_t n = 0; n < count; n++ )
{
int & rowOrCol = m_rowsOrCols[n];
if ( (size_t)rowOrCol >= pos )
{
if ( numRowsOrCols > 0 )
{
// If rows inserted, include row counter where necessary
rowOrCol += numRowsOrCols;
}
else if ( numRowsOrCols < 0)
{
// If rows deleted, either decrement row counter (if row still exists)
if ((size_t)rowOrCol >= pos - numRowsOrCols)
rowOrCol += numRowsOrCols;
else
{
m_rowsOrCols.RemoveAt((size_t)n);
m_attrs.RemoveAt((size_t)n);
n--; count--;
}
}
}
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellAttrProvider // wxGridCellAttrProvider
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -777,6 +875,26 @@ void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr, int col)
m_data->m_colAttrs.SetAttr(attr, col); m_data->m_colAttrs.SetAttr(attr, col);
} }
void wxGridCellAttrProvider::UpdateAttrRows( size_t pos, int numRows )
{
if ( m_data )
{
m_data->m_cellAttrs.UpdateAttrRows( pos, numRows );
m_data->m_rowAttrs.UpdateAttrRowsOrCols( pos, numRows );
}
}
void wxGridCellAttrProvider::UpdateAttrCols( size_t pos, int numCols )
{
if ( m_data )
{
m_data->m_cellAttrs.UpdateAttrCols( pos, numCols );
m_data->m_colAttrs.UpdateAttrRowsOrCols( pos, numCols );
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridTableBase // wxGridTableBase
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -855,6 +973,22 @@ void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col)
} }
} }
void wxGridTableBase::UpdateAttrRows( size_t pos, int numRows )
{
if ( m_attrProvider )
{
m_attrProvider->UpdateAttrRows( pos, numRows );
}
}
void wxGridTableBase::UpdateAttrCols( size_t pos, int numCols )
{
if ( m_attrProvider )
{
m_attrProvider->UpdateAttrCols( pos, numCols );
}
}
bool wxGridTableBase::InsertRows( size_t pos, size_t numRows ) bool wxGridTableBase::InsertRows( size_t pos, size_t numRows )
{ {
wxFAIL_MSG( wxT("Called grid table class function InsertRows\n" wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
@@ -1082,7 +1216,7 @@ bool wxGridStringTable::InsertRows( size_t pos, size_t numRows )
{ {
m_data.Insert( sa, row ); m_data.Insert( sa, row );
} }
UpdateAttrRows( pos, numRows );
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,
@@ -1162,7 +1296,7 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows )
m_data.Remove( pos ); m_data.Remove( pos );
} }
} }
UpdateAttrRows( pos, -numRows );
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,
@@ -1195,7 +1329,7 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
m_data[row].Insert( wxEmptyString, col ); m_data[row].Insert( wxEmptyString, col );
} }
} }
UpdateAttrCols( pos, numCols );
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,
@@ -1279,7 +1413,7 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
} }
} }
} }
UpdateAttrCols( pos, -numCols );
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,