From: Robert Roebling Date: Tue, 8 Mar 2005 22:50:46 +0000 (+0000) Subject: Applied DnD patch, adding a field for setting a default action. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/917ae499da53826e9b154a786eae1b563317f47f Applied DnD patch, adding a field for setting a default action. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dnd.h b/include/wx/dnd.h index 3c893f685a..93bc0f1e18 100644 --- a/include/wx/dnd.h +++ b/include/wx/dnd.h @@ -141,7 +141,7 @@ public: // by wxDropTarget and deleted by it automatically. If you don't give it // here, you can use SetDataObject() later. wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL) - { m_dataObject = dataObject; } + { m_dataObject = dataObject; m_defaultAction = wxDragNone; } // dtor deletes our data object virtual ~wxDropTargetBase() { delete m_dataObject; } @@ -192,8 +192,21 @@ public: // with the data from the drop source if it returns true virtual bool GetData() = 0; + // sets the default action for drag and drop: + // use wxDragMove or wxDragCopy to set deafult action to move or copy + // and use wxDragNone (default) to set default action specified by + // initialization of draging (see wxDropSourceBase::DoDragDrop()) + void SetDefaultAction(wxDragResult action) + { m_defaultAction = action; } + + // returns default action for drag and drop or + // wxDragNone if this not specified + wxDragResult GetDefaultAction() + { return m_defaultAction; } + protected: wxDataObject *m_dataObject; + wxDragResult m_defaultAction; DECLARE_NO_COPY_CLASS(wxDropTargetBase) }; diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index 02701c7a54..b8b6ecfb7f 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -187,6 +187,9 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), // only good if we don't have our own preferences - but also the actions // field wxDragResult result; + if (drop_target->GetDefaultAction() == wxDragNone) + { + // use default action set by wxDropSource::DoDragDrop() if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove && (context->actions & GDK_ACTION_MOVE ) ) { @@ -204,6 +207,21 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), result = wxDragCopy; } } + } + else if (drop_target->GetDefaultAction() == wxDragMove && + (context->actions & GDK_ACTION_MOVE)) + { + result = wxDragMove; + } + else + { + if (context->actions & GDK_ACTION_COPY) + result = wxDragCopy; + else if (context->actions & GDK_ACTION_MOVE) + result = wxDragMove; + else + result = wxDragNone; + } if (drop_target->m_firstMotion) { @@ -220,9 +238,7 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), if (ret) { GdkDragAction action; - if ((result == wxDragCopy) && (context->actions & GDK_ACTION_COPY) || - (result == wxDragMove) && !(context->actions & GDK_ACTION_MOVE) || - (result == wxDragLink) && !(context->actions & GDK_ACTION_LINK)) + if (result == wxDragCopy) action = GDK_ACTION_COPY; else if (result == wxDragLink) action = GDK_ACTION_LINK; diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index 02701c7a54..b8b6ecfb7f 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -187,6 +187,9 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), // only good if we don't have our own preferences - but also the actions // field wxDragResult result; + if (drop_target->GetDefaultAction() == wxDragNone) + { + // use default action set by wxDropSource::DoDragDrop() if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove && (context->actions & GDK_ACTION_MOVE ) ) { @@ -204,6 +207,21 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), result = wxDragCopy; } } + } + else if (drop_target->GetDefaultAction() == wxDragMove && + (context->actions & GDK_ACTION_MOVE)) + { + result = wxDragMove; + } + else + { + if (context->actions & GDK_ACTION_COPY) + result = wxDragCopy; + else if (context->actions & GDK_ACTION_MOVE) + result = wxDragMove; + else + result = wxDragNone; + } if (drop_target->m_firstMotion) { @@ -220,9 +238,7 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), if (ret) { GdkDragAction action; - if ((result == wxDragCopy) && (context->actions & GDK_ACTION_COPY) || - (result == wxDragMove) && !(context->actions & GDK_ACTION_MOVE) || - (result == wxDragLink) && !(context->actions & GDK_ACTION_LINK)) + if (result == wxDragCopy) action = GDK_ACTION_COPY; else if (result == wxDragLink) action = GDK_ACTION_LINK; diff --git a/src/msw/ole/droptgt.cpp b/src/msw/ole/droptgt.cpp index 2aee28affe..7072586f09 100644 --- a/src/msw/ole/droptgt.cpp +++ b/src/msw/ole/droptgt.cpp @@ -85,7 +85,7 @@ protected: HWND m_hwnd; // window we're associated with // get default drop effect for given keyboard flags - static inline DWORD GetDropEffect(DWORD flags); + static inline DWORD GetDropEffect(DWORD flags, wxDragResult defaultAction); DECLARE_NO_COPY_CLASS(wxIDropTarget) }; @@ -109,8 +109,10 @@ static DWORD ConvertDragResultToEffect(wxDragResult result); // Notes : We do "move" normally and "copy" if is pressed, // which is the standard behaviour (currently there is no // way to redefine it) -DWORD wxIDropTarget::GetDropEffect(DWORD flags) +DWORD wxIDropTarget::GetDropEffect(DWORD flags, wxDragResult defaultAction) { + if (defaultAction == wxDragCopy) + return flags & MK_SHIFT ? DROPEFFECT_MOVE : DROPEFFECT_COPY; return flags & MK_CONTROL ? DROPEFFECT_COPY : DROPEFFECT_MOVE; } @@ -189,8 +191,8 @@ STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource, // give some visual feedback *pdwEffect = ConvertDragResultToEffect( - m_pTarget->OnEnter(pt.x, pt.y, - ConvertDragEffectToResult(GetDropEffect(grfKeyState)) + m_pTarget->OnEnter(pt.x, pt.y, ConvertDragEffectToResult( + GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction())) ) ); @@ -214,7 +216,8 @@ STDMETHODIMP wxIDropTarget::DragOver(DWORD grfKeyState, wxDragResult result; if ( m_pIDataObject ) { - result = ConvertDragEffectToResult(GetDropEffect(grfKeyState)); + result = ConvertDragEffectToResult( + GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction())); } else { // can't accept data anyhow normally @@ -286,7 +289,8 @@ STDMETHODIMP wxIDropTarget::Drop(IDataObject *pIDataSource, m_pTarget->SetDataSource(pIDataSource); // and now it has the data - wxDragResult rc = ConvertDragEffectToResult(GetDropEffect(grfKeyState)); + wxDragResult rc = ConvertDragEffectToResult( + GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction())); rc = m_pTarget->OnData(pt.x, pt.y, rc); if ( wxIsDragResultOk(rc) ) { // operation succeeded