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
This commit is contained in:
Vadim Zeitlin
2012-04-29 23:22:25 +00:00
parent 167fc10e3b
commit c04be1a29f
5 changed files with 54 additions and 3 deletions

View File

@@ -525,6 +525,7 @@ All (GUI):
- Added wxTimePickerCtrl::Get/SetTime(). - Added wxTimePickerCtrl::Get/SetTime().
- Fix WXK_MENU handling in wxStyledTextCtrl under wxGTK (cantabile). - Fix WXK_MENU handling in wxStyledTextCtrl under wxGTK (cantabile).
- Added wxAcceleratorEntry::ToRawString() (Armel Asselin). - Added wxAcceleratorEntry::ToRawString() (Armel Asselin).
- Added wxDataViewEvent::SetDragFlags() and GetDropEffect() (Friedrich).
GTK: GTK:

View File

@@ -19,6 +19,7 @@
#include "wx/textctrl.h" #include "wx/textctrl.h"
#include "wx/headercol.h" #include "wx/headercol.h"
#include "wx/variant.h" #include "wx/variant.h"
#include "wx/dnd.h" // For wxDragResult declaration only.
#include "wx/dynarray.h" #include "wx/dynarray.h"
#include "wx/icon.h" #include "wx/icon.h"
#include "wx/itemid.h" #include "wx/itemid.h"
@@ -761,7 +762,9 @@ public:
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
, m_dataObject(NULL), , m_dataObject(NULL),
m_dataBuffer(NULL), m_dataBuffer(NULL),
m_dataSize(0) m_dataSize(0),
m_dragFlags(0),
m_dropEffect(wxDragNone)
#endif #endif
{ } { }
@@ -780,7 +783,9 @@ public:
, m_dataObject(event.m_dataObject), , m_dataObject(event.m_dataObject),
m_dataFormat(event.m_dataFormat), m_dataFormat(event.m_dataFormat),
m_dataBuffer(event.m_dataBuffer), 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 #endif
{ } { }
@@ -826,6 +831,10 @@ public:
size_t GetDataSize() const { return m_dataSize; } size_t GetDataSize() const { return m_dataSize; }
void SetDataBuffer( void* buf ) { m_dataBuffer = buf;} void SetDataBuffer( void* buf ) { m_dataBuffer = buf;}
void *GetDataBuffer() const { return m_dataBuffer; } 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 #endif // wxUSE_DRAG_AND_DROP
virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
@@ -847,6 +856,9 @@ protected:
wxDataFormat m_dataFormat; wxDataFormat m_dataFormat;
void* m_dataBuffer; void* m_dataBuffer;
size_t m_dataSize; size_t m_dataSize;
int m_dragFlags;
wxDragResult m_dropEffect;
#endif // wxUSE_DRAG_AND_DROP #endif // wxUSE_DRAG_AND_DROP
private: private:

View File

@@ -3011,6 +3011,41 @@ public:
*/ */
void *GetDataBuffer() const; 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. Return the first row that will be displayed.
*/ */

View File

@@ -841,6 +841,7 @@ void MyFrame::OnBeginDrag( wxDataViewEvent &event )
wxTextDataObject *obj = new wxTextDataObject; wxTextDataObject *obj = new wxTextDataObject;
obj->SetText( node->m_title ); obj->SetText( node->m_title );
event.SetDataObject( obj ); event.SetDataObject( obj );
event.SetDragFlags(wxDrag_AllowMove); // allows both copy and move
} }
void MyFrame::OnDropPossible( wxDataViewEvent &event ) void MyFrame::OnDropPossible( wxDataViewEvent &event )

View File

@@ -1490,6 +1490,7 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
event.SetItem( item ); event.SetItem( item );
event.SetModel( model ); event.SetModel( model );
event.SetDataFormat( format ); event.SetDataFormat( format );
event.SetDropEffect( def );
if (!m_owner->HandleWindowEvent( event )) if (!m_owner->HandleWindowEvent( event ))
{ {
RemoveDropHint(); RemoveDropHint();
@@ -1566,6 +1567,7 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo
event.SetDataFormat( format ); event.SetDataFormat( format );
event.SetDataSize( obj->GetSize() ); event.SetDataSize( obj->GetSize() );
event.SetDataBuffer( obj->GetData() ); event.SetDataBuffer( obj->GetData() );
event.SetDropEffect( def );
if (!m_owner->HandleWindowEvent( event )) if (!m_owner->HandleWindowEvent( event ))
return wxDragNone; return wxDragNone;
@@ -4083,7 +4085,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
wxDataViewDropSource drag( this, drag_item_row ); wxDataViewDropSource drag( this, drag_item_row );
drag.SetData( *obj ); drag.SetData( *obj );
/* wxDragResult res = */ drag.DoDragDrop(); /* wxDragResult res = */ drag.DoDragDrop(event.GetDragFlags());
delete obj; delete obj;
} }
return; return;