Override this to allow getting values from the model.
+
+\membersection{wxDataViewIndexListModel::Reset}\label{wxdataviewindexlistmodelreset}
+
+\func{void}{Reset}{\param{unsigned int }{new\_size}}
+
+Call this after if the data has to be read again from
+the model. This is useful after major changes when
+calling the methods below (possibly thousands of times)
+doesn't make sense.
+
\membersection{wxDataViewIndexListModel::RowAppended}\label{wxdataviewindexlistmodelrowappended}
\func{void}{RowAppended}{\void}
\func{virtual bool}{Cleared}{\void}
-Called to inform the model that all data has been deleted.
+Called to inform the model that all data has been cleared. The
+control will reread the data from the model again.
\membersection{wxDataViewModel::Compare}\label{wxdataviewmodelcompare}
void RowsDeleted( const wxArrayInt &rows );
void RowChanged( unsigned int row );
void RowValueChanged( unsigned int row, unsigned int col );
+ void Reset( unsigned int new_size );
// convert to/from row/wxDataViewItem
friend class wxDataViewCtrlDCImpl;
friend class wxDataViewColumn;
friend class wxGtkDataViewModelNotifier;
+ friend class wxDataViewCtrlInternal;
+
GtkWidget *m_treeview;
wxDataViewModelNotifier *m_notifier;
wxDataViewCtrlInternal *m_internal;
public:
MyListModel() :
#ifdef __WXMAC__
- wxDataViewIndexListModel( 1000 )
+ wxDataViewIndexListModel( 1000 + 100 )
#else
- wxDataViewIndexListModel( 100000 )
+ wxDataViewIndexListModel( 100000 + 100 )
#endif
{
+#ifdef __WXMAC__
+ m_virtualItems = 1000;
+#else
+ m_virtualItems = 100000;
+#endif
+
unsigned int i;
for (i = 0; i < 100; i++)
{
wxString str;
- str.Printf( "row number %d", i );
+ str.Printf( "Test %d", i );
m_array.Add( str );
}
void DeleteItem( const wxDataViewItem &item )
{
unsigned int row = GetRow( item );
+ if (row >= m_array.GetCount())
+ return;
+
m_array.RemoveAt( row );
RowDeleted( row );
}
for (i = 0; i < items.GetCount(); i++)
{
unsigned int row = GetRow( items[i] );
- rows.Add( row );
+ if (row < m_array.GetCount())
+ rows.Add( row );
}
// Sort in descending order so that the last
void AddMany()
{
+ m_virtualItems += 1000;
+ Reset( m_array.GetCount() + m_virtualItems );
}
// implementation of base class virtuals to define model
return "string";
}
- virtual unsigned int GetRowCount()
- {
- return m_array.GetCount();
- }
-
virtual void GetValue( wxVariant &variant,
unsigned int row, unsigned int col ) const
{
if (row >= m_array.GetCount())
{
wxString str;
- str.Printf( "row %d", row );
+ str.Printf( "row %d", row - m_array.GetCount() );
variant = str;
}
else
} else
if (col==2)
{
- if ((row % 2) == 1)
- variant = "Blue";
+ if (row >= m_array.GetCount())
+ variant = "plain";
else
- variant = "Italic";
+ variant = "blue italic";
}
}
if (col != 2)
return false;
- if ((row % 2) == 1)
+ if (row < m_array.GetCount())
+ {
attr.SetColour( *wxBLUE );
- else
attr.SetItalic( true );
+ }
return true;
}
wxArrayString m_array;
wxIcon m_icon;
+ int m_virtualItems;
};
// -------------------------------------
{
}
+void wxDataViewIndexListModel::Reset( unsigned int new_size )
+{
+ if (m_useHash)
+ {
+ m_hash.Clear();
+
+ // IDs are ordered until an item gets deleted or inserted
+ m_ordered = true;
+
+ // build initial index
+ unsigned int i;
+ for (i = 1; i < new_size+1; i++)
+ m_hash.Add( (void*) i );
+ m_lastIndex = new_size + 1;
+ }
+ else
+ {
+ m_lastIndex = new_size-1;
+ }
+
+ wxDataViewModel::Cleared();
+}
+
void wxDataViewIndexListModel::RowPrepended()
{
if (m_useHash)
return 0;
children = m_hash;
-
+
return m_hash.GetCount();
}
bool wxDataViewMainWindow::Cleared()
{
- SortPrepare();
-
DestroyTree();
+
+ SortPrepare();
+ BuildTree( GetOwner()->GetModel() );
+
UpdateDisplay();
return true;
GtkTreeIter *iter)
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
+
+ if (wxtree_model->stamp != iter->stamp)
+ wxPrintf( "crash\n" );
+
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
-
+
return wxtree_model->internal->iter_next( iter );
}
virtual bool Cleared();
virtual void Resort();
+ void SetGtkModel( GtkWxTreeModel *model ) { m_wxgtk_model = model; }
+
+private:
GtkWxTreeModel *m_wxgtk_model;
wxDataViewModel *m_wx_model;
wxDataViewCtrl *m_owner;
bool wxGtkDataViewModelNotifier::Cleared()
{
- // TODO: delete everything
-
+ gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL );
+
+ // this will create a new GTK model
m_owner->GtkGetInternal()->Cleared();
+
+ SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() );
+ gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) );
+
return false;
}
}
}
+bool wxDataViewCtrlInternal::Cleared()
+{
+ if (m_root)
+ {
+ delete m_root;
+ InitTree();
+ }
+
+ // Create new GTK model
+ g_object_unref( m_gtk_model );
+ m_gtk_model = wxgtk_tree_model_new();
+ m_gtk_model->internal = this;
+
+ return true;
+}
+
void wxDataViewCtrlInternal::Resort()
{
if (!m_wx_model->IsIndexListModel())
return true;
}
-bool wxDataViewCtrlInternal::Cleared()
-{
- return true;
-}
-
GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
{
if (m_wx_model->IsIndexListModel())
void wxDataViewCtrl::Init()
{
m_notifier = NULL;
+ m_internal = NULL;
}
bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
{
+ if (GetModel())
+ {
+ delete m_internal;
+ m_internal = NULL;
+
+ delete m_notifier;
+ m_notifier = NULL;
+ }
+
if (!wxDataViewCtrlBase::AssociateModel( model ))
return false;
virtual bool Cleared(void)
{
- return (this->m_dataViewControlPtr->RemoveItems() == noErr);
+ bool noFailureFlag = (this->m_dataViewControlPtr->RemoveItems() == noErr);
+ wxDataViewItem item;
+ wxDataViewItemArray array;
+ GetOwner()->GetChildren( item, array );
+ ItemsAdded( item, array );
+ return noFailureFlag;
} /* Cleared(void) */
virtual void Resort(void)