Refactor wxDataViewEvent constructors
Take care of all the common stuff such as setting the event object and the model, which is used for all events, in the ctor. Also set both the column pointer and the column index at once instead of having two separate setters for them which could result in inconsistent event objects (and did, as sometimes only one or only the other field was set). This makes the code shorter (we save 160 lines) and more clear and ensures that everything is always initialized. Closes #12649.
This commit is contained in:
@@ -769,25 +769,32 @@ protected:
|
||||
class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
|
||||
{
|
||||
public:
|
||||
wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
|
||||
: wxNotifyEvent(commandType, winid),
|
||||
m_item(0),
|
||||
m_col(-1),
|
||||
m_model(NULL),
|
||||
m_value(wxNullVariant),
|
||||
m_column(NULL),
|
||||
m_pos(-1,-1),
|
||||
m_cacheFrom(0),
|
||||
m_cacheTo(0),
|
||||
m_editCancelled(false)
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
, m_dataObject(NULL),
|
||||
m_dataBuffer(NULL),
|
||||
m_dataSize(0),
|
||||
m_dragFlags(0),
|
||||
m_dropEffect(wxDragNone)
|
||||
#endif
|
||||
{ }
|
||||
// Default ctor, normally shouldn't be used and mostly exists only for
|
||||
// backwards compatibility.
|
||||
wxDataViewEvent()
|
||||
: wxNotifyEvent()
|
||||
{
|
||||
Init(NULL, NULL, wxDataViewItem());
|
||||
}
|
||||
|
||||
// Constructor for the events affecting columns (and possibly also items).
|
||||
wxDataViewEvent(wxEventType evtType,
|
||||
wxDataViewCtrlBase* dvc,
|
||||
wxDataViewColumn* column,
|
||||
const wxDataViewItem& item = wxDataViewItem())
|
||||
: wxNotifyEvent(evtType, dvc->GetId())
|
||||
{
|
||||
Init(dvc, column, item);
|
||||
}
|
||||
|
||||
// Constructor for the events affecting only the items.
|
||||
wxDataViewEvent(wxEventType evtType,
|
||||
wxDataViewCtrlBase* dvc,
|
||||
const wxDataViewItem& item)
|
||||
: wxNotifyEvent(evtType, dvc->GetId())
|
||||
{
|
||||
Init(dvc, NULL, item);
|
||||
}
|
||||
|
||||
wxDataViewEvent(const wxDataViewEvent& event)
|
||||
: wxNotifyEvent(event),
|
||||
@@ -811,13 +818,8 @@ public:
|
||||
{ }
|
||||
|
||||
wxDataViewItem GetItem() const { return m_item; }
|
||||
void SetItem( const wxDataViewItem &item ) { m_item = item; }
|
||||
|
||||
int GetColumn() const { return m_col; }
|
||||
void SetColumn( int col ) { m_col = col; }
|
||||
|
||||
wxDataViewModel* GetModel() const { return m_model; }
|
||||
void SetModel( wxDataViewModel *model ) { m_model = model; }
|
||||
|
||||
const wxVariant &GetValue() const { return m_value; }
|
||||
void SetValue( const wxVariant &value ) { m_value = value; }
|
||||
@@ -827,7 +829,6 @@ public:
|
||||
void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
|
||||
|
||||
// for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
|
||||
void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
|
||||
wxDataViewColumn *GetDataViewColumn() const { return m_column; }
|
||||
|
||||
// for wxEVT_DATAVIEW_CONTEXT_MENU only
|
||||
@@ -860,6 +861,20 @@ public:
|
||||
|
||||
virtual wxEvent *Clone() const wxOVERRIDE { return new wxDataViewEvent(*this); }
|
||||
|
||||
// These methods shouldn't be used outside of wxWidgets and wxWidgets
|
||||
// itself doesn't use them any longer neither as it constructs the events
|
||||
// with the appropriate ctors directly.
|
||||
#if WXWIN_COMPATIBILITY_3_0
|
||||
wxDEPRECATED_MSG("Pass the argument to the ctor instead")
|
||||
void SetModel( wxDataViewModel *model ) { m_model = model; }
|
||||
wxDEPRECATED_MSG("Pass the argument to the ctor instead")
|
||||
void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
|
||||
wxDEPRECATED_MSG("Pass the argument to the ctor instead")
|
||||
void SetColumn( int col ) { m_col = col; }
|
||||
wxDEPRECATED_MSG("Pass the argument to the ctor instead")
|
||||
void SetItem( const wxDataViewItem &item ) { m_item = item; }
|
||||
#endif // WXWIN_COMPATIBILITY_3_0
|
||||
|
||||
protected:
|
||||
wxDataViewItem m_item;
|
||||
int m_col;
|
||||
@@ -883,6 +898,11 @@ protected:
|
||||
#endif // wxUSE_DRAG_AND_DROP
|
||||
|
||||
private:
|
||||
// Common part of non-copy ctors.
|
||||
void Init(wxDataViewCtrlBase* dvc,
|
||||
wxDataViewColumn* column,
|
||||
const wxDataViewItem& item);
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user