summaryrefslogtreecommitdiff
path: root/src/gui/widgets/qcocoamenu_mac.mm
diff options
context:
space:
mode:
authorPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-11-11 12:29:44 +0100
committerPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-11-11 16:09:52 +0100
commit4b618e48c909fcc5665e9d60645023c48b2ffb43 (patch)
tree9a6ced55ae1f354f2632b6dfc97e452e3c5a7c4d /src/gui/widgets/qcocoamenu_mac.mm
parent54865d47cfd859a0e84ba8e1bbff3b56c93d4e0d (diff)
downloadqt4-tools-4b618e48c909fcc5665e9d60645023c48b2ffb43.tar.gz
ShortcutOverride has no effect on some shortcuts on Mac OS X (Cocoa).
When generating the native key sequences for menu items, Qt prefers the non private unicode characters. But the characters in the NSEvent for keyboard events can contain characters form the unicode range reserved for Apple. For e.g. when user presses the "delete" key, the event contains NSDeleteFunctionKey, where in Qt is expecting NSDeleteCharacter. For now this is the only key identified for translation. If we find similar translations, those can be added to qt_mac_removePrivateUnicode(). Task-number: QTBUG-12495 Reviewed-by: Denis
Diffstat (limited to 'src/gui/widgets/qcocoamenu_mac.mm')
-rw-r--r--src/gui/widgets/qcocoamenu_mac.mm22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/gui/widgets/qcocoamenu_mac.mm b/src/gui/widgets/qcocoamenu_mac.mm
index 15fae23c20..b670186790 100644
--- a/src/gui/widgets/qcocoamenu_mac.mm
+++ b/src/gui/widgets/qcocoamenu_mac.mm
@@ -156,10 +156,14 @@ QT_USE_NAMESPACE
// In every other case we return NO, which means that Cocoa can do as it pleases
// (i.e., fire the menu action).
NSMenuItem *whichItem;
+ // Change the private unicode keys to the ones used in setting the "Key Equivalents"
+ extern NSString *qt_mac_removePrivateUnicode(NSString* string);
+ NSString *characters = qt_mac_removePrivateUnicode([event characters]);
if ([self hasShortcut:menu
- forKey:[event characters]
- forModifiers:([event modifierFlags] & NSDeviceIndependentModifierFlagsMask)
- whichItem:&whichItem]) {
+ forKey:characters
+ // Interested only in Shift, Cmd, Ctrl & Alt Keys, so ignoring masks like, Caps lock, Num Lock ...
+ forModifiers:([event modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask))
+ whichItem:&whichItem]) {
QWidget *widget = 0;
QAction *qaction = 0;
if (whichItem && [whichItem tag]) {
@@ -170,6 +174,9 @@ QT_USE_NAMESPACE
qApp->activePopupWidget()->focusWidget() : qApp->activePopupWidget());
else if (QApplicationPrivate::focus_widget)
widget = QApplicationPrivate::focus_widget;
+ // If we could not find any receivers, pass it to the active window
+ if (!widget)
+ widget = qApp->activeWindow();
if (qaction && widget) {
int key = qaction->shortcut();
QKeyEvent accel_ev(QEvent::ShortcutOverride, (key & (~Qt::KeyboardModifierMask)),
@@ -177,11 +184,10 @@ QT_USE_NAMESPACE
accel_ev.ignore();
qt_sendSpontaneousEvent(widget, &accel_ev);
if (accel_ev.isAccepted()) {
- if (qt_dispatchKeyEvent(event, widget)) {
- *target = nil;
- *action = nil;
- return YES;
- }
+ qt_dispatchKeyEvent(event, widget);
+ *target = nil;
+ *action = nil;
+ return YES;
}
}
}