Implemented dataview_model notification event to the ctrl

(and then the user).


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46231 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-05-28 14:46:52 +00:00
parent 63415a4212
commit 1821abd1ce
3 changed files with 102 additions and 17 deletions

View File

@ -60,6 +60,24 @@ macros to direct input to member functions that take a
\end{twocollist}
Additionally, you can get informed about changes to the
\helpref{model}{wxDataViewListModel}, to which a wxDataViewCtrl
has been associated. These events correspond to the interface
offered by \helpref{wxDataViewListModelNotifier}{wxdataviewlistmodelnotifier}.
\twocolwidtha{7cm}
\begin{twocollist}\itemsep=0pt
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROW\_PREPENDED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROW\_PREPENDED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROW\_APPENDED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROW\_APPENDED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROW\_INSERTED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROW\_INSERTED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROW\_DELETED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROW\_DELETED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROW\_CHANGED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROW\_CHANGED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_VALUE\_CHANGED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_VALUE\_CHANGED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_ROWS\_REORDERED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_ROWS\_REORDERED event.}
\twocolitem{{\bf EVT\_DATAVIEW\_MODEL\_CLEARED(id, func)}}{Processes a wxEVT\_COMMAND\_DATAVIEW\_MODEL\_CLEARED event.}
\end{twocollist}
\wxheading{Derived from}

View File

@ -44,6 +44,7 @@ class WXDLLIMPEXP_ADV wxDataViewListModel;
class WXDLLIMPEXP_ADV wxDataViewCtrl;
class WXDLLIMPEXP_ADV wxDataViewColumn;
class WXDLLIMPEXP_ADV wxDataViewRenderer;
class wxDataViewEventListModelNotifier;
extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
@ -104,19 +105,6 @@ private:
// wxDataViewListModel
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewViewingColumn: public wxObject
{
public:
wxDataViewViewingColumn( wxDataViewColumn *view_column, unsigned int model_column )
{
m_viewColumn = view_column;
m_modelColumn = model_column;
}
wxDataViewColumn *m_viewColumn;
unsigned int m_modelColumn;
};
class WXDLLIMPEXP_ADV wxDataViewListModel: public wxDataViewModel
{
public:
@ -151,10 +139,9 @@ protected:
// the user should not delete this class directly: he should use DecRef() instead!
virtual ~wxDataViewListModel();
wxList m_notifiers;
wxList m_notifiers;
};
// ---------------------------------------------------------
// wxDataViewSortedListModel
// ---------------------------------------------------------
@ -481,6 +468,7 @@ public:
private:
wxDataViewListModel *m_model;
wxList m_cols;
wxDataViewEventListModelNotifier *m_eventNotifier;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
@ -553,6 +541,15 @@ BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
// notifications from the model to the control
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED, -1)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
@ -568,6 +565,15 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
#define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
#define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
#define EVT_DATAVIEW_MODEL_ROW_APPENDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_APPENDED, id, fn)
#define EVT_DATAVIEW_MODEL_ROW_PREPENDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_PREPENDED, id, fn)
#define EVT_DATAVIEW_MODEL_ROW_INSERTED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_INSERTED, id, fn)
#define EVT_DATAVIEW_MODEL_ROW_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_DELETED, id, fn)
#define EVT_DATAVIEW_MODEL_ROW_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_CHANGED, id, fn)
#define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn)
#define EVT_DATAVIEW_MODEL_ROWS_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROWS_REORDERED, id, fn)
#define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn)
#if defined(wxUSE_GENERICDATAVIEWCTRL)
#include "wx/generic/dataview.h"

View File

@ -872,6 +872,44 @@ void wxDataViewColumnBase::SetFlags(int flags)
SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
}
// ---------------------------------------------------------
// wxDataViewEventListModelNotifier
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewEventListModelNotifier: public wxDataViewListModelNotifier
{
public:
wxDataViewEventListModelNotifier( wxDataViewCtrl *ctrl ) { m_ctrl = ctrl; }
bool SendEvent( wxEventType event_type, unsigned int row = 0, unsigned int col = 0 )
{
wxDataViewEvent event( event_type, m_ctrl->GetId() );
event.SetEventObject( m_ctrl );
event.SetModel( m_ctrl->GetModel() );
event.SetRow( row );
event.SetColumn( col );
m_ctrl->GetEventHandler()->ProcessEvent( event );
return true;
}
virtual bool RowAppended() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED ); }
virtual bool RowPrepended() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED ); }
virtual bool RowInserted( unsigned int before )
{ return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED, before ); }
virtual bool RowDeleted( unsigned int row )
{ return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED, row ); }
virtual bool RowChanged( unsigned int row )
{ return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED, row ); }
virtual bool ValueChanged( unsigned int col, unsigned int row )
{ return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, row, col ); }
virtual bool RowsReordered( unsigned int *new_order )
{ return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED ); }
virtual bool Cleared() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED ); }
private:
wxDataViewCtrl *m_ctrl;
};
// ---------------------------------------------------------
// wxDataViewCtrlBase
@ -883,6 +921,7 @@ wxDataViewCtrlBase::wxDataViewCtrlBase()
{
m_model = NULL;
m_cols.DeleteContents( true );
m_eventNotifier = NULL;
}
wxDataViewCtrlBase::~wxDataViewCtrlBase()
@ -894,6 +933,10 @@ wxDataViewCtrlBase::~wxDataViewCtrlBase()
if (m_model)
{
if (m_eventNotifier)
m_model->RemoveNotifier( m_eventNotifier );
m_eventNotifier = NULL;
m_model->DecRef();
m_model = NULL;
}
@ -901,13 +944,23 @@ wxDataViewCtrlBase::~wxDataViewCtrlBase()
bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
{
if ( m_model )
if (m_model)
{
if (m_eventNotifier)
m_model->RemoveNotifier( m_eventNotifier );
m_eventNotifier = NULL;
m_model->DecRef(); // discard old model, if any
}
// add our own reference to the new model:
m_model = model;
if ( m_model )
if (m_model)
{
m_model->IncRef();
m_eventNotifier = new wxDataViewEventListModelNotifier( (wxDataViewCtrl*) this );
m_model->AddNotifier( m_eventNotifier );
}
return true;
}
@ -1035,5 +1088,13 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED)
#endif