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:
Vadim Zeitlin
2016-03-18 23:33:27 +01:00
parent e2e7d3d391
commit 9829446755
6 changed files with 166 additions and 325 deletions

View File

@@ -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);
};

View File

@@ -669,16 +669,13 @@ wxDataViewCtrl* wxDataViewRendererBase::GetView() const
bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
{
wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
wxDataViewColumn* const column = GetOwner();
wxDataViewCtrl* const dv_ctrl = column->GetOwner();
// Before doing anything we send an event asking if editing of this item is really wanted.
wxDataViewEvent start_event( wxEVT_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() );
start_event.SetDataViewColumn( GetOwner() );
start_event.SetModel( dv_ctrl->GetModel() );
start_event.SetItem( item );
start_event.SetEventObject( dv_ctrl );
dv_ctrl->GetEventHandler()->ProcessEvent( start_event );
if( !start_event.IsAllowed() )
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_START_EDITING, dv_ctrl, column, item);
dv_ctrl->GetEventHandler()->ProcessEvent( event );
if( !event.IsAllowed() )
return false;
unsigned int col = GetOwner()->GetModelColumn();
@@ -712,11 +709,7 @@ void wxDataViewRendererBase::NotifyEditingStarted(const wxDataViewItem& item)
wxDataViewColumn* const column = GetOwner();
wxDataViewCtrl* const dv_ctrl = column->GetOwner();
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() );
event.SetDataViewColumn( column );
event.SetModel( dv_ctrl->GetModel() );
event.SetItem( item );
event.SetEventObject( dv_ctrl );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl, column, item);
dv_ctrl->GetEventHandler()->ProcessEvent( event );
}
@@ -756,7 +749,8 @@ bool wxDataViewRendererBase::FinishEditing()
wxVariant value;
const bool gotValue = GetValueFromEditorCtrl(m_editorCtrl, value);
wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
wxDataViewColumn* const column = GetOwner();
wxDataViewCtrl* const dv_ctrl = column->GetOwner();
DestroyEditControl();
@@ -769,14 +763,9 @@ bool wxDataViewRendererBase::FinishEditing()
unsigned int col = GetOwner()->GetModelColumn();
// Now we should send Editing Done event
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
event.SetDataViewColumn( GetOwner() );
event.SetModel( dv_ctrl->GetModel() );
event.SetItem( m_item );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl, column, m_item);
event.SetValue( value );
event.SetColumn( col );
event.SetEditCanceled( !isValid );
event.SetEventObject( dv_ctrl );
dv_ctrl->GetEventHandler()->ProcessEvent( event );
bool accepted = false;
@@ -1591,6 +1580,29 @@ wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP, wxDataViewEvent );
// Common part of non-copy ctors.
void wxDataViewEvent::Init(wxDataViewCtrlBase* dvc,
wxDataViewColumn* column,
const wxDataViewItem& item)
{
m_item = item;
m_col = column ? column->GetModelColumn() : -1;
m_model = dvc->GetModel();
m_column = column;
m_pos = wxDefaultPosition;
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 // wxUSE_DRAG_AND_DROP
SetEventObject(dvc);
}
#if wxUSE_SPINCTRL

View File

@@ -293,12 +293,7 @@ private:
bool SendEvent(wxEventType type, unsigned int n)
{
wxDataViewCtrl * const owner = GetOwner();
wxDataViewEvent event(type, owner->GetId());
event.SetEventObject(owner);
event.SetColumn(n);
event.SetDataViewColumn(owner->GetColumn(n));
event.SetModel(owner->GetModel());
wxDataViewEvent event(type, owner, owner->GetColumn(n));
// for events created by wxDataViewHeaderWindow the
// row / value fields are not valid
@@ -1658,12 +1653,7 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
if ( row < GetRowCount() && xx <= GetEndOfLastCol() )
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item);
event.SetDataFormat( format );
event.SetDropEffect( def );
if ( !m_owner->HandleWindowEvent( event ) || !event.IsAllowed() )
@@ -1702,12 +1692,7 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
if ( row < GetRowCount() && xx <= GetEndOfLastCol())
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item);
event.SetDataFormat( format );
if (!m_owner->HandleWindowEvent( event ) || !event.IsAllowed())
return false;
@@ -1728,14 +1713,9 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo
if ( row < GetRowCount() && xx <= GetEndOfLastCol() )
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
wxCustomDataObject *obj = (wxCustomDataObject *) GetDropTarget()->GetDataObject();
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, m_owner, item);
event.SetDataFormat( format );
event.SetDataSize( obj->GetSize() );
event.SetDataBuffer( obj->GetData() );
@@ -1851,11 +1831,9 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
unsigned int item_last = item_start + item_count;
// Send the event to wxDataViewCtrl itself.
wxWindow * const parent = GetParent();
wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, parent->GetId());
cache_event.SetEventObject(parent);
wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, m_owner, NULL);
cache_event.SetCache(item_start, item_last - 1);
parent->ProcessWindowEvent(cache_event);
m_owner->ProcessWindowEvent(cache_event);
// compute which columns needs to be redrawn
unsigned int cols = GetOwner()->GetColumnCount();
@@ -2537,12 +2515,8 @@ bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
GetOwner()->InvalidateColBestWidths();
// Send event
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
le.SetEventObject(parent);
le.SetModel(GetModel());
le.SetItem(item);
parent->ProcessWindowEvent(le);
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, item);
m_owner->ProcessWindowEvent(le);
return true;
}
@@ -2568,14 +2542,9 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
GetOwner()->InvalidateColBestWidth(view_column);
// Send event
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
le.SetEventObject(parent);
le.SetModel(GetModel());
le.SetItem(item);
le.SetColumn(view_column);
le.SetDataViewColumn(GetOwner()->GetColumn(view_column));
parent->ProcessWindowEvent(le);
wxDataViewColumn* const column = m_owner->GetColumn(view_column);
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, column, item);
m_owner->ProcessWindowEvent(le);
return true;
}
@@ -2824,14 +2793,8 @@ bool wxDataViewMainWindow::IsRowSelected( unsigned int row )
void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem& item)
{
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_DATAVIEW_SELECTION_CHANGED, parent->GetId());
le.SetEventObject(parent);
le.SetModel(GetModel());
le.SetItem( item );
parent->ProcessWindowEvent(le);
wxDataViewEvent le(wxEVT_DATAVIEW_SELECTION_CHANGED, m_owner, item);
m_owner->ProcessWindowEvent(le);
}
void wxDataViewMainWindow::RefreshRow( unsigned int row )
@@ -3122,14 +3085,8 @@ bool
wxDataViewMainWindow::SendExpanderEvent(wxEventType type,
const wxDataViewItem& item)
{
wxWindow *parent = GetParent();
wxDataViewEvent le(type, parent->GetId());
le.SetEventObject(parent);
le.SetModel(GetModel());
le.SetItem( item );
return !parent->ProcessWindowEvent(le) || le.IsAllowed();
wxDataViewEvent le(type, m_owner, item);
return !m_owner->ProcessWindowEvent(le) || le.IsAllowed();
}
bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
@@ -3709,13 +3666,8 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
const wxDataViewItem item = GetItemByRow(m_currentRow);
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED,
parent->GetId());
le.SetItem(item);
le.SetEventObject(parent);
le.SetModel(GetModel());
if ( parent->ProcessWindowEvent(le) )
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, m_owner, item);
if ( m_owner->ProcessWindowEvent(le) )
break;
// else: fall through to WXK_SPACE handling
}
@@ -4121,19 +4073,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
// the other ones.
if (event.RightUp())
{
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
le.SetEventObject(parent);
le.SetModel(model);
if ( item.IsOk() && col )
{
le.SetItem( item );
le.SetColumn( col->GetModelColumn() );
le.SetDataViewColumn( col );
}
parent->ProcessWindowEvent(le);
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, m_owner, col, item);
m_owner->ProcessWindowEvent(le);
return;
}
@@ -4162,10 +4103,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
wxDataViewItem itemDragged = GetItemByRow( drag_item_row );
// Notify cell about drag
wxDataViewEvent evt( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
evt.SetEventObject( m_owner );
evt.SetItem( itemDragged );
evt.SetModel( model );
wxDataViewEvent evt(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner, itemDragged);
if (!m_owner->HandleWindowEvent( evt ))
return;
@@ -4279,15 +4217,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
{
if ( !hoverOverExpander && (current == m_lineLastClicked) )
{
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
le.SetItem( item );
le.SetColumn( col->GetModelColumn() );
le.SetDataViewColumn( col );
le.SetEventObject(parent);
le.SetModel(GetModel());
if ( parent->ProcessWindowEvent(le) )
wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, m_owner, col, item);
if ( m_owner->ProcessWindowEvent(le) )
{
// Item activation was handled from the user code.
return;

View File

@@ -979,9 +979,8 @@ wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
if (gs_lastLeftClickHeader)
{
wxDataViewCtrl *dv = tree_model->internal->GetOwner();
wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_SORTED, dv->GetId() );
event.SetDataViewColumn( gs_lastLeftClickHeader );
event.SetModel( dv->GetModel() );
wxDataViewEvent
event(wxEVT_DATAVIEW_COLUMN_SORTED, dv, gs_lastLeftClickHeader);
dv->HandleWindowEvent( event );
}
@@ -1129,11 +1128,7 @@ static GtkCellEditable *gtk_wx_cell_renderer_text_start_editing(
item(column->GetOwner()->GTKPathToItem(wxGtkTreePath(path)));
wxDataViewCtrl *dv = column->GetOwner();
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_START_EDITING, dv->GetId() );
event.SetDataViewColumn( column );
event.SetModel( dv->GetModel() );
event.SetColumn( column->GetModelColumn() );
event.SetItem( item );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_START_EDITING, dv, column, item);
dv->HandleWindowEvent( event );
if (event.IsAllowed())
@@ -3002,9 +2997,7 @@ gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
gs_lastLeftClickHeader = column;
wxDataViewCtrl *dv = column->GetOwner();
wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
event.SetDataViewColumn( column );
event.SetModel( dv->GetModel() );
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dv, column);
if (dv->HandleWindowEvent( event ))
return FALSE;
}
@@ -3012,9 +3005,8 @@ gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
if (gdk_event->button == 3)
{
wxDataViewCtrl *dv = column->GetOwner();
wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
event.SetDataViewColumn( column );
event.SetModel( dv->GetModel() );
wxDataViewEvent
event(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv, column);
if (dv->HandleWindowEvent( event ))
return FALSE;
}
@@ -3605,14 +3597,12 @@ gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag
delete m_dragDataObject;
m_dragDataObject = NULL;
wxDataViewItem item(GetOwner()->GTKPathToItem(path));
wxDataViewCtrl* const dvc = GetOwner();
wxDataViewItem item(dvc->GTKPathToItem(path));
if ( !item )
return FALSE;
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( m_wx_model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, dvc, item);
gint x, y;
gtk_widget_get_pointer(m_owner->GtkGetTreeView(), &x, &y);
event.SetPosition(x, y);
@@ -3676,10 +3666,7 @@ wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest),
{
wxDataViewItem item(GetOwner()->GTKPathToItem(path));
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( m_wx_model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, m_owner, item);
event.SetDataFormat(gtk_selection_data_get_target(selection_data));
event.SetDataSize(gtk_selection_data_get_length(selection_data));
event.SetDataBuffer(const_cast<guchar*>(gtk_selection_data_get_data(selection_data)));
@@ -3699,10 +3686,7 @@ wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
{
wxDataViewItem item(GetOwner()->GTKPathToItem(path));
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetModel( m_wx_model );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item);
event.SetDataFormat(gtk_selection_data_get_target(selection_data));
event.SetDataSize(gtk_selection_data_get_length(selection_data));
if (!m_owner->HandleWindowEvent( event ))
@@ -3822,10 +3806,7 @@ bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wx
bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetModel( m_owner->GetModel() );
event.SetItem( item );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, item);
m_owner->HandleWindowEvent( event );
return true;
@@ -3833,12 +3814,9 @@ bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int view_column )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetModel( m_owner->GetModel() );
event.SetColumn( view_column );
event.SetDataViewColumn( GetOwner()->GetColumn(view_column) );
event.SetItem( item );
wxDataViewColumn* const column = m_owner->GetColumn(view_column);
wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, column, item);
m_owner->HandleWindowEvent( event );
return true;
@@ -4371,10 +4349,8 @@ wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wx
if (!gtk_widget_get_realized(dv->m_widget))
return;
wxDataViewEvent event( wxEVT_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
event.SetEventObject( dv );
event.SetItem( dv->GetSelection() );
event.SetModel( dv->GetModel() );
wxDataViewEvent
event(wxEVT_DATAVIEW_SELECTION_CHANGED, dv, dv->GetSelection());
dv->HandleWindowEvent( event );
}
@@ -4382,11 +4358,8 @@ static void
wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path,
GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
wxDataViewItem item(dv->GTKPathToItem(path));
event.SetItem( item );
event.SetModel( dv->GetModel() );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED, dv, item);
dv->HandleWindowEvent( event );
}
@@ -4394,11 +4367,8 @@ static gboolean
wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
wxDataViewItem item( (void*) iter->user_data );;
event.SetItem( item );
event.SetModel( dv->GetModel() );
wxDataViewItem item( (void*) iter->user_data );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING, dv, item);
dv->HandleWindowEvent( event );
return !event.IsAllowed();
@@ -4408,11 +4378,8 @@ static void
wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
wxDataViewItem item( (void*) iter->user_data );;
event.SetItem( item );
event.SetModel( dv->GetModel() );
wxDataViewItem item( (void*) iter->user_data );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED, dv, item);
dv->HandleWindowEvent( event );
}
@@ -4420,11 +4387,8 @@ static gboolean
wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
wxDataViewItem item( (void*) iter->user_data );;
event.SetItem( item );
event.SetModel( dv->GetModel() );
wxDataViewItem item( (void*) iter->user_data );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING, dv, item);
dv->HandleWindowEvent( event );
return !event.IsAllowed();
@@ -4434,11 +4398,8 @@ static void
wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
wxDataViewItem item( (void*) iter->user_data );;
event.SetItem( item );
event.SetModel( dv->GetModel() );
wxDataViewItem item( (void*) iter->user_data );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED, dv, item);
dv->HandleWindowEvent( event );
}
@@ -4531,10 +4492,8 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
gtk_tree_selection_select_path(selection, path);
}
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() );
if (path)
event.SetItem(dv->GTKPathToItem(path));
event.SetModel( dv->GetModel() );
wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv, dv->GTKPathToItem(path));
return dv->HandleWindowEvent( event );
}

View File

@@ -544,10 +544,7 @@ outlineView:(NSOutlineView*)outlineView
wxCHECK_MSG( dvc->GetModel(), false,
"Pointer to model not set correctly." );
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, dvc->GetId());
event.SetEventObject(dvc);
event.SetItem(wxDataViewItemFromItem(item));
event.SetModel(dvc->GetModel());
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, dvc, wxDataViewItemFromItem(item));
BOOL dragSuccessful = false;
if ( [bestType compare:DataViewPboardType] == NSOrderedSame )
@@ -755,16 +752,10 @@ outlineView:(NSOutlineView*)outlineView
// send first the event to wxWidgets that the sorting has changed so that
// the program can do special actions before the sorting actually starts:
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_SORTED,dvc->GetId()); // variable definition
event.SetEventObject(dvc);
if (noOfDescriptors > 0)
{
wxDataViewColumn* const col = [[wxSortDescriptors objectAtIndex:0] columnPtr];
event.SetColumn(dvc->GetColumnPosition(col));
event.SetDataViewColumn(col);
}
wxDataViewColumn* const col = noOfDescriptors > 0
? [[wxSortDescriptors objectAtIndex:0] columnPtr]
: NULL;
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_SORTED, dvc, col);
dvc->GetEventHandler()->ProcessEvent(event);
// start re-ordering the data;
@@ -793,12 +784,7 @@ outlineView:(NSOutlineView*)outlineView
wxCHECK_MSG(dvc, false, "Pointer to data view control not set correctly.");
wxCHECK_MSG(dvc->GetModel(), false, "Pointer to model not set correctly.");
wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem(wxDataViewItemFromItem(item));
event.SetModel(dvc->GetModel());
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, dvc, wxDataViewItemFromItem(item));
if ([bestType compare:DataViewPboardType] == NSOrderedSame)
{
NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]);
@@ -898,22 +884,16 @@ outlineView:(NSOutlineView*)outlineView
// send a begin drag event for all selected items and proceed with
// dragging unless the event is vetoed:
wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG,dvc->GetId());
event.SetEventObject(dvc);
event.SetModel(dvc->GetModel());
for (size_t itemCounter=0; itemCounter<[writeItems count]; ++itemCounter)
{
bool itemStringAvailable(false); // a flag indicating if for the current item a string is available
wxDataObjectComposite* itemObject(new wxDataObjectComposite()); // data object for current item
wxString itemString; // contains the TAB concatenated data of an item
event.SetItem(
wxDataViewItemFromItem([writeItems objectAtIndex:itemCounter]));
itemString = ::ConcatenateDataViewItemValues(dvc,event.GetItem());
const wxDataViewItem item = wxDataViewItemFromItem([writeItems objectAtIndex:itemCounter]);
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, dvc, item);
itemString = ::ConcatenateDataViewItemValues(dvc, item);
itemObject->Add(new wxTextDataObject(itemString));
event.SetDataObject(itemObject);
// check if event has not been vetoed:
if (dvc->HandleWindowEvent(event) && event.IsAllowed() && (event.GetDataObject()->GetFormatCount() > 0))
{
@@ -1616,11 +1596,8 @@ outlineView:(NSOutlineView*)outlineView
// sent whether the cell is editable or not
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem(wxDataViewItemFromItem([self itemAtRow:[self clickedRow]]));
const wxDataViewItem item = wxDataViewItemFromItem([self itemAtRow:[self clickedRow]]);
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc, item);
dvc->GetEventHandler()->ProcessEvent(event);
}
@@ -1633,12 +1610,8 @@ outlineView:(NSOutlineView*)outlineView
characterAtIndex: 0] == NSCarriageReturnCharacter )
{
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent eventDV( wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc->GetId() );
eventDV.SetEventObject(dvc);
eventDV.SetItem( wxDataViewItem( [[self itemAtRow:[self selectedRow]] pointer]) );
eventDV.SetModel( dvc->GetModel() );
const wxDataViewItem item = wxDataViewItem( [[self itemAtRow:[self selectedRow]] pointer]);
wxDataViewEvent eventDV(wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc, item);
if ( !dvc->GetEventHandler()->ProcessEvent(eventDV) )
[super keyDown:event];
}
@@ -1660,19 +1633,16 @@ outlineView:(NSOutlineView*)outlineView
// menu should be shown or not
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU,dvc->GetId());
wxDataViewItemArray selectedItems;
event.SetEventObject(dvc);
event.SetModel(dvc->GetModel());
// get the item information;
// theoretically more than one ID can be returned but the event can only
// handle one item, therefore only the first item of the array is
// returned:
wxDataViewItem item;
wxDataViewItemArray selectedItems;
if (dvc->GetSelections(selectedItems) > 0)
event.SetItem(selectedItems[0]);
item = selectedItems[0];
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dvc, item);
dvc->GetEventHandler()->ProcessEvent(event);
// nothing is done:
return nil;
@@ -1688,14 +1658,8 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent
event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK,dvc->GetId());
// first, send an event that the user clicked into a column's header:
event.SetEventObject(dvc);
event.SetColumn(dvc->GetColumnPosition(col));
event.SetDataViewColumn(col);
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dvc, col);
dvc->HandleWindowEvent(event);
// now, check if the click may have had an influence on sorting, too;
@@ -1731,13 +1695,7 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem (wxDataViewItemFromItem(item));
event.SetModel (dvc->GetModel());
// finally send the equivalent wxWidget event:
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING, dvc, wxDataViewItemFromItem(item));
dvc->GetEventHandler()->ProcessEvent(event);
// opening the container is allowed if not vetoed:
return event.IsAllowed();
@@ -1749,13 +1707,7 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem (wxDataViewItemFromItem(item));
event.SetModel (dvc->GetModel());
// finally send the equivalent wxWidget event:
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING, dvc, wxDataViewItemFromItem(item));
dvc->GetEventHandler()->ProcessEvent(event);
// opening the container is allowed if not vetoed:
return event.IsAllowed();
@@ -1818,12 +1770,7 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_REORDERED,dvc->GetId());
event.SetEventObject(dvc);
event.SetColumn(dvc->GetColumnPosition(col));
event.SetDataViewColumn(col);
wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_REORDERED, dvc, col);
dvc->GetEventHandler()->ProcessEvent(event);
}
@@ -1831,12 +1778,9 @@ outlineView:(NSOutlineView*)outlineView
{
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem(wxDataViewItemFromItem(
[[notification userInfo] objectForKey:@"NSObject"]));
const wxDataViewItem item = wxDataViewItemFromItem(
[[notification userInfo] objectForKey:@"NSObject"]);
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED, dvc, item);
dvc->GetEventHandler()->ProcessEvent(event);
}
@@ -1844,12 +1788,9 @@ outlineView:(NSOutlineView*)outlineView
{
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED,dvc->GetId());
event.SetEventObject(dvc);
event.SetItem(wxDataViewItemFromItem(
[[notification userInfo] objectForKey:@"NSObject"]));
const wxDataViewItem item = wxDataViewItemFromItem(
[[notification userInfo] objectForKey:@"NSObject"]);
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED, dvc, item);
dvc->GetEventHandler()->ProcessEvent(event);
}
@@ -1859,11 +1800,7 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
wxDataViewEvent event(wxEVT_DATAVIEW_SELECTION_CHANGED,dvc->GetId());
event.SetEventObject(dvc);
event.SetModel(dvc->GetModel());
event.SetItem(dvc->GetSelection());
wxDataViewEvent event(wxEVT_DATAVIEW_SELECTION_CHANGED, dvc, dvc->GetSelection());
dvc->GetEventHandler()->ProcessEvent(event);
}
@@ -1928,15 +1865,11 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
// send event to wxWidgets:
wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_EDITING_DONE,dvc->GetId());
const wxDataViewItem
item = wxDataViewItemFromItem([self itemAtRow:currentlyEditedRow]);
event.SetEventObject(dvc);
event.SetItem(
wxDataViewItemFromItem([self itemAtRow:currentlyEditedRow]));
event.SetColumn(dvc->GetColumnPosition(col));
event.SetDataViewColumn(col);
// send event to wxWidgets:
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_DONE, dvc, col, item);
dvc->GetEventHandler()->ProcessEvent(event);

View File

@@ -122,13 +122,8 @@ bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item)
wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized.");
if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
{
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel());
dataViewEvent.SetItem(item);
// sent the equivalent wxWidget event:
// send the equivalent wxWidgets event:
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_DataViewCtrlPtr, item);
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// row height may have to be adjusted:
AdjustRowHeight(item);
@@ -144,16 +139,11 @@ bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items)
{
size_t const noOfItems = items.GetCount();
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel());
for (size_t indexItem=0; indexItem<noOfItems; ++indexItem)
if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(items[indexItem]),items[indexItem]))
{
// send for all changed items a wxWidget event:
dataViewEvent.SetItem(items[indexItem]);
// send for all changed items a wxWidgets event:
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr,items[indexItem]);
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
}
else
@@ -211,13 +201,9 @@ bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsign
wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized.");
if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
{
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_DataViewCtrlPtr, m_DataViewCtrlPtr->GetColumn(col), item);
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel());
dataViewEvent.SetColumn(col);
dataViewEvent.SetItem(item);
// send the equivalent wxWidget event:
// send the equivalent wxWidgets event:
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
AdjustAutosizedColumns();