diff options
Diffstat (limited to 'src')
23 files changed, 347 insertions, 1232 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1c82003b1c..4fa6a9954b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -272,7 +272,7 @@ namespace QT_NAMESPACE {} #endif #if defined(Q_OS_DARWIN) -# define Q_OS_MAC /* Q_OS_MAC is mostly for compatibility, but also more clear */ +# define Q_OS_MAC # define Q_OS_MACX /* Q_OS_MACX is only for compatibility.*/ # if defined(Q_OS_DARWIN64) # define Q_OS_MAC64 @@ -281,15 +281,6 @@ namespace QT_NAMESPACE {} # endif #endif -#ifdef QT_AUTODETECT_COCOA -# ifdef Q_OS_MAC64 -# define QT_MAC_USE_COCOA 1 -# define QT_BUILD_KEY QT_BUILD_KEY_COCOA -# else -# define QT_BUILD_KEY QT_BUILD_KEY_CARBON -# endif -#endif - #if defined(Q_WS_MAC64) && !defined(QT_MAC_USE_COCOA) && !defined(QT_BUILD_QMAKE) && !defined(QT_BOOTSTRAPPED) #error "You are building a 64-bit application, but using a 32-bit version of Qt. Check your build configuration." #endif @@ -877,15 +868,7 @@ namespace QT_NAMESPACE {} # define Q_WS_PM # error "Qt does not work with OS/2 Presentation Manager or Workplace Shell" #elif defined(Q_OS_UNIX) -# if defined(Q_OS_MAC) && !defined(__USE_WS_X11__) && !defined(Q_WS_QWS) && !defined(Q_WS_QPA) -# define Q_WS_MAC -# define Q_WS_MACX -# if defined(Q_OS_MAC64) -# define Q_WS_MAC64 -# elif defined(Q_OS_MAC32) -# define Q_WS_MAC32 -# endif -# elif defined(Q_OS_SYMBIAN) +# if defined(Q_OS_SYMBIAN) # if !defined(QT_NO_S60) # define Q_WS_S60 # endif diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 00c38ea095..ad01a72a45 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -234,6 +234,13 @@ static void init_plugins(const QList<QByteArray> &pluginList) void QGuiApplicationPrivate::createPlatformIntegration() { + Q_Q(QGuiApplication); + + // Use the Qt menus by default. Platform plugins that + // want to enable a native menu implementation can clear + // this flag. + q->setAttribute(Qt::AA_DontUseNativeMenuBar, true); + // Load the platform integration QString platformPluginPath = QLatin1String(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH")); QByteArray platformName; diff --git a/src/widgets/kernel/mac.pri b/src/widgets/kernel/mac.pri index df457dd166..5474a41f15 100644 --- a/src/widgets/kernel/mac.pri +++ b/src/widgets/kernel/mac.pri @@ -1,4 +1,4 @@ -!x11:!qpa:mac { - LIBS_PRIVATE += -framework Carbon -lz +!x11::mac { + LIBS_PRIVATE += -framework Carbon -framework Cocoa -lz *-mwerks:INCLUDEPATH += compat } diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h index db2b4bf0b3..da8c24e184 100644 --- a/src/widgets/kernel/qaction.h +++ b/src/widgets/kernel/qaction.h @@ -246,7 +246,7 @@ private: friend class QMenuBar; friend class QShortcutMap; friend class QToolButton; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC friend void qt_mac_clear_status_text(QAction *action); #endif }; diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 517df5252f..fd745c16b5 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -2281,31 +2281,6 @@ void QApplication::aboutQt() \sa QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason */ - -#ifndef QT_NO_TRANSLATION -#if defined(Q_WS_MAC) -static const char *application_menu_strings[] = { - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1") - }; -QString qt_mac_applicationmenu_string(int type) -{ - QString menuString = QString::fromLatin1(application_menu_strings[type]); - QString translated = qApp->translate("QMenuBar", application_menu_strings[type]); - if (translated != menuString) - return translated; - else - return qApp->translate("MAC_APPLICATION_MENU", - application_menu_strings[type]); -} -#endif -#endif - /*!\reimp */ diff --git a/src/widgets/platforms/mac/qapplication_mac.mm b/src/widgets/platforms/mac/qapplication_mac.mm index cb1f0cdbe4..5868849836 100644 --- a/src/widgets/platforms/mac/qapplication_mac.mm +++ b/src/widgets/platforms/mac/qapplication_mac.mm @@ -181,7 +181,6 @@ static struct { static bool app_do_modal = false; // modal mode extern QWidgetList *qt_modal_stack; // stack of modal widgets extern bool qt_tab_all_widgets; // from qapplication.cpp -bool qt_mac_app_fullscreen = false; bool qt_scrollbar_jump_to_pos = false; static bool qt_mac_collapse_on_dblclick = true; extern int qt_antialiasing_threshold; // from qapplication.cpp diff --git a/src/widgets/platforms/mac/qcocoamenuloader_mac.mm b/src/widgets/platforms/mac/qcocoamenuloader_mac.mm index da11c3a1c6..3516ad18d3 100644 --- a/src/widgets/platforms/mac/qcocoamenuloader_mac.mm +++ b/src/widgets/platforms/mac/qcocoamenuloader_mac.mm @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qmacdefines_mac.h" -#ifdef QT_MAC_USE_COCOA #include <qaction.h> #include <qcoreapplication.h> #include <private/qcocoamenuloader_mac_p.h> @@ -261,4 +260,3 @@ QT_USE_NAMESPACE [NSApp orderFrontCharacterPalette:sender]; } @end -#endif // QT_MAC_USE_COCOA diff --git a/src/widgets/platforms/mac/qcocoamenuloader_mac_p.h b/src/widgets/platforms/mac/qcocoamenuloader_mac_p.h index 1e637fdc39..9da200a24e 100644 --- a/src/widgets/platforms/mac/qcocoamenuloader_mac_p.h +++ b/src/widgets/platforms/mac/qcocoamenuloader_mac_p.h @@ -54,7 +54,6 @@ // #include "qmacdefines_mac.h" -#ifdef QT_MAC_USE_COCOA #import <Cocoa/Cocoa.h> @interface QT_MANGLE_NAMESPACE(QCocoaMenuLoader) : NSResponder @@ -91,5 +90,4 @@ - (void)orderFrontCharacterPalette:(id)sender; @end -#endif // QT_MAC_USE_COCOA #endif // QCOCOAMENULOADER_P_H diff --git a/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm b/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm index 97ed7f7e39..8227a888f7 100644 --- a/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm +++ b/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm @@ -319,24 +319,6 @@ void macWindowFlush(void * /*OSWindowRef*/ window) #endif } -void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm) -{ - QMacCocoaAutoReleasePool pool; - if(QCFType<CGImageRef> image = pm.toMacCGImageRef()) { - NSImage *newImage = 0; - NSRect imageRect = NSMakeRect(0.0, 0.0, CGImageGetWidth(image), CGImageGetHeight(image)); - newImage = [[NSImage alloc] initWithSize:imageRect.size]; - [newImage lockFocus]; - { - CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; - CGContextDrawImage(imageContext, *(CGRect*)&imageRect, image); - } - [newImage unlockFocus]; - return newImage; - } - return 0; -} - void qt_mac_update_mouseTracking(QWidget *widget) { #ifdef QT_MAC_USE_COCOA @@ -695,27 +677,6 @@ Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags) return qtMods; } -NSString *qt_mac_removePrivateUnicode(NSString* string) -{ - int len = [string length]; - if (len) { - QVarLengthArray <unichar, 10> characters(len); - bool changed = false; - for (int i = 0; i<len; i++) { - characters[i] = [string characterAtIndex:i]; - // check if they belong to key codes in private unicode range - // currently we need to handle only the NSDeleteFunctionKey - if (characters[i] == NSDeleteFunctionKey) { - characters[i] = NSDeleteCharacter; - changed = true; - } - } - if (changed) - return [NSString stringWithCharacters:characters.data() length:len]; - } - return string; -} - Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations) { Qt::KeyboardModifiers qtMods =Qt::NoModifier; @@ -1625,39 +1586,6 @@ void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayI } #ifdef QT_MAC_USE_COCOA -void qt_mac_menu_collapseSeparators(void */*NSMenu **/ theMenu, bool collapse) -{ - QMacCocoaAutoReleasePool pool; - OSMenuRef menu = static_cast<OSMenuRef>(theMenu); - if (collapse) { - bool previousIsSeparator = true; // setting to true kills all the separators placed at the top. - NSMenuItem *previousItem = nil; - - NSArray *itemArray = [menu itemArray]; - for (unsigned int i = 0; i < [itemArray count]; ++i) { - NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); - if ([item isSeparatorItem]) { - [item setHidden:previousIsSeparator]; - } - - if (![item isHidden]) { - previousItem = item; - previousIsSeparator = ([previousItem isSeparatorItem]); - } - } - - // We now need to check the final item since we don't want any separators at the end of the list. - if (previousItem && previousIsSeparator) - [previousItem setHidden:YES]; - } else { - NSArray *itemArray = [menu itemArray]; - for (unsigned int i = 0; i < [itemArray count]; ++i) { - NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); - if (QAction *action = reinterpret_cast<QAction *>([item tag])) - [item setHidden:!action->isVisible()]; - } - } -} class CocoaPostMessageAfterEventLoopExitHelp : public QObject { @@ -1701,19 +1629,6 @@ void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount #endif -QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() -{ -#ifndef QT_MAC_USE_COCOA - NSApplicationLoad(); -#endif - pool = (void*)[[NSAutoreleasePool alloc] init]; -} - -QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool() -{ - [(NSAutoreleasePool*)pool release]; -} - void qt_mac_post_retranslateAppMenu() { #ifdef QT_MAC_USE_COCOA diff --git a/src/widgets/platforms/mac/qt_cocoa_helpers_mac_p.h b/src/widgets/platforms/mac/qt_cocoa_helpers_mac_p.h index 14be29e61c..070ecfb030 100644 --- a/src/widgets/platforms/mac/qt_cocoa_helpers_mac_p.h +++ b/src/widgets/platforms/mac/qt_cocoa_helpers_mac_p.h @@ -143,14 +143,11 @@ void qt_mac_update_mouseTracking(QWidget *widget); OSStatus qt_mac_drawCGImage(CGContextRef cg, const CGRect *inbounds, CGImageRef); bool qt_mac_checkForNativeSizeGrip(const QWidget *widget); void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent); -#ifdef QT_MAC_USE_COCOA bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); // These methods exists only for supporting unified mode. void macDrawRectOnTop(void * /*OSWindowRef */ window); void macSyncDrawingOnFirstInvocation(void * /*OSWindowRef */window); void qt_cocoaStackChildWindowOnTopOfOtherChildren(QWidget *widget); -void qt_mac_menu_collapseSeparators(void * /*NSMenu */ menu, bool collapse); -#endif bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent); bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */event); @@ -163,7 +160,7 @@ QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height); void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon = QStyle::SP_CustomBase); -#if QT_MAC_USE_COCOA && __OBJC__ +#ifdef __OBJC__ struct DnDParams { NSView *view; @@ -217,7 +214,6 @@ inline QString qt_mac_NSStringToQString(const NSString *nsstr) inline NSString *qt_mac_QStringToNSString(const QString &qstr) { return [reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)) autorelease]; } -#ifdef QT_MAC_USE_COCOA class QCocoaPostMessageArgs { public: id target; @@ -242,7 +238,6 @@ public: }; void qt_cocoaPostMessage(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0); void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0); -#endif #endif @@ -301,11 +296,9 @@ public: void qt_mac_post_retranslateAppMenu(); -#ifdef QT_MAC_USE_COCOA void qt_mac_display(QWidget *widget); void qt_mac_setNeedsDisplay(QWidget *widget); void qt_mac_setNeedsDisplayInRect(QWidget *widget, QRegion region); -#endif // QT_MAC_USE_COCOA // Utility functions to ease the use of Core Graphics contexts. diff --git a/src/widgets/platforms/mac/qt_widget_helpers_mac.mm b/src/widgets/platforms/mac/qt_widget_helpers_mac.mm new file mode 100644 index 0000000000..2fe72be553 --- /dev/null +++ b/src/widgets/platforms/mac/qt_widget_helpers_mac.mm @@ -0,0 +1,113 @@ +/**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the QtGui module of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** GNU Lesser General Public License Usage + ** This file may be used under the terms of the GNU Lesser General Public + ** License version 2.1 as published by the Free Software Foundation and + ** appearing in the file LICENSE.LGPL included in the packaging of this + ** file. Please review the following information to ensure the GNU Lesser + ** General Public License version 2.1 requirements will be met: + ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + ** + ** In addition, as a special exception, Nokia gives you certain additional + ** rights. These rights are described in the Nokia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU General + ** Public License version 3.0 as published by the Free Software Foundation + ** and appearing in the file LICENSE.GPL included in the packaging of this + ** file. Please review the following information to ensure the GNU General + ** Public License version 3.0 requirements will be met: + ** http://www.gnu.org/copyleft/gpl.html. + ** + ** Other Usage + ** Alternatively, this file may be used in accordance with the terms and + ** conditions contained in a signed written agreement between you and Nokia. + ** + ** + ** + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include <private/qt_widget_helpers_mac_p.h> + +#include <QtCore> +#include <QtGui> + +// +// Globabal variables +// +bool qt_mac_app_fullscreen = false; + +// +// QMacCocoaAutoReleasePool +// +QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() +{ + pool = (void*)[[NSAutoreleasePool alloc] init]; +} + +QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool() +{ + [(NSAutoreleasePool*)pool release]; +} + +// +// Functions +// +void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm) +{ + QMacCocoaAutoReleasePool pool; + qWarning("Unimplemented: qt_mac_create_nsimage"); +#if 0 + if(QCFType<CGImageRef> image = pm.toMacCGImageRef()) { + NSImage *newImage = 0; + NSRect imageRect = NSMakeRect(0.0, 0.0, CGImageGetWidth(image), CGImageGetHeight(image)); + newImage = [[NSImage alloc] initWithSize:imageRect.size]; + [newImage lockFocus]; + { + CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + CGContextDrawImage(imageContext, *(CGRect*)&imageRect, image); + } + [newImage unlockFocus]; + return newImage; + } +#endif + return 0; +} + + +QString qt_mac_removeMnemonics(const QString &original) +{ + QString returnText(original.size(), 0); + int finalDest = 0; + int currPos = 0; + int l = original.length(); + while (l) { + if (original.at(currPos) == QLatin1Char('&') + && (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) { + ++currPos; + --l; + if (l == 0) + break; + } + returnText[finalDest] = original.at(currPos); + ++currPos; + ++finalDest; + --l; + } + returnText.truncate(finalDest); + return returnText; +} + + diff --git a/src/widgets/platforms/mac/qt_widget_helpers_mac_p.h b/src/widgets/platforms/mac/qt_widget_helpers_mac_p.h new file mode 100644 index 0000000000..64f7e0a721 --- /dev/null +++ b/src/widgets/platforms/mac/qt_widget_helpers_mac_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the QtGui module of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** GNU Lesser General Public License Usage + ** This file may be used under the terms of the GNU Lesser General Public + ** License version 2.1 as published by the Free Software Foundation and + ** appearing in the file LICENSE.LGPL included in the packaging of this + ** file. Please review the following information to ensure the GNU Lesser + ** General Public License version 2.1 requirements will be met: + ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + ** + ** In addition, as a special exception, Nokia gives you certain additional + ** rights. These rights are described in the Nokia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU General + ** Public License version 3.0 as published by the Free Software Foundation + ** and appearing in the file LICENSE.GPL included in the packaging of this + ** file. Please review the following information to ensure the GNU General + ** Public License version 3.0 requirements will be met: + ** http://www.gnu.org/copyleft/gpl.html. + ** + ** Other Usage + ** Alternatively, this file may be used in accordance with the terms and + ** conditions contained in a signed written agreement between you and Nokia. + ** + ** + ** + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#ifndef QT_WIDGET_HELPERS_MAC_P_H +#define QT_WIDGET_HELPERS_MAC_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It provides helper functions +// for the QWidget implementation on Mac OS X. This header file may +// change from version to version without notice, or even be removed. +// +// We mean it. +// + +#include <private/qt_mac_p.h> + +class QPixmap; +class QString; + +void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm); +QString qt_mac_removeMnemonics(const QString &original); + + +#endif //QT_WIDGET_HELPERS_MAC_P_H diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 40c28f6674..86b30cf7e0 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -395,29 +395,6 @@ static inline bool isTreeView(const QWidget *widget) )); } -QString qt_mac_removeMnemonics(const QString &original) -{ - QString returnText(original.size(), 0); - int finalDest = 0; - int currPos = 0; - int l = original.length(); - while (l) { - if (original.at(currPos) == QLatin1Char('&') - && (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) { - ++currPos; - --l; - if (l == 0) - break; - } - returnText[finalDest] = original.at(currPos); - ++currPos; - ++finalDest; - --l; - } - returnText.truncate(finalDest); - return returnText; -} - static inline ThemeTabDirection getTabDirection(QTabBar::Shape shape) { ThemeTabDirection ttd; diff --git a/src/widgets/widgets/qcocoamenu_mac.mm b/src/widgets/widgets/qcocoamenu_mac.mm index 95075b95d1..36e356cd4c 100644 --- a/src/widgets/widgets/qcocoamenu_mac.mm +++ b/src/widgets/widgets/qcocoamenu_mac.mm @@ -41,7 +41,7 @@ #include "qmacdefines_mac.h" #include "qapplication.h" -#ifdef QT_MAC_USE_COCOA +#include "qvarlengtharray.h" #import <private/qcocoamenu_mac_p.h> #import <private/qcocoamenuloader_mac_p.h> #import <private/qcocoaapplication_mac_p.h> @@ -50,7 +50,7 @@ #include <private/qaction_p.h> #include <private/qcocoaapplication_mac_p.h> -#include <QtGui/QMenu> +#include <QtWidgets/QMenu> QT_FORWARD_DECLARE_CLASS(QAction) QT_FORWARD_DECLARE_CLASS(QWidget) @@ -62,7 +62,8 @@ QT_FORWARD_DECLARE_CLASS(QEvent) QT_BEGIN_NAMESPACE extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); //qapplication.cpp -extern NSString *qt_mac_removePrivateUnicode(NSString* string); +extern void qt_mac_menu_collapseSeparators(NSMenu *menu, bool collapse); +void qt_mac_clear_status_text(QAction *action); QT_END_NAMESPACE QT_USE_NAMESPACE @@ -149,6 +150,27 @@ QT_USE_NAMESPACE return NO; } +NSString *qt_mac_removePrivateUnicode(NSString* string) +{ + int len = [string length]; + if (len) { + QVarLengthArray <unichar, 10> characters(len); + bool changed = false; + for (int i = 0; i<len; i++) { + characters[i] = [string characterAtIndex:i]; + // check if they belong to key codes in private unicode range + // currently we need to handle only the NSDeleteFunctionKey + if (characters[i] == NSDeleteFunctionKey) { + characters[i] = NSDeleteCharacter; + changed = true; + } + } + if (changed) + return [NSString stringWithCharacters:characters.data() length:len]; + } + return string; +} + - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id *)target action:(SEL *)action { // Check if the menu actually has a keysequence defined for this key event. @@ -186,7 +208,10 @@ QT_USE_NAMESPACE accel_ev.ignore(); qt_sendSpontaneousEvent(widget, &accel_ev); if (accel_ev.isAccepted()) { + qWarning("Unimplemented: qt_dispatchKeyEvent"); +#if 0 qt_dispatchKeyEvent(event, widget); +#endif *target = nil; *action = nil; return YES; @@ -241,4 +266,3 @@ void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action) QT_END_NAMESPACE -#endif diff --git a/src/widgets/widgets/qcocoamenu_mac_p.h b/src/widgets/widgets/qcocoamenu_mac_p.h index 6160a2656f..392060c90a 100644 --- a/src/widgets/widgets/qcocoamenu_mac_p.h +++ b/src/widgets/widgets/qcocoamenu_mac_p.h @@ -51,7 +51,6 @@ // #include "qmacdefines_mac.h" -#ifdef QT_MAC_USE_COCOA #import <Cocoa/Cocoa.h> QT_FORWARD_DECLARE_CLASS(QMenu) @@ -78,5 +77,4 @@ QT_FORWARD_DECLARE_CLASS(QAction) - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id *)target action:(SEL *)action; - (NSInteger)indexOfItemWithTarget:(id)anObject andAction:(SEL)actionSelector; @end -#endif diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 932b14f6e7..8494c9eca2 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -77,7 +77,7 @@ # include <private/qt_x11_p.h> #endif -#if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) +#if defined(Q_OS_MAC) && !defined(QT_NO_EFFECTS) # include <private/qcore_mac_p.h> # include <private/qt_cocoa_helpers_mac_p.h> #endif @@ -417,7 +417,7 @@ QRect QMenuPrivate::actionRect(QAction *act) const return actionRects.at(index); } -#if defined(Q_WS_MAC) +#if defined(Q_OS_MAC) static const qreal MenuFadeTimeInSec = 0.150; #endif @@ -2366,7 +2366,7 @@ void QMenu::changeEvent(QEvent *e) if (d->tornPopup) // torn-off menu d->tornPopup->setEnabled(isEnabled()); d->menuAction->setEnabled(isEnabled()); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (d->mac_menu) d->setMacMenuEnabled(isEnabled()); #endif @@ -2473,7 +2473,7 @@ void QMenu::keyPressEvent(QKeyEvent *e) else if (key == Qt::Key_Right) key = Qt::Key_Left; } -#ifndef Q_WS_MAC +#ifndef Q_OS_MAC if (key == Qt::Key_Tab) //means down key = Qt::Key_Down; if (key == Qt::Key_Backtab) //means up @@ -2922,7 +2922,7 @@ void QMenu::actionEvent(QActionEvent *e) d->widgetItems.remove(e->action()); } -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (d->mac_menu) { if (e->type() == QEvent::ActionAdded) d->mac_menu->addAction(e->action(), d->mac_menu->findAction(e->before()), d); @@ -3122,7 +3122,7 @@ void QMenu::setSeparatorsCollapsible(bool collapse) d->updateActionRects(); update(); } -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (d->mac_menu) d->syncSeparatorsCollapsible(collapse); #endif diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index f8bedb3da4..84a1f1ef14 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -46,6 +46,10 @@ #include <QtCore/qstring.h> #include <QtWidgets/qicon.h> #include <QtWidgets/qaction.h> +#ifdef Q_OS_MAC +#include "QtWidgets/qmacdefines_mac.h" +#endif + #ifdef QT3_SUPPORT #include <QtGui/qpixmap.h> @@ -141,7 +145,7 @@ public: void setIcon(const QIcon &icon); void setNoReplayFor(QWidget *widget); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC OSMenuRef macMenu(OSMenuRef merge=0); #endif @@ -415,7 +419,7 @@ private: friend class QAction; friend class QToolButtonPrivate; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC friend void qt_mac_trayicon_activate_action(QMenu *, QAction *action); friend bool qt_mac_watchingAboutToShow(QMenu *); friend OSStatus qt_mac_menu_event(EventHandlerCallRef, EventRef, void *); diff --git a/src/widgets/widgets/qmenu_mac.mm b/src/widgets/widgets/qmenu_mac.mm index 9db068c77f..7d3bd3939c 100644 --- a/src/widgets/widgets/qmenu_mac.mm +++ b/src/widgets/widgets/qmenu_mac.mm @@ -118,30 +118,75 @@ void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp *****************************************************************************/ bool qt_mac_watchingAboutToShow(QMenu *menu) { - return menu && menu->receivers(SIGNAL(aboutToShow())); + return menu; /* && menu->receivers(SIGNAL(aboutToShow()));*/ } static int qt_mac_CountMenuItems(OSMenuRef menu) { if (menu) { -#ifndef QT_MAC_USE_COCOA - int ret = 0; - const int items = CountMenuItems(menu); - for(int i = 0; i < items; i++) { - MenuItemAttributes attr; - if (GetMenuItemAttributes(menu, i+1, &attr) == noErr && - attr & kMenuItemAttrHidden) - continue; - ++ret; - } - return ret; -#else return [menu numberOfItems]; -#endif } return 0; } +void qt_mac_menu_collapseSeparators(NSMenu * theMenu, bool collapse) +{ + QMacCocoaAutoReleasePool pool; + OSMenuRef menu = static_cast<OSMenuRef>(theMenu); + if (collapse) { + bool previousIsSeparator = true; // setting to true kills all the separators placed at the top. + NSMenuItem *previousItem = nil; + + NSArray *itemArray = [menu itemArray]; + for (unsigned int i = 0; i < [itemArray count]; ++i) { + NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); + if ([item isSeparatorItem]) { + [item setHidden:previousIsSeparator]; + } + + if (![item isHidden]) { + previousItem = item; + previousIsSeparator = ([previousItem isSeparatorItem]); + } + } + + // We now need to check the final item since we don't want any separators at the end of the list. + if (previousItem && previousIsSeparator) + [previousItem setHidden:YES]; + } else { + NSArray *itemArray = [menu itemArray]; + for (unsigned int i = 0; i < [itemArray count]; ++i) { + NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); + if (QAction *action = reinterpret_cast<QAction *>([item tag])) + [item setHidden:!action->isVisible()]; + } + } +} + +#ifndef QT_NO_TRANSLATION +static const char *application_menu_strings[] = { + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1") + }; + +QString qt_mac_applicationmenu_string(int type) +{ + QString menuString = QString::fromLatin1(application_menu_strings[type]); + QString translated = qApp->translate("QMenuBar", application_menu_strings[type]); + if (translated != menuString) + return translated; + else + return qApp->translate("MAC_APPLICATION_MENU", + application_menu_strings[type]); +} +#endif + + static quint32 constructModifierMask(quint32 accel_key) { quint32 ret = 0; @@ -177,7 +222,6 @@ static quint32 constructModifierMask(quint32 accel_key) static void cancelAllMenuTracking() { -#ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; NSMenu *mainMenu = [NSApp mainMenu]; [mainMenu cancelTracking]; @@ -186,9 +230,6 @@ static void cancelAllMenuTracking() [[item submenu] cancelTracking]; } } -#else - CancelMenuTracking(AcquireRootMenu(), true, 0); -#endif } static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp, @@ -205,409 +246,6 @@ static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate * return visible; } -#ifndef QT_MAC_USE_COCOA -bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent action_e, bool by_accel) -{ - //fire event - QMacMenuAction *action = 0; - if (GetMenuCommandProperty(menu, command, kMenuCreatorQt, kMenuPropertyQAction, sizeof(action), 0, &action) != noErr) { - QMenuMergeList *list = 0; - GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list); - if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { - MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu; - GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list); - if (list) - menu = apple_menu; - } - if (list) { - for(int i = 0; i < list->size(); ++i) { - QMenuMergeItem item = list->at(i); - if (item.command == command && item.action) { - action = item.action; - break; - } - } - } - if (!action) - return false; - } - - if (action_e == QAction::Trigger && by_accel && action->ignore_accel) //no, not a real accel (ie tab) - return false; - - // Unhighlight the highlighted menu item before triggering the action to - // prevent items from staying highlighted while a modal dialog is shown. - // This also fixed the problem that parentless modal dialogs leave - // the menu item highlighted (since the menu bar is cleared for these types of dialogs). - if (action_e == QAction::Trigger) - HiliteMenu(0); - - action->action->activate(action_e); - - //now walk up firing for each "caused" widget (like in the platform independent menu) - QWidget *caused = 0; - if (action_e == QAction::Hover && GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) { - MenuRef caused_menu = 0; - if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) - caused_menu = qmenu2->macMenu(); - else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) - caused_menu = qmenubar2->macMenu(); - else - caused_menu = 0; - while(caused_menu) { - //fire - QWidget *widget = 0; - GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget); - if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { - action->action->showStatusText(widget); - emit qmenu->hovered(action->action); - } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) { - action->action->showStatusText(widget); - emit qmenubar->hovered(action->action); - break; //nothing more.. - } - - //walk up - if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, - sizeof(caused), 0, &caused) != noErr) - break; - if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) - caused_menu = qmenu2->macMenu(); - else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused)) - caused_menu = qmenubar2->macMenu(); - else - caused_menu = 0; - } - } - return true; -} - -//lookup a QMacMenuAction in a menu -static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd) -{ - MenuItemIndex ret_idx; - MenuRef ret_menu; - if (GetIndMenuItemWithCommandID(menu, cmd, 1, &ret_menu, &ret_idx) == noErr) { - if (ret_menu == menu) - return (int)ret_idx; - } - return -1; -} -static int qt_mac_menu_find_action(MenuRef menu, QMacMenuAction *action) -{ - return qt_mac_menu_find_action(menu, action->command); -} - -typedef QMultiHash<OSMenuRef, EventHandlerRef> EventHandlerHash; -Q_GLOBAL_STATIC(EventHandlerHash, menu_eventHandlers_hash) - -static EventTypeSpec widget_in_menu_events[] = { - { kEventClassMenu, kEventMenuMeasureItemWidth }, - { kEventClassMenu, kEventMenuMeasureItemHeight }, - { kEventClassMenu, kEventMenuDrawItem }, - { kEventClassMenu, kEventMenuCalculateSize } -}; - -static OSStatus qt_mac_widget_in_menu_eventHandler(EventHandlerCallRef er, EventRef event, void *) -{ - UInt32 ekind = GetEventKind(event); - UInt32 eclass = GetEventClass(event); - OSStatus result = eventNotHandledErr; - switch (eclass) { - case kEventClassMenu: - switch (ekind) { - default: - break; - case kEventMenuMeasureItemWidth: { - MenuItemIndex item; - GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex, - 0, sizeof(item), 0, &item); - OSMenuRef menu; - GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu); - QWidget *widget; - if (GetMenuItemProperty(menu, item, kMenuCreatorQt, kMenuPropertyWidgetActionWidget, - sizeof(widget), 0, &widget) == noErr) { - short width = short(widget->sizeHint().width()); - SetEventParameter(event, kEventParamMenuItemWidth, typeSInt16, - sizeof(short), &width); - result = noErr; - } - break; } - case kEventMenuMeasureItemHeight: { - MenuItemIndex item; - GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex, - 0, sizeof(item), 0, &item); - OSMenuRef menu; - GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu); - QWidget *widget; - if (GetMenuItemProperty(menu, item, kMenuCreatorQt, kMenuPropertyWidgetActionWidget, - sizeof(widget), 0, &widget) == noErr && widget) { - short height = short(widget->sizeHint().height()); - SetEventParameter(event, kEventParamMenuItemHeight, typeSInt16, - sizeof(short), &height); - result = noErr; - } - break; } - case kEventMenuDrawItem: - result = noErr; - break; - case kEventMenuCalculateSize: { - result = CallNextEventHandler(er, event); - if (result == noErr) { - OSMenuRef menu; - GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu); - HIViewRef content; - HIMenuGetContentView(menu, kThemeMenuTypePullDown, &content); - UInt16 count = CountMenuItems(menu); - for (MenuItemIndex i = 1; i <= count; ++i) { - QWidget *widget; - if (GetMenuItemProperty(menu, i, kMenuCreatorQt, kMenuPropertyWidgetActionWidget, - sizeof(widget), 0, &widget) == noErr && widget) { - RgnHandle itemRgn = qt_mac_get_rgn(); - GetControlRegion(content, i, itemRgn); - - Rect bounds; - GetRegionBounds( itemRgn, &bounds ); - qt_mac_dispose_rgn(itemRgn); - widget->setGeometry(bounds.left, bounds.top, - bounds.right - bounds.left, bounds.bottom - bounds.top); - } - } - } - break; } - } - } - return result; -} - -//handling of events for menurefs created by Qt.. -static EventTypeSpec menu_events[] = { - { kEventClassCommand, kEventCommandProcess }, - { kEventClassMenu, kEventMenuTargetItem }, - { kEventClassMenu, kEventMenuOpening }, - { kEventClassMenu, kEventMenuClosed } -}; - -// Special case for kEventMenuMatchKey, see qt_mac_create_menu below. -static EventTypeSpec menu_menu_events[] = { - { kEventClassMenu, kEventMenuMatchKey } -}; - -OSStatus qt_mac_menu_event(EventHandlerCallRef er, EventRef event, void *) -{ - QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); - - bool handled_event = true; - UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); - switch(eclass) { - case kEventClassCommand: - if (ekind == kEventCommandProcess) { - UInt32 context; - GetEventParameter(event, kEventParamMenuContext, typeUInt32, - 0, sizeof(context), 0, &context); - HICommand cmd; - GetEventParameter(event, kEventParamDirectObject, typeHICommand, - 0, sizeof(cmd), 0, &cmd); - if (!mac_keyboard_grabber && (context & kMenuContextKeyMatching)) { - QMacMenuAction *action = 0; - if (GetMenuCommandProperty(cmd.menu.menuRef, cmd.commandID, kMenuCreatorQt, - kMenuPropertyQAction, sizeof(action), 0, &action) == noErr) { - QWidget *widget = 0; - if (qApp->activePopupWidget()) - widget = (qApp->activePopupWidget()->focusWidget() ? - qApp->activePopupWidget()->focusWidget() : qApp->activePopupWidget()); - else if (QApplicationPrivate::focus_widget) - widget = QApplicationPrivate::focus_widget; - if (widget) { - int key = action->action->shortcut(); - QKeyEvent accel_ev(QEvent::ShortcutOverride, (key & (~Qt::KeyboardModifierMask)), - Qt::KeyboardModifiers(key & Qt::KeyboardModifierMask)); - accel_ev.ignore(); - qt_sendSpontaneousEvent(widget, &accel_ev); - if (accel_ev.isAccepted()) { - handled_event = false; - break; - } - } - } - } - handled_event = qt_mac_activate_action(cmd.menu.menuRef, cmd.commandID, - QAction::Trigger, context & kMenuContextKeyMatching); - } - break; - case kEventClassMenu: { - MenuRef menu; - GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu), NULL, &menu); - if (ekind == kEventMenuMatchKey) { - // Don't activate any actions if we are showing a native modal dialog, - // the key events should go to the dialog in this case. - if (QApplicationPrivate::native_modal_dialog_active) - return menuItemNotFoundErr; - - handled_event = false; - } else if (ekind == kEventMenuTargetItem) { - MenuCommand command; - GetEventParameter(event, kEventParamMenuCommand, typeMenuCommand, - 0, sizeof(command), 0, &command); - handled_event = qt_mac_activate_action(menu, command, QAction::Hover, false); - } else if (ekind == kEventMenuOpening || ekind == kEventMenuClosed) { - qt_mac_menus_open_count += (ekind == kEventMenuOpening) ? 1 : -1; - MenuRef mr; - GetEventParameter(event, kEventParamDirectObject, typeMenuRef, - 0, sizeof(mr), 0, &mr); - - QWidget *widget = 0; - if (GetMenuItemProperty(mr, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget) == noErr) { - if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { - handled_event = true; - if (ekind == kEventMenuOpening) { - emit qmenu->aboutToShow(); - - int merged = 0; - const QMenuPrivate::QMacMenuPrivate *mac_menu = qmenu->d_func()->mac_menu; - const int ActionItemsCount = mac_menu->actionItems.size(); - for(int i = 0; i < ActionItemsCount; ++i) { - QMacMenuAction *action = mac_menu->actionItems.at(i); - if (action->action->isSeparator()) { - bool hide = false; - if(!action->action->isVisible()) { - hide = true; - } else if (merged && merged == i) { - hide = true; - } else { - for(int l = i+1; l < mac_menu->actionItems.size(); ++l) { - QMacMenuAction *action = mac_menu->actionItems.at(l); - if (action->merged) { - hide = true; - } else if (action->action->isSeparator()) { - if (hide) - break; - } else if (!action->merged) { - hide = false; - break; - } - } - } - - const int index = qt_mac_menu_find_action(mr, action); - if (hide) { - ++merged; - ChangeMenuItemAttributes(mr, index, kMenuItemAttrHidden, 0); - } else { - ChangeMenuItemAttributes(mr, index, 0, kMenuItemAttrHidden); - } - } else if (action->merged) { - ++merged; - } - } - } else { - emit qmenu->aboutToHide(); - } - } - } - } else { - handled_event = false; - } - break; } - default: - handled_event = false; - break; - } - if (!handled_event) //let the event go through - return CallNextEventHandler(er, event); - return noErr; //we eat the event -} -static EventHandlerRef mac_menu_event_handler = 0; -static EventHandlerUPP mac_menu_eventUPP = 0; -static void qt_mac_cleanup_menu_event() -{ - if (mac_menu_event_handler) { - RemoveEventHandler(mac_menu_event_handler); - mac_menu_event_handler = 0; - } - if (mac_menu_eventUPP) { - DisposeEventHandlerUPP(mac_menu_eventUPP); - mac_menu_eventUPP = 0; - } -} -static inline void qt_mac_create_menu_event_handler() -{ - if (!mac_menu_event_handler) { - mac_menu_eventUPP = NewEventHandlerUPP(qt_mac_menu_event); - InstallEventHandler(GetApplicationEventTarget(), mac_menu_eventUPP, - GetEventTypeCount(menu_events), menu_events, 0, - &mac_menu_event_handler); - qAddPostRoutine(qt_mac_cleanup_menu_event); - } -} - - -//enabling of commands -static void qt_mac_command_set_enabled(MenuRef menu, UInt32 cmd, bool b) -{ - if (cmd == kHICommandQuit) - qt_mac_quit_menu_item_enabled = b; - - if (b) { - EnableMenuCommand(menu, cmd); - if (MenuRef dock_menu = GetApplicationDockTileMenu()) - EnableMenuCommand(dock_menu, cmd); - } else { - DisableMenuCommand(menu, cmd); - if (MenuRef dock_menu = GetApplicationDockTileMenu()) - DisableMenuCommand(dock_menu, cmd); - } -} - -static bool qt_mac_auto_apple_menu(MenuCommand cmd) -{ - return (cmd == kHICommandPreferences || cmd == kHICommandQuit); -} - -static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) { - if (modif) { - *modif = constructModifierMask(accel_key); - } - - accel_key &= ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL); - if (key) { - *key = 0; - if (accel_key == Qt::Key_Return) - *key = kMenuReturnGlyph; - else if (accel_key == Qt::Key_Enter) - *key = kMenuEnterGlyph; - else if (accel_key == Qt::Key_Tab) - *key = kMenuTabRightGlyph; - else if (accel_key == Qt::Key_Backspace) - *key = kMenuDeleteLeftGlyph; - else if (accel_key == Qt::Key_Delete) - *key = kMenuDeleteRightGlyph; - else if (accel_key == Qt::Key_Escape) - *key = kMenuEscapeGlyph; - else if (accel_key == Qt::Key_PageUp) - *key = kMenuPageUpGlyph; - else if (accel_key == Qt::Key_PageDown) - *key = kMenuPageDownGlyph; - else if (accel_key == Qt::Key_Up) - *key = kMenuUpArrowGlyph; - else if (accel_key == Qt::Key_Down) - *key = kMenuDownArrowGlyph; - else if (accel_key == Qt::Key_Left) - *key = kMenuLeftArrowGlyph; - else if (accel_key == Qt::Key_Right) - *key = kMenuRightArrowGlyph; - else if (accel_key == Qt::Key_CapsLock) - *key = kMenuCapsLockGlyph; - else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) - *key = (accel_key - Qt::Key_F1) + kMenuF1Glyph; - else if (accel_key == Qt::Key_Home) - *key = kMenuNorthwestArrowGlyph; - else if (accel_key == Qt::Key_End) - *key = kMenuSoutheastArrowGlyph; - } -} -#else // Cocoa static inline void syncNSMenuItemVisiblity(NSMenuItem *menuItem, bool actionVisibility) { [menuItem setHidden:NO]; @@ -644,27 +282,10 @@ static NSMenuItem *createNSMenuItem(const QString &title) [item setTarget:nil]; return item; } -#endif - - // helper that recurses into a menu structure and en/dis-ables them void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bool on) { -#ifndef QT_MAC_USE_COCOA - for (int i = 0; i < CountMenuItems(menu); i++) { - OSMenuRef submenu; - GetMenuItemHierarchicalMenu(menu, i+1, &submenu); - if (submenu != merge) { - if (submenu) - qt_mac_set_modal_state_helper_recursive(submenu, merge, on); - if (on) - DisableMenuItem(submenu, 0); - else - EnableMenuItem(submenu, 0); - } - } -#else bool modalWindowOnScreen = qApp->activeModalWidget() != 0; for (NSMenuItem *item in [menu itemArray]) { OSMenuRef submenu = [item submenu]; @@ -694,57 +315,14 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo } } } -#endif } //toggling of modal state static void qt_mac_set_modal_state(OSMenuRef menu, bool on) { -#ifndef QT_MAC_USE_COCOA - OSMenuRef merge = 0; - GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu, - sizeof(merge), 0, &merge); - - qt_mac_set_modal_state_helper_recursive(menu, merge, on); - - UInt32 commands[] = { kHICommandQuit, kHICommandPreferences, kHICommandAbout, kHICommandAboutQt, 0 }; - for(int c = 0; commands[c]; c++) { - bool enabled = !on; - if (enabled) { - QMacMenuAction *action = 0; - GetMenuCommandProperty(menu, commands[c], kMenuCreatorQt, kMenuPropertyQAction, - sizeof(action), 0, &action); - if (!action && merge) { - GetMenuCommandProperty(merge, commands[c], kMenuCreatorQt, kMenuPropertyQAction, - sizeof(action), 0, &action); - if (!action) { - QMenuMergeList *list = 0; - GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list); - for(int i = 0; list && i < list->size(); ++i) { - QMenuMergeItem item = list->at(i); - if (item.command == commands[c] && item.action) { - action = item.action; - break; - } - } - } - } - - if (!action) { - if (commands[c] != kHICommandQuit) - enabled = false; - } else { - enabled = action->action ? action->action->isEnabled() : 0; - } - } - qt_mac_command_set_enabled(menu, commands[c], enabled); - } -#else OSMenuRef merge = QMenuPrivate::mergeMenuHash.value(menu); qt_mac_set_modal_state_helper_recursive(menu, merge, on); // I'm ignoring the special items now, since they should get handled via a syncAction() -#endif } bool qt_mac_menubar_is_open() @@ -754,7 +332,6 @@ bool qt_mac_menubar_is_open() QMacMenuAction::~QMacMenuAction() { -#ifdef QT_MAC_USE_COCOA [menu release]; // Update the menu item if this action still owns it. For some items // (like 'Quit') ownership will be transferred between all menu bars... @@ -772,14 +349,9 @@ QMacMenuAction::~QMacMenuAction() [menuItem setTag:nil]; } [menuItem release]; -#endif } -#ifndef QT_MAC_USE_COCOA -static MenuCommand qt_mac_menu_merge_action(MenuRef merge, QMacMenuAction *action) -#else static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *action) -#endif { if (qt_mac_no_menubar_merge || action->action->menu() || action->action->isSeparator() || action->action->menuRole() == QAction::NoRole) @@ -791,120 +363,50 @@ static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *act t.remove(st, t.length()-st); t.replace(QRegExp(QString::fromLatin1("\\.*$")), QLatin1String("")); //no ellipses //now the fun part -#ifndef QT_MAC_USE_COCOA - MenuCommand ret = 0; -#else NSMenuItem *ret = 0; QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); -#endif + switch (action->action->menuRole()) { case QAction::NoRole: ret = 0; break; case QAction::ApplicationSpecificRole: -#ifndef QT_MAC_USE_COCOA - { - QMenuMergeList *list = 0; - if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list) == noErr && list) { - MenuCommand lastCustom = kHICommandCustomMerge; - for(int i = 0; i < list->size(); ++i) { - QMenuMergeItem item = list->at(i); - if (item.command == lastCustom) - ++lastCustom; - } - ret = lastCustom; - } else { - // The list hasn't been created, so, must be the first one. - ret = kHICommandCustomMerge; - } - } -#else ret = [loader appSpecificMenuItem]; -#endif break; case QAction::AboutRole: -#ifndef QT_MAC_USE_COCOA - ret = kHICommandAbout; -#else ret = [loader aboutMenuItem]; -#endif break; case QAction::AboutQtRole: -#ifndef QT_MAC_USE_COCOA - ret = kHICommandAboutQt; -#else ret = [loader aboutQtMenuItem]; -#endif break; case QAction::QuitRole: -#ifndef QT_MAC_USE_COCOA - ret = kHICommandQuit; -#else ret = [loader quitMenuItem]; -#endif break; case QAction::PreferencesRole: -#ifndef QT_MAC_USE_COCOA - ret = kHICommandPreferences; -#else ret = [loader preferencesMenuItem]; -#endif break; case QAction::TextHeuristicRole: { QString aboutString = QMenuBar::tr("About").toLower(); if (t.startsWith(aboutString) || t.endsWith(aboutString)) { if (t.indexOf(QRegExp(QString::fromLatin1("qt$"), Qt::CaseInsensitive)) == -1) { -#ifndef QT_MAC_USE_COCOA - ret = kHICommandAbout; -#else ret = [loader aboutMenuItem]; -#endif } else { -#ifndef QT_MAC_USE_COCOA - ret = kHICommandAboutQt; -#else ret = [loader aboutQtMenuItem]; -#endif } } else if (t.startsWith(QMenuBar::tr("Config").toLower()) || t.startsWith(QMenuBar::tr("Preference").toLower()) || t.startsWith(QMenuBar::tr("Options").toLower()) || t.startsWith(QMenuBar::tr("Setting").toLower()) || t.startsWith(QMenuBar::tr("Setup").toLower())) { -#ifndef QT_MAC_USE_COCOA - ret = kHICommandPreferences; -#else ret = [loader preferencesMenuItem]; -#endif } else if (t.startsWith(QMenuBar::tr("Quit").toLower()) || t.startsWith(QMenuBar::tr("Exit").toLower())) { -#ifndef QT_MAC_USE_COCOA - ret = kHICommandQuit; -#else ret = [loader quitMenuItem]; -#endif } } break; } -#ifndef QT_MAC_USE_COCOA - QMenuMergeList *list = 0; - if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list) == noErr && list) { - for(int i = 0; i < list->size(); ++i) { - QMenuMergeItem item = list->at(i); - if (item.command == ret && item.action) - return 0; - } - } - - QAction *cmd_action = 0; - if (GetMenuCommandProperty(merge, ret, kMenuCreatorQt, kMenuPropertyQAction, - sizeof(cmd_action), 0, &cmd_action) == noErr && cmd_action) - return 0; //already taken -#else if (QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge)) { for(int i = 0; i < list->size(); ++i) { const QMenuMergeItem &item = list->at(i); @@ -913,7 +415,6 @@ static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *act } } -#endif return ret; } @@ -921,21 +422,9 @@ static QString qt_mac_menu_merge_text(QMacMenuAction *action) { QString ret; extern QString qt_mac_applicationmenu_string(int type); -#ifdef QT_MAC_USE_COCOA QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); -#endif if (action->action->menuRole() == QAction::ApplicationSpecificRole) ret = action->action->text(); -#ifndef QT_MAC_USE_COCOA - else if (action->command == kHICommandAbout) - ret = qt_mac_applicationmenu_string(6).arg(qAppName()); - else if (action->command == kHICommandAboutQt) - ret = QMenuBar::tr("About Qt"); - else if (action->command == kHICommandPreferences) - ret = qt_mac_applicationmenu_string(4); - else if (action->command == kHICommandQuit) - ret = qt_mac_applicationmenu_string(5).arg(qAppName()); -#else else if (action->menuItem == [loader aboutMenuItem]) { ret = qt_mac_applicationmenu_string(6).arg(qAppName()); } else if (action->menuItem == [loader aboutQtMenuItem]) { @@ -948,29 +437,19 @@ static QString qt_mac_menu_merge_text(QMacMenuAction *action) } else if (action->menuItem == [loader quitMenuItem]) { ret = qt_mac_applicationmenu_string(5).arg(qAppName()); } -#endif return ret; } static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action) { QKeySequence ret; -#ifdef QT_MAC_USE_COCOA QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); -#endif if (action->action->menuRole() == QAction::ApplicationSpecificRole) ret = action->action->shortcut(); -#ifndef QT_MAC_USE_COCOA - else if (action->command == kHICommandPreferences) - ret = QKeySequence(QKeySequence::Preferences); - else if (action->command == kHICommandQuit) - ret = QKeySequence(QKeySequence::Quit); -#else else if (action->menuItem == [loader preferencesMenuItem]) ret = QKeySequence(QKeySequence::Preferences); else if (action->menuItem == [loader quitMenuItem]) ret = QKeySequence(QKeySequence::Quit); -#endif return ret; } @@ -989,34 +468,6 @@ QMenuPrivate::QMacMenuPrivate::QMacMenuPrivate() : menu(0) QMenuPrivate::QMacMenuPrivate::~QMacMenuPrivate() { -#ifndef QT_MAC_USE_COCOA - for(QList<QMacMenuAction*>::Iterator it = actionItems.begin(); it != actionItems.end(); ++it) { - QMacMenuAction *action = (*it); - RemoveMenuCommandProperty(action->menu, action->command, kMenuCreatorQt, kMenuPropertyQAction); - if (action->merged) { - QMenuMergeList *list = 0; - GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list); - for(int i = 0; list && i < list->size(); ) { - QMenuMergeItem item = list->at(i); - if (item.action == action) - list->removeAt(i); - else - ++i; - } - } - delete action; - } - if (menu) { - EventHandlerHash::iterator it = menu_eventHandlers_hash()->find(menu); - while (it != menu_eventHandlers_hash()->end() && it.key() == menu) { - RemoveEventHandler(it.value()); - ++it; - } - menu_eventHandlers_hash()->remove(menu); - ReleaseMenu(menu); - } -#else QMacCocoaAutoReleasePool pool; while (actionItems.size()) { QMacMenuAction *action = actionItems.takeFirst(); @@ -1035,7 +486,6 @@ QMenuPrivate::QMacMenuPrivate::~QMacMenuPrivate() mergeMenuHash.remove(menu); mergeMenuItemsHash.remove(menu); [menu release]; -#endif } void @@ -1046,19 +496,14 @@ QMenuPrivate::QMacMenuPrivate::addAction(QAction *a, QMacMenuAction *before, QMe action->ignore_accel = 0; action->merged = 0; action->menu = 0; -#ifndef QT_MAC_USE_COCOA - action->command = qt_mac_menu_static_cmd_id++; -#endif addAction(action, before, qmenu); } void QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction *before, QMenuPrivate *qmenu) { -#ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; Q_UNUSED(qmenu); -#endif if (!action) return; int before_index = actionItems.indexOf(before); @@ -1068,43 +513,15 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction } actionItems.insert(before_index, action); -#ifndef QT_MAC_USE_COCOA - int index = qt_mac_menu_find_action(menu, action); -#else [menu retain]; [action->menu release]; -#endif action->menu = menu; /* When the action is considered a mergable action it will stay that way, until removed.. */ if (!qt_mac_no_menubar_merge) { -#ifndef QT_MAC_USE_COCOA - MenuRef merge = 0; - GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu, - sizeof(merge), 0, &merge); -#else OSMenuRef merge = QMenuPrivate::mergeMenuHash.value(menu); -#endif if (merge) { -#ifndef QT_MAC_USE_COCOA - if (MenuCommand cmd = qt_mac_menu_merge_action(merge, action)) { - action->merged = 1; - action->menu = merge; - action->command = cmd; - if (qt_mac_auto_apple_menu(cmd)) - index = 0; //no need - - QMenuMergeList *list = 0; - if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list) != noErr || !list) { - list = new QMenuMergeList; - SetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), &list); - } - list->append(QMenuMergeItem(cmd, action)); - } -#else if (NSMenuItem *cmd = qt_mac_menu_merge_action(merge, action)) { action->merged = 1; [merge retain]; @@ -1122,102 +539,24 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction } list->append(QMenuMergeItem(cmd, action)); } -#endif } } -#ifdef QT_MAC_USE_COCOA NSMenuItem *newItem = action->menuItem; -#endif - if ( -#ifndef QT_MAC_USE_COCOA - index == -1 -#else - newItem == 0 -#endif - ) { -#ifndef QT_MAC_USE_COCOA - index = before_index; - MenuItemAttributes attr = kMenuItemAttrAutoRepeat; -#else + if (newItem == 0) { newItem = createNSMenuItem(action->action->text()); action->menuItem = newItem; -#endif if (before) { -#ifndef QT_MAC_USE_COCOA - InsertMenuItemTextWithCFString(action->menu, 0, qMax(before_index, 0), attr, action->command); -#else [menu insertItem:newItem atIndex:qMax(before_index, 0)]; -#endif } else { -#ifndef QT_MAC_USE_COCOA - // Append the menu item to the menu. If it is a kHICommandAbout or a kHICommandAboutQt append - // a separator also (to get a separator above "Preferences"), but make sure that we don't - // add separators between two "about" items. - - // Build a set of all commands that could possibly be before the separator. - QSet<MenuCommand> mergedItems; - mergedItems.insert(kHICommandAbout); - mergedItems.insert(kHICommandAboutQt); - mergedItems.insert(kHICommandCustomMerge); - - QMenuMergeList *list = 0; - if (GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list) == noErr && list) { - for (int i = 0; i < list->size(); ++i) { - MenuCommand command = list->at(i).command; - if (command > kHICommandCustomMerge) { - mergedItems.insert(command); - } - } - } - - const int itemCount = CountMenuItems(action->menu); - MenuItemAttributes testattr; - GetMenuItemAttributes(action->menu, itemCount , &testattr); - if (mergedItems.contains(action->command) - && (testattr & kMenuItemAttrSeparator)) { - InsertMenuItemTextWithCFString(action->menu, 0, qMax(itemCount - 1, 0), attr, action->command); - index = itemCount; - } else { - MenuItemIndex tmpIndex; - AppendMenuItemTextWithCFString(action->menu, 0, attr, action->command, &tmpIndex); - index = tmpIndex; - if (mergedItems.contains(action->command)) - AppendMenuItemTextWithCFString(action->menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex); - } -#else [menu addItem:newItem]; -#endif } QWidget *widget = qmenu ? qmenu->widgetItems.value(action->action) : 0; if (widget) { -#ifndef QT_MAC_USE_COCOA - ChangeMenuAttributes(action->menu, kMenuAttrDoNotCacheImage, 0); - attr = kMenuItemAttrCustomDraw; - SetMenuItemProperty(action->menu, index, kMenuCreatorQt, kMenuPropertyWidgetActionWidget, - sizeof(QWidget *), &widget); - HIViewRef content; - HIMenuGetContentView(action->menu, kThemeMenuTypePullDown, &content); - - EventHandlerRef eventHandlerRef; - InstallMenuEventHandler(action->menu, qt_mac_widget_in_menu_eventHandler, - GetEventTypeCount(widget_in_menu_events), - widget_in_menu_events, 0, &eventHandlerRef); - menu_eventHandlers_hash()->insert(action->menu, eventHandlerRef); - - QWidget *menuWidget = 0; - GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyWidgetMenu, - sizeof(menuWidget), 0, &menuWidget); - if(!menuWidget) { - menuWidget = new QMacNativeWidget(content); - SetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyWidgetMenu, - sizeof(menuWidget), &menuWidget); - menuWidget->show(); - } - widget->setParent(menuWidget); -#else + qWarning("QMacMenuPrivate: Widgets in menus not implemented."); +#if 0 + QMacNativeWidget *container = new QMacNativeWidget(0); container->resize(widget->sizeHint()); widget->setAttribute(Qt::WA_LayoutUsesWidgetRect); @@ -1230,35 +569,30 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction [newItem setView:containerView]; container->show(); -#endif widget->show(); +#endif } } else { -#ifndef QT_MAC_USE_COCOA - qt_mac_command_set_enabled(action->menu, action->command, !QApplicationPrivate::modalState()); -#else [newItem setEnabled:!QApplicationPrivate::modalState()]; -#endif } -#ifndef QT_MAC_USE_COCOA - SetMenuCommandProperty(action->menu, action->command, kMenuCreatorQt, kMenuPropertyQAction, - sizeof(action), &action); -#else [newItem setTag:long(static_cast<QAction *>(action->action))]; -#endif syncAction(action); } // return an autoreleased string given a QKeySequence (currently only looks at the first one). NSString *keySequenceToKeyEqivalent(const QKeySequence &accel) { + qWarning("Unimplemented: keySequenceToKeyEqivalent"); + return @""; +#if 0 quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL)); extern QChar qtKey2CocoaKey(Qt::Key key); QChar cocoa_key = qtKey2CocoaKey(Qt::Key(accel_key)); if (cocoa_key.isNull()) cocoa_key = QChar(accel_key).toLower().unicode(); return [NSString stringWithCharacters:&cocoa_key.unicode() length:1]; +#endif } // return the cocoa modifier mask for the QKeySequence (currently only looks at the first one). @@ -1273,38 +607,17 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) if (!action) return; -#ifndef QT_MAC_USE_COCOA - const int index = qt_mac_menu_find_action(action->menu, action); - if (index == -1) - return; -#else NSMenuItem *item = action->menuItem; if (!item) return; -#endif -#ifndef QT_MAC_USE_COCOA - if (!action->action->isVisible()) { - ChangeMenuItemAttributes(action->menu, index, kMenuItemAttrHidden, 0); - return; - } - ChangeMenuItemAttributes(action->menu, index, 0, kMenuItemAttrHidden); -#else QMacCocoaAutoReleasePool pool; NSMenu *menu = [item menu]; bool actionVisible = action->action->isVisible(); [item setHidden:!actionVisible]; if (!actionVisible) return; -#endif -#ifndef QT_MAC_USE_COCOA - if (action->action->isSeparator()) { - ChangeMenuItemAttributes(action->menu, index, kMenuItemAttrSeparator, 0); - return; - } - ChangeMenuItemAttributes(action->menu, index, 0, kMenuItemAttrSeparator); -#else int itemIndex = [menu indexOfItem:item]; Q_ASSERT(itemIndex != -1); if (action->action->isSeparator()) { @@ -1323,7 +636,6 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) [item release]; item = action->menuItem; } -#endif //find text (and accel) action->ignore_accel = 0; @@ -1348,42 +660,11 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) if (accel.count() > 1) text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")"); +#if 0 QString finalString = qt_mac_removeMnemonics(text); - -#ifndef QT_MAC_USE_COCOA - MenuItemDataRec data; - memset(&data, '\0', sizeof(data)); - - //Carbon text - data.whichData |= kMenuItemDataCFString; - QCFString cfstring(finalString); // Hold the reference to the end of the function. - data.cfText = cfstring; - - // Carbon enabled - data.whichData |= kMenuItemDataEnabled; - data.enabled = action->action->isEnabled(); - // Carbon icon - data.whichData |= kMenuItemDataIconHandle; - if (!action->action->icon().isNull() - && action->action->isIconVisibleInMenu()) { - data.iconType = kMenuIconRefType; - data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(16, QIcon::Normal)); - } else { - data.iconType = kMenuNoIcon; - } - if (action->action->font().resolve()) { // Carbon font - if (action->action->font().bold()) - data.style |= bold; - if (action->action->font().underline()) - data.style |= underline; - if (action->action->font().italic()) - data.style |= italic; - if (data.style) - data.whichData |= kMenuItemDataStyle; - data.whichData |= kMenuItemDataFontID; - data.fontID = action->action->font().macFontID(); - } #else + QString finalString = qt_mac_removeMnemonics(text); +#endif // Cocoa Font and title if (action->action->font().resolve()) { const QFont &actionFont = action->action->font(); @@ -1414,16 +695,8 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) } [item setImage:nsimage]; [nsimage release]; -#endif if (action->action->menu()) { //submenu -#ifndef QT_MAC_USE_COCOA - data.whichData |= kMenuItemDataSubmenuHandle; - data.submenuHandle = action->action->menu()->macMenu(); - QWidget *caused = 0; - GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused); - SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); -#else NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu()); if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) { // The menu is already a sub-menu of another one. Cocoa will throw an exception, @@ -1433,19 +706,7 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) } else { [item setSubmenu:subMenu]; } -#endif } else { //respect some other items -#ifndef QT_MAC_USE_COCOA - //shortcuts (say we are setting them all so that we can also clear them). - data.whichData |= kMenuItemDataCmdKey; - data.whichData |= kMenuItemDataCmdKeyModifiers; - data.whichData |= kMenuItemDataCmdKeyGlyph; - if (accel.count() == 1) { - qt_mac_get_accel(accel[0], (quint32*)&data.cmdKeyModifiers, (quint32*)&data.cmdKeyGlyph); - if (data.cmdKeyGlyph == 0) - data.cmdKey = (UniChar)accel[0]; - } -#else [item setSubmenu:0]; // No key equivalent set for multiple key QKeySequence. if (accel.count() == 1) { @@ -1455,33 +716,9 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) [item setKeyEquivalent:@""]; [item setKeyEquivalentModifierMask:NSCommandKeyMask]; } -#endif } -#ifndef QT_MAC_USE_COCOA - //mark glyph - data.whichData |= kMenuItemDataMark; - if (action->action->isChecked()) { -#if 0 - if (action->action->actionGroup() && - action->action->actionGroup()->isExclusive()) - data.mark = diamondMark; - else -#endif - data.mark = checkMark; - } else { - data.mark = noMark; - } - - //actually set it - SetMenuItemData(action->menu, action->command, true, &data); - - // Free up memory - if (data.iconHandle) - ReleaseIconRef(IconRef(data.iconHandle)); -#else //mark glyph [item setState:action->action->isChecked() ? NSOnState : NSOffState]; -#endif } void @@ -1489,12 +726,6 @@ QMenuPrivate::QMacMenuPrivate::removeAction(QMacMenuAction *action) { if (!action) return; -#ifndef QT_MAC_USE_COCOA - if (action->command == kHICommandQuit || action->command == kHICommandPreferences) - qt_mac_command_set_enabled(action->menu, action->command, false); - else - DeleteMenuItem(action->menu, qt_mac_menu_find_action(action->menu, action)); -#else QMacCocoaAutoReleasePool pool; if (action->merged) { if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->action) { @@ -1508,7 +739,6 @@ QMenuPrivate::QMacMenuPrivate::removeAction(QMacMenuAction *action) } else { [[action->menuItem menu] removeItem:action->menuItem]; } -#endif actionItems.removeAll(action); } @@ -1523,11 +753,7 @@ QMenuPrivate::macMenu(OSMenuRef merge) mac_menu = new QMacMenuPrivate; mac_menu->menu = qt_mac_create_menu(q); if (merge) { -#ifndef QT_MAC_USE_COCOA - SetMenuItemProperty(mac_menu->menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu, sizeof(merge), &merge); -#else mergeMenuHash.insert(mac_menu->menu, merge); -#endif } QList<QAction*> items = q->actions(); for(int i = 0; i < items.count(); i++) @@ -1542,14 +768,7 @@ QMenuPrivate::macMenu(OSMenuRef merge) void QMenuPrivate::syncSeparatorsCollapsible(bool collapse) { -#ifndef QT_MAC_USE_COCOA - if (collapse) - ChangeMenuAttributes(mac_menu->menu, kMenuAttrCondenseSeparators, 0); - else - ChangeMenuAttributes(mac_menu->menu, 0, kMenuAttrCondenseSeparators); -#else qt_mac_menu_collapseSeparators(mac_menu->menu, collapse); -#endif } @@ -1567,24 +786,14 @@ void QMenuPrivate::setMacMenuEnabled(bool enable) for (int i = 0; i < mac_menu->actionItems.count(); ++i) { QMacMenuAction *menuItem = mac_menu->actionItems.at(i); if (menuItem && menuItem->action && menuItem->action->isEnabled()) { -#ifndef QT_MAC_USE_COCOA - // Only enable those items which contains an enabled QAction. - // i == 0 -> the menu itself, hence i + 1 for items. - EnableMenuItem(mac_menu->menu, i + 1); -#else [menuItem->menuItem setEnabled:true]; -#endif } } } else { -#ifndef QT_MAC_USE_COCOA - DisableAllMenuItems(mac_menu->menu); -#else NSMenu *menu = mac_menu->menu; for (NSMenuItem *item in [menu itemArray]) { [item setEnabled:false]; } -#endif } } @@ -1619,23 +828,8 @@ QMenuBarPrivate::QMacMenuBarPrivate::~QMacMenuBarPrivate() { for(QList<QMacMenuAction*>::Iterator it = actionItems.begin(); it != actionItems.end(); ++it) delete (*it); -#ifndef QT_MAC_USE_COCOA - if (apple_menu) { - QMenuMergeList *list = 0; - GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list); - if (list) { - RemoveMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList); - delete list; - } - ReleaseMenu(apple_menu); - } - if (menu) - ReleaseMenu(menu); -#else [apple_menu release]; [menu release]; -#endif } void @@ -1646,9 +840,6 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QMacMenuAction *befor QMacMenuAction *action = new QMacMenuAction; action->action = a; action->ignore_accel = 1; -#ifndef QT_MAC_USE_COCOA - action->command = qt_mac_menu_static_cmd_id++; -#endif addAction(action, before); } @@ -1668,32 +859,18 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QMacMenuAction *action, QMacMenuA MenuItemIndex index = actionItems.size()-1; action->menu = menu; -#ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; [action->menu retain]; NSMenuItem *newItem = createNSMenuItem(action->action->text()); action->menuItem = newItem; -#endif + if (before) { -#ifndef QT_MAC_USE_COCOA - InsertMenuItemTextWithCFString(action->menu, 0, qMax(1, before_index+1), 0, action->command); -#else [menu insertItem:newItem atIndex:qMax(1, before_index + 1)]; -#endif index = before_index; } else { -#ifndef QT_MAC_USE_COCOA - AppendMenuItemTextWithCFString(action->menu, 0, 0, action->command, &index); -#else [menu addItem:newItem]; -#endif } -#ifndef QT_MAC_USE_COCOA - SetMenuItemProperty(action->menu, index, kMenuCreatorQt, kMenuPropertyQAction, sizeof(action), - &action); -#else [newItem setTag:long(static_cast<QAction *>(action->action))]; -#endif syncAction(action); } @@ -1702,55 +879,28 @@ QMenuBarPrivate::QMacMenuBarPrivate::syncAction(QMacMenuAction *action) { if (!action || !menu) return; -#ifndef QT_MAC_USE_COCOA - const int index = qt_mac_menu_find_action(action->menu, action); -#else + QMacCocoaAutoReleasePool pool; NSMenuItem *item = action->menuItem; -#endif OSMenuRef submenu = 0; bool release_submenu = false; if (action->action->menu()) { if ((submenu = action->action->menu()->macMenu(apple_menu))) { -#ifndef QT_MAC_USE_COCOA - QWidget *caused = 0; - GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused); - SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); -#else if ([submenu supermenu] && [submenu supermenu] != [item menu]) return; else [item setSubmenu:submenu]; -#endif } -#ifndef QT_MAC_USE_COCOA - } else { // create a submenu to act as menu - release_submenu = true; - CreateNewMenu(0, 0, &submenu); -#endif } if (submenu) { bool visible = actualMenuItemVisibility(this, action); -#ifndef QT_MAC_USE_COCOA - SetMenuItemHierarchicalMenu(action->menu, index, submenu); - SetMenuTitleWithCFString(submenu, QCFString(qt_mac_removeMnemonics(action->action->text()))); - if (visible) - ChangeMenuAttributes(submenu, 0, kMenuAttrHidden); - else - ChangeMenuAttributes(submenu, kMenuAttrHidden, 0); -#else [item setSubmenu: submenu]; [submenu setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(action->action->text()))]; syncNSMenuItemVisiblity(item, visible); -#endif if (release_submenu) { //no pointers to it -#ifndef QT_MAC_USE_COCOA - ReleaseMenu(submenu); -#else [submenu release]; -#endif } } else { qWarning("QMenu: No OSMenuRef created for popup menu"); @@ -1762,12 +912,8 @@ QMenuBarPrivate::QMacMenuBarPrivate::removeAction(QMacMenuAction *action) { if (!action || !menu) return; -#ifndef QT_MAC_USE_COCOA - DeleteMenuItem(action->menu, qt_mac_menu_find_action(action->menu, action)); -#else QMacCocoaAutoReleasePool pool; [action->menu removeItem:action->menuItem]; -#endif actionItems.removeAll(action); } @@ -1804,8 +950,7 @@ QMenuBarPrivate::macCreateMenuBar(QWidget *parent) } if (qt_mac_no_native_menubar == false) { // INVARIANT: Use native menubar. - extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp - qt_event_request_menubarupdate(); + QMenuBar::macUpdateMenuBar(); if (!parent && !fallback) { fallback = q; mac_menubar = new QMacMenuBarPrivate; @@ -1828,14 +973,9 @@ void QMenuBarPrivate::macDestroyMenuBar() mac_menubar = 0; if (!qt_mac_current_menubar.qmenubar || qt_mac_current_menubar.qmenubar == q) { -#ifdef QT_MAC_USE_COCOA QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); [loader removeActionsFromAppMenu]; -#else - cancelAllMenuTracking(); -#endif - extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp - qt_event_request_menubarupdate(); + QMenuBar::macUpdateMenuBar(); } } @@ -1850,28 +990,14 @@ OSMenuRef QMenuBarPrivate::macMenu() if (GetCurrentProcess(&mine) == noErr && GetFrontProcess(&front) == noErr) { if (!qt_mac_no_menubar_merge && !mac_menubar->apple_menu) { mac_menubar->apple_menu = qt_mac_create_menu(q); -#ifndef QT_MAC_USE_COCOA - MenuItemIndex index; - AppendMenuItemTextWithCFString(mac_menubar->menu, 0, 0, 0, &index); - - SetMenuTitleWithCFString(mac_menubar->apple_menu, QCFString(QString(QChar(0x14)))); - SetMenuItemHierarchicalMenu(mac_menubar->menu, index, mac_menubar->apple_menu); - SetMenuItemProperty(mac_menubar->apple_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(q), &q); -#else [mac_menubar->apple_menu setTitle:qt_mac_QStringToNSString(QString(QChar(0x14)))]; NSMenuItem *apple_menuItem = [[NSMenuItem alloc] init]; [apple_menuItem setSubmenu:mac_menubar->menu]; [mac_menubar->apple_menu addItem:apple_menuItem]; [apple_menuItem release]; -#endif } if (mac_menubar->apple_menu) { -#ifndef QT_MAC_USE_COCOA - SetMenuItemProperty(mac_menubar->menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu, - sizeof(mac_menubar->apple_menu), &mac_menubar->apple_menu); -#else QMenuPrivate::mergeMenuHash.insert(mac_menubar->menu, mac_menubar->apple_menu); -#endif } QList<QAction*> items = q->actions(); for(int i = 0; i < items.count(); i++) @@ -2009,18 +1135,6 @@ void qt_mac_clear_menubar() if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) return; -#ifndef QT_MAC_USE_COCOA - MenuRef clear_menu = 0; - if (CreateNewMenu(0, 0, &clear_menu) == noErr) { - SetRootMenu(clear_menu); - ReleaseMenu(clear_menu); - } else { - qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__); - } - ClearMenuBar(); - qt_mac_command_set_enabled(0, kHICommandPreferences, false); - InvalMenuBar(); -#else QMacCocoaAutoReleasePool pool; QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); NSMenu *menu = [loader menu]; @@ -2031,7 +1145,6 @@ void qt_mac_clear_menubar() qt_mac_set_modal_state(menu, modal); qt_mac_current_menubar.qmenubar = 0; qt_mac_current_menubar.modal = modal; -#endif } /*! @@ -2046,13 +1159,11 @@ void qt_mac_clear_menubar() */ bool QMenuBar::macUpdateMenuBar() { -#ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; - qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar)); + qWarning("Unimplemented: QMenuBar::macUpdateMenuBar"); + //qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar)); + return true; -#else - return QMenuBarPrivate::macUpdateMenuBarImmediatly(); -#endif } bool QMenuBarPrivate::macUpdateMenuBarImmediatly() @@ -2083,13 +1194,8 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly() if (mb && mb->isNativeMenuBar()) { bool modal = QApplicationPrivate::modalState(); -#ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; -#endif if (OSMenuRef menu = mb->macMenu()) { -#ifndef QT_MAC_USE_COCOA - SetRootMenu(menu); -#else QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); [loader ensureAppMenuInMenu:menu]; [NSApp setMainMenu:menu]; @@ -2111,7 +1217,6 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly() } } } -#endif // Check if menu is modally shaddowed and should be disabled: modal = qt_mac_should_disable_menu(mb); if (mb != qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal) @@ -2127,14 +1232,10 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly() if (modal != qt_mac_current_menubar.modal) { ret = true; if (OSMenuRef menu = qt_mac_current_menubar.qmenubar->macMenu()) { -#ifndef QT_MAC_USE_COCOA - SetRootMenu(menu); -#else QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); [loader ensureAppMenuInMenu:menu]; [NSApp setMainMenu:menu]; syncMenuBarItemsVisiblity(qt_mac_current_menubar.qmenubar->d_func()->mac_menubar); -#endif qt_mac_set_modal_state(menu, modal); } qt_mac_current_menubar.modal = modal; @@ -2152,22 +1253,6 @@ QHash<OSMenuRef, QMenuMergeList*> QMenuPrivate::mergeMenuItemsHash; bool QMenuPrivate::QMacMenuPrivate::merged(const QAction *action) const { -#ifndef QT_MAC_USE_COCOA - MenuRef merge = 0; - GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu, - sizeof(merge), 0, &merge); - if (merge) { - QMenuMergeList *list = 0; - if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList, - sizeof(list), 0, &list) == noErr && list) { - for(int i = 0; i < list->size(); ++i) { - QMenuMergeItem item = list->at(i); - if (item.action->action == action) - return true; - } - } - } -#else if (OSMenuRef merge = mergeMenuHash.value(menu)) { if (QMenuMergeList *list = mergeMenuItemsHash.value(merge)) { for(int i = 0; i < list->size(); ++i) { @@ -2177,7 +1262,6 @@ bool QMenuPrivate::QMacMenuPrivate::merged(const QAction *action) const } } } -#endif return false; } @@ -2185,29 +1269,11 @@ bool QMenuPrivate::QMacMenuPrivate::merged(const QAction *action) const static OSMenuRef qt_mac_create_menu(QWidget *w) { OSMenuRef ret; -#ifndef QT_MAC_USE_COCOA - ret = 0; - if (CreateNewMenu(0, 0, &ret) == noErr) { - qt_mac_create_menu_event_handler(); - SetMenuItemProperty(ret, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(w), &w); - - // kEventMenuMatchKey is only sent to the menu itself and not to - // the application, install a separate handler for that event. - EventHandlerRef eventHandlerRef; - InstallMenuEventHandler(ret, qt_mac_menu_event, - GetEventTypeCount(menu_menu_events), - menu_menu_events, 0, &eventHandlerRef); - menu_eventHandlers_hash()->insert(ret, eventHandlerRef); - } else { - qWarning("QMenu: Internal error"); - } -#else if (QMenu *qmenu = qobject_cast<QMenu *>(w)){ ret = [[QT_MANGLE_NAMESPACE(QCocoaMenu) alloc] initWithQMenu:qmenu]; } else { ret = [[NSMenu alloc] init]; } -#endif return ret; } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 7ce1a58c0a..9cadb596c8 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -55,12 +55,16 @@ #include "QtWidgets/qmenubar.h" #include "QtWidgets/qstyleoption.h" +#ifdef Q_OS_MAC +#include "QtWidgets/qmacdefines_mac.h" +#endif #include "QtCore/qdatetime.h" #include "QtCore/qmap.h" #include "QtCore/qhash.h" #include "QtCore/qbasictimer.h" #include "private/qwidget_p.h" + #ifdef Q_WS_S60 class CEikMenuPane; #define QT_SYMBIAN_FIRST_MENU_ITEM 32000 @@ -79,7 +83,7 @@ void qt_symbian_show_submenu(CEikMenuPane* menuPane, int id); class QTornOffMenu; class QEventLoop; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC # ifdef __OBJC__ QT_END_NAMESPACE @class NSMenuItem; @@ -89,20 +93,12 @@ typedef void NSMenuItem; # endif //__OBJC__ struct QMacMenuAction { QMacMenuAction() -#ifndef QT_MAC_USE_COCOA - : command(0) -#else : menuItem(0) -#endif , ignore_accel(0), merged(0), menu(0) { } ~QMacMenuAction(); -#ifndef QT_MAC_USE_COCOA - uint command; -#else NSMenuItem *menuItem; -#endif uchar ignore_accel : 1; uchar merged : 1; QPointer<QAction> action; @@ -111,17 +107,12 @@ struct QMacMenuAction { struct QMenuMergeItem { -#ifndef QT_MAC_USE_COCOA - inline QMenuMergeItem(MenuCommand c, QMacMenuAction *a) : command(c), action(a) { } - MenuCommand command; -#else inline QMenuMergeItem(NSMenuItem *c, QMacMenuAction *a) : menuItem(c), action(a) { } NSMenuItem *menuItem; -#endif QMacMenuAction *action; }; typedef QList<QMenuMergeItem> QMenuMergeList; -#endif +#endif // Q_OS_MAC #ifdef Q_WS_WINCE struct QWceMenuAction { @@ -154,7 +145,7 @@ public: #endif scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), hasCheckableItems(0), sloppyAction(0), doChildEffects(false) -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC ,mac_menu(0) #endif #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) @@ -170,7 +161,7 @@ public: ~QMenuPrivate() { delete scroll; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC delete mac_menu; #endif #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) @@ -302,7 +293,7 @@ public: //menu fading/scrolling effects bool doChildEffects; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC //mac menu binding struct QMacMenuPrivate { QList<QMacMenuAction*> actionItems; diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 3ff98a4b90..1b8f1f8176 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -195,7 +195,7 @@ void QMenuBarPrivate::updateGeometries() } } -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. itemsDirty = false; return; @@ -728,7 +728,7 @@ void QMenuBarPrivate::init() Q_Q(QMenuBar); q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); q->setAttribute(Qt::WA_CustomWhatsThis); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC macCreateMenuBar(q->parentWidget()); if(mac_menubar) q->hide(); @@ -808,7 +808,7 @@ QMenuBar::QMenuBar(QWidget *parent, const char *name) : QWidget(*new QMenuBarPri */ QMenuBar::~QMenuBar() { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC Q_D(QMenuBar); d->macDestroyMenuBar(); #endif @@ -1072,7 +1072,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) */ void QMenuBar::setVisible(bool visible) { -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) +#if defined(Q_OS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) if (isNativeMenuBar()) { if (!visible) QWidget::setVisible(false); @@ -1275,9 +1275,9 @@ void QMenuBar::actionEvent(QActionEvent *e) { Q_D(QMenuBar); d->itemsDirty = true; -#if defined (Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) +#if defined (Q_OS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) if (isNativeMenuBar()) { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar; #elif defined(Q_WS_S60) QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar; @@ -1372,7 +1372,7 @@ void QMenuBarPrivate::handleReparent() oldParent = newParent; oldWindow = newWindow; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (q->isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { // If the new parent got a native menubar from before, keep that // menubar rather than replace it with this one (because a parents @@ -1659,7 +1659,7 @@ QRect QMenuBar::actionGeometry(QAction *act) const QSize QMenuBar::minimumSizeHint() const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) +#if defined(Q_OS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; @@ -1715,7 +1715,7 @@ QSize QMenuBar::minimumSizeHint() const QSize QMenuBar::sizeHint() const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) +#if defined(Q_OS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; @@ -1774,7 +1774,7 @@ QSize QMenuBar::sizeHint() const int QMenuBar::heightForWidth(int) const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) +#if defined(Q_OS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; @@ -1925,7 +1925,7 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar) Q_D(QMenuBar); if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) { d->nativeMenuBar = nativeMenuBar; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (!d->nativeMenuBar) { extern void qt_mac_clear_menubar(); qt_mac_clear_menubar(); diff --git a/src/widgets/widgets/qmenubar.h b/src/widgets/widgets/qmenubar.h index b2a2a227e9..990027f16a 100644 --- a/src/widgets/widgets/qmenubar.h +++ b/src/widgets/widgets/qmenubar.h @@ -43,6 +43,10 @@ #define QMENUBAR_H #include <QtWidgets/qmenu.h> +#ifdef Q_OS_MAC +#include "QtWidgets/qmacdefines_mac.h" +#endif + QT_BEGIN_HEADER @@ -106,7 +110,7 @@ public: void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner); QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC OSMenuRef macMenu(); static bool macUpdateMenuBar(); #endif @@ -351,7 +355,7 @@ private: friend class QMenuPrivate; friend class QWindowsStyle; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC friend class QApplicationPrivate; friend class QWidgetPrivate; friend bool qt_mac_activate_action(MenuRef, uint, QAction::ActionEvent, bool); diff --git a/src/widgets/widgets/qmenubar_p.h b/src/widgets/widgets/qmenubar_p.h index 44f71dfec3..e42162a48e 100644 --- a/src/widgets/widgets/qmenubar_p.h +++ b/src/widgets/widgets/qmenubar_p.h @@ -82,7 +82,7 @@ public: #ifdef QT3_SUPPORT , doAutoResize(false) #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC , mac_menubar(0) #endif @@ -96,7 +96,7 @@ public: { } ~QMenuBarPrivate() { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC delete mac_menubar; #endif #ifdef Q_WS_WINCE @@ -173,7 +173,7 @@ public: #ifdef QT3_SUPPORT bool doAutoResize; #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC //mac menubar binding struct QMacMenuBarPrivate { QList<QMacMenuAction*> actionItems; diff --git a/src/widgets/widgets/widgets.pri b/src/widgets/widgets/widgets.pri index 1a4b49ce0d..69c80238bf 100644 --- a/src/widgets/widgets/widgets.pri +++ b/src/widgets/widgets/widgets.pri @@ -150,12 +150,17 @@ SOURCES += \ widgets/qmaccocoaviewcontainer_mac.h OBJECTIVE_HEADERS += widgets/qcocoatoolbardelegate_mac_p.h \ widgets/qcocoamenu_mac_p.h - OBJECTIVE_SOURCES += widgets/qmenu_mac.mm \ - widgets/qmaccocoaviewcontainer_mac.mm \ + OBJECTIVE_SOURCES += widgets/qmaccocoaviewcontainer_mac.mm \ widgets/qcocoatoolbardelegate_mac.mm \ widgets/qmainwindowlayout_mac.mm \ widgets/qmacnativewidget_mac.mm \ - widgets/qcocoamenu_mac.mm +} + +mac { + OBJECTIVE_SOURCES += widgets/qmenu_mac.mm \ + widgets/qcocoamenu_mac.mm \ + platforms/mac/qt_widget_helpers_mac.mm \ + platforms/mac/qcocoamenuloader_mac.mm } wince*: { |