honour the drag effect supported by the drag source in wxIDropTarget (Tim Kosse)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44229 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4d1f840337
commit
c25db58432
@ -80,7 +80,7 @@ protected:
|
||||
HWND m_hwnd; // window we're associated with
|
||||
|
||||
// get default drop effect for given keyboard flags
|
||||
static DWORD GetDropEffect(DWORD flags, wxDragResult defaultAction);
|
||||
static DWORD GetDropEffect(DWORD flags, wxDragResult defaultAction, DWORD pdwEffect);
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxIDropTarget)
|
||||
};
|
||||
@ -104,11 +104,31 @@ static DWORD ConvertDragResultToEffect(wxDragResult result);
|
||||
// Notes : We do "move" normally and "copy" if <Ctrl> is pressed,
|
||||
// which is the standard behaviour (currently there is no
|
||||
// way to redefine it)
|
||||
DWORD wxIDropTarget::GetDropEffect(DWORD flags, wxDragResult defaultAction)
|
||||
DWORD wxIDropTarget::GetDropEffect(DWORD flags,
|
||||
wxDragResult defaultAction,
|
||||
DWORD pdwEffect)
|
||||
{
|
||||
if (defaultAction == wxDragCopy)
|
||||
return flags & MK_SHIFT ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
|
||||
return flags & MK_CONTROL ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
|
||||
DWORD effectiveAction;
|
||||
if ( defaultAction == wxDragCopy )
|
||||
effectiveAction = flags & MK_SHIFT ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
|
||||
else
|
||||
effectiveAction = flags & MK_CONTROL ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
|
||||
|
||||
if ( !(effectiveAction & pdwEffect) )
|
||||
{
|
||||
// the action is not supported by drag source, fall back to something
|
||||
// that it does support
|
||||
if ( pdwEffect & DROPEFFECT_MOVE )
|
||||
effectiveAction = DROPEFFECT_MOVE;
|
||||
else if ( pdwEffect & DROPEFFECT_COPY )
|
||||
effectiveAction = DROPEFFECT_COPY;
|
||||
else if ( pdwEffect & DROPEFFECT_LINK )
|
||||
effectiveAction = DROPEFFECT_LINK;
|
||||
else
|
||||
effectiveAction = DROPEFFECT_NONE;
|
||||
}
|
||||
|
||||
return effectiveAction;
|
||||
}
|
||||
|
||||
wxIDropTarget::wxIDropTarget(wxDropTarget *pTarget)
|
||||
@ -187,7 +207,7 @@ STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource,
|
||||
// give some visual feedback
|
||||
*pdwEffect = ConvertDragResultToEffect(
|
||||
m_pTarget->OnEnter(pt.x, pt.y, ConvertDragEffectToResult(
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction()))
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect))
|
||||
)
|
||||
);
|
||||
|
||||
@ -212,7 +232,7 @@ STDMETHODIMP wxIDropTarget::DragOver(DWORD grfKeyState,
|
||||
wxDragResult result;
|
||||
if ( m_pIDataObject ) {
|
||||
result = ConvertDragEffectToResult(
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction()));
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect));
|
||||
}
|
||||
else {
|
||||
// can't accept data anyhow normally
|
||||
@ -269,9 +289,6 @@ STDMETHODIMP wxIDropTarget::Drop(IDataObject *pIDataSource,
|
||||
// that it's the same we've already got in DragEnter
|
||||
wxASSERT( m_pIDataObject == pIDataSource );
|
||||
|
||||
// by default, nothing happens
|
||||
*pdwEffect = DROPEFFECT_NONE;
|
||||
|
||||
// we need client coordinates to pass to wxWin functions
|
||||
if ( !ScreenToClient(m_hwnd, (POINT *)&pt) )
|
||||
{
|
||||
@ -285,15 +302,20 @@ STDMETHODIMP wxIDropTarget::Drop(IDataObject *pIDataSource,
|
||||
|
||||
// and now it has the data
|
||||
wxDragResult rc = ConvertDragEffectToResult(
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction()));
|
||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect));
|
||||
rc = m_pTarget->OnData(pt.x, pt.y, rc);
|
||||
if ( wxIsDragResultOk(rc) ) {
|
||||
// operation succeeded
|
||||
*pdwEffect = ConvertDragResultToEffect(rc);
|
||||
}
|
||||
//else: *pdwEffect is already DROPEFFECT_NONE
|
||||
else {
|
||||
*pdwEffect = DROPEFFECT_NONE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// OnDrop() returned false, no need to copy data
|
||||
*pdwEffect = DROPEFFECT_NONE;
|
||||
}
|
||||
//else: OnDrop() returned false, no need to copy data
|
||||
|
||||
// release the held object
|
||||
RELEASE_AND_NULL(m_pIDataObject);
|
||||
|
Loading…
Reference in New Issue
Block a user