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:
@@ -80,7 +80,7 @@ protected:
|
|||||||
HWND m_hwnd; // window we're associated with
|
HWND m_hwnd; // window we're associated with
|
||||||
|
|
||||||
// get default drop effect for given keyboard flags
|
// 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)
|
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,
|
// Notes : We do "move" normally and "copy" if <Ctrl> is pressed,
|
||||||
// which is the standard behaviour (currently there is no
|
// which is the standard behaviour (currently there is no
|
||||||
// way to redefine it)
|
// way to redefine it)
|
||||||
DWORD wxIDropTarget::GetDropEffect(DWORD flags, wxDragResult defaultAction)
|
DWORD wxIDropTarget::GetDropEffect(DWORD flags,
|
||||||
|
wxDragResult defaultAction,
|
||||||
|
DWORD pdwEffect)
|
||||||
{
|
{
|
||||||
if (defaultAction == wxDragCopy)
|
DWORD effectiveAction;
|
||||||
return flags & MK_SHIFT ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
|
if ( defaultAction == wxDragCopy )
|
||||||
return flags & MK_CONTROL ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
|
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)
|
wxIDropTarget::wxIDropTarget(wxDropTarget *pTarget)
|
||||||
@@ -187,7 +207,7 @@ STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource,
|
|||||||
// give some visual feedback
|
// give some visual feedback
|
||||||
*pdwEffect = ConvertDragResultToEffect(
|
*pdwEffect = ConvertDragResultToEffect(
|
||||||
m_pTarget->OnEnter(pt.x, pt.y, ConvertDragEffectToResult(
|
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;
|
wxDragResult result;
|
||||||
if ( m_pIDataObject ) {
|
if ( m_pIDataObject ) {
|
||||||
result = ConvertDragEffectToResult(
|
result = ConvertDragEffectToResult(
|
||||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction()));
|
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// can't accept data anyhow normally
|
// 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
|
// that it's the same we've already got in DragEnter
|
||||||
wxASSERT( m_pIDataObject == pIDataSource );
|
wxASSERT( m_pIDataObject == pIDataSource );
|
||||||
|
|
||||||
// by default, nothing happens
|
|
||||||
*pdwEffect = DROPEFFECT_NONE;
|
|
||||||
|
|
||||||
// we need client coordinates to pass to wxWin functions
|
// we need client coordinates to pass to wxWin functions
|
||||||
if ( !ScreenToClient(m_hwnd, (POINT *)&pt) )
|
if ( !ScreenToClient(m_hwnd, (POINT *)&pt) )
|
||||||
{
|
{
|
||||||
@@ -285,15 +302,20 @@ STDMETHODIMP wxIDropTarget::Drop(IDataObject *pIDataSource,
|
|||||||
|
|
||||||
// and now it has the data
|
// and now it has the data
|
||||||
wxDragResult rc = ConvertDragEffectToResult(
|
wxDragResult rc = ConvertDragEffectToResult(
|
||||||
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction()));
|
GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect));
|
||||||
rc = m_pTarget->OnData(pt.x, pt.y, rc);
|
rc = m_pTarget->OnData(pt.x, pt.y, rc);
|
||||||
if ( wxIsDragResultOk(rc) ) {
|
if ( wxIsDragResultOk(rc) ) {
|
||||||
// operation succeeded
|
// operation succeeded
|
||||||
*pdwEffect = ConvertDragResultToEffect(rc);
|
*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 the held object
|
||||||
RELEASE_AND_NULL(m_pIDataObject);
|
RELEASE_AND_NULL(m_pIDataObject);
|
||||||
|
Reference in New Issue
Block a user