245 |
245 |
246 action->action->activate(action_e); |
246 action->action->activate(action_e); |
247 |
247 |
248 //now walk up firing for each "caused" widget (like in the platform independent menu) |
248 //now walk up firing for each "caused" widget (like in the platform independent menu) |
249 QWidget *caused = 0; |
249 QWidget *caused = 0; |
250 if (GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) { |
250 if (action_e == QAction::Hover && GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) { |
251 MenuRef caused_menu = 0; |
251 MenuRef caused_menu = 0; |
252 if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) |
252 if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) |
253 caused_menu = qmenu2->macMenu(); |
253 caused_menu = qmenu2->macMenu(); |
254 else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) |
254 else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) |
255 caused_menu = qmenubar2->macMenu(); |
255 caused_menu = qmenubar2->macMenu(); |
258 while(caused_menu) { |
258 while(caused_menu) { |
259 //fire |
259 //fire |
260 QWidget *widget = 0; |
260 QWidget *widget = 0; |
261 GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget); |
261 GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget); |
262 if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { |
262 if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { |
263 if (action_e == QAction::Trigger) { |
263 action->action->showStatusText(widget); |
264 emit qmenu->triggered(action->action); |
264 emit qmenu->hovered(action->action); |
265 } else if (action_e == QAction::Hover) { |
|
266 action->action->showStatusText(widget); |
|
267 emit qmenu->hovered(action->action); |
|
268 } |
|
269 } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) { |
265 } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) { |
270 if (action_e == QAction::Trigger) { |
266 action->action->showStatusText(widget); |
271 emit qmenubar->triggered(action->action); |
267 emit qmenubar->hovered(action->action); |
272 } else if (action_e == QAction::Hover) { |
|
273 action->action->showStatusText(widget); |
|
274 emit qmenubar->hovered(action->action); |
|
275 } |
|
276 break; //nothing more.. |
268 break; //nothing more.. |
277 } |
269 } |
278 |
270 |
279 //walk up |
271 //walk up |
280 if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, |
272 if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, |
281 sizeof(caused), 0, &caused) != noErr) |
273 sizeof(caused), 0, &caused) != noErr) |
282 break; |
274 break; |
283 if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) |
275 if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) |
284 caused_menu = qmenu2->macMenu(); |
276 caused_menu = qmenu2->macMenu(); |
285 else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) |
277 else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) |
286 caused_menu = qmenubar2->macMenu(); |
278 caused_menu = qmenubar2->macMenu(); |
671 else |
663 else |
672 EnableMenuItem(submenu, 0); |
664 EnableMenuItem(submenu, 0); |
673 } |
665 } |
674 } |
666 } |
675 #else |
667 #else |
|
668 bool modalWindowOnScreen = qApp->activeModalWidget() != 0; |
676 for (NSMenuItem *item in [menu itemArray]) { |
669 for (NSMenuItem *item in [menu itemArray]) { |
677 OSMenuRef submenu = [item submenu]; |
670 OSMenuRef submenu = [item submenu]; |
678 if (submenu != merge) { |
671 if (submenu != merge) { |
679 if (submenu) |
672 if (submenu) |
680 qt_mac_set_modal_state_helper_recursive(submenu, merge, on); |
673 qt_mac_set_modal_state_helper_recursive(submenu, merge, on); |
681 if (!on) { |
674 if (!on) { |
682 // The item should follow what the QAction has. |
675 // The item should follow what the QAction has. |
683 if ([item tag]) { |
676 if ([item tag]) { |
684 QAction *action = reinterpret_cast<QAction *>([item tag]); |
677 QAction *action = reinterpret_cast<QAction *>([item tag]); |
685 syncNSMenuItemEnabled(item, action->isEnabled()); |
678 syncNSMenuItemEnabled(item, action->isEnabled()); |
686 } else { |
679 } else { |
687 syncNSMenuItemEnabled(item, YES); |
680 syncNSMenuItemEnabled(item, YES); |
688 } |
681 } |
|
682 // We sneak in some extra code here to handle a menu problem: |
|
683 // If there is no window on screen, we cannot set 'nil' as |
|
684 // menu item target, because then cocoa will disable the item |
|
685 // (guess it assumes that there will be no first responder to |
|
686 // catch the trigger anyway?) OTOH, If we have a modal window, |
|
687 // then setting the menu loader as target will make cocoa not |
|
688 // deliver the trigger because the loader is then seen as modally |
|
689 // shaddowed). So either way there are shortcomings. Instead, we |
|
690 // decide the target as late as possible: |
|
691 [item setTarget:modalWindowOnScreen ? nil : getMenuLoader()]; |
689 } else { |
692 } else { |
690 syncNSMenuItemEnabled(item, NO); |
693 syncNSMenuItemEnabled(item, NO); |
691 } |
694 } |
692 } |
695 } |
693 } |
696 } |
747 bool qt_mac_menubar_is_open() |
750 bool qt_mac_menubar_is_open() |
748 { |
751 { |
749 return qt_mac_menus_open_count > 0; |
752 return qt_mac_menus_open_count > 0; |
750 } |
753 } |
751 |
754 |
752 void qt_mac_clear_menubar() |
|
753 { |
|
754 if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) |
|
755 return; |
|
756 |
|
757 #ifndef QT_MAC_USE_COCOA |
|
758 MenuRef clear_menu = 0; |
|
759 if (CreateNewMenu(0, 0, &clear_menu) == noErr) { |
|
760 SetRootMenu(clear_menu); |
|
761 ReleaseMenu(clear_menu); |
|
762 } else { |
|
763 qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__); |
|
764 } |
|
765 ClearMenuBar(); |
|
766 qt_mac_command_set_enabled(0, kHICommandPreferences, false); |
|
767 InvalMenuBar(); |
|
768 #else |
|
769 QMacCocoaAutoReleasePool pool; |
|
770 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
|
771 NSMenu *menu = [loader menu]; |
|
772 [loader ensureAppMenuInMenu:menu]; |
|
773 [NSApp setMainMenu:menu]; |
|
774 #endif |
|
775 } |
|
776 |
|
777 |
|
778 QMacMenuAction::~QMacMenuAction() |
755 QMacMenuAction::~QMacMenuAction() |
779 { |
756 { |
780 #ifdef QT_MAC_USE_COCOA |
757 #ifdef QT_MAC_USE_COCOA |
781 [menu release]; |
758 [menu release]; |
782 // Update the menu item if this action still owns it. For some items |
759 // Update the menu item if this action still owns it. For some items |
941 } |
918 } |
942 |
919 |
943 static QString qt_mac_menu_merge_text(QMacMenuAction *action) |
920 static QString qt_mac_menu_merge_text(QMacMenuAction *action) |
944 { |
921 { |
945 QString ret; |
922 QString ret; |
|
923 extern QString qt_mac_applicationmenu_string(int type); |
946 #ifdef QT_MAC_USE_COCOA |
924 #ifdef QT_MAC_USE_COCOA |
947 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
925 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
948 #endif |
926 #endif |
949 if (action->action->menuRole() == QAction::ApplicationSpecificRole) |
927 if (action->action->menuRole() == QAction::ApplicationSpecificRole) |
950 ret = action->action->text(); |
928 ret = action->action->text(); |
951 #ifndef QT_MAC_USE_COCOA |
929 #ifndef QT_MAC_USE_COCOA |
952 else if (action->command == kHICommandAbout) |
930 else if (action->command == kHICommandAbout) |
953 ret = QMenuBar::tr("About %1").arg(qAppName()); |
931 ret = qt_mac_applicationmenu_string(6).arg(qAppName()); |
954 else if (action->command == kHICommandAboutQt) |
932 else if (action->command == kHICommandAboutQt) |
955 ret = QMenuBar::tr("About Qt"); |
933 ret = QMenuBar::tr("About Qt"); |
956 else if (action->command == kHICommandPreferences) |
934 else if (action->command == kHICommandPreferences) |
957 ret = QMenuBar::tr("Preferences"); |
935 ret = qt_mac_applicationmenu_string(4); |
958 else if (action->command == kHICommandQuit) |
936 else if (action->command == kHICommandQuit) |
959 ret = QMenuBar::tr("Quit %1").arg(qAppName()); |
937 ret = qt_mac_applicationmenu_string(5).arg(qAppName()); |
960 #else |
938 #else |
961 else if (action->menuItem == [loader aboutMenuItem]) |
939 else if (action->menuItem == [loader aboutMenuItem]) { |
962 ret = QMenuBar::tr("About %1").arg(qAppName()); |
940 ret = qt_mac_applicationmenu_string(6).arg(qAppName()); |
963 else if (action->menuItem == [loader aboutQtMenuItem]) |
941 } else if (action->menuItem == [loader aboutQtMenuItem]) { |
964 ret = QMenuBar::tr("About Qt"); |
942 if (action->action->text() == QString("About Qt")) |
965 else if (action->menuItem == [loader preferencesMenuItem]) |
943 ret = QMenuBar::tr("About Qt"); |
966 ret = QMenuBar::tr("Preferences"); |
944 else |
967 else if (action->menuItem == [loader quitMenuItem]) |
945 ret = action->action->text(); |
968 ret = QMenuBar::tr("Quit %1").arg(qAppName()); |
946 } else if (action->menuItem == [loader preferencesMenuItem]) { |
|
947 ret = qt_mac_applicationmenu_string(4); |
|
948 } else if (action->menuItem == [loader quitMenuItem]) { |
|
949 ret = qt_mac_applicationmenu_string(5).arg(qAppName()); |
|
950 } |
969 #endif |
951 #endif |
970 return ret; |
952 return ret; |
971 } |
953 } |
972 |
954 |
973 static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action) |
955 static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action) |
1128 [merge retain]; |
1110 [merge retain]; |
1129 [action->menu release]; |
1111 [action->menu release]; |
1130 action->menu = merge; |
1112 action->menu = merge; |
1131 [cmd retain]; |
1113 [cmd retain]; |
1132 [cmd setAction:@selector(qtDispatcherToQAction:)]; |
1114 [cmd setAction:@selector(qtDispatcherToQAction:)]; |
1133 [cmd setTarget:getMenuLoader()]; |
1115 [cmd setTarget:nil]; |
1134 [action->menuItem release]; |
1116 [action->menuItem release]; |
1135 action->menuItem = cmd; |
1117 action->menuItem = cmd; |
1136 QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge); |
1118 QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge); |
1137 if (!list) { |
1119 if (!list) { |
1138 list = new QMenuMergeList; |
1120 list = new QMenuMergeList; |
1934 /* ! |
1920 /* ! |
1935 \internal |
1921 \internal |
1936 Returns true if the entries of menuBar should be disabled, |
1922 Returns true if the entries of menuBar should be disabled, |
1937 based on the modality type of modalWidget. |
1923 based on the modality type of modalWidget. |
1938 */ |
1924 */ |
1939 static bool qt_mac_should_disable_menu(QMenuBar *menuBar, QWidget *modalWidget) |
1925 static bool qt_mac_should_disable_menu(QMenuBar *menuBar) |
1940 { |
1926 { |
1941 if (modalWidget == 0 || menuBar == 0) |
1927 QWidget *modalWidget = qApp->activeModalWidget(); |
|
1928 if (!modalWidget) |
1942 return false; |
1929 return false; |
1943 |
1930 |
1944 // If there is an application modal window on |
1931 if (menuBar && menuBar == menubars()->value(modalWidget)) |
1945 // screen, the entries of the menubar should be disabled: |
1932 // The menu bar is owned by the modal widget. |
|
1933 // In that case we should enable it: |
|
1934 return false; |
|
1935 |
|
1936 // When there is an application modal window on screen, the entries of |
|
1937 // the menubar should be disabled. The exception in Qt is that if the |
|
1938 // modal window is the only window on screen, then we enable the menu bar. |
1946 QWidget *w = modalWidget; |
1939 QWidget *w = modalWidget; |
|
1940 QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); |
1947 while (w) { |
1941 while (w) { |
1948 if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) |
1942 if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) { |
1949 return true; |
1943 for (int i=0; i<topLevelWidgets.size(); ++i) { |
|
1944 QWidget *top = topLevelWidgets.at(i); |
|
1945 if (w != top && top->isVisible()) { |
|
1946 // INVARIANT: we found another visible window |
|
1947 // on screen other than our modalWidget. We therefore |
|
1948 // disable the menu bar to follow normal modality logic: |
|
1949 return true; |
|
1950 } |
|
1951 } |
|
1952 // INVARIANT: We have only one window on screen that happends |
|
1953 // to be application modal. We choose to enable the menu bar |
|
1954 // in that case to e.g. enable the quit menu item. |
|
1955 return false; |
|
1956 } |
1950 w = w->parentWidget(); |
1957 w = w->parentWidget(); |
1951 } |
1958 } |
1952 |
1959 |
1953 // INVARIANT: modalWidget is window modal. Disable menu entries |
1960 // INVARIANT: modalWidget is window modal. Disable menu entries |
1954 // if the menu bar belongs to an ancestor of modalWidget: |
1961 // if the menu bar belongs to an ancestor of modalWidget. If menuBar |
1955 return qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget); |
1962 // is nil, we understand it as the default menu bar set by the nib: |
1956 } |
1963 return menuBar ? qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget) : false; |
1957 |
1964 } |
1958 /*! |
1965 |
1959 \internal |
1966 static QWidget *findWindowThatShouldDisplayMenubar() |
1960 |
1967 { |
1961 This function will update the current menu bar and set it as the |
|
1962 active menu bar in the Menu Manager. |
|
1963 |
|
1964 \warning This function is not portable. |
|
1965 |
|
1966 \sa QMenu::macMenu(), QMenuBar::macMenu() |
|
1967 */ |
|
1968 bool QMenuBar::macUpdateMenuBar() |
|
1969 { |
|
1970 cancelAllMenuTracking(); |
|
1971 QMenuBar *mb = 0; |
|
1972 //find a menu bar |
|
1973 QWidget *w = qApp->activeWindow(); |
1968 QWidget *w = qApp->activeWindow(); |
1974 |
|
1975 if (!w) { |
1969 if (!w) { |
|
1970 // We have no active window on screen. Try to |
|
1971 // find a window from the list of top levels: |
1976 QWidgetList tlws = QApplication::topLevelWidgets(); |
1972 QWidgetList tlws = QApplication::topLevelWidgets(); |
1977 for(int i = 0; i < tlws.size(); ++i) { |
1973 for(int i = 0; i < tlws.size(); ++i) { |
1978 QWidget *tlw = tlws.at(i); |
1974 QWidget *tlw = tlws.at(i); |
1979 if ((tlw->isVisible() && tlw->windowType() != Qt::Tool && |
1975 if ((tlw->isVisible() && tlw->windowType() != Qt::Tool && |
1980 tlw->windowType() != Qt::Popup)) { |
1976 tlw->windowType() != Qt::Popup)) { |
1981 w = tlw; |
1977 w = tlw; |
1982 break; |
1978 break; |
1983 } |
1979 } |
1984 } |
1980 } |
1985 } |
1981 } |
|
1982 return w; |
|
1983 } |
|
1984 |
|
1985 static QMenuBar *findMenubarForWindow(QWidget *w) |
|
1986 { |
|
1987 QMenuBar *mb = 0; |
1986 if (w) { |
1988 if (w) { |
1987 mb = menubars()->value(w); |
1989 mb = menubars()->value(w); |
1988 #ifndef QT_NO_MAINWINDOW |
1990 #ifndef QT_NO_MAINWINDOW |
1989 QDockWidget *dw = qobject_cast<QDockWidget *>(w); |
1991 QDockWidget *dw = qobject_cast<QDockWidget *>(w); |
1990 if (!mb && dw) { |
1992 if (!mb && dw) { |
1994 } |
1996 } |
1995 #endif |
1997 #endif |
1996 while(w && !mb) |
1998 while(w && !mb) |
1997 mb = menubars()->value((w = w->parentWidget())); |
1999 mb = menubars()->value((w = w->parentWidget())); |
1998 } |
2000 } |
1999 if (!mb) |
2001 |
|
2002 if (!mb) { |
|
2003 // We could not find a menu bar for the window. Lets |
|
2004 // check if we have a global (parentless) menu bar instead: |
2000 mb = fallback; |
2005 mb = fallback; |
2001 //now set it |
2006 } |
|
2007 |
|
2008 return mb; |
|
2009 } |
|
2010 |
|
2011 void qt_mac_clear_menubar() |
|
2012 { |
|
2013 if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) |
|
2014 return; |
|
2015 |
|
2016 #ifndef QT_MAC_USE_COCOA |
|
2017 MenuRef clear_menu = 0; |
|
2018 if (CreateNewMenu(0, 0, &clear_menu) == noErr) { |
|
2019 SetRootMenu(clear_menu); |
|
2020 ReleaseMenu(clear_menu); |
|
2021 } else { |
|
2022 qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__); |
|
2023 } |
|
2024 ClearMenuBar(); |
|
2025 qt_mac_command_set_enabled(0, kHICommandPreferences, false); |
|
2026 InvalMenuBar(); |
|
2027 #else |
|
2028 QMacCocoaAutoReleasePool pool; |
|
2029 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
|
2030 NSMenu *menu = [loader menu]; |
|
2031 [loader ensureAppMenuInMenu:menu]; |
|
2032 [NSApp setMainMenu:menu]; |
|
2033 const bool modal = qt_mac_should_disable_menu(0); |
|
2034 if (qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal) |
|
2035 qt_mac_set_modal_state(menu, modal); |
|
2036 qt_mac_current_menubar.qmenubar = 0; |
|
2037 qt_mac_current_menubar.modal = modal; |
|
2038 #endif |
|
2039 } |
|
2040 |
|
2041 /*! |
|
2042 \internal |
|
2043 |
|
2044 This function will update the current menu bar and set it as the |
|
2045 active menu bar in the Menu Manager. |
|
2046 |
|
2047 \warning This function is not portable. |
|
2048 |
|
2049 \sa QMenu::macMenu(), QMenuBar::macMenu() |
|
2050 */ |
|
2051 bool QMenuBar::macUpdateMenuBar() |
|
2052 { |
|
2053 #ifdef QT_MAC_USE_COCOA |
|
2054 QMacCocoaAutoReleasePool pool; |
|
2055 if (!qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar))) |
|
2056 return QMenuBarPrivate::macUpdateMenuBarImmediatly(); |
|
2057 return true; |
|
2058 #else |
|
2059 return QMenuBarPrivate::macUpdateMenuBarImmediatly(); |
|
2060 #endif |
|
2061 } |
|
2062 |
|
2063 bool QMenuBarPrivate::macUpdateMenuBarImmediatly() |
|
2064 { |
2002 bool ret = false; |
2065 bool ret = false; |
|
2066 cancelAllMenuTracking(); |
|
2067 QWidget *w = findWindowThatShouldDisplayMenubar(); |
|
2068 QMenuBar *mb = findMenubarForWindow(w); |
|
2069 extern bool qt_mac_app_fullscreen; //qapplication_mac.mm |
|
2070 |
|
2071 // We need to see if we are in full screen mode, if so we need to |
|
2072 // switch the full screen mode to be able to show or hide the menubar. |
|
2073 if(w && mb) { |
|
2074 // This case means we are creating a menubar, check if full screen |
|
2075 if(w->isFullScreen()) { |
|
2076 // Ok, switch to showing the menubar when hovering over it. |
|
2077 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
|
2078 qt_mac_app_fullscreen = true; |
|
2079 } |
|
2080 } else if(w) { |
|
2081 // Removing a menubar |
|
2082 if(w->isFullScreen()) { |
|
2083 // Ok, switch to not showing the menubar when hovering on it |
|
2084 SetSystemUIMode(kUIModeAllHidden, 0); |
|
2085 qt_mac_app_fullscreen = true; |
|
2086 } |
|
2087 } |
|
2088 |
2003 if (mb && mb->isNativeMenuBar()) { |
2089 if (mb && mb->isNativeMenuBar()) { |
|
2090 bool modal = QApplicationPrivate::modalState(); |
2004 #ifdef QT_MAC_USE_COCOA |
2091 #ifdef QT_MAC_USE_COCOA |
2005 QMacCocoaAutoReleasePool pool; |
2092 QMacCocoaAutoReleasePool pool; |
2006 #endif |
2093 #endif |
2007 if (OSMenuRef menu = mb->macMenu()) { |
2094 if (OSMenuRef menu = mb->macMenu()) { |
2008 #ifndef QT_MAC_USE_COCOA |
2095 #ifndef QT_MAC_USE_COCOA |
2028 [mergeItem.menuItem setHidden:!(mergeItem.action->action->isVisible())]; |
2115 [mergeItem.menuItem setHidden:!(mergeItem.action->action->isVisible())]; |
2029 } |
2116 } |
2030 } |
2117 } |
2031 } |
2118 } |
2032 #endif |
2119 #endif |
2033 QWidget *modalWidget = qApp->activeModalWidget(); |
2120 // Check if menu is modally shaddowed and should be disabled: |
2034 if (mb != menubars()->value(modalWidget)) { |
2121 modal = qt_mac_should_disable_menu(mb); |
2035 qt_mac_set_modal_state(menu, qt_mac_should_disable_menu(mb, modalWidget)); |
2122 if (mb != qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal) |
2036 } |
2123 qt_mac_set_modal_state(menu, modal); |
2037 } |
2124 } |
2038 qt_mac_current_menubar.qmenubar = mb; |
2125 qt_mac_current_menubar.qmenubar = mb; |
2039 qt_mac_current_menubar.modal = QApplicationPrivate::modalState(); |
2126 qt_mac_current_menubar.modal = modal; |
2040 ret = true; |
2127 ret = true; |
2041 } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { |
2128 } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { |
2042 const bool modal = QApplicationPrivate::modalState(); |
2129 // INVARIANT: The currently active menu bar (if any) is not native. But we do have a |
|
2130 // native menu bar from before. So we need to decide whether or not is should be enabled: |
|
2131 const bool modal = qt_mac_should_disable_menu(qt_mac_current_menubar.qmenubar); |
2043 if (modal != qt_mac_current_menubar.modal) { |
2132 if (modal != qt_mac_current_menubar.modal) { |
2044 ret = true; |
2133 ret = true; |
2045 if (OSMenuRef menu = qt_mac_current_menubar.qmenubar->macMenu()) { |
2134 if (OSMenuRef menu = qt_mac_current_menubar.qmenubar->macMenu()) { |
2046 #ifndef QT_MAC_USE_COCOA |
2135 #ifndef QT_MAC_USE_COCOA |
2047 SetRootMenu(menu); |
2136 SetRootMenu(menu); |
2049 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
2138 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); |
2050 [loader ensureAppMenuInMenu:menu]; |
2139 [loader ensureAppMenuInMenu:menu]; |
2051 [NSApp setMainMenu:menu]; |
2140 [NSApp setMainMenu:menu]; |
2052 syncMenuBarItemsVisiblity(qt_mac_current_menubar.qmenubar->d_func()->mac_menubar); |
2141 syncMenuBarItemsVisiblity(qt_mac_current_menubar.qmenubar->d_func()->mac_menubar); |
2053 #endif |
2142 #endif |
2054 QWidget *modalWidget = qApp->activeModalWidget(); |
2143 qt_mac_set_modal_state(menu, modal); |
2055 if (qt_mac_current_menubar.qmenubar != menubars()->value(modalWidget)) { |
|
2056 qt_mac_set_modal_state(menu, qt_mac_should_disable_menu(mb, modalWidget)); |
|
2057 } |
|
2058 } |
2144 } |
2059 qt_mac_current_menubar.modal = modal; |
2145 qt_mac_current_menubar.modal = modal; |
2060 } |
2146 } |
2061 } |
2147 } |
2062 if(!ret) |
2148 |
|
2149 if (!ret) { |
2063 qt_mac_clear_menubar(); |
2150 qt_mac_clear_menubar(); |
|
2151 } |
2064 return ret; |
2152 return ret; |
2065 } |
2153 } |
2066 |
2154 |
2067 QHash<OSMenuRef, OSMenuRef> QMenuPrivate::mergeMenuHash; |
2155 QHash<OSMenuRef, OSMenuRef> QMenuPrivate::mergeMenuHash; |
2068 QHash<OSMenuRef, QMenuMergeList*> QMenuPrivate::mergeMenuItemsHash; |
2156 QHash<OSMenuRef, QMenuMergeList*> QMenuPrivate::mergeMenuItemsHash; |