Start porting the Mac menu system to QPA.

Global changes: 
qglobal.h: remove code that sets Q_WS_MAC and
Q_MAC_USE_COCOA - this is dead code now. Add 
qt_widget_helpers_mac_p.h/mm which will contain
helper functions needed for widgets on Qt 5. 

Menu-related changes:
Set AA_DontUseNativeMenuBar before creating the 
platform plugin. Change Q_WS_MAC to Q_OS_MAC in the
menu code. Remove Q_MAC_USE_COCOA defines and Carbon
code paths. Move some qt_mac helper functions only
used by the menu system to qmenu_mac.mm. #ifdef out 
some code paths that require further porting.

Native menus are now disabled by default but can 
be enabled by the QPA plugins that want them by
clearing AA_DontUseNativeMenuBar. Since we at compile
time don't know which plugin will be loaded the Mac
menu code is always included when building on OS X.
(The above is currently only relevant for the Cocoa
plugin.)
This commit is contained in:
Morten Sorvig 2011-07-05 15:02:39 +02:00
parent 14757fedb2
commit 4ed17a6508
23 changed files with 346 additions and 1231 deletions

View File

@ -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

View File

@ -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;

View File

@ -1,4 +1,4 @@
!x11:!qpa:mac {
LIBS_PRIVATE += -framework Carbon -lz
!x11::mac {
LIBS_PRIVATE += -framework Carbon -framework Cocoa -lz
*-mwerks:INCLUDEPATH += compat
}

View File

@ -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
};

View File

@ -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
*/

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 *);

File diff suppressed because it is too large Load Diff

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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*: {