Changeset 561 for trunk/src/gui/widgets/qmenu_mac.mm
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qmenu_mac.mm
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 72 72 QMenu globals 73 73 *****************************************************************************/ 74 bool qt_mac_no_native_menubar = false;75 74 bool qt_mac_no_menubar_merge = false; 76 75 bool qt_mac_quit_menu_item_enabled = true; … … 144 143 } 145 144 145 static quint32 constructModifierMask(quint32 accel_key) 146 { 147 quint32 ret = 0; 148 const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta); 149 #ifndef QT_MAC_USE_COCOA 150 if ((accel_key & Qt::ALT) == Qt::ALT) 151 ret |= kMenuOptionModifier; 152 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 153 ret |= kMenuShiftModifier; 154 if (dontSwap) { 155 if ((accel_key & Qt::META) != Qt::META) 156 ret |= kMenuNoCommandModifier; 157 if ((accel_key & Qt::CTRL) == Qt::CTRL) 158 ret |= kMenuControlModifier; 159 } else { 160 if ((accel_key & Qt::CTRL) != Qt::CTRL) 161 ret |= kMenuNoCommandModifier; 162 if ((accel_key & Qt::META) == Qt::META) 163 ret |= kMenuControlModifier; 164 } 165 #else 166 if ((accel_key & Qt::CTRL) == Qt::CTRL) 167 ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask); 168 if ((accel_key & Qt::META) == Qt::META) 169 ret |= (dontSwap ? NSCommandKeyMask : NSControlKeyMask); 170 if ((accel_key & Qt::ALT) == Qt::ALT) 171 ret |= NSAlternateKeyMask; 172 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 173 ret |= NSShiftKeyMask; 174 #endif 175 return ret; 176 } 177 146 178 static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp, 147 179 const QMacMenuAction *action) … … 167 199 GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, 168 200 sizeof(list), 0, &list); 169 if (!list && qt_mac_current_menubar.qmenubar ) {201 if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { 170 202 MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu; 171 203 GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list); … … 427 459 int merged = 0; 428 460 const QMenuPrivate::QMacMenuPrivate *mac_menu = qmenu->d_func()->mac_menu; 429 for(int i = 0; i < mac_menu->actionItems.size(); ++i) { 461 const int ActionItemsCount = mac_menu->actionItems.size(); 462 for(int i = 0; i < ActionItemsCount; ++i) { 430 463 QMacMenuAction *action = mac_menu->actionItems.at(i); 431 464 if (action->action->isSeparator()) { … … 527 560 static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) { 528 561 if (modif) { 529 *modif = 0; 530 if ((accel_key & Qt::CTRL) != Qt::CTRL) 531 *modif |= kMenuNoCommandModifier; 532 if ((accel_key & Qt::META) == Qt::META) 533 *modif |= kMenuControlModifier; 534 if ((accel_key & Qt::ALT) == Qt::ALT) 535 *modif |= kMenuOptionModifier; 536 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 537 *modif |= kMenuShiftModifier; 562 *modif = constructModifierMask(accel_key); 538 563 } 539 564 … … 583 608 } 584 609 610 static inline void syncNSMenuItemEnabled(NSMenuItem *menuItem, bool enabled) 611 { 612 [menuItem setEnabled:NO]; 613 [menuItem setEnabled:YES]; 614 [menuItem setEnabled:enabled]; 615 } 616 585 617 static inline void syncMenuBarItemsVisiblity(const QMenuBarPrivate::QMacMenuBarPrivate *mac_menubar) 586 618 { … … 600 632 { 601 633 NSMenuItem *item = [[NSMenuItem alloc] 602 initWithTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(title)))634 initWithTitle:qt_mac_QStringToNSString(title) 603 635 action:@selector(qtDispatcherToQAction:) keyEquivalent:@""]; 604 636 [item setTarget:getMenuLoader()]; … … 635 667 if ([item tag]) { 636 668 QAction *action = reinterpret_cast<QAction *>([item tag]); 637 [item setEnabled:action->isEnabled()];669 syncNSMenuItemEnabled(item, action->isEnabled()); 638 670 } else { 639 [item setEnabled:YES];671 syncNSMenuItemEnabled(item, YES); 640 672 } 641 673 } else { 642 [item setEnabled:NO];674 syncNSMenuItemEnabled(item, NO); 643 675 } 644 676 } … … 704 736 void qt_mac_clear_menubar() 705 737 { 738 if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) 739 return; 740 706 741 #ifndef QT_MAC_USE_COCOA 707 742 MenuRef clear_menu = 0; … … 729 764 #ifdef QT_MAC_USE_COCOA 730 765 [menu release]; 731 [menuItem setTag:nil]; 766 // Update the menu item if this action still owns it. For some items 767 // (like 'Quit') ownership will be transferred between all menu bars... 768 if (action && action.data() == reinterpret_cast<QAction *>([menuItem tag])) { 769 QAction::MenuRole role = action->menuRole(); 770 // Check if the item is owned by Qt, and should be hidden to keep it from causing 771 // problems. Do it for everything but the quit menu item since that should always 772 // be visible. 773 if (role > QAction::ApplicationSpecificRole && role < QAction::QuitRole) { 774 [menuItem setHidden:YES]; 775 } else if (role == QAction::TextHeuristicRole 776 && menuItem != [getMenuLoader() quitMenuItem]) { 777 [menuItem setHidden:YES]; 778 } 779 [menuItem setTag:nil]; 780 } 732 781 [menuItem release]; 733 782 #endif … … 872 921 } 873 922 874 if ([ret tag] != 0)875 ret = 0; // already taken876 923 #endif 877 924 return ret; … … 918 965 #ifndef QT_MAC_USE_COCOA 919 966 else if (action->command == kHICommandPreferences) 920 ret = QKeySequence(Q t::CTRL+Qt::Key_Comma);967 ret = QKeySequence(QKeySequence::Preferences); 921 968 else if (action->command == kHICommandQuit) 922 ret = QKeySequence(Q t::CTRL+Qt::Key_Q);969 ret = QKeySequence(QKeySequence::Quit); 923 970 #else 924 971 else if (action->menuItem == [loader preferencesMenuItem]) 925 ret = QKeySequence(Q t::CTRL+Qt::Key_Comma);972 ret = QKeySequence(QKeySequence::Preferences); 926 973 else if (action->menuItem == [loader quitMenuItem]) 927 ret = QKeySequence(Q t::CTRL+Qt::Key_Q);974 ret = QKeySequence(QKeySequence::Quit); 928 975 #endif 929 976 return ret; … … 932 979 void Q_GUI_EXPORT qt_mac_set_menubar_icons(bool b) 933 980 { QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, !b); } 934 void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) { qt_mac_no_native_menubar = !b; } 981 void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) 982 { QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, !b); } 935 983 void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !b; } 936 984 … … 1132 1180 if (mergedItems.contains(action->command) 1133 1181 && (testattr & kMenuItemAttrSeparator)) { 1134 1135 1136 1137 1138 1139 1140 1141 1142 1182 InsertMenuItemTextWithCFString(action->menu, 0, qMax(itemCount - 1, 0), attr, action->command); 1183 index = itemCount; 1184 } else { 1185 MenuItemIndex tmpIndex; 1186 AppendMenuItemTextWithCFString(action->menu, 0, attr, action->command, &tmpIndex); 1187 index = tmpIndex; 1188 if (mergedItems.contains(action->command)) 1189 AppendMenuItemTextWithCFString(action->menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex); 1190 } 1143 1191 #else 1144 1192 [menu addItem:newItem]; … … 1209 1257 { 1210 1258 quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL)); 1211 unichar keyEquiv[1] = { 0 }; 1212 if (accel_key == Qt::Key_Return) 1213 keyEquiv[0] = kReturnCharCode; 1214 else if (accel_key == Qt::Key_Enter) 1215 keyEquiv[0] = kEnterCharCode; 1216 else if (accel_key == Qt::Key_Tab) 1217 keyEquiv[0] = kTabCharCode; 1218 else if (accel_key == Qt::Key_Backspace) 1219 keyEquiv[0] = kBackspaceCharCode; 1220 else if (accel_key == Qt::Key_Delete) 1221 keyEquiv[0] = NSDeleteFunctionKey; 1222 else if (accel_key == Qt::Key_Escape) 1223 keyEquiv[0] = kEscapeCharCode; 1224 else if (accel_key == Qt::Key_PageUp) 1225 keyEquiv[0] = NSPageUpFunctionKey; 1226 else if (accel_key == Qt::Key_PageDown) 1227 keyEquiv[0] = NSPageDownFunctionKey; 1228 else if (accel_key == Qt::Key_Up) 1229 keyEquiv[0] = NSUpArrowFunctionKey; 1230 else if (accel_key == Qt::Key_Down) 1231 keyEquiv[0] = NSDownArrowFunctionKey; 1232 else if (accel_key == Qt::Key_Left) 1233 keyEquiv[0] = NSLeftArrowFunctionKey; 1234 else if (accel_key == Qt::Key_Right) 1235 keyEquiv[0] = NSRightArrowFunctionKey; 1236 else if (accel_key == Qt::Key_CapsLock) 1237 keyEquiv[0] = kMenuCapsLockGlyph; // ### Cocoa has no equivalent 1238 else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) 1239 keyEquiv[0] = (accel_key - Qt::Key_F1) + NSF1FunctionKey; 1240 else if (accel_key == Qt::Key_Home) 1241 keyEquiv[0] = NSHomeFunctionKey; 1242 else if (accel_key == Qt::Key_End) 1243 keyEquiv[0] = NSEndFunctionKey; 1244 else 1245 keyEquiv[0] = unichar(QChar(accel_key).toLower().unicode()); 1246 return [NSString stringWithCharacters:keyEquiv length:1]; 1259 extern QChar qt_macSymbolForQtKey(int key); // qkeysequence.cpp 1260 QChar keyEquiv = qt_macSymbolForQtKey(accel_key); 1261 if (keyEquiv.isNull()) { 1262 if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) 1263 keyEquiv = (accel_key - Qt::Key_F1) + NSF1FunctionKey; 1264 else 1265 keyEquiv = unichar(QChar(accel_key).toLower().unicode()); 1266 } 1267 return [NSString stringWithCharacters:&keyEquiv.unicode() length:1]; 1247 1268 } 1248 1269 … … 1250 1271 NSUInteger keySequenceModifierMask(const QKeySequence &accel) 1251 1272 { 1252 NSUInteger ret = 0; 1253 quint32 accel_key = accel[0]; 1254 if ((accel_key & Qt::CTRL) == Qt::CTRL) 1255 ret |= NSCommandKeyMask; 1256 if ((accel_key & Qt::META) == Qt::META) 1257 ret |= NSControlKeyMask; 1258 if ((accel_key & Qt::ALT) == Qt::ALT) 1259 ret |= NSAlternateKeyMask; 1260 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 1261 ret |= NSShiftKeyMask; 1262 return ret; 1273 return constructModifierMask(accel[0]); 1263 1274 } 1264 1275 … … 1340 1351 } 1341 1352 } 1353 // Show multiple key sequences as part of the menu text. 1342 1354 if (accel.count() > 1) 1343 text += QLatin1String(" ( ****)"); //just to denote a multi stroke shortcut1355 text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")"); 1344 1356 1345 1357 QString finalString = qt_mac_removeMnemonics(text); … … 1362 1374 && action->action->isIconVisibleInMenu()) { 1363 1375 data.iconType = kMenuIconRefType; 1364 data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap( 22, QIcon::Normal));1376 data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(16, QIcon::Normal)); 1365 1377 } else { 1366 1378 data.iconType = kMenuNoIcon; … … 1382 1394 if (action->action->font().resolve()) { 1383 1395 const QFont &actionFont = action->action->font(); 1384 NSFont *customMenuFont = [NSFont fontWithName: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(actionFont.family())))1396 NSFont *customMenuFont = [NSFont fontWithName:qt_mac_QStringToNSString(actionFont.family()) 1385 1397 size:actionFont.pointSize()]; 1386 1398 NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil]; 1387 1399 NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil]; 1388 1400 NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; 1389 NSAttributedString *str = [[[NSAttributedString alloc] initWithString: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(finalString)))1401 NSAttributedString *str = [[[NSAttributedString alloc] initWithString:qt_mac_QStringToNSString(finalString) 1390 1402 attributes:attributes] autorelease]; 1391 1403 [item setAttributedTitle: str]; 1392 1404 } else { 1393 [item setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(finalString)))];1394 } 1395 [item setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(qt_mac_removeMnemonics(text))))];1405 [item setTitle: qt_mac_QStringToNSString(finalString)]; 1406 } 1407 [item setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(text))]; 1396 1408 1397 1409 // Cocoa Enabled … … 1401 1413 NSImage *nsimage = 0; 1402 1414 if (!action->action->icon().isNull() && action->action->isIconVisibleInMenu()) { 1403 nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap( 22, QIcon::Normal)));1415 nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap(16, QIcon::Normal))); 1404 1416 } 1405 1417 [item setImage:nsimage]; … … 1415 1427 SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); 1416 1428 #else 1417 [item setSubmenu:static_cast<NSMenu *>(action->action->menu()->macMenu())]; 1429 NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu()); 1430 if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) { 1431 // The menu is already a sub-menu of another one. Cocoa will throw an exception, 1432 // in such cases. For the time being, a new QMenu with same set of actions is the 1433 // only workaround. 1434 action->action->setEnabled(false); 1435 } else { 1436 [item setSubmenu:subMenu]; 1437 } 1418 1438 #endif 1419 1439 } else { //respect some other items … … 1423 1443 data.whichData |= kMenuItemDataCmdKeyModifiers; 1424 1444 data.whichData |= kMenuItemDataCmdKeyGlyph; 1425 if ( !accel.isEmpty()) {1445 if (accel.count() == 1) { 1426 1446 qt_mac_get_accel(accel[0], (quint32*)&data.cmdKeyModifiers, (quint32*)&data.cmdKeyGlyph); 1427 1447 if (data.cmdKeyGlyph == 0) … … 1430 1450 #else 1431 1451 [item setSubmenu:0]; 1432 if (!accel.isEmpty()) { 1452 // No key equivalent set for multiple key QKeySequence. 1453 if (accel.count() == 1) { 1433 1454 [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; 1434 1455 [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; … … 1478 1499 #else 1479 1500 QMacCocoaAutoReleasePool pool; 1480 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); 1481 if (action->menuItem == [loader quitMenuItem] || action->menuItem == [loader preferencesMenuItem]) 1482 [action->menuItem setEnabled:false]; 1483 else 1501 if (action->merged) { 1502 if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->action) { 1503 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); 1504 [action->menuItem setEnabled:false]; 1505 if (action->menuItem != [loader quitMenuItem] 1506 && action->menuItem != [loader preferencesMenuItem]) { 1507 [[action->menuItem menu] removeItem:action->menuItem]; 1508 } 1509 } 1510 } else { 1484 1511 [[action->menuItem menu] removeItem:action->menuItem]; 1512 } 1485 1513 #endif 1486 1514 actionItems.removeAll(action); … … 1507 1535 for(int i = 0; i < items.count(); i++) 1508 1536 mac_menu->addAction(items[i], 0, this); 1537 syncSeparatorsCollapsible(collapsibleSeparators); 1509 1538 return mac_menu->menu; 1510 1539 } 1540 1541 /*! 1542 \internal 1543 */ 1544 void 1545 QMenuPrivate::syncSeparatorsCollapsible(bool collapse) 1546 { 1547 #ifndef QT_MAC_USE_COCOA 1548 if (collapse) 1549 ChangeMenuAttributes(mac_menu->menu, kMenuAttrCondenseSeparators, 0); 1550 else 1551 ChangeMenuAttributes(mac_menu->menu, 0, kMenuAttrCondenseSeparators); 1552 #else 1553 qt_mac_menu_collapseSeparators(mac_menu->menu, collapse); 1554 #endif 1555 } 1556 1557 1511 1558 1512 1559 /*! … … 1674 1721 SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); 1675 1722 #else 1676 [item setSubmenu:submenu]; 1723 if ([submenu supermenu] && [submenu supermenu] != [item menu]) 1724 return; 1725 else 1726 [item setSubmenu:submenu]; 1677 1727 #endif 1678 1728 } … … 1695 1745 #else 1696 1746 [item setSubmenu: submenu]; 1697 [submenu setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(qt_mac_removeMnemonics(action->action->text()))))];1747 [submenu setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(action->action->text()))]; 1698 1748 syncNSMenuItemVisiblity(item, visible); 1699 1749 #endif … … 1724 1774 } 1725 1775 1776 bool QMenuBarPrivate::macWidgetHasNativeMenubar(QWidget *widget) 1777 { 1778 // This function is different from q->isNativeMenuBar(), as 1779 // it returns true only if a native menu bar is actually 1780 // _created_. 1781 if (!widget) 1782 return false; 1783 return menubars()->contains(widget->window()); 1784 } 1785 1726 1786 void 1727 1787 QMenuBarPrivate::macCreateMenuBar(QWidget *parent) 1728 1788 { 1729 1789 Q_Q(QMenuBar); 1730 static int checkEnv = -1; 1731 if (qt_mac_no_native_menubar == false && checkEnv < 0) { 1732 checkEnv = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty(); 1733 qt_mac_no_native_menubar = checkEnv; 1734 } 1735 if (!qt_mac_no_native_menubar) { 1790 static int dontUseNativeMenuBar = -1; 1791 // We call the isNativeMenuBar function here 1792 // because that will make sure that local overrides 1793 // are dealt with correctly. q->isNativeMenuBar() will, if not 1794 // overridden, depend on the attribute Qt::AA_DontUseNativeMenuBar: 1795 bool qt_mac_no_native_menubar = !q->isNativeMenuBar(); 1796 if (qt_mac_no_native_menubar == false && dontUseNativeMenuBar < 0) { 1797 // The menubar is set to be native. Let's check (one time only 1798 // for all menubars) if this is OK with the rest of the environment. 1799 // As a result, Qt::AA_DontUseNativeMenuBar is set. NB: the application 1800 // might still choose to not respect, or change, this flag. 1801 bool isPlugin = QApplication::testAttribute(Qt::AA_MacPluginApplication); 1802 bool environmentSaysNo = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty(); 1803 dontUseNativeMenuBar = isPlugin || environmentSaysNo; 1804 QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, dontUseNativeMenuBar); 1805 qt_mac_no_native_menubar = !q->isNativeMenuBar(); 1806 } 1807 if (qt_mac_no_native_menubar == false) { 1808 // INVARIANT: Use native menubar. 1736 1809 extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp 1737 1810 qt_event_request_menubarupdate(); … … 1766 1839 { 1767 1840 Q_Q(QMenuBar); 1768 if (! mac_menubar) {1841 if (!q->isNativeMenuBar() || !mac_menubar) { 1769 1842 return 0; 1770 1843 } else if (!mac_menubar->menu) { … … 1782 1855 SetMenuItemProperty(mac_menubar->apple_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(q), &q); 1783 1856 #else 1784 [mac_menubar->apple_menu setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(QString(QChar(0x14)))))];1857 [mac_menubar->apple_menu setTitle:qt_mac_QStringToNSString(QString(QChar(0x14)))]; 1785 1858 NSMenuItem *apple_menuItem = [[NSMenuItem alloc] init]; 1786 1859 [apple_menuItem setSubmenu:mac_menubar->menu]; … … 1825 1898 static bool qt_mac_is_ancestor(QWidget* possibleAncestor, QWidget *child) 1826 1899 { 1900 if (!possibleAncestor) 1901 return false; 1902 1827 1903 QWidget * current = child->parentWidget(); 1828 1904 while (current != 0) { … … 1843 1919 if (modalWidget == 0 || menuBar == 0) 1844 1920 return false; 1845 const Qt::WindowModality modality = modalWidget->windowModality(); 1846 if (modality == Qt::ApplicationModal) { 1847 return true; 1848 } else if (modality == Qt::WindowModal) { 1849 QWidget * parent = menuBar->parentWidget(); 1850 1851 // Special case for the global menu bar: It's not associated 1852 // with a window so don't disable it. 1853 if (parent == 0) 1854 return false; 1855 1856 // Disable menu entries in menu bars that belong to ancestors of 1857 // the modal widget, leave entries in unrelated menu bars enabled. 1858 return qt_mac_is_ancestor(parent, modalWidget); 1859 } 1860 return false; // modality == NonModal 1921 1922 // If there is an application modal window on 1923 // screen, the entries of the menubar should be disabled: 1924 QWidget *w = modalWidget; 1925 while (w) { 1926 if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) 1927 return true; 1928 w = w->parentWidget(); 1929 } 1930 1931 // INVARIANT: modalWidget is window modal. Disable menu entries 1932 // if the menu bar belongs to an ancestor of modalWidget: 1933 return qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget); 1861 1934 } 1862 1935 … … 1887 1960 bool QMenuBar::macUpdateMenuBar() 1888 1961 { 1889 if (qt_mac_no_native_menubar) //nothing to be done..1890 return true;1891 1892 1962 cancelAllMenuTracking(); 1893 1963 QMenuBar *mb = 0; … … 1923 1993 //now set it 1924 1994 bool ret = false; 1925 if (mb ) {1995 if (mb && mb->isNativeMenuBar()) { 1926 1996 #ifdef QT_MAC_USE_COCOA 1927 1997 QMacCocoaAutoReleasePool pool; … … 1935 2005 [NSApp setMainMenu:menu]; 1936 2006 syncMenuBarItemsVisiblity(mb->d_func()->mac_menubar); 2007 2008 if (OSMenuRef tmpMerge = QMenuPrivate::mergeMenuHash.value(menu)) { 2009 if (QMenuMergeList *mergeList 2010 = QMenuPrivate::mergeMenuItemsHash.value(tmpMerge)) { 2011 const int mergeListSize = mergeList->size(); 2012 2013 for (int i = 0; i < mergeListSize; ++i) { 2014 const QMenuMergeItem &mergeItem = mergeList->at(i); 2015 // Ideally we would call QMenuPrivate::syncAction, but that requires finding 2016 // the original QMen and likely doing more work than we need. 2017 // For example, enabled is handled below. 2018 [mergeItem.menuItem setTag:reinterpret_cast<long>( 2019 static_cast<QAction *>(mergeItem.action->action))]; 2020 [mergeItem.menuItem setHidden:!(mergeItem.action->action->isVisible())]; 2021 } 2022 } 2023 } 1937 2024 #endif 1938 2025 QWidget *modalWidget = qApp->activeModalWidget(); … … 1944 2031 qt_mac_current_menubar.modal = QApplicationPrivate::modalState(); 1945 2032 ret = true; 1946 } else if (qt_mac_current_menubar.qmenubar ) {2033 } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { 1947 2034 const bool modal = QApplicationPrivate::modalState(); 1948 2035 if (modal != qt_mac_current_menubar.modal) {
Note:
See TracChangeset
for help on using the changeset viewer.