Show default shortcut menu when user right click window's caption

In windows platform, Qt5 will not show the system default shortcut menu
when the user right click in the window's caption. This is a regression
from Qt4.
This patch will let DefWindowProc() to handle the message WM_CONTEXTMENU
if the mouse pointer is in the non-client area of the window. Thus the
default Windows shortcut menu will show up.

Change-Id: I88638ad1d4f0e73b088204b83c3f7ec0fe2033f0
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Jian Liang 2013-02-05 13:01:25 +08:00 committed by The Qt Project
parent be8c47b140
commit 328c7ee6b8
2 changed files with 16 additions and 4 deletions

View File

@ -874,8 +874,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
#endif
#ifndef QT_NO_CONTEXTMENU
case QtWindows::ContextMenu:
handleContextMenuEvent(platformWindow->window(), msg);
return true;
return handleContextMenuEvent(platformWindow->window(), msg);
#endif
default:
break;
@ -909,7 +908,7 @@ void QWindowsContext::handleFocusEvent(QtWindows::WindowsEventType et,
}
#ifndef QT_NO_CONTEXTMENU
void QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
bool QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
{
bool mouseTriggered = false;
QPoint globalPos;
@ -919,10 +918,23 @@ void QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
globalPos.setX(msg.pt.x);
globalPos.setY(msg.pt.y);
pos = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, globalPos);
RECT clientRect;
if (GetClientRect(msg.hwnd, &clientRect)) {
if (pos.x() < (int)clientRect.left || pos.x() >= (int)clientRect.right ||
pos.y() < (int)clientRect.top || pos.y() >= (int)clientRect.bottom)
{
// This is the case that user has right clicked in the window's caption,
// We should call DefWindowProc() to display a default shortcut menu
// instead of sending a Qt window system event.
return false;
}
}
}
QWindowSystemInterface::handleContextMenuEvent(window, mouseTriggered, pos, globalPos,
QWindowsKeyMapper::queryKeyboardModifiers());
return true;
}
#endif

View File

@ -192,7 +192,7 @@ public:
private:
void handleFocusEvent(QtWindows::WindowsEventType et, QWindowsWindow *w);
#ifndef QT_NO_CONTEXTMENU
void handleContextMenuEvent(QWindow *window, const MSG &msg);
bool handleContextMenuEvent(QWindow *window, const MSG &msg);
#endif
void unregisterWindowClasses();