diff options
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsdrag.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsdrag.cpp | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/src/plugins/platforms/windows/qwindowsdrag.cpp b/src/plugins/platforms/windows/qwindowsdrag.cpp index 26a5131927..58175b39fa 100644 --- a/src/plugins/platforms/windows/qwindowsdrag.cpp +++ b/src/plugins/platforms/windows/qwindowsdrag.cpp @@ -84,7 +84,7 @@ public: void setPixmap(const QPixmap &p); protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE + void paintEvent(QPaintEvent *) override { QPainter painter(this); painter.drawPixmap(0, 0, m_pixmap); @@ -190,6 +190,20 @@ static inline Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState) return modifiers; } +static inline Qt::MouseButtons toQtMouseButtons(DWORD keyState) +{ + Qt::MouseButtons buttons = Qt::NoButton; + + if (keyState & MK_LBUTTON) + buttons |= Qt::LeftButton; + if (keyState & MK_RBUTTON) + buttons |= Qt::RightButton; + if (keyState & MK_MBUTTON) + buttons |= Qt::MidButton; + + return buttons; +} + /*! \class QWindowsOleDropSource \brief Implementation of IDropSource @@ -398,43 +412,39 @@ QWindowsOleDropSource::Release(void) QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QWindowsOleDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState) { - HRESULT hr = S_OK; - do { - if (fEscapePressed || QWindowsDrag::isCanceled()) { - hr = ResultFromScode(DRAGDROP_S_CANCEL); - break; - } - - // grfKeyState is broken on CE & some Windows XP versions, - // therefore we need to check the state manually - if ((GetAsyncKeyState(VK_LBUTTON) == 0) - && (GetAsyncKeyState(VK_MBUTTON) == 0) - && (GetAsyncKeyState(VK_RBUTTON) == 0)) { - hr = ResultFromScode(DRAGDROP_S_DROP); - break; - } + Qt::MouseButtons buttons = toQtMouseButtons(grfKeyState); - const Qt::MouseButtons buttons = QWindowsMouseHandler::keyStateToMouseButtons(grfKeyState); - if (m_currentButtons == Qt::NoButton) { - m_currentButtons = buttons; + SCODE result = S_OK; + if (fEscapePressed || QWindowsDrag::isCanceled()) { + result = DRAGDROP_S_CANCEL; + buttons = Qt::NoButton; } else { - // Button changed: Complete Drop operation. - if (!(m_currentButtons & buttons)) { - hr = ResultFromScode(DRAGDROP_S_DROP); - break; + if (buttons && !m_currentButtons) { + m_currentButtons = buttons; + } else if (!(m_currentButtons & buttons)) { // Button changed: Complete Drop operation. + result = DRAGDROP_S_DROP; } } - QGuiApplication::processEvents(); + switch (result) { + case DRAGDROP_S_DROP: + case DRAGDROP_S_CANCEL: + QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState); + QGuiApplicationPrivate::mouse_buttons = buttons; + m_currentButtons = Qt::NoButton; + break; - } while (false); + default: + QGuiApplication::processEvents(); + break; + } - if (QWindowsContext::verbose > 1 || hr != S_OK) { + if (QWindowsContext::verbose > 1 || result != S_OK) { qCDebug(lcQpaMime) << __FUNCTION__ << "fEscapePressed=" << fEscapePressed << "grfKeyState=" << grfKeyState << "buttons" << m_currentButtons - << "returns 0x" << hex <<int(hr) << dec; + << "returns 0x" << hex << int(result) << dec; } - return hr; + return ResultFromScode(result); } /*! @@ -489,8 +499,7 @@ QWindowsOleDropSource::GiveFeedback(DWORD dwEffect) \ingroup qt-lighthouse-win */ -QWindowsOleDropTarget::QWindowsOleDropTarget(QWindow *w) : - m_refs(1), m_window(w), m_chosenEffect(0), m_lastKeyState(0) +QWindowsOleDropTarget::QWindowsOleDropTarget(QWindow *w) : m_window(w) { qCDebug(lcQpaMime) << __FUNCTION__ << this << w; } @@ -538,7 +547,7 @@ void QWindowsOleDropTarget::handleDrag(QWindow *window, DWORD grfKeyState, QWindowsDrag *windowsDrag = QWindowsDrag::instance(); const Qt::DropActions actions = translateToQDragDropActions(*pdwEffect); QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState); - QGuiApplicationPrivate::mouse_buttons = QWindowsMouseHandler::keyStateToMouseButtons(grfKeyState); + QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(grfKeyState); const QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(window, windowsDrag->dropData(), m_lastPoint, actions); @@ -606,6 +615,12 @@ QWindowsOleDropTarget::DragLeave() qCDebug(lcQpaMime) << __FUNCTION__ << ' ' << m_window; QWindowSystemInterface::handleDrag(m_window, 0, QPoint(), Qt::IgnoreAction); + + if (!QDragManager::self()->source()) { + QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier; + QGuiApplicationPrivate::mouse_buttons = Qt::NoButton; + m_lastKeyState = 0; + } QWindowsDrag::instance()->releaseDropDataObject(); return NOERROR; @@ -624,11 +639,9 @@ QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, << "keys=" << grfKeyState << "pt=" << pt.x << ',' << pt.y; m_lastPoint = QWindowsGeometryHint::mapFromGlobal(m_window, QPoint(pt.x,pt.y)); - // grfKeyState does not all ways contain button state in the drop so if - // it doesn't then use the last known button state; - if ((grfKeyState & KEY_STATE_BUTTON_MASK) == 0) - grfKeyState |= m_lastKeyState & KEY_STATE_BUTTON_MASK; - m_lastKeyState = grfKeyState; + // grfKeyState does not all ways contain button state in the drop + QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(m_lastKeyState); + QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState); QWindowsDrag *windowsDrag = QWindowsDrag::instance(); @@ -636,6 +649,10 @@ QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, QWindowSystemInterface::handleDrop(m_window, windowsDrag->dropData(), m_lastPoint, translateToQDragDropActions(*pdwEffect)); + + QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(grfKeyState); + m_lastKeyState = grfKeyState; + if (response.isAccepted()) { const Qt::DropAction action = response.acceptedAction(); if (action == Qt::MoveAction || action == Qt::TargetMoveAction) { @@ -682,10 +699,7 @@ QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, bool QWindowsDrag::m_canceled = false; -QWindowsDrag::QWindowsDrag() : - m_dropDataObject(0), m_cachedDropTargetHelper(0) -{ -} +QWindowsDrag::QWindowsDrag() = default; QWindowsDrag::~QWindowsDrag() { |