m_value(wxNullVariant),
m_column(NULL),
m_pos(-1,-1),
- m_isDraggable(false),
- m_dragDataSize(-1)
+ m_dataObject(NULL)
{ }
wxDataViewEvent(const wxDataViewEvent& event)
m_value(event.m_value),
m_column(event.m_column),
m_pos(m_pos),
- m_isDraggable(event.m_isDraggable),
- m_dragDataSize(event.m_dragDataSize)
+ m_dataObject(event.m_dataObject)
{ }
wxDataViewItem GetItem() const { return m_item; }
wxPoint GetPosition() const { return m_pos; }
void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
- // For Drag operations
- bool IsDraggable() const { return m_isDraggable; }
- void SetDraggable( bool can_drag = true ) { m_isDraggable = can_drag; }
- int GetDragDataSize() const { return m_dragDataSize; }
- void SetDragDataSize( int size ) { m_dragDataSize = size; }
- void* GetDragDataBuffer() const { return m_dragDataBuffer; }
- void SetDragDataBuffer( void *buffer ) { m_dragDataBuffer = buffer; }
- wxDataFormat GetDataFormat() const { return m_dataFormat; }
- void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
+ // For DnD operations
+ void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
+ wxDataObject *GetDataObject() { return m_dataObject; }
virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
wxVariant m_value;
wxDataViewColumn *m_column;
wxPoint m_pos;
-
- bool m_isDraggable;
- int m_dragDataSize;
- void *m_dragDataBuffer;
- wxDataFormat m_dataFormat;
+ wxDataObject *m_dataObject;
private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent )
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent )
-wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DRAGGABLE, wxDataViewEvent )
-wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA_SIZE, wxDataViewEvent )
-wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA, wxDataViewEvent )
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent )
typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
#define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
#define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
-#define EVT_DATAVIEW_ITEM_DRAGGABLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DRAGGABLE, id, fn)
-#define EVT_DATAVIEW_ITEM_GET_DRAG_DATA_SIZE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_GET_DRAG_DATA_SIZE, id, fn)
-#define EVT_DATAVIEW_ITEM_GET_DRAG_DATA(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_GET_DRAG_DATA, id, fn)
+#define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
// this symbol doesn't follow the convention for wxUSE_XXX symbols which
Process a wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED event.
@event{EVT_DATAVIEW_COLUMN_REORDERED(id, func)}
Process a wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED event.
+ @event{EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, func)}
+ Process a wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG event.
@endEventTable
@library{wxadv}
class wxDataViewEvent : public wxNotifyEvent
{
public:
- //@{
/**
Constructor. Typically used by wxWidgets internals only.
*/
wxDataViewEvent(wxEventType commandType = wxEVT_NULL,
int winid = 0);
- wxDataViewEvent(const wxDataViewEvent& event);
- //@}
/**
Returns the position of the column in the control or -1
Sets the value associated with this event.
*/
void SetValue(const wxVariant& value);
+
+ /**
+ Set wxDataObject for Drag'n'drop data transfer.
+ */
+ void SetDataObject( wxDataObject *obj );
+
+ /**
+ Gets associated wxDataObject for Drag'n'drop data transfer.
+ */
+ wxDataObject *GetDataObject();
};
void OnGoto( wxCommandEvent &event);
void OnAddMany( wxCommandEvent &event);
- // DnD
- void OnDraggable( wxDataViewEvent &event );
- void OnGetDragDataSize( wxDataViewEvent &event );
- void OnGetDragData( wxDataViewEvent &event );
+ void OnBeginDrag( wxDataViewEvent &event );
private:
wxDataViewCtrl* m_musicCtrl;
EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
- EVT_DATAVIEW_ITEM_DRAGGABLE( ID_MUSIC_CTRL, MyFrame::OnDraggable )
- EVT_DATAVIEW_ITEM_GET_DRAG_DATA_SIZE( ID_MUSIC_CTRL, MyFrame::OnGetDragDataSize )
- EVT_DATAVIEW_ITEM_GET_DRAG_DATA( ID_MUSIC_CTRL, MyFrame::OnGetDragData )
+ EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL, MyFrame::OnBeginDrag )
EVT_RIGHT_UP(MyFrame::OnRightClick)
END_EVENT_TABLE()
wxAboutBox(info);
}
-void MyFrame::OnDraggable( wxDataViewEvent &event )
+void MyFrame::OnBeginDrag( wxDataViewEvent &event )
{
- // only allow drags for item, not containers
- event.SetDraggable( !m_music_model->IsContainer( event.GetItem() ) );
-}
-
-void MyFrame::OnGetDragDataSize( wxDataViewEvent &event )
-{
- if (event.GetDataFormat() == wxDF_TEXT)
- {
- wxDataViewItem item( event.GetItem() );
- MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
+ wxDataViewItem item( event.GetItem() );
- wxTextDataObject obj;
- obj.SetText( node->m_artist );
- size_t size = obj.GetDataSize( wxDF_TEXT );
- event.SetDragDataSize( size );
- return;
- }
-
- event.Skip();
-}
-
-void MyFrame::OnGetDragData( wxDataViewEvent &event )
-{
- if (event.GetDataFormat() == wxDF_TEXT)
+ // only allow drags for item, not containers
+ if (m_music_model->IsContainer( item ) )
{
- wxDataViewItem item( event.GetItem() );
- MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
-
- wxTextDataObject obj;
- obj.SetText( node->m_artist );
- obj.GetDataHere( wxDF_TEXT, event.GetDragDataBuffer() );
+ event.Veto();
return;
}
- event.Skip();
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
+ wxTextDataObject *obj = new wxTextDataObject;
+ obj->SetText( node->m_title );
+ event.SetDataObject( obj );
}
wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent )
wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DRAGGABLE, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA_SIZE, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent )
// -------------------------------------
// wxDataViewSpinRenderer
int m_sort_column;
GtkTargetEntry m_dragSourceTargetEntry;
wxCharBuffer m_dragSourceTargetEntryTarget;
+ wxDataObject *m_dragDataObject;
+ wxDataObject *m_dropDataObject;
};
m_sort_order = GTK_SORT_ASCENDING;
m_sort_column = -1;
m_dataview_sort_column = NULL;
+
+ m_dragDataObject = NULL;
+ m_dropDataObject = NULL;
if (!m_wx_model->IsVirtualListModel())
InitTree();
wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
{
g_object_unref( m_gtk_model );
+
+ delete m_dragDataObject;
+ delete m_dropDataObject;
}
void wxDataViewCtrlInternal::InitTree()
gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source),
GtkTreePath *path )
{
+ delete m_dragDataObject;
+
GtkTreeIter iter;
if (!get_iter( &iter, path )) return FALSE;
wxDataViewItem item( (void*) iter.user_data );
- wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DRAGGABLE, m_owner->GetId() );
+ wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
event.SetItem( item );
event.SetModel( m_wx_model );
- m_owner->HandleWindowEvent( event );
+ if (!m_owner->HandleWindowEvent( event ))
+ return FALSE;
+
+ if (!event.IsAllowed())
+ return FALSE;
+
+ wxDataObject *obj = event.GetDataObject();
+ if (!obj)
+ return FALSE;
+
+ m_dragDataObject = obj;
- return event.IsDraggable();
+ return TRUE;
}
gboolean
if (!get_iter( &iter, path )) return FALSE;
wxDataViewItem item( (void*) iter.user_data );
- wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA_SIZE, m_owner->GetId() );
- event.SetItem( item );
- event.SetModel( m_wx_model );
- event.SetDataFormat( selection_data->target );
- m_owner->HandleWindowEvent( event );
- if (event.GetDragDataSize() < 1) return FALSE;
- size_t size = (size_t) event.GetDragDataSize();
-
- void *data = malloc( size );
+ if (!m_dragDataObject->IsSupported( selection_data->target ))
+ return FALSE;
- event.SetEventType( wxEVT_COMMAND_DATAVIEW_ITEM_GET_DRAG_DATA );
- event.SetDragDataBuffer( data );
+ size_t size = m_dragDataObject->GetDataSize( selection_data->target );
+ if (size == 0)
+ return FALSE;
+
+ void *buf = malloc( size );
+
gboolean res = FALSE;
- if (m_owner->HandleWindowEvent( event ))
+ if (m_dragDataObject->GetDataHere( selection_data->target, buf ))
{
- gtk_selection_data_set( selection_data, selection_data->target,
- 8, (const guchar*) data, size );
res = TRUE;
+
+ gtk_selection_data_set( selection_data, selection_data->target,
+ 8, (const guchar*) buf, size );
}
- free( data );
+ free( buf );
return res;
}