diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenuitem.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoamenuitem.mm | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 3504f967bf..cac166a409 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -68,6 +68,7 @@ static quint32 constructModifierMask(quint32 accel_key) return ret; } +#ifndef QT_NO_SHORTCUT // return an autoreleased string given a QKeySequence (currently only looks at the first one). NSString *keySequenceToKeyEqivalent(const QKeySequence &accel) { @@ -86,20 +87,22 @@ NSUInteger keySequenceModifierMask(const QKeySequence &accel) { return constructModifierMask(accel[0]); } +#endif QCocoaMenuItem::QCocoaMenuItem() : m_native(NULL), m_itemView(nil), - m_textSynced(false), m_menu(NULL), + m_role(NoRole), + m_tag(0), + m_iconSize(16), + m_textSynced(false), m_isVisible(true), m_enabled(true), + m_parentEnabled(true), m_isSeparator(false), - m_role(NoRole), m_checked(false), - m_merged(false), - m_tag(0), - m_iconSize(16) + m_merged(false) { } @@ -135,15 +138,23 @@ void QCocoaMenuItem::setMenu(QPlatformMenu *menu) if (menu == m_menu) return; - if (m_menu) { - if (m_menu->menuParent() == this) - m_menu->setMenuParent(0); + if (m_menu && m_menu->menuParent() == this) { + m_menu->setMenuParent(0); + // Free the menu from its parent's influence + m_menu->propagateEnabledState(true); + if (m_native && m_menu->attachedItem() == m_native) + m_menu->setAttachedItem(nil); } QMacAutoReleasePool pool; m_menu = static_cast<QCocoaMenu *>(menu); if (m_menu) { + if (m_native) { + // Skip automatic menu item validation + m_native.action = nil; + } m_menu->setMenuParent(this); + m_menu->propagateEnabledState(isEnabled()); } else { // we previously had a menu, but no longer // clear out our item so the nexy sync() call builds a new one @@ -174,10 +185,12 @@ void QCocoaMenuItem::setRole(MenuRole role) m_role = role; } +#ifndef QT_NO_SHORTCUT void QCocoaMenuItem::setShortcut(const QKeySequence& shortcut) { m_shortcut = shortcut; } +#endif void QCocoaMenuItem::setChecked(bool isChecked) { @@ -186,7 +199,11 @@ void QCocoaMenuItem::setChecked(bool isChecked) void QCocoaMenuItem::setEnabled(bool enabled) { - m_enabled = enabled; + if (m_enabled != enabled) { + m_enabled = enabled; + if (m_menu) + m_menu->propagateEnabledState(isEnabled()); + } } void QCocoaMenuItem::setNativeContents(WId item) @@ -301,11 +318,13 @@ NSMenuItem *QCocoaMenuItem::sync() [m_native setView:m_itemView]; QString text = mergeText(); +#ifndef QT_NO_SHORTCUT QKeySequence accel = mergeAccel(); // Show multiple key sequences as part of the menu text. if (accel.count() > 1) text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")"); +#endif QString finalString = QPlatformTheme::removeMnemonics(text); bool useAttributedTitle = false; @@ -327,10 +346,13 @@ NSMenuItem *QCocoaMenuItem::sync() [m_native setTitle: QCFString::toNSString(finalString)]; } +#ifndef QT_NO_SHORTCUT if (accel.count() == 1) { [m_native setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; [m_native setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; - } else { + } else +#endif + { [m_native setKeyEquivalent:@""]; [m_native setKeyEquivalentModifierMask:NSCommandKeyMask]; } @@ -371,6 +393,7 @@ QString QCocoaMenuItem::mergeText() return m_text; } +#ifndef QT_NO_SHORTCUT QKeySequence QCocoaMenuItem::mergeAccel() { QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; @@ -383,6 +406,7 @@ QKeySequence QCocoaMenuItem::mergeAccel() return m_shortcut; } +#endif void QCocoaMenuItem::syncMerged() { @@ -394,12 +418,13 @@ void QCocoaMenuItem::syncMerged() [m_native setHidden: !m_isVisible]; } -void QCocoaMenuItem::syncModalState(bool modal) +void QCocoaMenuItem::setParentEnabled(bool enabled) { - if (modal) - [m_native setEnabled:NO]; - else - [m_native setEnabled:YES]; + if (m_parentEnabled != enabled) { + m_parentEnabled = enabled; + if (m_menu) + m_menu->propagateEnabledState(isEnabled()); + } } QPlatformMenuItem::MenuRole QCocoaMenuItem::effectiveRole() const |