From: Robert Roebling Date: Tue, 21 Feb 2006 20:52:05 +0000 (+0000) Subject: Add notifier class. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6e2e590f2adca1d43ab654c2128459ebc339c87d?ds=inline Add notifier class. Only use listmodel for now, treemodel later. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37662 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 2cfc416dd1..47b2edef57 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -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) diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index c7660680b5..4da012ab87 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -52,7 +52,7 @@ public: virtual bool AppendStringColumn( const wxString &label ); - virtual bool AssociateModel( wxDataViewModel *model ); + virtual bool AssociateModel( wxDataViewListModel *model ); private: diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index b48d1a9573..2cd8efd21b 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -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; } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 01deedecbb..79b977e885 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -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; }