Fix Windows DnD: Alt key modificator was interpreted as mouse Xbutton

Qt4->Qt5 regression:
QWindowsMouseHandler::keyStateToMouseButtons() cannot be used instead
of the old Qt4 function toQtMouseButtons() because Alt key and mouse
Xbutton have the same code on the Windows.

Task-number: QTBUG-55885
Change-Id: Ibad35cfe83145d03fd05f397c0afba9c86817a0c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Serge Lysenko 2016-08-26 15:41:59 +03:00 committed by Serge Lysenko
parent 278e557cea
commit 6ac4410228

View File

@ -190,6 +190,20 @@ static inline Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
return modifiers; 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 \class QWindowsOleDropSource
\brief Implementation of IDropSource \brief Implementation of IDropSource
@ -405,16 +419,7 @@ QWindowsOleDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
break; break;
} }
// grfKeyState is broken on CE & some Windows XP versions, const Qt::MouseButtons buttons = toQtMouseButtons(grfKeyState);
// 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;
}
const Qt::MouseButtons buttons = QWindowsMouseHandler::keyStateToMouseButtons(grfKeyState);
if (m_currentButtons == Qt::NoButton) { if (m_currentButtons == Qt::NoButton) {
m_currentButtons = buttons; m_currentButtons = buttons;
} else { } else {
@ -538,7 +543,7 @@ void QWindowsOleDropTarget::handleDrag(QWindow *window, DWORD grfKeyState,
QWindowsDrag *windowsDrag = QWindowsDrag::instance(); QWindowsDrag *windowsDrag = QWindowsDrag::instance();
const Qt::DropActions actions = translateToQDragDropActions(*pdwEffect); const Qt::DropActions actions = translateToQDragDropActions(*pdwEffect);
QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState); QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState);
QGuiApplicationPrivate::mouse_buttons = QWindowsMouseHandler::keyStateToMouseButtons(grfKeyState); QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(grfKeyState);
const QPlatformDragQtResponse response = const QPlatformDragQtResponse response =
QWindowSystemInterface::handleDrag(window, windowsDrag->dropData(), m_lastPoint, actions); QWindowSystemInterface::handleDrag(window, windowsDrag->dropData(), m_lastPoint, actions);