Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qmenu_mac.mm

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    7272  QMenu globals
    7373 *****************************************************************************/
    74 bool qt_mac_no_native_menubar = false;
    7574bool qt_mac_no_menubar_merge = false;
    7675bool qt_mac_quit_menu_item_enabled = true;
     
    144143}
    145144
     145static 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
    146178static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp,
    147179                                     const QMacMenuAction *action)
     
    167199        GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
    168200                            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()) {
    170202            MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu;
    171203            GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list);
     
    427459                        int merged = 0;
    428460                        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) {
    430463                            QMacMenuAction *action = mac_menu->actionItems.at(i);
    431464                            if (action->action->isSeparator()) {
     
    527560static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) {
    528561    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);
    538563    }
    539564
     
    583608}
    584609
     610static inline void syncNSMenuItemEnabled(NSMenuItem *menuItem, bool enabled)
     611{
     612    [menuItem setEnabled:NO];
     613    [menuItem setEnabled:YES];
     614    [menuItem setEnabled:enabled];
     615}
     616
    585617static inline void syncMenuBarItemsVisiblity(const QMenuBarPrivate::QMacMenuBarPrivate *mac_menubar)
    586618{
     
    600632{
    601633    NSMenuItem *item = [[NSMenuItem alloc]
    602                          initWithTitle:reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(title)))
     634                         initWithTitle:qt_mac_QStringToNSString(title)
    603635                         action:@selector(qtDispatcherToQAction:) keyEquivalent:@""];
    604636    [item setTarget:getMenuLoader()];
     
    635667                if ([item tag]) {
    636668                    QAction *action = reinterpret_cast<QAction *>([item tag]);
    637                     [item setEnabled:action->isEnabled()];
     669                     syncNSMenuItemEnabled(item, action->isEnabled());
    638670                 } else {
    639                      [item setEnabled:YES];
     671                     syncNSMenuItemEnabled(item, YES);
    640672                 }
    641673            } else {
    642                 [item setEnabled:NO];
     674                syncNSMenuItemEnabled(item, NO);
    643675            }
    644676        }
     
    704736void qt_mac_clear_menubar()
    705737{
     738    if (QApplication::testAttribute(Qt::AA_MacPluginApplication))
     739        return;
     740
    706741#ifndef QT_MAC_USE_COCOA
    707742    MenuRef clear_menu = 0;
     
    729764#ifdef QT_MAC_USE_COCOA
    730765    [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    }
    732781    [menuItem release];
    733782#endif
     
    872921    }
    873922
    874     if ([ret tag] != 0)
    875         ret = 0; // already taken
    876923#endif
    877924    return ret;
     
    918965#ifndef QT_MAC_USE_COCOA
    919966    else if (action->command == kHICommandPreferences)
    920         ret = QKeySequence(Qt::CTRL+Qt::Key_Comma);
     967        ret = QKeySequence(QKeySequence::Preferences);
    921968    else if (action->command == kHICommandQuit)
    922         ret = QKeySequence(Qt::CTRL+Qt::Key_Q);
     969        ret = QKeySequence(QKeySequence::Quit);
    923970#else
    924971    else if (action->menuItem == [loader preferencesMenuItem])
    925         ret = QKeySequence(Qt::CTRL+Qt::Key_Comma);
     972        ret = QKeySequence(QKeySequence::Preferences);
    926973    else if (action->menuItem == [loader quitMenuItem])
    927         ret = QKeySequence(Qt::CTRL+Qt::Key_Q);
     974        ret = QKeySequence(QKeySequence::Quit);
    928975#endif
    929976    return ret;
     
    932979void Q_GUI_EXPORT qt_mac_set_menubar_icons(bool b)
    933980{ 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; }
     981void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b)
     982{  QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, !b); }
    935983void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !b; }
    936984
     
    11321180            if (mergedItems.contains(action->command)
    11331181                 && (testattr & kMenuItemAttrSeparator)) {
    1134                     InsertMenuItemTextWithCFString(action->menu, 0, qMax(itemCount - 1, 0), attr, action->command);
    1135                     index = itemCount;
    1136                  } else {
    1137                     MenuItemIndex tmpIndex;
    1138                     AppendMenuItemTextWithCFString(action->menu, 0, attr, action->command, &tmpIndex);
    1139                     index = tmpIndex;
    1140                     if (mergedItems.contains(action->command))
    1141                         AppendMenuItemTextWithCFString(action->menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex);
    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            }
    11431191#else
    11441192            [menu addItem:newItem];
     
    12091257{
    12101258    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];
    12471268}
    12481269
     
    12501271NSUInteger keySequenceModifierMask(const QKeySequence &accel)
    12511272{
    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]);
    12631274}
    12641275
     
    13401351        }
    13411352    }
     1353    // Show multiple key sequences as part of the menu text.
    13421354    if (accel.count() > 1)
    1343         text += QLatin1String(" (****)"); //just to denote a multi stroke shortcut
     1355        text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")");
    13441356
    13451357    QString finalString = qt_mac_removeMnemonics(text);
     
    13621374            && action->action->isIconVisibleInMenu()) {
    13631375        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));
    13651377    } else {
    13661378        data.iconType = kMenuNoIcon;
     
    13821394    if (action->action->font().resolve()) {
    13831395        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())
    13851397                                  size:actionFont.pointSize()];
    13861398        NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil];
    13871399        NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil];
    13881400        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)
    13901402                                 attributes:attributes] autorelease];
    13911403       [item setAttributedTitle: str];
    13921404    } 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))];
    13961408
    13971409    // Cocoa Enabled
     
    14011413    NSImage *nsimage = 0;
    14021414    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)));
    14041416    }
    14051417    [item setImage:nsimage];
     
    14151427        SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
    14161428#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        }
    14181438#endif
    14191439    } else { //respect some other items
     
    14231443        data.whichData |= kMenuItemDataCmdKeyModifiers;
    14241444        data.whichData |= kMenuItemDataCmdKeyGlyph;
    1425         if (!accel.isEmpty()) {
     1445        if (accel.count() == 1) {
    14261446            qt_mac_get_accel(accel[0], (quint32*)&data.cmdKeyModifiers, (quint32*)&data.cmdKeyGlyph);
    14271447            if (data.cmdKeyGlyph == 0)
     
    14301450#else
    14311451        [item setSubmenu:0];
    1432         if (!accel.isEmpty()) {
     1452        // No key equivalent set for multiple key QKeySequence.
     1453        if (accel.count() == 1) {
    14331454            [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)];
    14341455            [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)];
     
    14781499#else
    14791500    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 {
    14841511        [[action->menuItem menu] removeItem:action->menuItem];
     1512    }
    14851513#endif
    14861514    actionItems.removeAll(action);
     
    15071535    for(int i = 0; i < items.count(); i++)
    15081536        mac_menu->addAction(items[i], 0, this);
     1537    syncSeparatorsCollapsible(collapsibleSeparators);
    15091538    return mac_menu->menu;
    15101539}
     1540
     1541/*!
     1542  \internal
     1543*/
     1544void
     1545QMenuPrivate::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
    15111558
    15121559/*!
     
    16741721            SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
    16751722#else
    1676             [item setSubmenu:submenu];
     1723            if ([submenu supermenu] && [submenu supermenu] != [item menu])
     1724                return;
     1725            else
     1726                [item setSubmenu:submenu];
    16771727#endif
    16781728        }
     
    16951745#else
    16961746        [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()))];
    16981748        syncNSMenuItemVisiblity(item, visible);
    16991749#endif
     
    17241774}
    17251775
     1776bool 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
    17261786void
    17271787QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
    17281788{
    17291789    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.
    17361809        extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp
    17371810        qt_event_request_menubarupdate();
     
    17661839{
    17671840    Q_Q(QMenuBar);
    1768     if (!mac_menubar) {
     1841    if (!q->isNativeMenuBar() || !mac_menubar) {
    17691842        return 0;
    17701843    } else if (!mac_menubar->menu) {
     
    17821855                SetMenuItemProperty(mac_menubar->apple_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(q), &q);
    17831856#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)))];
    17851858                NSMenuItem *apple_menuItem = [[NSMenuItem alloc] init];
    17861859                [apple_menuItem setSubmenu:mac_menubar->menu];
     
    18251898static bool qt_mac_is_ancestor(QWidget* possibleAncestor, QWidget *child)
    18261899{
     1900    if (!possibleAncestor)
     1901        return false;
     1902
    18271903    QWidget * current = child->parentWidget();
    18281904    while (current != 0) {
     
    18431919    if (modalWidget == 0 || menuBar == 0)
    18441920        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);
    18611934}
    18621935
     
    18871960bool QMenuBar::macUpdateMenuBar()
    18881961{
    1889     if (qt_mac_no_native_menubar) //nothing to be done..
    1890         return true;
    1891 
    18921962    cancelAllMenuTracking();
    18931963    QMenuBar *mb = 0;
     
    19231993    //now set it
    19241994    bool ret = false;
    1925     if (mb) {
     1995    if (mb && mb->isNativeMenuBar()) {
    19261996#ifdef QT_MAC_USE_COCOA
    19271997        QMacCocoaAutoReleasePool pool;
     
    19352005            [NSApp setMainMenu:menu];
    19362006            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            }
    19372024#endif
    19382025            QWidget *modalWidget = qApp->activeModalWidget();
     
    19442031        qt_mac_current_menubar.modal = QApplicationPrivate::modalState();
    19452032        ret = true;
    1946     } else if (qt_mac_current_menubar.qmenubar) {
     2033    } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) {
    19472034        const bool modal = QApplicationPrivate::modalState();
    19482035        if (modal != qt_mac_current_menubar.modal) {
Note: See TracChangeset for help on using the changeset viewer.