From: Robert Roebling Date: Mon, 27 Feb 2006 13:09:41 +0000 (+0000) Subject: Added generic MVC hookup code. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b5d777c78eef2b5d2a949f2898bc3190dd135e6f Added generic MVC hookup code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37749 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 5996daccfa..5d2b516d77 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -64,8 +64,9 @@ public: virtual bool RowInserted( size_t before ) = 0; virtual bool RowDeleted( size_t row ) = 0; virtual bool RowChanged( size_t row ) = 0; - virtual bool ValueChanged( size_t row, size_t col ) = 0; + virtual bool ValueChanged( size_t col, size_t row ) = 0; virtual bool Cleared() = 0; + virtual bool ValueChanged( wxDataViewColumn *view_column, size_t model_column, size_t row ) = 0; }; // --------------------------------------------------------- @@ -95,12 +96,18 @@ public: bool RowChanged( size_t row ); bool ValueChanged( size_t col, size_t row ); bool Cleared(); + + // Used internally + void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column ); + void RemoveViewingColumn( wxDataViewColumn *column ); + // Used internally void SetNotifier( wxDataViewListModelNotifier *notifier ); wxDataViewListModelNotifier* GetNotifier(); private: wxDataViewListModelNotifier *m_notifier; + wxList m_viewingColumns; protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 109b136e9a..d7d71ca59c 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -34,11 +34,26 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject) // wxDataViewListModel // --------------------------------------------------------- +class wxDataViewViewingColumn: public wxObject +{ +public: + wxDataViewViewingColumn( wxDataViewColumn *view_column, size_t model_column ) + { + m_viewColumn = view_column; + m_modelColumn = model_column; + } + + wxDataViewColumn *m_viewColumn; + size_t m_modelColumn; +}; + + IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel) wxDataViewListModel::wxDataViewListModel() { m_notifier = NULL; + m_viewingColumns.DeleteContents( true ); } wxDataViewListModel::~wxDataViewListModel() @@ -89,10 +104,23 @@ bool wxDataViewListModel::RowChanged( size_t row ) bool wxDataViewListModel::ValueChanged( size_t col, size_t row ) { + bool ret = false; + if (m_notifier) - return m_notifier->ValueChanged( col, row ); + ret = m_notifier->ValueChanged( col, row ); - return false; + wxNode *node = m_viewingColumns.GetFirst(); + while (node) + { + wxDataViewViewingColumn* tmp = (wxDataViewViewingColumn*) node->GetData(); + + if (tmp->m_modelColumn == col) + m_notifier->ValueChanged( tmp->m_viewColumn, col, row ); + + node = node->GetNext(); + } + + return ret; } bool wxDataViewListModel::Cleared() @@ -103,6 +131,28 @@ bool wxDataViewListModel::Cleared() return false; } +void wxDataViewListModel::AddViewingColumn( wxDataViewColumn *view_column, size_t model_column ) +{ + m_viewingColumns.Append( new wxDataViewViewingColumn( view_column, model_column ) ); +} + +void wxDataViewListModel::RemoveViewingColumn( wxDataViewColumn *column ) +{ + wxNode *node = m_viewingColumns.GetFirst(); + while (node) + { + wxDataViewViewingColumn* tmp = (wxDataViewViewingColumn*) node->GetData(); + + if (tmp->m_viewColumn == column) + { + m_viewingColumns.DeleteObject( tmp ); + return; + } + + node = node->GetNext(); + } +} + void wxDataViewListModel::SetNotifier( wxDataViewListModelNotifier *notifier ) { if (m_notifier) @@ -148,6 +198,11 @@ wxDataViewColumnBase::~wxDataViewColumnBase() { if (m_cell) delete m_cell; + + if (GetOwner()) + { + GetOwner()->GetModel()->RemoveViewingColumn( (wxDataViewColumn*) this ); + } } void wxDataViewColumnBase::SetTitle( const wxString &title ) @@ -217,6 +272,7 @@ bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) { m_cols.Append( (wxObject*) col ); col->SetOwner( (wxDataViewCtrl*) this ); + m_model->AddViewingColumn( col, col->GetModelColumn() ); return true; } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 104854c009..76f1fe07fa 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -736,6 +736,7 @@ public: virtual bool RowChanged( size_t row ); virtual bool ValueChanged( size_t col, size_t row ); virtual bool Cleared(); + virtual bool ValueChanged( wxDataViewColumn *view_column, size_t model_column, size_t row ); GtkWxListStore *m_gtk_store; wxDataViewListModel *m_wx_model; @@ -814,6 +815,11 @@ bool wxGtkDataViewListModelNotifier::Cleared() return false; } +bool wxGtkDataViewListModelNotifier::ValueChanged( wxDataViewColumn *view_column, size_t model_column, size_t row ) +{ + return false; +} + // --------------------------------------------------------- // wxDataViewCell // ---------------------------------------------------------