-// ----------------------------------------------------------------------------
-// wxGridCellAttr
-// ----------------------------------------------------------------------------
-
-void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
-{
- m_nRef = 1;
-
- m_isReadOnly = Unset;
-
- m_renderer = NULL;
- m_editor = NULL;
-
- m_attrkind = wxGridCellAttr::Cell;
-
- m_sizeRows = m_sizeCols = 1;
- m_overflow = UnsetOverflow;
-
- SetDefAttr(attrDefault);
-}
-
-wxGridCellAttr *wxGridCellAttr::Clone() const
-{
- wxGridCellAttr *attr = new wxGridCellAttr(m_defGridAttr);
-
- if ( HasTextColour() )
- attr->SetTextColour(GetTextColour());
- if ( HasBackgroundColour() )
- attr->SetBackgroundColour(GetBackgroundColour());
- if ( HasFont() )
- attr->SetFont(GetFont());
- if ( HasAlignment() )
- attr->SetAlignment(m_hAlign, m_vAlign);
-
- attr->SetSize( m_sizeRows, m_sizeCols );
-
- if ( m_renderer )
- {
- attr->SetRenderer(m_renderer);
- m_renderer->IncRef();
- }
- if ( m_editor )
- {
- attr->SetEditor(m_editor);
- m_editor->IncRef();
- }
-
- if ( IsReadOnly() )
- attr->SetReadOnly();
-
- attr->SetOverflow( m_overflow == Overflow );
- attr->SetKind( m_attrkind );
-
- return attr;
-}
-
-void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
-{
- if ( !HasTextColour() && mergefrom->HasTextColour() )
- SetTextColour(mergefrom->GetTextColour());
- if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() )
- SetBackgroundColour(mergefrom->GetBackgroundColour());
- if ( !HasFont() && mergefrom->HasFont() )
- SetFont(mergefrom->GetFont());
- if ( !HasAlignment() && mergefrom->HasAlignment() )
- {
- int hAlign, vAlign;
- mergefrom->GetAlignment( &hAlign, &vAlign);
- SetAlignment(hAlign, vAlign);
- }
- if ( !HasSize() && mergefrom->HasSize() )
- mergefrom->GetSize( &m_sizeRows, &m_sizeCols );
-
- // Directly access member functions as GetRender/Editor don't just return
- // m_renderer/m_editor
- //
- // Maybe add support for merge of Render and Editor?
- if (!HasRenderer() && mergefrom->HasRenderer() )
- {
- m_renderer = mergefrom->m_renderer;
- m_renderer->IncRef();
- }
- if ( !HasEditor() && mergefrom->HasEditor() )
- {
- m_editor = mergefrom->m_editor;
- m_editor->IncRef();
- }
- if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
- SetReadOnly(mergefrom->IsReadOnly());
-
- if (!HasOverflowMode() && mergefrom->HasOverflowMode() )
- SetOverflow(mergefrom->GetOverflow());
-
- SetDefAttr(mergefrom->m_defGridAttr);
-}
-
-void wxGridCellAttr::SetSize(int num_rows, int num_cols)
-{
- // The size of a cell is normally 1,1
-
- // If this cell is larger (2,2) then this is the top left cell
- // the other cells that will be covered (lower right cells) must be
- // set to negative or zero values such that
- // row + num_rows of the covered cell points to the larger cell (this cell)
- // same goes for the col + num_cols.
-
- // Size of 0,0 is NOT valid, neither is <=0 and any positive value
-
- wxASSERT_MSG( (!((num_rows > 0) && (num_cols <= 0)) ||
- !((num_rows <= 0) && (num_cols > 0)) ||
- !((num_rows == 0) && (num_cols == 0))),
- wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
-
- m_sizeRows = num_rows;
- m_sizeCols = num_cols;
-}
-
-const wxColour& wxGridCellAttr::GetTextColour() const
-{
- if (HasTextColour())
- {
- return m_colText;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetTextColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-const wxColour& wxGridCellAttr::GetBackgroundColour() const
-{
- if (HasBackgroundColour())
- {
- return m_colBack;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetBackgroundColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-const wxFont& wxGridCellAttr::GetFont() const
-{
- if (HasFont())
- {
- return m_font;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetFont();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullFont;
- }
-}
-
-void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const
-{
- if (HasAlignment())
- {
- if ( hAlign )
- *hAlign = m_hAlign;
- if ( vAlign )
- *vAlign = m_vAlign;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- m_defGridAttr->GetAlignment(hAlign, vAlign);
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- }
-}
-
-void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const
-{
- if ( num_rows )
- *num_rows = m_sizeRows;
- if ( num_cols )
- *num_cols = m_sizeCols;
-}
-
-// GetRenderer and GetEditor use a slightly different decision path about
-// which attribute to use. If a non-default attr object has one then it is
-// used, otherwise the default editor or renderer is fetched from the grid and
-// used. It should be the default for the data type of the cell. If it is
-// NULL (because the table has a type that the grid does not have in its
-// registry), then the grid's default editor or renderer is used.
-
-wxGridCellRenderer* wxGridCellAttr::GetRenderer(const wxGrid* grid, int row, int col) const
-{
- wxGridCellRenderer *renderer = NULL;
-
- if ( m_renderer && this != m_defGridAttr )
- {
- // use the cells renderer if it has one
- renderer = m_renderer;
- renderer->IncRef();
- }
- else // no non-default cell renderer
- {
- // get default renderer for the data type
- if ( grid )
- {
- // GetDefaultRendererForCell() will do IncRef() for us
- renderer = grid->GetDefaultRendererForCell(row, col);
- }
-
- if ( renderer == NULL )
- {
- if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) )
- {
- // if we still don't have one then use the grid default
- // (no need for IncRef() here neither)
- renderer = m_defGridAttr->GetRenderer(NULL, 0, 0);
- }
- else // default grid attr
- {
- // use m_renderer which we had decided not to use initially
- renderer = m_renderer;
- if ( renderer )
- renderer->IncRef();
- }
- }
- }
-
- // we're supposed to always find something
- wxASSERT_MSG(renderer, wxT("Missing default cell renderer"));
-
- return renderer;
-}
-
-// same as above, except for s/renderer/editor/g
-wxGridCellEditor* wxGridCellAttr::GetEditor(const wxGrid* grid, int row, int col) const
-{
- wxGridCellEditor *editor = NULL;
-
- if ( m_editor && this != m_defGridAttr )
- {
- // use the cells editor if it has one
- editor = m_editor;
- editor->IncRef();
- }
- else // no non default cell editor
- {
- // get default editor for the data type
- if ( grid )
- {
- // GetDefaultEditorForCell() will do IncRef() for us
- editor = grid->GetDefaultEditorForCell(row, col);
- }
-
- if ( editor == NULL )
- {
- if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) )
- {
- // if we still don't have one then use the grid default
- // (no need for IncRef() here neither)
- editor = m_defGridAttr->GetEditor(NULL, 0, 0);
- }
- else // default grid attr
- {
- // use m_editor which we had decided not to use initially
- editor = m_editor;
- if ( editor )
- editor->IncRef();
- }
- }
- }
-
- // we're supposed to always find something
- wxASSERT_MSG(editor, wxT("Missing default cell editor"));
-
- return editor;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttrData
-// ----------------------------------------------------------------------------
-
-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 )
- {
- if ( attr )
- {
- // add the attribute
- m_attrs.Add(new wxGridCellWithAttr(row, col, attr));
- }
- //else: nothing to do
- }
- else // we already have an attribute for this cell
- {
- if ( attr )
- {
- // change the attribute
- m_attrs[(size_t)n].ChangeAttr(attr);
- }
- else
- {
- // remove this attribute
- m_attrs.RemoveAt((size_t)n);
- }
- }
-}
-
-wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
-{
- wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
-
- int n = FindIndex(row, col);
- if ( n != wxNOT_FOUND )
- {
- attr = m_attrs[(size_t)n].attr;
- attr->IncRef();
- }
-
- 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(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(n);
- n--;
- count--;
- }
- }
- }
- }
-}
-
-int wxGridCellAttrData::FindIndex(int row, int col) const
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- const wxGridCellCoords& coords = m_attrs[n].coords;
- if ( (coords.GetRow() == row) && (coords.GetCol() == col) )
- {
- return n;
- }
- }
-
- return wxNOT_FOUND;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridRowOrColAttrData
-// ----------------------------------------------------------------------------
-
-wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- m_attrs[n]->DecRef();
- }
-}
-
-wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(int rowOrCol) const
-{
- wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
-
- int n = m_rowsOrCols.Index(rowOrCol);
- if ( n != wxNOT_FOUND )
- {
- attr = m_attrs[(size_t)n];
- attr->IncRef();
- }
-
- return attr;
-}
-
-void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol)
-{
- int i = m_rowsOrCols.Index(rowOrCol);
- if ( i == wxNOT_FOUND )
- {
- if ( attr )
- {
- // 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);
- }
- // nothing to remove
- }
- else
- {
- size_t n = (size_t)i;
- if ( m_attrs[n] == attr )
- // nothing to do
- return;
- if ( attr )
- {
- // 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, handling reference count manually
- m_attrs[n]->DecRef();
- m_rowsOrCols.RemoveAt(n);
- m_attrs.RemoveAt(n);
- }
- }
-}
-
-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(n);
- m_attrs[n]->DecRef();
- m_attrs.RemoveAt(n);
- n--;
- count--;
- }
- }
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttrProvider
-// ----------------------------------------------------------------------------
-
-wxGridCellAttrProvider::wxGridCellAttrProvider()
-{
- m_data = (wxGridCellAttrProviderData *)NULL;
-}
-
-wxGridCellAttrProvider::~wxGridCellAttrProvider()
-{
- delete m_data;
-}
-
-void wxGridCellAttrProvider::InitData()
-{
- m_data = new wxGridCellAttrProviderData;
-}
-
-wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col,
- wxGridCellAttr::wxAttrKind kind ) const
-{
- wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
- if ( m_data )
- {
- switch (kind)
- {
- case (wxGridCellAttr::Any):
- // Get cached merge attributes.
- // Currently not used as no cache implemented as not mutable
- // attr = m_data->m_mergeAttr.GetAttr(row, col);
- if (!attr)
- {
- // Basically implement old version.
- // Also check merge cache, so we don't have to re-merge every time..
- wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col);
- wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row);
- wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col);
-
- if ((attrcell != attrrow) && (attrrow != attrcol) && (attrcell != attrcol))
- {
- // Two or more are non NULL
- attr = new wxGridCellAttr;
- attr->SetKind(wxGridCellAttr::Merged);
-
- // Order is important..
- if (attrcell)
- {
- attr->MergeWith(attrcell);
- attrcell->DecRef();
- }
- if (attrcol)
- {
- attr->MergeWith(attrcol);
- attrcol->DecRef();
- }
- if (attrrow)
- {
- attr->MergeWith(attrrow);
- attrrow->DecRef();
- }
-
- // store merge attr if cache implemented
- //attr->IncRef();
- //m_data->m_mergeAttr.SetAttr(attr, row, col);
- }
- else
- {
- // one or none is non null return it or null.
- if (attrrow)
- attr = attrrow;
- if (attrcol)
- {
- if (attr)
- attr->DecRef();
- attr = attrcol;
- }
- if (attrcell)
- {
- if (attr)
- attr->DecRef();
- attr = attrcell;
- }
- }
- }
- break;
-
- case (wxGridCellAttr::Cell):
- attr = m_data->m_cellAttrs.GetAttr(row, col);
- break;
-
- case (wxGridCellAttr::Col):
- attr = m_data->m_colAttrs.GetAttr(col);
- break;
-
- case (wxGridCellAttr::Row):
- attr = m_data->m_rowAttrs.GetAttr(row);
- break;
-
- default:
- // unused as yet...
- // (wxGridCellAttr::Default):
- // (wxGridCellAttr::Merged):
- break;
- }
- }
-
- return attr;
-}
-
-void wxGridCellAttrProvider::SetAttr(wxGridCellAttr *attr,
- int row, int col)
-{
- if ( !m_data )
- InitData();
-
- m_data->m_cellAttrs.SetAttr(attr, row, col);
-}
-
-void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr *attr, int row)
-{
- if ( !m_data )
- InitData();
-
- m_data->m_rowAttrs.SetAttr(attr, row);
-}
-
-void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr, int col)
-{
- if ( !m_data )
- InitData();
-
- 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 );
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridTypeRegistry
-// ----------------------------------------------------------------------------
-
-wxGridTypeRegistry::~wxGridTypeRegistry()
-{
- size_t count = m_typeinfo.GetCount();
- for ( size_t i = 0; i < count; i++ )
- delete m_typeinfo[i];
-}
-
-void wxGridTypeRegistry::RegisterDataType(const wxString& typeName,
- wxGridCellRenderer* renderer,
- wxGridCellEditor* editor)
-{
- wxGridDataTypeInfo* info = new wxGridDataTypeInfo(typeName, renderer, editor);
-
- // is it already registered?
- int loc = FindRegisteredDataType(typeName);
- if ( loc != wxNOT_FOUND )
- {
- delete m_typeinfo[loc];
- m_typeinfo[loc] = info;
- }
- else
- {
- m_typeinfo.Add(info);
- }
-}
-
-int wxGridTypeRegistry::FindRegisteredDataType(const wxString& typeName)
-{
- size_t count = m_typeinfo.GetCount();
- for ( size_t i = 0; i < count; i++ )
- {
- if ( typeName == m_typeinfo[i]->m_typeName )
- {
- return i;
- }
- }
-
- return wxNOT_FOUND;
-}
-
-int wxGridTypeRegistry::FindDataType(const wxString& typeName)
-{
- int index = FindRegisteredDataType(typeName);
- if ( index == wxNOT_FOUND )
- {
- // check whether this is one of the standard ones, in which case
- // register it "on the fly"
-#if wxUSE_TEXTCTRL
- if ( typeName == wxGRID_VALUE_STRING )
- {
- RegisterDataType(wxGRID_VALUE_STRING,
- new wxGridCellStringRenderer,
- new wxGridCellTextEditor);
- }
- else
-#endif // wxUSE_TEXTCTRL
-#if wxUSE_CHECKBOX
- if ( typeName == wxGRID_VALUE_BOOL )
- {
- RegisterDataType(wxGRID_VALUE_BOOL,
- new wxGridCellBoolRenderer,
- new wxGridCellBoolEditor);
- }
- else
-#endif // wxUSE_CHECKBOX
-#if wxUSE_TEXTCTRL
- if ( typeName == wxGRID_VALUE_NUMBER )
- {
- RegisterDataType(wxGRID_VALUE_NUMBER,
- new wxGridCellNumberRenderer,
- new wxGridCellNumberEditor);
- }
- else if ( typeName == wxGRID_VALUE_FLOAT )
- {
- RegisterDataType(wxGRID_VALUE_FLOAT,
- new wxGridCellFloatRenderer,
- new wxGridCellFloatEditor);
- }
- else
-#endif // wxUSE_TEXTCTRL
-#if wxUSE_COMBOBOX
- if ( typeName == wxGRID_VALUE_CHOICE )
- {
- RegisterDataType(wxGRID_VALUE_CHOICE,
- new wxGridCellStringRenderer,
- new wxGridCellChoiceEditor);
- }
- else
-#endif // wxUSE_COMBOBOX
- {
- return wxNOT_FOUND;
- }
-
- // we get here only if just added the entry for this type, so return
- // the last index
- index = m_typeinfo.GetCount() - 1;
- }
-
- return index;
-}
-
-int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName)
-{
- int index = FindDataType(typeName);
- if ( index == wxNOT_FOUND )
- {
- // the first part of the typename is the "real" type, anything after ':'
- // are the parameters for the renderer
- index = FindDataType(typeName.BeforeFirst(_T(':')));
- if ( index == wxNOT_FOUND )
- {
- return wxNOT_FOUND;
- }
-
- wxGridCellRenderer *renderer = GetRenderer(index);
- wxGridCellRenderer *rendererOld = renderer;
- renderer = renderer->Clone();
- rendererOld->DecRef();
-
- wxGridCellEditor *editor = GetEditor(index);
- wxGridCellEditor *editorOld = editor;
- editor = editor->Clone();
- editorOld->DecRef();
-
- // do it even if there are no parameters to reset them to defaults
- wxString params = typeName.AfterFirst(_T(':'));
- renderer->SetParameters(params);
- editor->SetParameters(params);
-
- // register the new typename
- RegisterDataType(typeName, renderer, editor);
-
- // we just registered it, it's the last one
- index = m_typeinfo.GetCount() - 1;
- }
-
- return index;
-}
-
-wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index)
-{
- wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer;
- if (renderer)
- renderer->IncRef();
-
- return renderer;
-}
-
-wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index)
-{
- wxGridCellEditor* editor = m_typeinfo[index]->m_editor;
- if (editor)
- editor->IncRef();
-
- return editor;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridTableBase
-// ----------------------------------------------------------------------------
-
-IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase, wxObject )
-
-wxGridTableBase::wxGridTableBase()
-{
- m_view = (wxGrid *) NULL;
- m_attrProvider = (wxGridCellAttrProvider *) NULL;
-}
-
-wxGridTableBase::~wxGridTableBase()
-{
- delete m_attrProvider;
-}
-
-void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider *attrProvider)
-{
- delete m_attrProvider;
- m_attrProvider = attrProvider;
-}
-
-bool wxGridTableBase::CanHaveAttributes()
-{
- if ( ! GetAttrProvider() )
- {
- // use the default attr provider by default
- SetAttrProvider(new wxGridCellAttrProvider);
- }
-
- return true;
-}
-
-wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind)
-{
- if ( m_attrProvider )
- return m_attrProvider->GetAttr(row, col, kind);
- else
- return (wxGridCellAttr *)NULL;
-}
-
-void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col)
-{
- if ( m_attrProvider )
- {
- if ( attr )
- attr->SetKind(wxGridCellAttr::Cell);
- m_attrProvider->SetAttr(attr, row, col);
- }
- else
- {
- // as we take ownership of the pointer and don't store it, we must
- // free it now
- wxSafeDecRef(attr);
- }
-}
-
-void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row)
-{
- if ( m_attrProvider )
- {
- attr->SetKind(wxGridCellAttr::Row);
- m_attrProvider->SetRowAttr(attr, row);
- }
- else
- {
- // as we take ownership of the pointer and don't store it, we must
- // free it now
- wxSafeDecRef(attr);
- }
-}
-
-void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col)
-{
- if ( m_attrProvider )
- {
- attr->SetKind(wxGridCellAttr::Col);
- m_attrProvider->SetColAttr(attr, col);
- }
- else
- {
- // as we take ownership of the pointer and don't store it, we must
- // free it now
- wxSafeDecRef(attr);
- }
-}
-
-bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos),
- size_t WXUNUSED(numRows) )
-{
- wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
-
- return false;
-}
-
-bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows) )
-{
- wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
-
- return false;
-}
-
-bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos),
- size_t WXUNUSED(numRows) )
-{
- wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
-
- return false;
-}
-
-bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos),
- size_t WXUNUSED(numCols) )
-{
- wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
-
- return false;
-}
-
-bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols) )
-{
- wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
-
- return false;
-}
-
-bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos),
- size_t WXUNUSED(numCols) )
-{
- wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
-
- return false;
-}
-
-wxString wxGridTableBase::GetRowLabelValue( int row )
-{
- wxString s;
-
- // RD: Starting the rows at zero confuses users,
- // no matter how much it makes sense to us geeks.
- s << row + 1;
-
- return s;
-}
-
-wxString wxGridTableBase::GetColLabelValue( int col )
-{
- // default col labels are:
- // cols 0 to 25 : A-Z
- // cols 26 to 675 : AA-ZZ
- // etc.
-
- wxString s;
- unsigned int i, n;
- for ( n = 1; ; n++ )
- {
- s += (wxChar) (_T('A') + (wxChar)(col % 26));
- col = col / 26 - 1;
- if ( col < 0 )
- break;
- }
-
- // reverse the string...
- wxString s2;
- for ( i = 0; i < n; i++ )
- {
- s2 += s[n - i - 1];
- }
-
- return s2;
-}
-
-wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) )
-{
- return wxGRID_VALUE_STRING;
-}
-
-bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row), int WXUNUSED(col),
- const wxString& typeName )
-{
- return typeName == wxGRID_VALUE_STRING;
-}
-
-bool wxGridTableBase::CanSetValueAs( int row, int col, const wxString& typeName )
-{
- return CanGetValueAs(row, col, typeName);
-}
-
-long wxGridTableBase::GetValueAsLong( int WXUNUSED(row), int WXUNUSED(col) )
-{
- return 0;
-}
-
-double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col) )
-{
- return 0.0;
-}
-
-bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row), int WXUNUSED(col) )
-{
- return false;
-}
-
-void wxGridTableBase::SetValueAsLong( int WXUNUSED(row), int WXUNUSED(col),
- long WXUNUSED(value) )
-{
-}
-
-void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col),
- double WXUNUSED(value) )
-{
-}
-
-void wxGridTableBase::SetValueAsBool( int WXUNUSED(row), int WXUNUSED(col),
- bool WXUNUSED(value) )
-{
-}
-
-void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col),
- const wxString& WXUNUSED(typeName) )
-{
- return NULL;
-}
-
-void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col),
- const wxString& WXUNUSED(typeName),
- void* WXUNUSED(value) )
-{
-}
-
-//////////////////////////////////////////////////////////////////////
-//
-// Message class for the grid table to send requests and notifications
-// to the grid view
-//
-
-wxGridTableMessage::wxGridTableMessage()
-{
- m_table = (wxGridTableBase *) NULL;
- m_id = -1;
- m_comInt1 = -1;
- m_comInt2 = -1;
-}
-
-wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id,
- int commandInt1, int commandInt2 )
-{
- m_table = table;
- m_id = id;
- m_comInt1 = commandInt1;
- m_comInt2 = commandInt2;
-}
-
-//////////////////////////////////////////////////////////////////////
-//
-// A basic grid table for string data. An object of this class will
-// created by wxGrid if you don't specify an alternative table class.
-//
-
-WX_DEFINE_OBJARRAY(wxGridStringArray)
-
-IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase )
-
-wxGridStringTable::wxGridStringTable()
- : wxGridTableBase()
-{
-}
-
-wxGridStringTable::wxGridStringTable( int numRows, int numCols )
- : wxGridTableBase()
-{
- m_data.Alloc( numRows );
-
- wxArrayString sa;
- sa.Alloc( numCols );
- sa.Add( wxEmptyString, numCols );
-
- m_data.Add( sa, numRows );
-}
-
-wxGridStringTable::~wxGridStringTable()
-{
-}
-
-int wxGridStringTable::GetNumberRows()
-{
- return m_data.GetCount();
-}
-
-int wxGridStringTable::GetNumberCols()
-{
- if ( m_data.GetCount() > 0 )
- return m_data[0].GetCount();
- else
- return 0;
-}
-
-wxString wxGridStringTable::GetValue( int row, int col )
-{
- wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
- wxEmptyString,
- _T("invalid row or column index in wxGridStringTable") );
-
- return m_data[row][col];
-}
-
-void wxGridStringTable::SetValue( int row, int col, const wxString& value )
-{
- wxCHECK_RET( (row < GetNumberRows()) && (col < GetNumberCols()),
- _T("invalid row or column index in wxGridStringTable") );
-
- m_data[row][col] = value;
-}
-
-bool wxGridStringTable::IsEmptyCell( int row, int col )
-{
- wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
- true,
- _T("invalid row or column index in wxGridStringTable") );
-
- return (m_data[row][col] == wxEmptyString);
-}
-
-void wxGridStringTable::Clear()
-{
- int row, col;
- int numRows, numCols;
-
- numRows = m_data.GetCount();
- if ( numRows > 0 )
- {
- numCols = m_data[0].GetCount();
-
- for ( row = 0; row < numRows; row++ )
- {
- for ( col = 0; col < numCols; col++ )
- {
- m_data[row][col] = wxEmptyString;
- }
- }
- }
-}
-
-bool wxGridStringTable::InsertRows( size_t pos, size_t numRows )
-{
- size_t curNumRows = m_data.GetCount();
- size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
- ( GetView() ? GetView()->GetNumberCols() : 0 ) );
-
- if ( pos >= curNumRows )
- {
- return AppendRows( numRows );
- }
-
- wxArrayString sa;
- sa.Alloc( curNumCols );
- sa.Add( wxEmptyString, curNumCols );
- m_data.Insert( sa, pos, numRows );
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
- pos,
- numRows );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-bool wxGridStringTable::AppendRows( size_t numRows )
-{
- size_t curNumRows = m_data.GetCount();
- size_t curNumCols = ( curNumRows > 0
- ? m_data[0].GetCount()
- : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
-
- wxArrayString sa;
- if ( curNumCols > 0 )
- {
- sa.Alloc( curNumCols );
- sa.Add( wxEmptyString, curNumCols );
- }
-
- m_data.Add( sa, numRows );
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
- numRows );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows )
-{
- size_t curNumRows = m_data.GetCount();
-
- if ( pos >= curNumRows )
- {
- wxFAIL_MSG( wxString::Format
- (
- wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
- (unsigned long)pos,
- (unsigned long)numRows,
- (unsigned long)curNumRows
- ) );
-
- return false;
- }
-
- if ( numRows > curNumRows - pos )
- {
- numRows = curNumRows - pos;
- }
-
- if ( numRows >= curNumRows )
- {
- m_data.Clear();
- }
- else
- {
- m_data.RemoveAt( pos, numRows );
- }
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_ROWS_DELETED,
- pos,
- numRows );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
-{
- size_t row, col;
-
- size_t curNumRows = m_data.GetCount();
- size_t curNumCols = ( curNumRows > 0
- ? m_data[0].GetCount()
- : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
-
- if ( pos >= curNumCols )
- {
- return AppendCols( numCols );
- }
-
- if ( !m_colLabels.IsEmpty() )
- {
- m_colLabels.Insert( wxEmptyString, pos, numCols );
-
- size_t i;
- for ( i = pos; i < pos + numCols; i++ )
- m_colLabels[i] = wxGridTableBase::GetColLabelValue( i );
- }
-
- for ( row = 0; row < curNumRows; row++ )
- {
- for ( col = pos; col < pos + numCols; col++ )
- {
- m_data[row].Insert( wxEmptyString, col );
- }
- }
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_COLS_INSERTED,
- pos,
- numCols );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-bool wxGridStringTable::AppendCols( size_t numCols )
-{
- size_t row;
-
- size_t curNumRows = m_data.GetCount();
-
- for ( row = 0; row < curNumRows; row++ )
- {
- m_data[row].Add( wxEmptyString, numCols );
- }
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_COLS_APPENDED,
- numCols );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
-{
- size_t row;
-
- size_t curNumRows = m_data.GetCount();
- size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
- ( GetView() ? GetView()->GetNumberCols() : 0 ) );
-
- if ( pos >= curNumCols )
- {
- wxFAIL_MSG( wxString::Format
- (
- wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
- (unsigned long)pos,
- (unsigned long)numCols,
- (unsigned long)curNumCols
- ) );
- return false;
- }
-
- int colID;
- if ( GetView() )
- colID = GetView()->GetColAt( pos );
- else
- colID = pos;
-
- if ( numCols > curNumCols - colID )
- {
- numCols = curNumCols - colID;
- }
-
- if ( !m_colLabels.IsEmpty() )
- {
- // m_colLabels stores just as many elements as it needs, e.g. if only
- // the label of the first column had been set it would have only one
- // element and not numCols, so account for it
- int nToRm = m_colLabels.size() - colID;
- if ( nToRm > 0 )
- m_colLabels.RemoveAt( colID, nToRm );
- }
-
- for ( row = 0; row < curNumRows; row++ )
- {
- if ( numCols >= curNumCols )
- {
- m_data[row].Clear();
- }
- else
- {
- m_data[row].RemoveAt( colID, numCols );
- }
- }
-
- if ( GetView() )
- {
- wxGridTableMessage msg( this,
- wxGRIDTABLE_NOTIFY_COLS_DELETED,
- pos,
- numCols );
-
- GetView()->ProcessTableMessage( msg );
- }
-
- return true;
-}
-
-wxString wxGridStringTable::GetRowLabelValue( int row )