From c04be1a29f4897942c606923cd9dcdde57832019 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 29 Apr 2012 23:22:25 +0000 Subject: [PATCH] Added wxDataViewEvent::SetDragFlags() and GetDropEffect() methods. Allow specifying the drag operation flags and retrieving the drop effect when it's over for wxDataViewCtrl drag-and-drop. Currently this is only implemented in the generic version. Closes #12583. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/dataview.h | 16 ++++++++++++++-- interface/wx/dataview.h | 35 +++++++++++++++++++++++++++++++++++ samples/dataview/dataview.cpp | 1 + src/generic/datavgen.cpp | 4 +++- 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0cb1b1aea2..111ec6fb62 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -525,6 +525,7 @@ All (GUI): - Added wxTimePickerCtrl::Get/SetTime(). - Fix WXK_MENU handling in wxStyledTextCtrl under wxGTK (cantabile). - Added wxAcceleratorEntry::ToRawString() (Armel Asselin). +- Added wxDataViewEvent::SetDragFlags() and GetDropEffect() (Friedrich). GTK: diff --git a/include/wx/dataview.h b/include/wx/dataview.h index c0aed4734b..cd7be97bed 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -19,6 +19,7 @@ #include "wx/textctrl.h" #include "wx/headercol.h" #include "wx/variant.h" +#include "wx/dnd.h" // For wxDragResult declaration only. #include "wx/dynarray.h" #include "wx/icon.h" #include "wx/itemid.h" @@ -761,7 +762,9 @@ public: #if wxUSE_DRAG_AND_DROP , m_dataObject(NULL), m_dataBuffer(NULL), - m_dataSize(0) + m_dataSize(0), + m_dragFlags(0), + m_dropEffect(wxDragNone) #endif { } @@ -780,7 +783,9 @@ public: , m_dataObject(event.m_dataObject), m_dataFormat(event.m_dataFormat), m_dataBuffer(event.m_dataBuffer), - m_dataSize(event.m_dataSize) + m_dataSize(event.m_dataSize), + m_dragFlags(event.m_dragFlags), + m_dropEffect(event.m_dropEffect) #endif { } @@ -826,6 +831,10 @@ public: size_t GetDataSize() const { return m_dataSize; } void SetDataBuffer( void* buf ) { m_dataBuffer = buf;} void *GetDataBuffer() const { return m_dataBuffer; } + void SetDragFlags( int flags ) { m_dragFlags = flags; } + int GetDragFlags() const { return m_dragFlags; } + void SetDropEffect( wxDragResult effect ) { m_dropEffect = effect; } + wxDragResult GetDropEffect() const { return m_dropEffect; } #endif // wxUSE_DRAG_AND_DROP virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } @@ -847,6 +856,9 @@ protected: wxDataFormat m_dataFormat; void* m_dataBuffer; size_t m_dataSize; + + int m_dragFlags; + wxDragResult m_dropEffect; #endif // wxUSE_DRAG_AND_DROP private: diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index dcb4b7c429..f51a81a681 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -3011,6 +3011,41 @@ public: */ void *GetDataBuffer() const; + /** + Specify the kind of the drag operation to perform. + + This method can be used inside a wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG + handler in order to configure the drag operation. Valid values are + ::wxDrag_CopyOnly (default), ::wxDrag_AllowMove (allow the data to be + moved) and ::wxDrag_DefaultMove. + + Currently it is only honoured by the generic version of wxDataViewCtrl + (used e.g. under MSW) and not supported by the native GTK and OS X + versions. + + @see GetDropEffect() + + @since 2.9.4 + */ + void SetDragFlags(int flags); + + /** + Returns the effect the user requested to happen to the dropped data. + + This function can be used inside + wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE and + wxEVT_COMMAND_DATAVIEW_ITEM_DROP handlers and returns whether the user + is trying to copy (the return value is ::wxDragCopy) or move (if the + return value is ::wxDragMove) the data. + + Currently this is only available when using the generic version of + wxDataViewCtrl (used e.g. under MSW) and always returns ::wxDragNone in + the GTK and OS X native versions. + + @since 2.9.4 + */ + wxDragResult GetDropEffect() const; + /** Return the first row that will be displayed. */ diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 2feca42856..857992884d 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -841,6 +841,7 @@ void MyFrame::OnBeginDrag( wxDataViewEvent &event ) wxTextDataObject *obj = new wxTextDataObject; obj->SetText( node->m_title ); event.SetDataObject( obj ); + event.SetDragFlags(wxDrag_AllowMove); // allows both copy and move } void MyFrame::OnDropPossible( wxDataViewEvent &event ) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index e1e1e425db..2eb606f6f1 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1490,6 +1490,7 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x, event.SetItem( item ); event.SetModel( model ); event.SetDataFormat( format ); + event.SetDropEffect( def ); if (!m_owner->HandleWindowEvent( event )) { RemoveDropHint(); @@ -1566,6 +1567,7 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo event.SetDataFormat( format ); event.SetDataSize( obj->GetSize() ); event.SetDataBuffer( obj->GetData() ); + event.SetDropEffect( def ); if (!m_owner->HandleWindowEvent( event )) return wxDragNone; @@ -4083,7 +4085,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) wxDataViewDropSource drag( this, drag_item_row ); drag.SetData( *obj ); - /* wxDragResult res = */ drag.DoDragDrop(); + /* wxDragResult res = */ drag.DoDragDrop(event.GetDragFlags()); delete obj; } return; -- 2.45.2