]> git.saurik.com Git - wxWidgets.git/commitdiff
Add notifier class.
authorRobert Roebling <robert@roebling.de>
Tue, 21 Feb 2006 20:52:05 +0000 (20:52 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 21 Feb 2006 20:52:05 +0000 (20:52 +0000)
  Only use listmodel for now, treemodel later.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37662 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
include/wx/gtk/dataview.h
src/common/datavcmn.cpp
src/gtk/dataview.cpp

index 2cfc416dd1ec9c28992a64d1ea78d43fc6608cc0..47b2edef5735af34d0e33857074d6a1cf546bd9d 100644 (file)
@@ -111,11 +111,11 @@ public:
 
     virtual bool AppendStringColumn( const wxString &label ) = 0;
     
-    virtual bool AssociateModel( wxDataViewModel *model );
-    wxDataViewModel* GetModel();
+    virtual bool AssociateModel( wxDataViewListModel *model );
+    wxDataViewListModel* GetModel();
     
 private:
-    wxDataViewModel    *m_model;
+    wxDataViewListModel    *m_model;
 
 protected:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
index c7660680b5db11f062fbe2bb021daf6e614a812d..4da012ab872f0352b257e67276d7cb62bb765ead 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     virtual bool AppendStringColumn( const wxString &label );
 
-    virtual bool AssociateModel( wxDataViewModel *model );
+    virtual bool AssociateModel( wxDataViewListModel *model );
     
     
 private:
index b48d1a9573ad750fd94f2fc6befcf5388639886c..2cd8efd21b8eda40d986253a873b129fe581ada1 100644 (file)
@@ -129,7 +129,7 @@ wxDataViewCtrlBase::~wxDataViewCtrlBase()
         delete m_model;
 }
 
-bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
+bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
 {
     if (m_model)
         delete m_model;
@@ -139,7 +139,7 @@ bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
     return true;
 }
 
-wxDataViewModel* wxDataViewCtrlBase::GetModel()
+wxDataViewListModel* wxDataViewCtrlBase::GetModel()
 {
     return m_model;
 }
index 01deedecbb16b5c4328769b80a02b0f6d44ddcf1..79b977e88593f4ed9c90d262fe80e151b571d387 100644 (file)
@@ -423,6 +423,84 @@ wxgtk_list_store_iter_parent (GtkTreeModel *tree_model,
     return FALSE;
 }
 
+// --------------------------------------------------------- 
+// wxGtkDataViewListModelNotifier
+// --------------------------------------------------------- 
+
+class wxGtkDataViewListModelNotifier: public wxDataViewListModelNotifier
+{
+public:
+    wxGtkDataViewListModelNotifier( GtkWxListStore* gtk_store, wxDataViewListModel *wx_model );
+    
+    virtual bool RowAppended();
+    virtual bool RowPrepended();
+    virtual bool RowInserted( size_t before );
+    virtual bool RowDeleted( size_t row );
+    virtual bool RowChanged( size_t row );
+    virtual bool ValueChanged( size_t row, size_t col );
+    virtual bool Cleared();
+    
+    GtkWxListStore      *m_gtk_store;
+    wxDataViewListModel *m_wx_model;
+};
+
+// --------------------------------------------------------- 
+// wxGtkDataViewListModelNotifier
+// --------------------------------------------------------- 
+
+wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier( 
+    GtkWxListStore* gtk_store, wxDataViewListModel *wx_model )
+{
+    m_gtk_store = gtk_store;
+    m_wx_model = wx_model;
+}
+    
+bool wxGtkDataViewListModelNotifier::RowAppended()
+{
+    size_t pos = m_wx_model->GetNumberOfRows()-1;
+    
+    GtkTreeIter iter;
+    iter.stamp = m_gtk_store->stamp;
+    iter.user_data = (gpointer) pos;
+    
+    GtkTreePath *path = gtk_tree_path_new ();
+    gtk_tree_path_append_index (path, (gint) pos);
+    gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store), path, &iter);
+    gtk_tree_path_free (path);
+    
+    return true;
+}
+
+bool wxGtkDataViewListModelNotifier::RowPrepended()
+{
+    return false;
+}
+
+bool wxGtkDataViewListModelNotifier::RowInserted( size_t before )
+{
+    return false;
+}
+
+bool wxGtkDataViewListModelNotifier::RowDeleted( size_t row )
+{
+    return false;
+}
+
+bool wxGtkDataViewListModelNotifier::RowChanged( size_t row )
+{
+    return false;
+}
+
+bool wxGtkDataViewListModelNotifier::ValueChanged( size_t row, size_t col )
+{
+    return false;
+}
+
+bool wxGtkDataViewListModelNotifier::Cleared()
+{
+    return false;
+}
+
 
 //-----------------------------------------------------------------------------
 // wxDataViewCtrl
@@ -476,15 +554,20 @@ bool wxDataViewCtrl::AppendStringColumn( const wxString &label )
     return true;
 }
 
-bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
+bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model )
 {
     if (!wxDataViewCtrlBase::AssociateModel( model ))
         return false;
 
-    GtkWxListStore *wxmodel = wxgtk_list_store_new();
-    wxmodel->model = (wxDataViewListModel*) model;
+    GtkWxListStore *gtk_store = wxgtk_list_store_new();
+    gtk_store->model = model;
+
+    wxGtkDataViewListModelNotifier *notifier = 
+        new wxGtkDataViewListModelNotifier( gtk_store, model );
+
+    model->SetNotifier( notifier );    
 
-    gtk_tree_view_set_model( GTK_TREE_VIEW(m_widget), GTK_TREE_MODEL(wxmodel) );
+    gtk_tree_view_set_model( GTK_TREE_VIEW(m_widget), GTK_TREE_MODEL(gtk_store) );
     
     return true;
 }