Cocoa: QMenu refactor.
This change prepares for enabling native menus on OS X. Move code from src/widgets to cocoa: - qcocoaapplicaiton - qcocoaapplicaitondelegate - qcocoamenuloader - qcocoamenu - qmenu_mac - misc helpers to qcocoahelpers Create a QNSApplication and QCocoaApplicationDelegate at application startup. New Lighthouse API: - class QPlatformMenu - class QPlatformMenuBar - QPlatformIntegration::createPlatformMenu() - QPlatformIntegration::createPlatformMenuBar() Platforms that wants a native menu integration subclasses QPlatformMenu[|Bar] and implements the create function. The default implementation returns 0, which causes QMenu to use the standard Qt menus. This API is based on the current native menu abstraction that Mac, Wince and S60 uses in Qt 4. The main difference is that the platform classes are proper standalone classes and not #ifdeffed into QMenuPrivate. Change-Id: I3da41f80b0ae903a476937908b1f9b88014b7954 Reviewed-on: http://codereview.qt.nokia.com/4068 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
e2be53891f
commit
cee63e2c17
@ -743,20 +743,6 @@ void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on)
|
||||
QCoreApplicationPrivate::attribs |= 1 << attribute;
|
||||
else
|
||||
QCoreApplicationPrivate::attribs &= ~(1 << attribute);
|
||||
#ifdef Q_OS_MAC
|
||||
// Turn on the no native menubar here, since we used to
|
||||
// do this implicitly. We DO NOT flip it off if someone sets
|
||||
// it to false.
|
||||
// Ideally, we'd have magic that would be something along the lines of
|
||||
// "follow MacPluginApplication" unless explicitly set.
|
||||
// Considering this attribute isn't only at the beginning
|
||||
// it's unlikely it will ever be a problem, but I want
|
||||
// to have the behavior documented here.
|
||||
if (attribute == Qt::AA_MacPluginApplication && on
|
||||
&& !testAttribute(Qt::AA_DontUseNativeMenuBar)) {
|
||||
setAttribute(Qt::AA_DontUseNativeMenuBar, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -227,6 +227,17 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
QPlatformMenu *QPlatformIntegration::createPlatformMenu(QMenu *menu) const
|
||||
{
|
||||
Q_UNUSED(menu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QPlatformMenuBar *QPlatformIntegration::createPlatformMenuBar(QMenuBar *menuBar) const
|
||||
{
|
||||
Q_UNUSED(menuBar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
Should be called by the implementation whenever a new screen is added.
|
||||
|
@ -63,6 +63,10 @@ class QPlatformOpenGLContext;
|
||||
class QGuiGLFormat;
|
||||
class QAbstractEventDispatcher;
|
||||
class QPlatformInputContext;
|
||||
class QMenu;
|
||||
class QMenuBar;
|
||||
class QPlatformMenu;
|
||||
class QPlatformMenuBar;
|
||||
|
||||
class Q_GUI_EXPORT QPlatformIntegration
|
||||
{
|
||||
@ -95,6 +99,9 @@ public:
|
||||
#endif
|
||||
virtual QPlatformInputContext *inputContext() const;
|
||||
|
||||
virtual QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
||||
virtual QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
||||
|
||||
// Access native handles. The window handle is already available from Wid;
|
||||
virtual QPlatformNativeInterface *nativeInterface() const;
|
||||
|
||||
|
@ -13,6 +13,10 @@ OBJECTIVE_SOURCES += main.mm \
|
||||
qcocoanativeinterface.mm \
|
||||
qcocoaeventdispatcher.mm \
|
||||
qcocoamenuloader.mm \
|
||||
qcocoaapplicationdelegate.mm \
|
||||
qcocoaapplication.mm \
|
||||
qcocoamenu.mm \
|
||||
qmenu_mac.mm \
|
||||
qcocoahelpers.mm \
|
||||
|
||||
HEADERS += qcocoaintegration.h \
|
||||
@ -25,15 +29,18 @@ HEADERS += qcocoaintegration.h \
|
||||
qcocoanativeinterface.h \
|
||||
qcocoaeventdispatcher.h \
|
||||
qcocoamenuloader.h \
|
||||
qcocoaapplicationdelegate.h \
|
||||
qcocoaapplication.h \
|
||||
qcocoamenu.h \
|
||||
qmenu_mac.h \
|
||||
qcocoahelpers.h \
|
||||
|
||||
|
||||
RESOURCES += qcocoaresources.qrc
|
||||
|
||||
#add libz for freetype.
|
||||
LIBS += -lz -framework Cocoa
|
||||
|
||||
QT += core-private gui-private platformsupport-private
|
||||
QT += core-private gui-private widgets-private platformsupport-private
|
||||
|
||||
CONFIG += qpa/basicunixfontdatabase
|
||||
target.path += $$[QT_INSTALL_PLUGINS]/platforms
|
||||
|
@ -4,7 +4,7 @@
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
@ -88,8 +88,8 @@
|
||||
/*
|
||||
Cocoa Application Categories
|
||||
*/
|
||||
#include "qmacdefines_mac.h"
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
#include "qglobal.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
QT_FORWARD_DECLARE_CLASS(QApplicationPrivate)
|
||||
@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader);
|
||||
@ -114,4 +114,3 @@ void qt_redirectNSApplicationSendEvent();
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
@ -73,12 +73,12 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qglobal.h>
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
#include <private/qcocoaapplication_mac_p.h>
|
||||
#include <private/qcocoaapplicationdelegate_mac_p.h>
|
||||
#include <private/qt_cocoa_helpers_mac_p.h>
|
||||
#include <private/qcocoaintrospection_p.h>
|
||||
#include <qcocoaapplication.h>
|
||||
|
||||
#include <qcocoaapplicationdelegate.h>
|
||||
#include <qcocoahelpers.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
@ -112,7 +112,8 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (void)qt_sendPostedMessage:(NSEvent *)event
|
||||
{
|
||||
// WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
|
||||
/*
|
||||
// WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
|
||||
// That is why we need to split the address in two parts:
|
||||
quint64 lower = [event data1];
|
||||
quint64 upper = [event data2];
|
||||
@ -134,10 +135,12 @@ QT_USE_NAMESPACE
|
||||
}
|
||||
|
||||
delete args;
|
||||
*/
|
||||
}
|
||||
|
||||
- (BOOL)qt_filterEvent:(NSEvent *)event
|
||||
{
|
||||
/*
|
||||
if (qApp->macEventFilter(0, reinterpret_cast<EventRef>(event)))
|
||||
return true;
|
||||
|
||||
@ -150,6 +153,7 @@ QT_USE_NAMESPACE
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -200,6 +204,7 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
void qt_redirectNSApplicationSendEvent()
|
||||
{
|
||||
/*
|
||||
if ([NSApp isMemberOfClass:[QNSApplication class]]) {
|
||||
// No need to change implementation since Qt
|
||||
// already controls a subclass of NSApplication
|
||||
@ -216,7 +221,7 @@ void qt_redirectNSApplicationSendEvent()
|
||||
[QNSApplication class],
|
||||
@selector(qt_sendEvent_replacement:),
|
||||
@selector(qt_sendEvent_original:));
|
||||
*/
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
@ -87,10 +87,10 @@
|
||||
//
|
||||
|
||||
|
||||
#include "qmacdefines_mac.h"
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QApplicationPrivate);
|
||||
|
||||
@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader);
|
||||
@ -125,4 +125,3 @@ QT_FORWARD_DECLARE_CLASS(QApplicationPrivate);
|
||||
- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate;
|
||||
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
|
||||
@end
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
@ -73,30 +73,14 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmacdefines_mac.h"
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
|
||||
#import <private/qcocoaapplicationdelegate_mac_p.h>
|
||||
#import <private/qcocoamenuloader_mac_p.h>
|
||||
#import <private/qcocoaapplication_mac_p.h>
|
||||
#include <private/qapplication_p.h>
|
||||
#include <private/qt_mac_p.h>
|
||||
#include <private/qt_cocoa_helpers_mac_p.h>
|
||||
#include <private/qdesktopwidget_mac_p.h>
|
||||
#import "qcocoaapplicationdelegate.h"
|
||||
#import "qnswindowdelegate.h"
|
||||
#include <qevent.h>
|
||||
#include <qurl.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdebug.h>
|
||||
#include <qguiapplication.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
extern void onApplicationChangedActivation(bool); // qapplication_mac.mm
|
||||
extern void qt_release_apple_event_handler(); //qapplication_mac.mm
|
||||
extern QPointer<QWidget> qt_last_mouse_receiver; // qapplication_mac.cpp
|
||||
extern QPointer<QWidget> qt_last_native_mouse_receiver; // qt_cocoa_helpers_mac.mm
|
||||
extern QPointer<QWidget> qt_button_down; // qapplication_mac.cpp
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QDesktopWidgetImplementation)
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
static QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *sharedCocoaApplicationDelegate = nil;
|
||||
@ -188,6 +172,7 @@ static void cleanupCocoaApplicationDelegate()
|
||||
// QApplicationPrivate::globalAppleEventProcessor in qapplication_mac.mm
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||
{
|
||||
/*
|
||||
Q_UNUSED(sender);
|
||||
// The reflection delegate gets precedence
|
||||
if (reflectionDelegate
|
||||
@ -212,17 +197,25 @@ static void cleanupCocoaApplicationDelegate()
|
||||
}
|
||||
|
||||
return NSTerminateCancel;
|
||||
*/
|
||||
return NSTerminateNow;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
Q_UNUSED(aNotification);
|
||||
inLaunch = false;
|
||||
qt_release_apple_event_handler();
|
||||
// qt_release_apple_event_handler();
|
||||
|
||||
|
||||
// Insert code here to initialize your application
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
|
||||
{
|
||||
/*
|
||||
for (NSString *fileName in filenames) {
|
||||
QString qtFileName = qt_mac_NSStringToQString(fileName);
|
||||
if (inLaunch) {
|
||||
@ -240,6 +233,7 @@ static void cleanupCocoaApplicationDelegate()
|
||||
if (reflectionDelegate &&
|
||||
[reflectionDelegate respondsToSelector:@selector(application:openFiles:)])
|
||||
[reflectionDelegate application:sender openFiles:filenames];
|
||||
*/
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
|
||||
@ -255,6 +249,7 @@ static void cleanupCocoaApplicationDelegate()
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
/*
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)])
|
||||
[reflectionDelegate applicationDidBecomeActive:notification];
|
||||
@ -272,10 +267,12 @@ static void cleanupCocoaApplicationDelegate()
|
||||
qt_last_native_mouse_receiver = widgetUnderMouse ?
|
||||
(widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)applicationDidResignActive:(NSNotification *)notification
|
||||
{
|
||||
/*
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)])
|
||||
[reflectionDelegate applicationDidResignActive:notification];
|
||||
@ -287,12 +284,13 @@ static void cleanupCocoaApplicationDelegate()
|
||||
qt_last_mouse_receiver = 0;
|
||||
qt_last_native_mouse_receiver = 0;
|
||||
qt_button_down = 0;
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
|
||||
{
|
||||
Q_UNUSED(notification);
|
||||
QDesktopWidgetImplementation::instance()->onResize();
|
||||
//QDesktopWidgetImplementation::instance()->onResize();
|
||||
}
|
||||
|
||||
- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate
|
||||
@ -331,24 +329,26 @@ static void cleanupCocoaApplicationDelegate()
|
||||
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
||||
{
|
||||
Q_UNUSED(replyEvent);
|
||||
|
||||
/*
|
||||
NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
||||
QUrl url(qt_mac_NSStringToQString(urlString));
|
||||
QFileOpenEvent qtEvent(url);
|
||||
qt_sendSpontaneousEvent(qAppInstance(), &qtEvent);
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(replyEvent);
|
||||
qDebug() << "appleEventQuit";
|
||||
|
||||
[NSApp terminate:self];
|
||||
}
|
||||
|
||||
- (void)qtDispatcherToQAction:(id)sender
|
||||
{
|
||||
[[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender];
|
||||
//[[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender];
|
||||
}
|
||||
|
||||
@end
|
||||
#endif
|
@ -103,17 +103,6 @@ typedef struct _QCocoaModalSessionInfo {
|
||||
void *nswindow;
|
||||
} QCocoaModalSessionInfo;
|
||||
|
||||
class Q_GUI_EXPORT QMacCocoaAutoReleasePool
|
||||
{
|
||||
private:
|
||||
void *pool;
|
||||
public:
|
||||
QMacCocoaAutoReleasePool();
|
||||
~QMacCocoaAutoReleasePool();
|
||||
|
||||
inline void *handle() const { return pool; }
|
||||
};
|
||||
|
||||
class QCocoaEventDispatcherPrivate;
|
||||
class QCocoaEventDispatcher : public QEventDispatcherUNIX
|
||||
{
|
||||
|
@ -74,6 +74,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "qcocoaeventdispatcher.h"
|
||||
#include "qcocoaautoreleasepool.h"
|
||||
|
||||
#include "qguiapplication.h"
|
||||
#include "qevent.h"
|
||||
#include "qhash.h"
|
||||
@ -84,8 +86,6 @@
|
||||
#include "private/qguiapplication_p.h"
|
||||
#include <qdebug.h>
|
||||
|
||||
//#include <private/qcocoaapplication_mac_p.h>
|
||||
//#include "private/qt_cocoa_helpers_mac_p.h"
|
||||
#undef slots
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
@ -104,17 +104,6 @@ static inline CFRunLoopRef mainRunLoop()
|
||||
return CFRunLoopGetMain();
|
||||
}
|
||||
|
||||
QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool()
|
||||
{
|
||||
pool = (void*)[[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
|
||||
QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool()
|
||||
{
|
||||
[(NSAutoreleasePool*)pool release];
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
Timers stuff
|
||||
*****************************************************************************/
|
||||
@ -541,7 +530,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
if (d->interrupt)
|
||||
break;
|
||||
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
NSEvent* event = 0;
|
||||
|
||||
// First, send all previously excluded input events, if any:
|
||||
@ -776,7 +765,7 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
|
||||
// continue;
|
||||
|
||||
if (!info.session) {
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
NSWindow *window = reinterpret_cast<NSWindow *>(info.window->handle()->winId());
|
||||
if (!window)
|
||||
continue;
|
||||
@ -822,7 +811,7 @@ void QCocoaEventDispatcherPrivate::updateChildrenWorksWhenModal()
|
||||
// Make the dialog children of the window
|
||||
// active. And make the dialog children of
|
||||
// the previous modal dialog unactive again:
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
int size = cocoaModalSessionStack.size();
|
||||
if (size > 0){
|
||||
if (QWindow *prevModal = cocoaModalSessionStack[size-1].window)
|
||||
@ -843,7 +832,7 @@ void QCocoaEventDispatcherPrivate::cleanupModalSessions()
|
||||
// point they were marked as stopped), is that ending a session
|
||||
// when no other session runs below it on the stack will make cocoa
|
||||
// drop some events on the floor.
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
int stackSize = cocoaModalSessionStack.size();
|
||||
|
||||
for (int i=stackSize-1; i>=0; --i) {
|
||||
@ -1035,7 +1024,7 @@ void QCocoaEventDispatcherPrivate::cancelWaitForMoreEvents()
|
||||
{
|
||||
// In case the event dispatcher is waiting for more
|
||||
// events somewhere, we post a dummy event to wake it up:
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
[NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint
|
||||
modifierFlags:0 timestamp:0. windowNumber:0 context:0
|
||||
subtype:QtCocoaEventSubTypeWakeup data1:0 data2:0] atStart:NO];
|
||||
|
@ -53,9 +53,9 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/private/qcore_mac_p.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <private/qt_mac_p.h>
|
||||
|
||||
class QPixmap;
|
||||
class QString;
|
||||
|
||||
// Conversion functions
|
||||
@ -71,10 +71,19 @@ 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]; }
|
||||
|
||||
CGImageRef qt_mac_image_to_cgimage(const QImage &image);
|
||||
NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge);
|
||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||
|
||||
QChar qt_mac_qtKey2CocoaKey(Qt::Key key);
|
||||
Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode);
|
||||
|
||||
// Misc
|
||||
|
||||
void qt_mac_transformProccessToForegroundApplication();
|
||||
|
||||
QString qt_mac_removeMnemonics(const QString &original);
|
||||
CGColorSpaceRef qt_mac_genericColorSpace();
|
||||
CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
|
||||
QString qt_mac_applicationName();
|
||||
|
||||
|
||||
#endif //QCOCOAHELPERS_H
|
||||
|
@ -41,6 +41,8 @@
|
||||
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#include "qcocoaautoreleasepool.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
@ -66,6 +68,199 @@ void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void drawImageReleaseData (void *info, const void *, size_t)
|
||||
{
|
||||
delete static_cast<QImage *>(info);
|
||||
}
|
||||
|
||||
CGImageRef qt_mac_image_to_cgimage(const QImage &img)
|
||||
{
|
||||
QImage *image;
|
||||
if (img.depth() != 32)
|
||||
image = new QImage(img.convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
||||
else
|
||||
image = new QImage(img);
|
||||
|
||||
uint cgflags = kCGImageAlphaNone;
|
||||
switch (image->format()) {
|
||||
case QImage::Format_ARGB32_Premultiplied:
|
||||
cgflags = kCGImageAlphaPremultipliedFirst;
|
||||
break;
|
||||
case QImage::Format_ARGB32:
|
||||
cgflags = kCGImageAlphaFirst;
|
||||
break;
|
||||
case QImage::Format_RGB32:
|
||||
cgflags = kCGImageAlphaNoneSkipFirst;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cgflags |= kCGBitmapByteOrder32Host;
|
||||
QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(image,
|
||||
static_cast<const QImage *>(image)->bits(),
|
||||
image->byteCount(),
|
||||
drawImageReleaseData);
|
||||
|
||||
return CGImageCreate(image->width(), image->height(), 8, 32,
|
||||
image->bytesPerLine(),
|
||||
qt_mac_genericColorSpace(),
|
||||
cgflags, dataProvider, 0, false, kCGRenderingIntentDefault);
|
||||
|
||||
}
|
||||
|
||||
NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image)
|
||||
{
|
||||
QCocoaAutoReleasePool pool;
|
||||
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;
|
||||
}
|
||||
|
||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm)
|
||||
{
|
||||
QImage image = pm.toImage();
|
||||
return qt_mac_cgimage_to_nsimage(qt_mac_image_to_cgimage(image));
|
||||
}
|
||||
|
||||
|
||||
// Use this method to keep all the information in the TextSegment. As long as it is ordered
|
||||
// we are in OK shape, and we can influence that ourselves.
|
||||
struct KeyPair
|
||||
{
|
||||
QChar cocoaKey;
|
||||
Qt::Key qtKey;
|
||||
};
|
||||
|
||||
bool operator==(const KeyPair &entry, QChar qchar)
|
||||
{
|
||||
return entry.cocoaKey == qchar;
|
||||
}
|
||||
|
||||
bool operator<(const KeyPair &entry, QChar qchar)
|
||||
{
|
||||
return entry.cocoaKey < qchar;
|
||||
}
|
||||
|
||||
bool operator<(QChar qchar, const KeyPair &entry)
|
||||
{
|
||||
return qchar < entry.cocoaKey;
|
||||
}
|
||||
|
||||
bool operator<(const Qt::Key &key, const KeyPair &entry)
|
||||
{
|
||||
return key < entry.qtKey;
|
||||
}
|
||||
|
||||
bool operator<(const KeyPair &entry, const Qt::Key &key)
|
||||
{
|
||||
return entry.qtKey < key;
|
||||
}
|
||||
|
||||
static bool qtKey2CocoaKeySortLessThan(const KeyPair &entry1, const KeyPair &entry2)
|
||||
{
|
||||
return entry1.qtKey < entry2.qtKey;
|
||||
}
|
||||
|
||||
static const int NumEntries = 59;
|
||||
static const KeyPair entries[NumEntries] = {
|
||||
{ NSEnterCharacter, Qt::Key_Enter },
|
||||
{ NSBackspaceCharacter, Qt::Key_Backspace },
|
||||
{ NSTabCharacter, Qt::Key_Tab },
|
||||
{ NSNewlineCharacter, Qt::Key_Return },
|
||||
{ NSCarriageReturnCharacter, Qt::Key_Return },
|
||||
{ NSBackTabCharacter, Qt::Key_Backtab },
|
||||
{ kEscapeCharCode, Qt::Key_Escape },
|
||||
// Cocoa sends us delete when pressing backspace!
|
||||
// (NB when we reverse this list in qtKey2CocoaKey, there
|
||||
// will be two indices of Qt::Key_Backspace. But is seems to work
|
||||
// ok for menu shortcuts (which uses that function):
|
||||
{ NSDeleteCharacter, Qt::Key_Backspace },
|
||||
{ NSUpArrowFunctionKey, Qt::Key_Up },
|
||||
{ NSDownArrowFunctionKey, Qt::Key_Down },
|
||||
{ NSLeftArrowFunctionKey, Qt::Key_Left },
|
||||
{ NSRightArrowFunctionKey, Qt::Key_Right },
|
||||
{ NSF1FunctionKey, Qt::Key_F1 },
|
||||
{ NSF2FunctionKey, Qt::Key_F2 },
|
||||
{ NSF3FunctionKey, Qt::Key_F3 },
|
||||
{ NSF4FunctionKey, Qt::Key_F4 },
|
||||
{ NSF5FunctionKey, Qt::Key_F5 },
|
||||
{ NSF6FunctionKey, Qt::Key_F6 },
|
||||
{ NSF7FunctionKey, Qt::Key_F7 },
|
||||
{ NSF8FunctionKey, Qt::Key_F8 },
|
||||
{ NSF9FunctionKey, Qt::Key_F8 },
|
||||
{ NSF10FunctionKey, Qt::Key_F10 },
|
||||
{ NSF11FunctionKey, Qt::Key_F11 },
|
||||
{ NSF12FunctionKey, Qt::Key_F12 },
|
||||
{ NSF13FunctionKey, Qt::Key_F13 },
|
||||
{ NSF14FunctionKey, Qt::Key_F14 },
|
||||
{ NSF15FunctionKey, Qt::Key_F15 },
|
||||
{ NSF16FunctionKey, Qt::Key_F16 },
|
||||
{ NSF17FunctionKey, Qt::Key_F17 },
|
||||
{ NSF18FunctionKey, Qt::Key_F18 },
|
||||
{ NSF19FunctionKey, Qt::Key_F19 },
|
||||
{ NSF20FunctionKey, Qt::Key_F20 },
|
||||
{ NSF21FunctionKey, Qt::Key_F21 },
|
||||
{ NSF22FunctionKey, Qt::Key_F22 },
|
||||
{ NSF23FunctionKey, Qt::Key_F23 },
|
||||
{ NSF24FunctionKey, Qt::Key_F24 },
|
||||
{ NSF25FunctionKey, Qt::Key_F25 },
|
||||
{ NSF26FunctionKey, Qt::Key_F26 },
|
||||
{ NSF27FunctionKey, Qt::Key_F27 },
|
||||
{ NSF28FunctionKey, Qt::Key_F28 },
|
||||
{ NSF29FunctionKey, Qt::Key_F29 },
|
||||
{ NSF30FunctionKey, Qt::Key_F30 },
|
||||
{ NSF31FunctionKey, Qt::Key_F31 },
|
||||
{ NSF32FunctionKey, Qt::Key_F32 },
|
||||
{ NSF33FunctionKey, Qt::Key_F33 },
|
||||
{ NSF34FunctionKey, Qt::Key_F34 },
|
||||
{ NSF35FunctionKey, Qt::Key_F35 },
|
||||
{ NSInsertFunctionKey, Qt::Key_Insert },
|
||||
{ NSDeleteFunctionKey, Qt::Key_Delete },
|
||||
{ NSHomeFunctionKey, Qt::Key_Home },
|
||||
{ NSEndFunctionKey, Qt::Key_End },
|
||||
{ NSPageUpFunctionKey, Qt::Key_PageUp },
|
||||
{ NSPageDownFunctionKey, Qt::Key_PageDown },
|
||||
{ NSPrintScreenFunctionKey, Qt::Key_Print },
|
||||
{ NSScrollLockFunctionKey, Qt::Key_ScrollLock },
|
||||
{ NSPauseFunctionKey, Qt::Key_Pause },
|
||||
{ NSSysReqFunctionKey, Qt::Key_SysReq },
|
||||
{ NSMenuFunctionKey, Qt::Key_Menu },
|
||||
{ NSHelpFunctionKey, Qt::Key_Help },
|
||||
};
|
||||
static const KeyPair * const end = entries + NumEntries;
|
||||
|
||||
QChar qt_mac_qtKey2CocoaKey(Qt::Key key)
|
||||
{
|
||||
// The first time this function is called, create a reverse
|
||||
// looup table sorted on Qt Key rather than Cocoa key:
|
||||
static QVector<KeyPair> rev_entries(NumEntries);
|
||||
static bool mustInit = true;
|
||||
if (mustInit){
|
||||
mustInit = false;
|
||||
for (int i=0; i<NumEntries; ++i)
|
||||
rev_entries[i] = entries[i];
|
||||
qSort(rev_entries.begin(), rev_entries.end(), qtKey2CocoaKeySortLessThan);
|
||||
}
|
||||
const QVector<KeyPair>::iterator i
|
||||
= qBinaryFind(rev_entries.begin(), rev_entries.end(), key);
|
||||
if (i == rev_entries.end())
|
||||
return QChar();
|
||||
return i->cocoaKey;
|
||||
}
|
||||
|
||||
Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode)
|
||||
{
|
||||
const KeyPair *i = qBinaryFind(entries, end, keyCode);
|
||||
if (i == end)
|
||||
return Qt::Key(keyCode.unicode());
|
||||
return i->qtKey;
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
@ -118,3 +313,136 @@ void qt_mac_transformProccessToForegroundApplication()
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
CGColorSpaceRef m_genericColorSpace = 0;
|
||||
QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
|
||||
bool m_postRoutineRegistered = false;
|
||||
|
||||
CGColorSpaceRef qt_mac_genericColorSpace()
|
||||
{
|
||||
#if 0
|
||||
if (!m_genericColorSpace) {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
|
||||
m_genericColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
m_genericColorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
}
|
||||
if (!m_postRoutineRegistered) {
|
||||
m_postRoutineRegistered = true;
|
||||
qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces);
|
||||
}
|
||||
}
|
||||
return m_genericColorSpace;
|
||||
#else
|
||||
// Just return the main display colorspace for the moment.
|
||||
return qt_mac_displayColorSpace(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Ideally, we should pass the widget in here, and use CGGetDisplaysWithRect() etc.
|
||||
to support multiple displays correctly.
|
||||
*/
|
||||
CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget)
|
||||
{
|
||||
CGColorSpaceRef colorSpace;
|
||||
|
||||
CGDirectDisplayID displayID;
|
||||
CMProfileRef displayProfile = 0;
|
||||
if (widget == 0) {
|
||||
displayID = CGMainDisplayID();
|
||||
} else {
|
||||
displayID = CGMainDisplayID();
|
||||
/*
|
||||
### get correct display
|
||||
const QRect &qrect = widget->window()->geometry();
|
||||
CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
|
||||
CGDisplayCount throwAway;
|
||||
CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
|
||||
if (dErr != kCGErrorSuccess)
|
||||
return macDisplayColorSpace(0); // fall back on main display
|
||||
*/
|
||||
}
|
||||
if ((colorSpace = m_displayColorSpaceHash.value(displayID)))
|
||||
return colorSpace;
|
||||
|
||||
CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile);
|
||||
if (err == noErr) {
|
||||
colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile);
|
||||
} else if (widget) {
|
||||
return qt_mac_displayColorSpace(0); // fall back on main display
|
||||
}
|
||||
|
||||
if (colorSpace == 0)
|
||||
colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
m_displayColorSpaceHash.insert(displayID, colorSpace);
|
||||
CMCloseProfile(displayProfile);
|
||||
if (!m_postRoutineRegistered) {
|
||||
m_postRoutineRegistered = true;
|
||||
void qt_mac_cleanUpMacColorSpaces();
|
||||
qAddPostRoutine(qt_mac_cleanUpMacColorSpaces);
|
||||
}
|
||||
return colorSpace;
|
||||
}
|
||||
|
||||
void qt_mac_cleanUpMacColorSpaces()
|
||||
{
|
||||
if (m_genericColorSpace) {
|
||||
CFRelease(m_genericColorSpace);
|
||||
m_genericColorSpace = 0;
|
||||
}
|
||||
QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
|
||||
while (it != m_displayColorSpaceHash.constEnd()) {
|
||||
if (it.value())
|
||||
CFRelease(it.value());
|
||||
++it;
|
||||
}
|
||||
m_displayColorSpaceHash.clear();
|
||||
}
|
||||
|
||||
QString qt_mac_applicationName()
|
||||
{
|
||||
QString appName;
|
||||
CFTypeRef string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("CFBundleName"));
|
||||
if (string)
|
||||
appName = QCFString::toQString(static_cast<CFStringRef>(string));
|
||||
|
||||
if (appName.isEmpty()) {
|
||||
QString arg0 = qApp->arguments().at(0);
|
||||
if (arg0.contains("/")) {
|
||||
QStringList parts = arg0.split("/");
|
||||
appName = parts.at(parts.count() - 1);
|
||||
} else {
|
||||
appName = arg0;
|
||||
}
|
||||
}
|
||||
return appName;
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,9 @@ public:
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const;
|
||||
|
||||
QAbstractEventDispatcher *guiThreadEventDispatcher() const;
|
||||
|
||||
QPlatformFontDatabase *fontDatabase() const;
|
||||
QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
||||
QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
||||
|
||||
QPlatformNativeInterface *nativeInterface() const;
|
||||
private:
|
||||
|
@ -47,6 +47,11 @@
|
||||
#include "qcocoamenuloader.h"
|
||||
#include "qcocoaeventdispatcher.h"
|
||||
#include "qcocoahelpers.h"
|
||||
#include "qcocoaapplication.h"
|
||||
#include "qcocoaapplicationdelegate.h"
|
||||
#include "qmenu_mac.h"
|
||||
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
|
||||
#include <QtPlatformSupport/private/qbasicunixfontdatabase_p.h>
|
||||
|
||||
@ -78,9 +83,7 @@ QCocoaIntegration::QCocoaIntegration()
|
||||
{
|
||||
mPool = new QCocoaAutoReleasePool;
|
||||
|
||||
//Make sure we have a nsapplication :)
|
||||
[NSApplication sharedApplication];
|
||||
// [[OurApplication alloc] init];
|
||||
QNSApplication *cocoaApplication = [QNSApplication sharedApplication];
|
||||
|
||||
// Applications launched from plain executables (without an app
|
||||
// bundle) are "background" applications that does not take keybaord
|
||||
@ -93,12 +96,24 @@ QCocoaIntegration::QCocoaIntegration()
|
||||
// Ignoring other apps is neccessary (we must ignore the terminal), but makes
|
||||
// Qt apps play slightly less nice with other apps when lanching from Finder
|
||||
// (See the activateIgnoringOtherApps docs.)
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
|
||||
[cocoaApplication activateIgnoringOtherApps : YES];
|
||||
|
||||
// Load the application menu. This menu contains Preferences, Hide, Quit.
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init];
|
||||
qt_mac_loadMenuNib(qtMenuLoader);
|
||||
[[NSApplication sharedApplication] setMenu:[qtMenuLoader menu]];
|
||||
// ### For AA_MacPluginApplication we don't want to load the menu nib.
|
||||
// Qt 4 also does not set the application delegate, so that behavior
|
||||
// is matched here.
|
||||
if (!QCoreApplication::testAttribute(Qt::AA_MacPluginApplication)) {
|
||||
|
||||
// Set app delegate, link to the current delegate (if any)
|
||||
QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate];
|
||||
[newDelegate setReflectionDelegate:[cocoaApplication delegate]];
|
||||
[cocoaApplication setDelegate:newDelegate];
|
||||
|
||||
// Load the application menu. This menu contains Preferences, Hide, Quit.
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init];
|
||||
qt_mac_loadMenuNib(qtMenuLoader);
|
||||
[cocoaApplication setMenu:[qtMenuLoader menu]];
|
||||
[newDelegate setMenuLoader:qtMenuLoader];
|
||||
}
|
||||
|
||||
NSArray *screens = [NSScreen screens];
|
||||
for (uint i = 0; i < [screens count]; i++) {
|
||||
@ -149,6 +164,18 @@ QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
|
||||
return mFontDb;
|
||||
}
|
||||
|
||||
QPlatformMenu *QCocoaIntegration::createPlatformMenu(QMenu *menu) const
|
||||
{
|
||||
// return new QCocoaMenu(menu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QPlatformMenuBar *QCocoaIntegration::createPlatformMenuBar(QMenuBar *menuBar) const
|
||||
{
|
||||
//return new QCocoaMenuBar(menuBar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QPlatformNativeInterface *QCocoaIntegration::nativeInterface() const
|
||||
{
|
||||
return new QCocoaNativeInterface();
|
||||
|
@ -68,7 +68,7 @@ QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
|
||||
#endif
|
||||
|
||||
@interface QT_MANGLE_NAMESPACE(QCocoaMenu) : NSMenu <NSMenuDelegate>
|
||||
@interface QT_MANGLE_NAMESPACE(QNativeCocoaMenu) : NSMenu <NSMenuDelegate>
|
||||
{
|
||||
QMenu *qmenu;
|
||||
QAction *previousAction;
|
@ -39,18 +39,14 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmacdefines_mac.h"
|
||||
#include "qapplication.h"
|
||||
#include "qvarlengtharray.h"
|
||||
#import <private/qcocoamenu_mac_p.h>
|
||||
#import <private/qcocoamenuloader_mac_p.h>
|
||||
#import <private/qcocoaapplication_mac_p.h>
|
||||
#include <private/qt_cocoa_helpers_mac_p.h>
|
||||
#import "qcocoamenu.h"
|
||||
#import "qcocoamenuloader.h"
|
||||
#import "qcocoaapplication.h"
|
||||
#include "qcocoahelpers.h"
|
||||
#include <private/qapplication_p.h>
|
||||
#include <private/qaction_p.h>
|
||||
#include <private/qcocoaapplication_mac_p.h>
|
||||
|
||||
#include <QtWidgets/QMenu>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
QT_FORWARD_DECLARE_CLASS(QWidget)
|
||||
@ -61,14 +57,15 @@ QT_FORWARD_DECLARE_CLASS(QKeyEvent)
|
||||
QT_FORWARD_DECLARE_CLASS(QEvent)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); //qapplication.cpp
|
||||
extern void qt_mac_menu_collapseSeparators(NSMenu *menu, bool collapse);
|
||||
void qt_mac_clear_status_text(QAction *action);
|
||||
extern void qt_mac_emit_menuSignals(QMenu *menu, bool show);
|
||||
extern void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action);
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
@implementation QT_MANGLE_NAMESPACE(QCocoaMenu)
|
||||
@implementation QT_MANGLE_NAMESPACE(QNativeCocoaMenu)
|
||||
|
||||
- (id)initWithQMenu:(QMenu*)menu
|
||||
{
|
||||
@ -95,7 +92,7 @@ QT_USE_NAMESPACE
|
||||
}
|
||||
|
||||
if (QAction *action = reinterpret_cast<QAction *>([item tag])) {
|
||||
QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu;
|
||||
QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QNativeCocoaMenu) *>(menu)->qmenu;
|
||||
previousAction = action;
|
||||
action->activate(QAction::Hover);
|
||||
qt_mac_menu_emit_hovered(qtmenu, action);
|
||||
@ -108,14 +105,14 @@ QT_USE_NAMESPACE
|
||||
while (QWidget *popup
|
||||
= QApplication::activePopupWidget())
|
||||
popup->close();
|
||||
QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu;
|
||||
QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QNativeCocoaMenu) *>(menu)->qmenu;
|
||||
qt_mac_emit_menuSignals(qtmenu, true);
|
||||
qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible());
|
||||
}
|
||||
|
||||
- (void)menuDidClose:(NSMenu*)menu
|
||||
{
|
||||
qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, false);
|
||||
qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QNativeCocoaMenu) *)menu)->qmenu, false);
|
||||
if (previousAction) {
|
||||
qt_mac_clear_status_text(previousAction);
|
||||
previousAction = 0;
|
||||
@ -206,7 +203,9 @@ NSString *qt_mac_removePrivateUnicode(NSString* string)
|
||||
QKeyEvent accel_ev(QEvent::ShortcutOverride, (key & (~Qt::KeyboardModifierMask)),
|
||||
Qt::KeyboardModifiers(key & Qt::KeyboardModifierMask));
|
||||
accel_ev.ignore();
|
||||
qt_sendSpontaneousEvent(widget, &accel_ev);
|
||||
|
||||
// ### qt_sendSpontaneousEvent(widget, &accel_ev);
|
||||
|
||||
if (accel_ev.isAccepted()) {
|
||||
qWarning("Unimplemented: qt_dispatchKeyEvent");
|
||||
#if 0
|
||||
@ -226,7 +225,7 @@ NSString *qt_mac_removePrivateUnicode(NSString* string)
|
||||
NSInteger index = [super indexOfItemWithTarget:anObject andAction:actionSelector];
|
||||
static SEL selForOFCP = NSSelectorFromString(@"orderFrontCharacterPalette:");
|
||||
if (index == -1 && selForOFCP == actionSelector) {
|
||||
// Check if the 'orderFrontCharacterPalette' SEL exists for QCocoaMenuLoader object
|
||||
// Check if the 'orderFrontCharacterPalette' SEL exists for QNativeCocoaMenuLoader object
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)];
|
||||
return [super indexOfItemWithTarget:loader andAction:actionSelector];
|
||||
}
|
@ -41,10 +41,14 @@
|
||||
|
||||
#include "qcocoamenuloader.h"
|
||||
|
||||
#include "qmenu_mac.h"
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#include <QtCore/private/qcore_mac_p.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qdir.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QCFString)
|
||||
QT_FORWARD_DECLARE_CLASS(QString)
|
||||
@ -113,7 +117,7 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
||||
showAllItem = [[appMenu itemWithTitle:@"Show All"] retain];
|
||||
|
||||
// Get the names in the nib to match the app name set by Qt.
|
||||
const NSString *appName = reinterpret_cast<const NSString*>(QCFString::toCFStringRef(qAppName()));
|
||||
const NSString *appName = reinterpret_cast<const NSString*>(QCFString::toCFStringRef(qt_mac_applicationName()));
|
||||
[quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
|
||||
withString:const_cast<NSString *>(appName)]];
|
||||
[hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
|
||||
@ -269,28 +273,29 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
||||
|
||||
- (void)qtUpdateMenubar
|
||||
{
|
||||
// QMenuBarPrivate::macUpdateMenuBarImmediatly();
|
||||
QCocoaMenuBar::macUpdateMenuBarImmediatly();
|
||||
}
|
||||
|
||||
- (void)qtTranslateApplicationMenu
|
||||
{
|
||||
/*
|
||||
|
||||
qDebug() << "qtTranslateApplicationMenu";
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
[servicesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(0))];
|
||||
[hideItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(1).arg(qAppName()))];
|
||||
[hideItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(1).arg(qt_mac_applicationName()))];
|
||||
[hideAllOthersItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(2))];
|
||||
[showAllItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(3))];
|
||||
[preferencesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(4))];
|
||||
[quitItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(5).arg(qAppName()))];
|
||||
[aboutItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(6).arg(qAppName()))];
|
||||
[quitItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName()))];
|
||||
[aboutItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()))];
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
- (IBAction)qtDispatcherToQAction:(id)sender
|
||||
{
|
||||
/*
|
||||
QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
|
||||
//
|
||||
//QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
|
||||
NSMenuItem *item = static_cast<NSMenuItem *>(sender);
|
||||
if (QAction *action = reinterpret_cast<QAction *>([item tag])) {
|
||||
action->trigger();
|
||||
@ -300,7 +305,6 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
||||
// normal QApplication::quit().
|
||||
qApp->quit();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)orderFrontCharacterPalette:(id)sender
|
||||
|
85
src/plugins/platforms/cocoa/qmenu_mac.h
Normal file
85
src/plugins/platforms/cocoa/qmenu_mac.h
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
#include <private/qt_mac_p.h>
|
||||
#include <QtCore/qpointer.h>
|
||||
#include <QtWidgets/qmenu.h>
|
||||
#include <QtWidgets/qmenubar.h>
|
||||
#include <QtWidgets/qplatformmenu_qpa.h>
|
||||
|
||||
@class NSMenuItem;
|
||||
class QCocoaMenuAction : public QPlatformMenuAction
|
||||
{
|
||||
public:
|
||||
QCocoaMenuAction();
|
||||
~QCocoaMenuAction();
|
||||
|
||||
NSMenuItem *menuItem;
|
||||
uchar ignore_accel : 1;
|
||||
uchar merged : 1;
|
||||
OSMenuRef menu;
|
||||
QPointer<QMenu> qtMenu;
|
||||
};
|
||||
|
||||
struct QMenuMergeItem
|
||||
{
|
||||
inline QMenuMergeItem(NSMenuItem *c, QCocoaMenuAction *a) : menuItem(c), action(a) { }
|
||||
NSMenuItem *menuItem;
|
||||
QCocoaMenuAction *action;
|
||||
};
|
||||
typedef QList<QMenuMergeItem> QMenuMergeList;
|
||||
|
||||
class QCocoaMenu : public QPlatformMenu
|
||||
{
|
||||
public:
|
||||
QCocoaMenu(QMenu *qtMenu);
|
||||
~QCocoaMenu();
|
||||
|
||||
OSMenuRef macMenu(OSMenuRef merge = 0);
|
||||
void syncSeparatorsCollapsible(bool collapse);
|
||||
void setMenuEnabled(bool enable);
|
||||
|
||||
void addAction(QAction *action, QAction *before);
|
||||
void syncAction(QAction *action);
|
||||
void removeAction(QAction *action);
|
||||
|
||||
void addAction(QCocoaMenuAction *action, QCocoaMenuAction *before);
|
||||
void syncAction(QCocoaMenuAction *action);
|
||||
void removeAction(QCocoaMenuAction *action);
|
||||
bool merged(const QAction *action) const;
|
||||
QCocoaMenuAction *findAction(QAction *action) const;
|
||||
|
||||
OSMenuRef menu;
|
||||
static QHash<OSMenuRef, OSMenuRef> mergeMenuHash;
|
||||
static QHash<OSMenuRef, QMenuMergeList*> mergeMenuItemsHash;
|
||||
QList<QCocoaMenuAction*> actionItems;
|
||||
QMenu *qtMenu;
|
||||
};
|
||||
|
||||
class QCocoaMenuBar : public QPlatformMenuBar
|
||||
{
|
||||
public:
|
||||
QCocoaMenuBar(QMenuBar *qtMenuBar);
|
||||
~QCocoaMenuBar();
|
||||
|
||||
void handleReparent(QWidget *newParent);
|
||||
|
||||
void addAction(QAction *action, QAction *before);
|
||||
void syncAction(QAction *action);
|
||||
void removeAction(QAction *action);
|
||||
|
||||
void addAction(QCocoaMenuAction *action, QCocoaMenuAction *before);
|
||||
void syncAction(QCocoaMenuAction *action);
|
||||
void removeAction(QCocoaMenuAction *action);
|
||||
|
||||
bool macWidgetHasNativeMenubar(QWidget *widget);
|
||||
void macCreateMenuBar(QWidget *parent);
|
||||
void macDestroyMenuBar();
|
||||
OSMenuRef macMenu();
|
||||
static bool macUpdateMenuBarImmediatly();
|
||||
static void macUpdateMenuBar();
|
||||
QCocoaMenuAction *findAction(QAction *action) const;
|
||||
|
||||
OSMenuRef menu;
|
||||
OSMenuRef apple_menu;
|
||||
QList<QCocoaMenuAction*> actionItems;
|
||||
QMenuBar *qtMenuBar;
|
||||
};
|
@ -39,29 +39,30 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmenu_mac.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include "qmenu.h"
|
||||
#include "qhash.h"
|
||||
#include <qdebug.h>
|
||||
#include "qapplication.h"
|
||||
#include <private/qt_mac_p.h>
|
||||
#include "qregexp.h"
|
||||
#include "qmainwindow.h"
|
||||
#include "qdockwidget.h"
|
||||
#include "qtoolbar.h"
|
||||
#include "qevent.h"
|
||||
#include "qstyle.h"
|
||||
#include "qwidgetaction.h"
|
||||
#include "qmacnativewidget_mac.h"
|
||||
|
||||
#include <private/qapplication_p.h>
|
||||
#include <private/qcocoaapplication_mac_p.h>
|
||||
#include <private/qmenu_p.h>
|
||||
#include <private/qmenubar_p.h>
|
||||
#include <private/qcocoamenuloader_mac_p.h>
|
||||
#include <private/qcocoamenu_mac_p.h>
|
||||
#include <private/qt_cocoa_helpers_mac_p.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
|
||||
#include "qcocoahelpers.h"
|
||||
#include "qcocoaapplication.h"
|
||||
#include "qcocoamenuloader.h"
|
||||
#include "qcocoamenu.h"
|
||||
#include "qcocoahelpers.h"
|
||||
#include "qcocoaautoreleasepool.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -78,23 +79,6 @@ int qt_mac_menus_open_count = 0;
|
||||
|
||||
static OSMenuRef qt_mac_create_menu(QWidget *w);
|
||||
|
||||
#ifndef QT_MAC_USE_COCOA
|
||||
static uint qt_mac_menu_static_cmd_id = 'QT00';
|
||||
const UInt32 kMenuCreatorQt = 'cute';
|
||||
enum {
|
||||
kMenuPropertyQAction = 'QAcT',
|
||||
kMenuPropertyQWidget = 'QWId',
|
||||
kMenuPropertyCausedQWidget = 'QCAU',
|
||||
kMenuPropertyMergeMenu = 'QApP',
|
||||
kMenuPropertyMergeList = 'QAmL',
|
||||
kMenuPropertyWidgetActionWidget = 'QWid',
|
||||
kMenuPropertyWidgetMenu = 'QWMe',
|
||||
|
||||
kHICommandAboutQt = 'AOQT',
|
||||
kHICommandCustomMerge = 'AQt0'
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
QPointer<QMenuBar> qmenubar;
|
||||
bool modal;
|
||||
@ -107,7 +91,6 @@ static struct {
|
||||
Externals
|
||||
*****************************************************************************/
|
||||
extern OSViewRef qt_mac_hiview_for(const QWidget *w); //qwidget_mac.cpp
|
||||
extern HIViewRef qt_mac_hiview_for(OSWindowRef w); //qwidget_mac.cpp
|
||||
extern IconRef qt_mac_create_iconref(const QPixmap &px); //qpixmap_mac.cpp
|
||||
extern QWidget * mac_keyboard_grabber; //qwidget_mac.cpp
|
||||
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); //qapplication_xxx.cpp
|
||||
@ -132,7 +115,7 @@ static int qt_mac_CountMenuItems(OSMenuRef menu)
|
||||
|
||||
void qt_mac_menu_collapseSeparators(NSMenu * theMenu, bool collapse)
|
||||
{
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
OSMenuRef menu = static_cast<OSMenuRef>(theMenu);
|
||||
if (collapse) {
|
||||
bool previousIsSeparator = true; // setting to true kills all the separators placed at the top.
|
||||
@ -192,23 +175,6 @@ static quint32 constructModifierMask(quint32 accel_key)
|
||||
{
|
||||
quint32 ret = 0;
|
||||
const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
|
||||
#ifndef QT_MAC_USE_COCOA
|
||||
if ((accel_key & Qt::ALT) == Qt::ALT)
|
||||
ret |= kMenuOptionModifier;
|
||||
if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
|
||||
ret |= kMenuShiftModifier;
|
||||
if (dontSwap) {
|
||||
if ((accel_key & Qt::META) != Qt::META)
|
||||
ret |= kMenuNoCommandModifier;
|
||||
if ((accel_key & Qt::CTRL) == Qt::CTRL)
|
||||
ret |= kMenuControlModifier;
|
||||
} else {
|
||||
if ((accel_key & Qt::CTRL) != Qt::CTRL)
|
||||
ret |= kMenuNoCommandModifier;
|
||||
if ((accel_key & Qt::META) == Qt::META)
|
||||
ret |= kMenuControlModifier;
|
||||
}
|
||||
#else
|
||||
if ((accel_key & Qt::CTRL) == Qt::CTRL)
|
||||
ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask);
|
||||
if ((accel_key & Qt::META) == Qt::META)
|
||||
@ -217,13 +183,12 @@ static quint32 constructModifierMask(quint32 accel_key)
|
||||
ret |= NSAlternateKeyMask;
|
||||
if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
|
||||
ret |= NSShiftKeyMask;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void cancelAllMenuTracking()
|
||||
{
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
NSMenu *mainMenu = [NSApp mainMenu];
|
||||
[mainMenu cancelTracking];
|
||||
for (NSMenuItem *item in [mainMenu itemArray]) {
|
||||
@ -233,14 +198,15 @@ static void cancelAllMenuTracking()
|
||||
}
|
||||
}
|
||||
|
||||
static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp,
|
||||
const QMacMenuAction *action)
|
||||
static bool actualMenuItemVisibility(const QCocoaMenuBar *mbp,
|
||||
const QCocoaMenuAction *action)
|
||||
{
|
||||
bool visible = action->action->isVisible();
|
||||
if (visible && action->action->text() == QString(QChar(0x14)))
|
||||
return false;
|
||||
|
||||
if (visible && action->action->menu() && !action->action->menu()->actions().isEmpty() &&
|
||||
!qt_mac_CountMenuItems(action->action->menu()->macMenu(mbp->apple_menu)) &&
|
||||
/* ### !qt_mac_CountMenuItems(cocoaMenu->macMenu(mbp->apple_menu)) &&*/
|
||||
!qt_mac_watchingAboutToShow(action->action->menu())) {
|
||||
return false;
|
||||
}
|
||||
@ -261,11 +227,11 @@ static inline void syncNSMenuItemEnabled(NSMenuItem *menuItem, bool enabled)
|
||||
[menuItem setEnabled:enabled];
|
||||
}
|
||||
|
||||
static inline void syncMenuBarItemsVisiblity(const QMenuBarPrivate::QMacMenuBarPrivate *mac_menubar)
|
||||
static inline void syncMenuBarItemsVisiblity(const QCocoaMenuBar *mac_menubar)
|
||||
{
|
||||
const QList<QMacMenuAction *> &menubarActions = mac_menubar->actionItems;
|
||||
const QList<QCocoaMenuAction *> &menubarActions = mac_menubar->actionItems;
|
||||
for (int i = 0; i < menubarActions.size(); ++i) {
|
||||
const QMacMenuAction *action = menubarActions.at(i);
|
||||
const QCocoaMenuAction *action = menubarActions.at(i);
|
||||
syncNSMenuItemVisiblity(action->menuItem, actualMenuItemVisibility(mac_menubar, action));
|
||||
}
|
||||
}
|
||||
@ -321,7 +287,7 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo
|
||||
//toggling of modal state
|
||||
static void qt_mac_set_modal_state(OSMenuRef menu, bool on)
|
||||
{
|
||||
OSMenuRef merge = QMenuPrivate::mergeMenuHash.value(menu);
|
||||
OSMenuRef merge = QCocoaMenu::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()
|
||||
}
|
||||
@ -331,7 +297,7 @@ bool qt_mac_menubar_is_open()
|
||||
return qt_mac_menus_open_count > 0;
|
||||
}
|
||||
|
||||
QMacMenuAction::~QMacMenuAction()
|
||||
QCocoaMenuAction::~QCocoaMenuAction()
|
||||
{
|
||||
[menu release];
|
||||
// Update the menu item if this action still owns it. For some items
|
||||
@ -352,7 +318,7 @@ QMacMenuAction::~QMacMenuAction()
|
||||
[menuItem release];
|
||||
}
|
||||
|
||||
static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *action)
|
||||
static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QCocoaMenuAction *action)
|
||||
{
|
||||
if (qt_mac_no_menubar_merge || action->action->menu() || action->action->isSeparator()
|
||||
|| action->action->menuRole() == QAction::NoRole)
|
||||
@ -408,7 +374,7 @@ static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *act
|
||||
break;
|
||||
}
|
||||
|
||||
if (QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge)) {
|
||||
if (QMenuMergeList *list = QCocoaMenu::mergeMenuItemsHash.value(merge)) {
|
||||
for(int i = 0; i < list->size(); ++i) {
|
||||
const QMenuMergeItem &item = list->at(i);
|
||||
if (item.menuItem == ret && item.action)
|
||||
@ -419,7 +385,7 @@ static NSMenuItem *qt_mac_menu_merge_action(OSMenuRef merge, QMacMenuAction *act
|
||||
return ret;
|
||||
}
|
||||
|
||||
static QString qt_mac_menu_merge_text(QMacMenuAction *action)
|
||||
static QString qt_mac_menu_merge_text(QCocoaMenuAction *action)
|
||||
{
|
||||
QString ret;
|
||||
extern QString qt_mac_applicationmenu_string(int type);
|
||||
@ -427,7 +393,7 @@ static QString qt_mac_menu_merge_text(QMacMenuAction *action)
|
||||
if (action->action->menuRole() == QAction::ApplicationSpecificRole)
|
||||
ret = action->action->text();
|
||||
else if (action->menuItem == [loader aboutMenuItem]) {
|
||||
ret = qt_mac_applicationmenu_string(6).arg(qAppName());
|
||||
ret = qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName());
|
||||
} else if (action->menuItem == [loader aboutQtMenuItem]) {
|
||||
if (action->action->text() == QString("About Qt"))
|
||||
ret = QMenuBar::tr("About Qt");
|
||||
@ -436,12 +402,12 @@ static QString qt_mac_menu_merge_text(QMacMenuAction *action)
|
||||
} else if (action->menuItem == [loader preferencesMenuItem]) {
|
||||
ret = qt_mac_applicationmenu_string(4);
|
||||
} else if (action->menuItem == [loader quitMenuItem]) {
|
||||
ret = qt_mac_applicationmenu_string(5).arg(qAppName());
|
||||
ret = qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action)
|
||||
static QKeySequence qt_mac_menu_merge_accel(QCocoaMenuAction *action)
|
||||
{
|
||||
QKeySequence ret;
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
@ -463,15 +429,23 @@ void Q_WIDGETS_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge
|
||||
/*****************************************************************************
|
||||
QMenu bindings
|
||||
*****************************************************************************/
|
||||
QMenuPrivate::QMacMenuPrivate::QMacMenuPrivate() : menu(0)
|
||||
|
||||
QCocoaMenuAction::QCocoaMenuAction()
|
||||
: menuItem(0)
|
||||
, ignore_accel(0), merged(0), menu(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QCocoaMenu::QCocoaMenu(QMenu *a_qtMenu) : menu(0), qtMenu(a_qtMenu)
|
||||
{
|
||||
}
|
||||
|
||||
QMenuPrivate::QMacMenuPrivate::~QMacMenuPrivate()
|
||||
QCocoaMenu::~QCocoaMenu()
|
||||
{
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
while (actionItems.size()) {
|
||||
QMacMenuAction *action = actionItems.takeFirst();
|
||||
QCocoaMenuAction *action = static_cast<QCocoaMenuAction *>(actionItems.takeFirst());
|
||||
if (QMenuMergeList *list = mergeMenuItemsHash.value(action->menu)) {
|
||||
int i = 0;
|
||||
while (i < list->size()) {
|
||||
@ -489,22 +463,23 @@ QMenuPrivate::QMacMenuPrivate::~QMacMenuPrivate()
|
||||
[menu release];
|
||||
}
|
||||
|
||||
void
|
||||
QMenuPrivate::QMacMenuPrivate::addAction(QAction *a, QMacMenuAction *before, QMenuPrivate *qmenu)
|
||||
|
||||
void QCocoaMenu::addAction(QAction *a, QAction *before)
|
||||
{
|
||||
QMacMenuAction *action = new QMacMenuAction;
|
||||
QCocoaMenuAction *action = new QCocoaMenuAction;
|
||||
action->action = a;
|
||||
action->ignore_accel = 0;
|
||||
action->merged = 0;
|
||||
action->menu = 0;
|
||||
addAction(action, before, qmenu);
|
||||
|
||||
QCocoaMenuAction *cocoaBefore = findAction(before);
|
||||
addAction(action, cocoaBefore);
|
||||
}
|
||||
|
||||
void
|
||||
QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction *before, QMenuPrivate *qmenu)
|
||||
|
||||
void QCocoaMenu::addAction(QCocoaMenuAction *action, QCocoaMenuAction *before)
|
||||
{
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
Q_UNUSED(qmenu);
|
||||
QCocoaAutoReleasePool pool;
|
||||
if (!action)
|
||||
return;
|
||||
int before_index = actionItems.indexOf(before);
|
||||
@ -521,7 +496,7 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction
|
||||
/* When the action is considered a mergable action it
|
||||
will stay that way, until removed.. */
|
||||
if (!qt_mac_no_menubar_merge) {
|
||||
OSMenuRef merge = QMenuPrivate::mergeMenuHash.value(menu);
|
||||
OSMenuRef merge = QCocoaMenu::mergeMenuHash.value(menu);
|
||||
if (merge) {
|
||||
if (NSMenuItem *cmd = qt_mac_menu_merge_action(merge, action)) {
|
||||
action->merged = 1;
|
||||
@ -533,10 +508,10 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction
|
||||
[cmd setTarget:nil];
|
||||
[action->menuItem release];
|
||||
action->menuItem = cmd;
|
||||
QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge);
|
||||
QMenuMergeList *list = QCocoaMenu::mergeMenuItemsHash.value(merge);
|
||||
if (!list) {
|
||||
list = new QMenuMergeList;
|
||||
QMenuPrivate::mergeMenuItemsHash.insert(merge, list);
|
||||
QCocoaMenu::mergeMenuItemsHash.insert(merge, list);
|
||||
}
|
||||
list->append(QMenuMergeItem(cmd, action));
|
||||
}
|
||||
@ -552,48 +527,45 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction
|
||||
} else {
|
||||
[menu addItem:newItem];
|
||||
}
|
||||
|
||||
QWidget *widget = qmenu ? qmenu->widgetItems.value(action->action) : 0;
|
||||
if (widget) {
|
||||
qWarning("QMacMenuPrivate: Widgets in menus not implemented.");
|
||||
#if 0
|
||||
|
||||
QMacNativeWidget *container = new QMacNativeWidget(0);
|
||||
container->resize(widget->sizeHint());
|
||||
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
widget->setParent(container);
|
||||
|
||||
NSView *containerView = qt_mac_nativeview_for(container);
|
||||
[containerView setAutoresizesSubviews:YES];
|
||||
[containerView setAutoresizingMask:NSViewWidthSizable];
|
||||
[qt_mac_nativeview_for(widget) setAutoresizingMask:NSViewWidthSizable];
|
||||
|
||||
[newItem setView:containerView];
|
||||
container->show();
|
||||
widget->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
} else {
|
||||
[newItem setEnabled:!QApplicationPrivate::modalState()];
|
||||
[newItem setEnabled:YES];
|
||||
// ###
|
||||
//[newItem setEnabled:!QApplicationPrivate::modalState()];
|
||||
|
||||
}
|
||||
[newItem setTag:long(static_cast<QAction *>(action->action))];
|
||||
syncAction(action);
|
||||
}
|
||||
|
||||
void QCocoaMenu::syncAction(QAction *a)
|
||||
{
|
||||
syncAction(findAction(a));
|
||||
}
|
||||
|
||||
void QCocoaMenu::removeAction(QAction *a)
|
||||
{
|
||||
removeAction(findAction(a));
|
||||
}
|
||||
|
||||
QCocoaMenuAction *QCocoaMenu::findAction(QAction *action) const
|
||||
{
|
||||
for (int i = 0; i < actionItems.size(); i++) {
|
||||
QCocoaMenuAction *act = actionItems[i];
|
||||
if (action == act->action)
|
||||
return act;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 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));
|
||||
QChar cocoa_key = qt_mac_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).
|
||||
@ -602,8 +574,7 @@ NSUInteger keySequenceModifierMask(const QKeySequence &accel)
|
||||
return constructModifierMask(accel[0]);
|
||||
}
|
||||
|
||||
void
|
||||
QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
|
||||
void QCocoaMenu::syncAction(QCocoaMenuAction *action)
|
||||
{
|
||||
if (!action)
|
||||
return;
|
||||
@ -612,7 +583,7 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
NSMenu *menu = [item menu];
|
||||
bool actionVisible = action->action->isVisible();
|
||||
[item setHidden:!actionVisible];
|
||||
@ -678,7 +649,7 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
|
||||
attributes:attributes] autorelease];
|
||||
[item setAttributedTitle: str];
|
||||
} else {
|
||||
[item setTitle: qt_mac_QStringToNSString(finalString)];
|
||||
[item setTitle: qt_mac_QStringToNSString(finalString)];
|
||||
}
|
||||
|
||||
if (action->action->menuRole() == QAction::AboutRole || action->action->menuRole() == QAction::QuitRole)
|
||||
@ -698,7 +669,8 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
|
||||
[nsimage release];
|
||||
|
||||
if (action->action->menu()) { //submenu
|
||||
NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu());
|
||||
QCocoaMenu *cocoaMenu = static_cast<QCocoaMenu *>(action->action->menu()->platformMenu());
|
||||
NSMenu *subMenu = cocoaMenu->macMenu();
|
||||
if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) {
|
||||
// The menu is already a sub-menu of another one. Cocoa will throw an exception,
|
||||
// in such cases. For the time being, a new QMenu with same set of actions is the
|
||||
@ -722,12 +694,11 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
|
||||
[item setState:action->action->isChecked() ? NSOnState : NSOffState];
|
||||
}
|
||||
|
||||
void
|
||||
QMenuPrivate::QMacMenuPrivate::removeAction(QMacMenuAction *action)
|
||||
void QCocoaMenu::removeAction(QCocoaMenuAction *action)
|
||||
{
|
||||
if (!action)
|
||||
return;
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
if (action->merged) {
|
||||
if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->action) {
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
@ -743,55 +714,45 @@ QMenuPrivate::QMacMenuPrivate::removeAction(QMacMenuAction *action)
|
||||
actionItems.removeAll(action);
|
||||
}
|
||||
|
||||
OSMenuRef
|
||||
QMenuPrivate::macMenu(OSMenuRef merge)
|
||||
OSMenuRef QCocoaMenu::macMenu(OSMenuRef merge)
|
||||
{
|
||||
Q_UNUSED(merge);
|
||||
Q_Q(QMenu);
|
||||
if (mac_menu && mac_menu->menu)
|
||||
return mac_menu->menu;
|
||||
if (!mac_menu)
|
||||
mac_menu = new QMacMenuPrivate;
|
||||
mac_menu->menu = qt_mac_create_menu(q);
|
||||
if (menu)
|
||||
return menu;
|
||||
menu = qt_mac_create_menu(qtMenu);
|
||||
if (merge) {
|
||||
mergeMenuHash.insert(mac_menu->menu, merge);
|
||||
mergeMenuHash.insert(menu, merge);
|
||||
}
|
||||
QList<QAction*> items = q->actions();
|
||||
QList<QAction*> items = qtMenu->actions();
|
||||
for(int i = 0; i < items.count(); i++)
|
||||
mac_menu->addAction(items[i], 0, this);
|
||||
syncSeparatorsCollapsible(collapsibleSeparators);
|
||||
return mac_menu->menu;
|
||||
addAction(items[i], 0);
|
||||
syncSeparatorsCollapsible(qtMenu->separatorsCollapsible());
|
||||
return menu;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void
|
||||
QMenuPrivate::syncSeparatorsCollapsible(bool collapse)
|
||||
QCocoaMenu::syncSeparatorsCollapsible(bool collapse)
|
||||
{
|
||||
qt_mac_menu_collapseSeparators(mac_menu->menu, collapse);
|
||||
qt_mac_menu_collapseSeparators(menu, collapse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void QMenuPrivate::setMacMenuEnabled(bool enable)
|
||||
void QCocoaMenu::setMenuEnabled(bool enable)
|
||||
{
|
||||
if (!macMenu(0))
|
||||
return;
|
||||
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
if (enable) {
|
||||
for (int i = 0; i < mac_menu->actionItems.count(); ++i) {
|
||||
QMacMenuAction *menuItem = mac_menu->actionItems.at(i);
|
||||
for (int i = 0; i < actionItems.count(); ++i) {
|
||||
QCocoaMenuAction *menuItem = static_cast<QCocoaMenuAction *>(actionItems.at(i));
|
||||
if (menuItem && menuItem->action && menuItem->action->isEnabled()) {
|
||||
[menuItem->menuItem setEnabled:true];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NSMenu *menu = mac_menu->menu;
|
||||
NSMenu *menu = menu;
|
||||
for (NSMenuItem *item in [menu itemArray]) {
|
||||
[item setEnabled:false];
|
||||
}
|
||||
@ -813,7 +774,7 @@ void QMenuPrivate::setMacMenuEnabled(bool enable)
|
||||
|
||||
\sa QMenuBar::macMenu()
|
||||
*/
|
||||
OSMenuRef QMenu::macMenu(OSMenuRef merge) { return d_func()->macMenu(merge); }
|
||||
/// OSMenuRef QMenu::macMenu(OSMenuRef merge) { return d_func()->macMenu(merge); }
|
||||
|
||||
/*****************************************************************************
|
||||
QMenuBar bindings
|
||||
@ -821,31 +782,43 @@ OSMenuRef QMenu::macMenu(OSMenuRef merge) { return d_func()->macMenu(merge); }
|
||||
typedef QHash<QWidget *, QMenuBar *> MenuBarHash;
|
||||
Q_GLOBAL_STATIC(MenuBarHash, menubars)
|
||||
static QMenuBar *fallback = 0;
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::QMacMenuBarPrivate() : menu(0), apple_menu(0)
|
||||
|
||||
QCocoaMenuBar::QCocoaMenuBar(QMenuBar *a_qtMenuBar) : menu(0), apple_menu(0), qtMenuBar(a_qtMenuBar)
|
||||
{
|
||||
macCreateMenuBar(qtMenuBar->parentWidget());
|
||||
}
|
||||
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::~QMacMenuBarPrivate()
|
||||
QCocoaMenuBar::~QCocoaMenuBar()
|
||||
{
|
||||
for(QList<QMacMenuAction*>::Iterator it = actionItems.begin(); it != actionItems.end(); ++it)
|
||||
for(QList<QCocoaMenuAction*>::Iterator it = actionItems.begin(); it != actionItems.end(); ++it)
|
||||
delete (*it);
|
||||
[apple_menu release];
|
||||
[menu release];
|
||||
}
|
||||
|
||||
void
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QMacMenuAction *before)
|
||||
void QCocoaMenuBar::handleReparent(QWidget *newParent)
|
||||
{
|
||||
if (a->isSeparator() || !menu)
|
||||
return;
|
||||
QMacMenuAction *action = new QMacMenuAction;
|
||||
action->action = a;
|
||||
action->ignore_accel = 1;
|
||||
addAction(action, before);
|
||||
if (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
|
||||
// menubar has precedence over children menubars).
|
||||
macDestroyMenuBar();
|
||||
macCreateMenuBar(newParent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::addAction(QMacMenuAction *action, QMacMenuAction *before)
|
||||
void QCocoaMenuBar::addAction(QAction *action, QAction *beforeAction)
|
||||
{
|
||||
if (action->isSeparator() || !menu)
|
||||
return;
|
||||
QCocoaMenuAction *cocoaAction = new QCocoaMenuAction;
|
||||
cocoaAction->action = action;
|
||||
cocoaAction->ignore_accel = 1;
|
||||
QCocoaMenuAction *cocoaBeforeAction = findAction(beforeAction);
|
||||
addAction(cocoaAction, cocoaBeforeAction);
|
||||
}
|
||||
|
||||
void QCocoaMenuBar::addAction(QCocoaMenuAction *action, QCocoaMenuAction *before)
|
||||
{
|
||||
if (!action || !menu)
|
||||
return;
|
||||
@ -860,7 +833,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QMacMenuAction *action, QMacMenuA
|
||||
MenuItemIndex index = actionItems.size()-1;
|
||||
|
||||
action->menu = menu;
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
[action->menu retain];
|
||||
NSMenuItem *newItem = createNSMenuItem(action->action->text());
|
||||
action->menuItem = newItem;
|
||||
@ -875,19 +848,24 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QMacMenuAction *action, QMacMenuA
|
||||
syncAction(action);
|
||||
}
|
||||
|
||||
void
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::syncAction(QMacMenuAction *action)
|
||||
|
||||
void QCocoaMenuBar::syncAction(QCocoaMenuAction *action)
|
||||
{
|
||||
if (!action || !menu)
|
||||
return;
|
||||
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
NSMenuItem *item = action->menuItem;
|
||||
|
||||
OSMenuRef submenu = 0;
|
||||
bool release_submenu = false;
|
||||
if (action->action->menu()) {
|
||||
if ((submenu = action->action->menu()->macMenu(apple_menu))) {
|
||||
QCocoaMenu *cocoaMenu = static_cast<QCocoaMenu *>(action->action->menu()->platformMenu());
|
||||
if (!cocoaMenu) {
|
||||
|
||||
}
|
||||
|
||||
if ((submenu = cocoaMenu->macMenu(apple_menu))) {
|
||||
if ([submenu supermenu] && [submenu supermenu] != [item menu])
|
||||
return;
|
||||
else
|
||||
@ -908,17 +886,37 @@ QMenuBarPrivate::QMacMenuBarPrivate::syncAction(QMacMenuAction *action)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
QMenuBarPrivate::QMacMenuBarPrivate::removeAction(QMacMenuAction *action)
|
||||
|
||||
void QCocoaMenuBar::removeAction(QCocoaMenuAction *action)
|
||||
{
|
||||
if (!action || !menu)
|
||||
return;
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
[action->menu removeItem:action->menuItem];
|
||||
actionItems.removeAll(action);
|
||||
}
|
||||
|
||||
bool QMenuBarPrivate::macWidgetHasNativeMenubar(QWidget *widget)
|
||||
void QCocoaMenuBar::syncAction(QAction *a)
|
||||
{
|
||||
syncAction(findAction(a));
|
||||
}
|
||||
|
||||
void QCocoaMenuBar::removeAction(QAction *a)
|
||||
{
|
||||
removeAction(findAction(a));
|
||||
}
|
||||
|
||||
QCocoaMenuAction *QCocoaMenuBar::findAction(QAction *action) const
|
||||
{
|
||||
for (int i = 0; i < actionItems.size(); i++) {
|
||||
QCocoaMenuAction *act = actionItems[i];
|
||||
if (action == act->action)
|
||||
return act;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool QCocoaMenuBar::macWidgetHasNativeMenubar(QWidget *widget)
|
||||
{
|
||||
// This function is different from q->isNativeMenuBar(), as
|
||||
// it returns true only if a native menu bar is actually
|
||||
@ -928,16 +926,14 @@ bool QMenuBarPrivate::macWidgetHasNativeMenubar(QWidget *widget)
|
||||
return menubars()->contains(widget->window());
|
||||
}
|
||||
|
||||
void
|
||||
QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
|
||||
void QCocoaMenuBar::macCreateMenuBar(QWidget *parent)
|
||||
{
|
||||
Q_Q(QMenuBar);
|
||||
static int dontUseNativeMenuBar = -1;
|
||||
// We call the isNativeMenuBar function here
|
||||
// because that will make sure that local overrides
|
||||
// are dealt with correctly. q->isNativeMenuBar() will, if not
|
||||
// overridden, depend on the attribute Qt::AA_DontUseNativeMenuBar:
|
||||
bool qt_mac_no_native_menubar = !q->isNativeMenuBar();
|
||||
bool qt_mac_no_native_menubar = !qtMenuBar->isNativeMenuBar();
|
||||
if (qt_mac_no_native_menubar == false && dontUseNativeMenuBar < 0) {
|
||||
// The menubar is set to be native. Let's check (one time only
|
||||
// for all menubars) if this is OK with the rest of the environment.
|
||||
@ -947,65 +943,59 @@ QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
|
||||
bool environmentSaysNo = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty();
|
||||
dontUseNativeMenuBar = isPlugin || environmentSaysNo;
|
||||
QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, dontUseNativeMenuBar);
|
||||
qt_mac_no_native_menubar = !q->isNativeMenuBar();
|
||||
qt_mac_no_native_menubar = !qtMenuBar->isNativeMenuBar();
|
||||
}
|
||||
if (qt_mac_no_native_menubar == false) {
|
||||
// INVARIANT: Use native menubar.
|
||||
QMenuBar::macUpdateMenuBar();
|
||||
macUpdateMenuBar();
|
||||
if (!parent && !fallback) {
|
||||
fallback = q;
|
||||
mac_menubar = new QMacMenuBarPrivate;
|
||||
fallback = qtMenuBar;
|
||||
} else if (parent && parent->isWindow()) {
|
||||
menubars()->insert(q->window(), q);
|
||||
mac_menubar = new QMacMenuBarPrivate;
|
||||
menubars()->insert(qtMenuBar->window(), qtMenuBar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QMenuBarPrivate::macDestroyMenuBar()
|
||||
void QCocoaMenuBar::macDestroyMenuBar()
|
||||
{
|
||||
Q_Q(QMenuBar);
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
if (fallback == q)
|
||||
QCocoaAutoReleasePool pool;
|
||||
if (fallback == qtMenuBar)
|
||||
fallback = 0;
|
||||
delete mac_menubar;
|
||||
QWidget *tlw = q->window();
|
||||
QWidget *tlw = qtMenuBar->window();
|
||||
menubars()->remove(tlw);
|
||||
mac_menubar = 0;
|
||||
|
||||
if (!qt_mac_current_menubar.qmenubar || qt_mac_current_menubar.qmenubar == q) {
|
||||
if (!qt_mac_current_menubar.qmenubar || qt_mac_current_menubar.qmenubar == qtMenuBar) {
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
[loader removeActionsFromAppMenu];
|
||||
QMenuBar::macUpdateMenuBar();
|
||||
QCocoaMenuBar::macUpdateMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
OSMenuRef QMenuBarPrivate::macMenu()
|
||||
OSMenuRef QCocoaMenuBar::macMenu()
|
||||
{
|
||||
Q_Q(QMenuBar);
|
||||
if (!q->isNativeMenuBar() || !mac_menubar) {
|
||||
if (!qtMenuBar->isNativeMenuBar()) {
|
||||
return 0;
|
||||
} else if (!mac_menubar->menu) {
|
||||
mac_menubar->menu = qt_mac_create_menu(q);
|
||||
} else if (!menu) {
|
||||
menu = qt_mac_create_menu(qtMenuBar);
|
||||
ProcessSerialNumber mine, front;
|
||||
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);
|
||||
[mac_menubar->apple_menu setTitle:qt_mac_QStringToNSString(QString(QChar(0x14)))];
|
||||
if (!qt_mac_no_menubar_merge && !apple_menu) {
|
||||
apple_menu = qt_mac_create_menu(qtMenuBar);
|
||||
[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 setSubmenu:menu];
|
||||
[apple_menu addItem:apple_menuItem];
|
||||
[apple_menuItem release];
|
||||
}
|
||||
if (mac_menubar->apple_menu) {
|
||||
QMenuPrivate::mergeMenuHash.insert(mac_menubar->menu, mac_menubar->apple_menu);
|
||||
if (apple_menu) {
|
||||
QCocoaMenu::mergeMenuHash.insert(menu, apple_menu);
|
||||
}
|
||||
QList<QAction*> items = q->actions();
|
||||
QList<QAction*> items = qtMenuBar->actions();
|
||||
for(int i = 0; i < items.count(); i++)
|
||||
mac_menubar->addAction(items[i]);
|
||||
addAction(items[i], 0);
|
||||
}
|
||||
}
|
||||
return mac_menubar->menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -1019,7 +1009,7 @@ OSMenuRef QMenuBarPrivate::macMenu()
|
||||
|
||||
\sa QMenu::macMenu()
|
||||
*/
|
||||
OSMenuRef QMenuBar::macMenu() { return d_func()->macMenu(); }
|
||||
//OSMenuRef QMenuBar::macMenu() { return d_func()->macMenu(); }
|
||||
|
||||
/* !
|
||||
\internal
|
||||
@ -1089,6 +1079,7 @@ static bool qt_mac_should_disable_menu(QMenuBar *menuBar)
|
||||
static QWidget *findWindowThatShouldDisplayMenubar()
|
||||
{
|
||||
QWidget *w = qApp->activeWindow();
|
||||
|
||||
if (!w) {
|
||||
// We have no active window on screen. Try to
|
||||
// find a window from the list of top levels:
|
||||
@ -1102,6 +1093,7 @@ static QWidget *findWindowThatShouldDisplayMenubar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
@ -1110,7 +1102,10 @@ static QMenuBar *findMenubarForWindow(QWidget *w)
|
||||
QMenuBar *mb = 0;
|
||||
if (w) {
|
||||
mb = menubars()->value(w);
|
||||
#ifndef QT_NO_MAINWINDOW
|
||||
|
||||
#if 0
|
||||
// ###
|
||||
//#ifndef QT_NO_MAINWINDOW
|
||||
QDockWidget *dw = qobject_cast<QDockWidget *>(w);
|
||||
if (!mb && dw) {
|
||||
QMainWindow *mw = qobject_cast<QMainWindow *>(dw->parentWidget());
|
||||
@ -1136,7 +1131,7 @@ void qt_mac_clear_menubar()
|
||||
if (QApplication::testAttribute(Qt::AA_MacPluginApplication))
|
||||
return;
|
||||
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
QCocoaAutoReleasePool pool;
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
NSMenu *menu = [loader menu];
|
||||
[loader ensureAppMenuInMenu:menu];
|
||||
@ -1155,26 +1150,21 @@ void qt_mac_clear_menubar()
|
||||
active menu bar in the Menu Manager.
|
||||
|
||||
\warning This function is not portable.
|
||||
|
||||
\sa QMenu::macMenu(), QMenuBar::macMenu()
|
||||
*/
|
||||
bool QMenuBar::macUpdateMenuBar()
|
||||
void QCocoaMenuBar::macUpdateMenuBar()
|
||||
{
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
qWarning("Unimplemented: QMenuBar::macUpdateMenuBar");
|
||||
//qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar));
|
||||
|
||||
return true;
|
||||
[getMenuLoader() performSelectorOnMainThread: @selector(qtUpdateMenubar) withObject: nil waitUntilDone: NO];
|
||||
}
|
||||
|
||||
bool QMenuBarPrivate::macUpdateMenuBarImmediatly()
|
||||
bool QCocoaMenuBar::macUpdateMenuBarImmediatly()
|
||||
{
|
||||
bool ret = false;
|
||||
cancelAllMenuTracking();
|
||||
QWidget *w = findWindowThatShouldDisplayMenubar();
|
||||
QMenuBar *mb = findMenubarForWindow(w);
|
||||
extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
|
||||
|
||||
// ### extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
|
||||
bool qt_mac_app_fullscreen = false;
|
||||
// We need to see if we are in full screen mode, if so we need to
|
||||
// switch the full screen mode to be able to show or hide the menubar.
|
||||
if(w && mb) {
|
||||
@ -1194,22 +1184,25 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly()
|
||||
}
|
||||
|
||||
if (mb && mb->isNativeMenuBar()) {
|
||||
bool modal = QApplicationPrivate::modalState();
|
||||
QMacCocoaAutoReleasePool pool;
|
||||
if (OSMenuRef menu = mb->macMenu()) {
|
||||
|
||||
// ###
|
||||
bool modal = false;
|
||||
//bool modal = QGuiApplicationPrivate::modalState();
|
||||
QCocoaAutoReleasePool pool;
|
||||
if (OSMenuRef menu = reinterpret_cast<QCocoaMenuBar *>(mb->platformMenuBar())->macMenu()) {
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
[loader ensureAppMenuInMenu:menu];
|
||||
[NSApp setMainMenu:menu];
|
||||
syncMenuBarItemsVisiblity(mb->d_func()->mac_menubar);
|
||||
syncMenuBarItemsVisiblity(reinterpret_cast<QCocoaMenuBar *>(mb->platformMenuBar()));
|
||||
|
||||
if (OSMenuRef tmpMerge = QMenuPrivate::mergeMenuHash.value(menu)) {
|
||||
if (OSMenuRef tmpMerge = QCocoaMenu::mergeMenuHash.value(menu)) {
|
||||
if (QMenuMergeList *mergeList
|
||||
= QMenuPrivate::mergeMenuItemsHash.value(tmpMerge)) {
|
||||
= QCocoaMenu::mergeMenuItemsHash.value(tmpMerge)) {
|
||||
const int mergeListSize = mergeList->size();
|
||||
|
||||
for (int i = 0; i < mergeListSize; ++i) {
|
||||
const QMenuMergeItem &mergeItem = mergeList->at(i);
|
||||
// Ideally we would call QMenuPrivate::syncAction, but that requires finding
|
||||
// Ideally we would call QCocoaMenu::syncAction, but that requires finding
|
||||
// the original QMen and likely doing more work than we need.
|
||||
// For example, enabled is handled below.
|
||||
[mergeItem.menuItem setTag:reinterpret_cast<long>(
|
||||
@ -1232,11 +1225,11 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly()
|
||||
const bool modal = qt_mac_should_disable_menu(qt_mac_current_menubar.qmenubar);
|
||||
if (modal != qt_mac_current_menubar.modal) {
|
||||
ret = true;
|
||||
if (OSMenuRef menu = qt_mac_current_menubar.qmenubar->macMenu()) {
|
||||
if (OSMenuRef menu = reinterpret_cast<QCocoaMenuBar *>(qt_mac_current_menubar.qmenubar->platformMenuBar())->macMenu()) {
|
||||
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
|
||||
[loader ensureAppMenuInMenu:menu];
|
||||
[NSApp setMainMenu:menu];
|
||||
syncMenuBarItemsVisiblity(qt_mac_current_menubar.qmenubar->d_func()->mac_menubar);
|
||||
syncMenuBarItemsVisiblity(reinterpret_cast<QCocoaMenuBar *>(qt_mac_current_menubar.qmenubar->platformMenuBar()));
|
||||
qt_mac_set_modal_state(menu, modal);
|
||||
}
|
||||
qt_mac_current_menubar.modal = modal;
|
||||
@ -1249,10 +1242,10 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly()
|
||||
return ret;
|
||||
}
|
||||
|
||||
QHash<OSMenuRef, OSMenuRef> QMenuPrivate::mergeMenuHash;
|
||||
QHash<OSMenuRef, QMenuMergeList*> QMenuPrivate::mergeMenuItemsHash;
|
||||
QHash<OSMenuRef, OSMenuRef> QCocoaMenu::mergeMenuHash;
|
||||
QHash<OSMenuRef, QMenuMergeList*> QCocoaMenu::mergeMenuItemsHash;
|
||||
|
||||
bool QMenuPrivate::QMacMenuPrivate::merged(const QAction *action) const
|
||||
bool QCocoaMenu::merged(const QAction *action) const
|
||||
{
|
||||
if (OSMenuRef merge = mergeMenuHash.value(menu)) {
|
||||
if (QMenuMergeList *list = mergeMenuItemsHash.value(merge)) {
|
||||
@ -1271,14 +1264,11 @@ static OSMenuRef qt_mac_create_menu(QWidget *w)
|
||||
{
|
||||
OSMenuRef ret;
|
||||
if (QMenu *qmenu = qobject_cast<QMenu *>(w)){
|
||||
ret = [[QT_MANGLE_NAMESPACE(QCocoaMenu) alloc] initWithQMenu:qmenu];
|
||||
ret = [[QT_MANGLE_NAMESPACE(QNativeCocoaMenu) alloc] initWithQMenu:qmenu];
|
||||
} else {
|
||||
ret = [[NSMenu alloc] init];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#include "qnsview.h"
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#include <QtGui/QWindowSystemInterface>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
@ -276,44 +278,7 @@
|
||||
|
||||
- (int) convertKeyCode : (QChar)keyChar
|
||||
{
|
||||
if (keyChar.isLower())
|
||||
keyChar = keyChar.toUpper();
|
||||
int keyCode = keyChar.unicode();
|
||||
|
||||
int qtKeyCode = Qt::Key(keyCode); // default case, overrides below
|
||||
switch (keyCode) {
|
||||
case NSEnterCharacter: qtKeyCode = Qt::Key_Enter; break;
|
||||
case NSBackspaceCharacter: qtKeyCode = Qt::Key_Backspace; break;
|
||||
case NSTabCharacter: qtKeyCode = Qt::Key_Tab; break;
|
||||
case NSNewlineCharacter: qtKeyCode = Qt::Key_Return; break;
|
||||
case NSCarriageReturnCharacter: qtKeyCode = Qt::Key_Return; break;
|
||||
case NSBackTabCharacter: qtKeyCode = Qt::Key_Backtab; break;
|
||||
case 27 : qtKeyCode = Qt::Key_Escape; break;
|
||||
case NSDeleteCharacter : qtKeyCode = Qt::Key_Backspace; break; // Cocoa sends us delete when pressing backspace.
|
||||
case NSUpArrowFunctionKey: qtKeyCode = Qt::Key_Up; break;
|
||||
case NSDownArrowFunctionKey: qtKeyCode = Qt::Key_Down; break;
|
||||
case NSLeftArrowFunctionKey: qtKeyCode = Qt::Key_Left; break;
|
||||
case NSRightArrowFunctionKey: qtKeyCode = Qt::Key_Right; break;
|
||||
case NSInsertFunctionKey: qtKeyCode = Qt::Key_Insert; break;
|
||||
case NSDeleteFunctionKey: qtKeyCode = Qt::Key_Delete; break;
|
||||
case NSHomeFunctionKey: qtKeyCode = Qt::Key_Home; break;
|
||||
case NSEndFunctionKey: qtKeyCode = Qt::Key_End; break;
|
||||
case NSPageUpFunctionKey: qtKeyCode = Qt::Key_PageUp; break;
|
||||
case NSPageDownFunctionKey: qtKeyCode = Qt::Key_PageDown; break;
|
||||
case NSPrintScreenFunctionKey: qtKeyCode = Qt::Key_Print; break;
|
||||
case NSScrollLockFunctionKey: qtKeyCode = Qt::Key_ScrollLock; break;
|
||||
case NSPauseFunctionKey: qtKeyCode = Qt::Key_Pause; break;
|
||||
case NSSysReqFunctionKey: qtKeyCode = Qt::Key_SysReq; break;
|
||||
case NSMenuFunctionKey: qtKeyCode = Qt::Key_Menu; break;
|
||||
case NSHelpFunctionKey: qtKeyCode = Qt::Key_Help; break;
|
||||
default : break;
|
||||
}
|
||||
|
||||
// handle all function keys (F1-F35)
|
||||
if (keyCode >= NSF1FunctionKey && keyCode <= NSF35FunctionKey)
|
||||
qtKeyCode = Qt::Key_F1 + (keyCode - NSF1FunctionKey);
|
||||
|
||||
return qtKeyCode;
|
||||
return qt_mac_cocoaKey2QtKey(keyChar);
|
||||
}
|
||||
|
||||
- (Qt::KeyboardModifiers) convertKeyModifiers : (ulong)modifierFlags
|
||||
|
@ -174,12 +174,14 @@ qpa {
|
||||
HEADERS += \
|
||||
kernel/qdesktopwidget_qpa_p.h \
|
||||
kernel/qwidgetwindow_qpa_p.h \
|
||||
kernel/qplatformmenu_qpa.h \
|
||||
|
||||
SOURCES += \
|
||||
kernel/qapplication_qpa.cpp \
|
||||
kernel/qdesktopwidget_qpa.cpp \
|
||||
kernel/qwidget_qpa.cpp \
|
||||
kernel/qwidgetwindow_qpa.cpp \
|
||||
kernel/qplatformmenu_qpa.cpp \
|
||||
}
|
||||
|
||||
!qpa:!x11:mac {
|
||||
|
51
src/widgets/kernel/qplatformmenu_qpa.cpp
Normal file
51
src/widgets/kernel/qplatformmenu_qpa.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "qplatformmenu_qpa.h"
|
||||
|
||||
//
|
||||
// QPlatformMenuAction
|
||||
//
|
||||
|
||||
QPlatformMenuAction::~QPlatformMenuAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// QPlatformMenu
|
||||
//
|
||||
QPlatformMenu::QPlatformMenu()
|
||||
{
|
||||
}
|
||||
|
||||
QPlatformMenu::~QPlatformMenu()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QPlatformMenu::setMenuEnabled(bool enable)
|
||||
{
|
||||
Q_UNUSED(enable);
|
||||
}
|
||||
|
||||
void QPlatformMenu::syncSeparatorsCollapsible(bool enable)
|
||||
{
|
||||
Q_UNUSED(enable);
|
||||
}
|
||||
|
||||
//
|
||||
// QPlatformMenuBar
|
||||
//
|
||||
QPlatformMenuBar::QPlatformMenuBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QPlatformMenuBar::~QPlatformMenuBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QPlatformMenuBar::handleReparent(QWidget *newParent)
|
||||
{
|
||||
Q_UNUSED(newParent);
|
||||
}
|
||||
|
@ -39,27 +39,50 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QT_WIDGET_HELPERS_MAC_P_H
|
||||
#define QT_WIDGET_HELPERS_MAC_P_H
|
||||
#ifndef QPLATFORMMENU_H
|
||||
#define QPLATFORMMENU_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 <qglobal.h>
|
||||
#include <qpointer.h>
|
||||
#include <QtWidgets/qaction.h>
|
||||
|
||||
#include <private/qt_mac_p.h>
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QPixmap;
|
||||
class QString;
|
||||
class QMenuPrivate;
|
||||
class Q_WIDGETS_EXPORT QPlatformMenuAction
|
||||
{
|
||||
public:
|
||||
virtual ~QPlatformMenuAction();
|
||||
QPointer<QAction> action;
|
||||
};
|
||||
|
||||
void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm);
|
||||
QString qt_mac_removeMnemonics(const QString &original);
|
||||
class Q_WIDGETS_EXPORT QPlatformMenu {
|
||||
public:
|
||||
QPlatformMenu();
|
||||
virtual ~QPlatformMenu();
|
||||
|
||||
virtual bool merged(const QAction *action) const = 0;
|
||||
|
||||
virtual void addAction(QAction *action, QAction *before) = 0;
|
||||
virtual void removeAction(QAction *action) = 0;
|
||||
virtual void syncAction(QAction *action) = 0;
|
||||
|
||||
virtual void setMenuEnabled(bool enable);
|
||||
virtual void syncSeparatorsCollapsible(bool enable);
|
||||
};
|
||||
|
||||
struct Q_WIDGETS_EXPORT QPlatformMenuBar {
|
||||
QPlatformMenuBar();
|
||||
virtual ~QPlatformMenuBar();
|
||||
|
||||
virtual void addAction(QAction *action, QAction *before = 0) = 0;
|
||||
virtual void syncAction(QAction *action) = 0;
|
||||
virtual void removeAction(QAction *action) = 0;
|
||||
|
||||
virtual void handleReparent(QWidget *newParent);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
||||
#endif //QT_WIDGET_HELPERS_MAC_P_H
|
@ -1,262 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qmacdefines_mac.h"
|
||||
#include <qaction.h>
|
||||
#include <qcoreapplication.h>
|
||||
#include <private/qcocoamenuloader_mac_p.h>
|
||||
#include <private/qapplication_p.h>
|
||||
#include <private/qt_mac_p.h>
|
||||
#include <private/qmenubar_p.h>
|
||||
#include <qmenubar.h>
|
||||
#include <private/qt_cocoa_helpers_mac_p.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QCFString)
|
||||
QT_FORWARD_DECLARE_CLASS(QString)
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
QT_BEGIN_NAMESPACE
|
||||
extern QString qt_mac_applicationmenu_string(int type);
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
@implementation QT_MANGLE_NAMESPACE(QCocoaMenuLoader)
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
servicesItem = [[appMenu itemWithTitle:@"Services"] retain];
|
||||
hideAllOthersItem = [[appMenu itemWithTitle:@"Hide Others"] retain];
|
||||
showAllItem = [[appMenu itemWithTitle:@"Show All"] retain];
|
||||
|
||||
// Get the names in the nib to match the app name set by Qt.
|
||||
const NSString *appName = reinterpret_cast<const NSString*>(QCFString::toCFStringRef(qAppName()));
|
||||
[quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
|
||||
withString:const_cast<NSString *>(appName)]];
|
||||
[hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
|
||||
withString:const_cast<NSString *>(appName)]];
|
||||
[aboutItem setTitle:[[aboutItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
|
||||
withString:const_cast<NSString *>(appName)]];
|
||||
[appName release];
|
||||
// Disable the items that don't do anything. If someone associates a QAction with them
|
||||
// They should get synced back in.
|
||||
[preferencesItem setEnabled:NO];
|
||||
[preferencesItem setHidden:YES];
|
||||
[aboutItem setEnabled:NO];
|
||||
[aboutItem setHidden:YES];
|
||||
}
|
||||
|
||||
- (void)ensureAppMenuInMenu:(NSMenu *)menu
|
||||
{
|
||||
// The application menu is the menu in the menu bar that contains the
|
||||
// 'Quit' item. When changing menu bar (e.g when switching between
|
||||
// windows with different menu bars), we never recreate this menu, but
|
||||
// instead pull it out the current menu bar and place into the new one:
|
||||
NSMenu *mainMenu = [NSApp mainMenu];
|
||||
if ([NSApp mainMenu] == menu)
|
||||
return; // nothing to do (menu is the current menu bar)!
|
||||
|
||||
#ifndef QT_NAMESPACE
|
||||
Q_ASSERT(mainMenu);
|
||||
#endif
|
||||
// Grab the app menu out of the current menu.
|
||||
int numItems = [mainMenu numberOfItems];
|
||||
NSMenuItem *oldAppMenuItem = 0;
|
||||
for (int i = 0; i < numItems; ++i) {
|
||||
NSMenuItem *item = [mainMenu itemAtIndex:i];
|
||||
if ([item submenu] == appMenu) {
|
||||
oldAppMenuItem = item;
|
||||
[oldAppMenuItem retain];
|
||||
[mainMenu removeItemAtIndex:i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldAppMenuItem) {
|
||||
[oldAppMenuItem setSubmenu:nil];
|
||||
[oldAppMenuItem release];
|
||||
NSMenuItem *appMenuItem = [[NSMenuItem alloc] initWithTitle:@"Apple"
|
||||
action:nil keyEquivalent:@""];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
[menu insertItem:appMenuItem atIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeActionsFromAppMenu
|
||||
{
|
||||
for (NSMenuItem *item in [appMenu itemArray])
|
||||
[item setTag:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[servicesItem release];
|
||||
[hideAllOthersItem release];
|
||||
[showAllItem release];
|
||||
|
||||
[lastAppSpecificItem release];
|
||||
[theMenu release];
|
||||
[appMenu release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSMenu *)menu
|
||||
{
|
||||
return [[theMenu retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenu *)applicationMenu
|
||||
{
|
||||
return [[appMenu retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)quitMenuItem
|
||||
{
|
||||
return [[quitItem retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)preferencesMenuItem
|
||||
{
|
||||
return [[preferencesItem retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)aboutMenuItem
|
||||
{
|
||||
return [[aboutItem retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)aboutQtMenuItem
|
||||
{
|
||||
return [[aboutQtItem retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)hideMenuItem
|
||||
{
|
||||
return [[hideItem retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)appSpecificMenuItem
|
||||
{
|
||||
// Create an App-Specific menu item, insert it into the menu and return
|
||||
// it as an autorelease item.
|
||||
NSMenuItem *item = [[NSMenuItem alloc] init];
|
||||
|
||||
NSInteger location;
|
||||
if (lastAppSpecificItem == nil) {
|
||||
location = [appMenu indexOfItem:aboutQtItem];
|
||||
} else {
|
||||
location = [appMenu indexOfItem:lastAppSpecificItem];
|
||||
[lastAppSpecificItem release];
|
||||
}
|
||||
lastAppSpecificItem = item; // Keep track of this for later (i.e., don't release it)
|
||||
[appMenu insertItem:item atIndex:location + 1];
|
||||
|
||||
return [[item retain] autorelease];
|
||||
}
|
||||
|
||||
- (BOOL) acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)terminate:(id)sender
|
||||
{
|
||||
[NSApp terminate:sender];
|
||||
}
|
||||
|
||||
- (void)orderFrontStandardAboutPanel:(id)sender
|
||||
{
|
||||
[NSApp orderFrontStandardAboutPanel:sender];
|
||||
}
|
||||
|
||||
- (void)hideOtherApplications:(id)sender
|
||||
{
|
||||
[NSApp hideOtherApplications:sender];
|
||||
}
|
||||
|
||||
- (void)unhideAllApplications:(id)sender
|
||||
{
|
||||
[NSApp unhideAllApplications:sender];
|
||||
}
|
||||
|
||||
- (void)hide:(id)sender
|
||||
{
|
||||
[NSApp hide:sender];
|
||||
}
|
||||
|
||||
- (void)qtUpdateMenubar
|
||||
{
|
||||
QMenuBarPrivate::macUpdateMenuBarImmediatly();
|
||||
}
|
||||
|
||||
- (void)qtTranslateApplicationMenu
|
||||
{
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
[servicesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(0))];
|
||||
[hideItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(1).arg(qAppName()))];
|
||||
[hideAllOthersItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(2))];
|
||||
[showAllItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(3))];
|
||||
[preferencesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(4))];
|
||||
[quitItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(5).arg(qAppName()))];
|
||||
[aboutItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(6).arg(qAppName()))];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (IBAction)qtDispatcherToQAction:(id)sender
|
||||
{
|
||||
QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
|
||||
NSMenuItem *item = static_cast<NSMenuItem *>(sender);
|
||||
if (QAction *action = reinterpret_cast<QAction *>([item tag])) {
|
||||
action->trigger();
|
||||
} else if (item == quitItem) {
|
||||
// We got here because someone was once the quitItem, but it has been
|
||||
// abandoned (e.g., the menubar was deleted). In the meantime, just do
|
||||
// normal QApplication::quit().
|
||||
qApp->quit();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)orderFrontCharacterPalette:(id)sender
|
||||
{
|
||||
[NSApp orderFrontCharacterPalette:sender];
|
||||
}
|
||||
@end
|
@ -1,93 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 QCOCOAMENULOADER_P_H
|
||||
#define QCOCOAMENULOADER_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists for the convenience
|
||||
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
|
||||
// file may change from version to version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmacdefines_mac.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface QT_MANGLE_NAMESPACE(QCocoaMenuLoader) : NSResponder
|
||||
{
|
||||
IBOutlet NSMenu *theMenu;
|
||||
IBOutlet NSMenu *appMenu;
|
||||
IBOutlet NSMenuItem *quitItem;
|
||||
IBOutlet NSMenuItem *preferencesItem;
|
||||
IBOutlet NSMenuItem *aboutItem;
|
||||
IBOutlet NSMenuItem *aboutQtItem;
|
||||
IBOutlet NSMenuItem *hideItem;
|
||||
NSMenuItem *lastAppSpecificItem;
|
||||
NSMenuItem *servicesItem;
|
||||
NSMenuItem *hideAllOthersItem;
|
||||
NSMenuItem *showAllItem;
|
||||
}
|
||||
- (void)ensureAppMenuInMenu:(NSMenu *)menu;
|
||||
- (void)removeActionsFromAppMenu;
|
||||
- (NSMenu *)applicationMenu;
|
||||
- (NSMenu *)menu;
|
||||
- (NSMenuItem *)quitMenuItem;
|
||||
- (NSMenuItem *)preferencesMenuItem;
|
||||
- (NSMenuItem *)aboutMenuItem;
|
||||
- (NSMenuItem *)aboutQtMenuItem;
|
||||
- (NSMenuItem *)hideMenuItem;
|
||||
- (NSMenuItem *)appSpecificMenuItem;
|
||||
- (IBAction)terminate:(id)sender;
|
||||
- (IBAction)orderFrontStandardAboutPanel:(id)sender;
|
||||
- (IBAction)hideOtherApplications:(id)sender;
|
||||
- (IBAction)unhideAllApplications:(id)sender;
|
||||
- (IBAction)hide:(id)sender;
|
||||
- (IBAction)qtDispatcherToQAction:(id)sender;
|
||||
- (void)qtUpdateMenubar;
|
||||
- (void)orderFrontCharacterPalette:(id)sender;
|
||||
@end
|
||||
|
||||
#endif // QCOCOAMENULOADER_P_H
|
@ -317,64 +317,6 @@ CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace()
|
||||
return macDisplayColorSpace();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Ideally, we should pass the widget in here, and use CGGetDisplaysWithRect() etc.
|
||||
to support multiple displays correctly.
|
||||
*/
|
||||
CGColorSpaceRef QCoreGraphicsPaintEngine::macDisplayColorSpace(const QWidget *widget)
|
||||
{
|
||||
CGColorSpaceRef colorSpace;
|
||||
|
||||
CGDirectDisplayID displayID;
|
||||
CMProfileRef displayProfile = 0;
|
||||
if (widget == 0) {
|
||||
displayID = CGMainDisplayID();
|
||||
} else {
|
||||
const QRect &qrect = widget->window()->geometry();
|
||||
CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
|
||||
CGDisplayCount throwAway;
|
||||
CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
|
||||
if (dErr != kCGErrorSuccess)
|
||||
return macDisplayColorSpace(0); // fall back on main display
|
||||
}
|
||||
if ((colorSpace = m_displayColorSpaceHash.value(displayID)))
|
||||
return colorSpace;
|
||||
|
||||
CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile);
|
||||
if (err == noErr) {
|
||||
colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile);
|
||||
} else if (widget) {
|
||||
return macDisplayColorSpace(0); // fall back on main display
|
||||
}
|
||||
|
||||
if (colorSpace == 0)
|
||||
colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
m_displayColorSpaceHash.insert(displayID, colorSpace);
|
||||
CMCloseProfile(displayProfile);
|
||||
if (!m_postRoutineRegistered) {
|
||||
m_postRoutineRegistered = true;
|
||||
qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces);
|
||||
}
|
||||
return colorSpace;
|
||||
}
|
||||
|
||||
void QCoreGraphicsPaintEngine::cleanUpMacColorSpaces()
|
||||
{
|
||||
if (m_genericColorSpace) {
|
||||
CFRelease(m_genericColorSpace);
|
||||
m_genericColorSpace = 0;
|
||||
}
|
||||
QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
|
||||
while (it != m_displayColorSpaceHash.constEnd()) {
|
||||
if (it.value())
|
||||
CFRelease(it.value());
|
||||
++it;
|
||||
}
|
||||
m_displayColorSpaceHash.clear();
|
||||
}
|
||||
|
||||
void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform)
|
||||
{
|
||||
CGAffineTransform old_xform = CGAffineTransformIdentity;
|
||||
@ -990,48 +932,6 @@ void QCoreGraphicsPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, co
|
||||
d->restoreGraphicsState();
|
||||
}
|
||||
|
||||
static void drawImageReleaseData (void *info, const void *, size_t)
|
||||
{
|
||||
delete static_cast<QImage *>(info);
|
||||
}
|
||||
|
||||
CGImageRef qt_mac_createCGImageFromQImage(const QImage &img, const QImage **imagePtr = 0)
|
||||
{
|
||||
QImage *image;
|
||||
if (img.depth() != 32)
|
||||
image = new QImage(img.convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
||||
else
|
||||
image = new QImage(img);
|
||||
|
||||
uint cgflags = kCGImageAlphaNone;
|
||||
switch (image->format()) {
|
||||
case QImage::Format_ARGB32_Premultiplied:
|
||||
cgflags = kCGImageAlphaPremultipliedFirst;
|
||||
break;
|
||||
case QImage::Format_ARGB32:
|
||||
cgflags = kCGImageAlphaFirst;
|
||||
break;
|
||||
case QImage::Format_RGB32:
|
||||
cgflags = kCGImageAlphaNoneSkipFirst;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#if defined(kCGBitmapByteOrder32Host) //only needed because CGImage.h added symbols in the minor version
|
||||
cgflags |= kCGBitmapByteOrder32Host;
|
||||
#endif
|
||||
QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(image,
|
||||
static_cast<const QImage *>(image)->bits(),
|
||||
image->byteCount(),
|
||||
drawImageReleaseData);
|
||||
if (imagePtr)
|
||||
*imagePtr = image;
|
||||
return CGImageCreate(image->width(), image->height(), 8, 32,
|
||||
image->bytesPerLine(),
|
||||
QCoreGraphicsPaintEngine::macGenericColorSpace(),
|
||||
cgflags, dataProvider, 0, false, kCGRenderingIntentDefault);
|
||||
|
||||
}
|
||||
|
||||
void QCoreGraphicsPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRectF &sr,
|
||||
Qt::ImageConversionFlags flags)
|
||||
{
|
||||
|
@ -110,34 +110,6 @@ void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
|
||||
}
|
||||
}
|
||||
|
||||
CGImageRef qt_mac_image_to_cgimage(const QImage &image)
|
||||
{
|
||||
int bitsPerColor = 8;
|
||||
int bitsPerPixel = 32;
|
||||
if (image.depth() == 1) {
|
||||
bitsPerColor = 1;
|
||||
bitsPerPixel = 1;
|
||||
}
|
||||
QCFType<CGDataProviderRef> provider =
|
||||
CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(),
|
||||
0);
|
||||
|
||||
uint cgflags = kCGImageAlphaPremultipliedFirst;
|
||||
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
|
||||
cgflags |= kCGBitmapByteOrder32Host;
|
||||
#endif
|
||||
|
||||
CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel,
|
||||
image.bytesPerLine(),
|
||||
QCoreGraphicsPaintEngine::macGenericColorSpace(),
|
||||
cgflags, provider,
|
||||
0,
|
||||
0,
|
||||
kCGRenderingIntentDefault);
|
||||
|
||||
return cgImage;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
QPixmap member functions
|
||||
*****************************************************************************/
|
||||
|
@ -527,139 +527,7 @@ void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec)
|
||||
qt_sendSpontaneousEvent(qApp, &qtabletProximity);
|
||||
}
|
||||
|
||||
// Use this method to keep all the information in the TextSegment. As long as it is ordered
|
||||
// we are in OK shape, and we can influence that ourselves.
|
||||
struct KeyPair
|
||||
{
|
||||
QChar cocoaKey;
|
||||
Qt::Key qtKey;
|
||||
};
|
||||
|
||||
bool operator==(const KeyPair &entry, QChar qchar)
|
||||
{
|
||||
return entry.cocoaKey == qchar;
|
||||
}
|
||||
|
||||
bool operator<(const KeyPair &entry, QChar qchar)
|
||||
{
|
||||
return entry.cocoaKey < qchar;
|
||||
}
|
||||
|
||||
bool operator<(QChar qchar, const KeyPair &entry)
|
||||
{
|
||||
return qchar < entry.cocoaKey;
|
||||
}
|
||||
|
||||
bool operator<(const Qt::Key &key, const KeyPair &entry)
|
||||
{
|
||||
return key < entry.qtKey;
|
||||
}
|
||||
|
||||
bool operator<(const KeyPair &entry, const Qt::Key &key)
|
||||
{
|
||||
return entry.qtKey < key;
|
||||
}
|
||||
|
||||
static bool qtKey2CocoaKeySortLessThan(const KeyPair &entry1, const KeyPair &entry2)
|
||||
{
|
||||
return entry1.qtKey < entry2.qtKey;
|
||||
}
|
||||
|
||||
static const int NumEntries = 59;
|
||||
static const KeyPair entries[NumEntries] = {
|
||||
{ NSEnterCharacter, Qt::Key_Enter },
|
||||
{ NSBackspaceCharacter, Qt::Key_Backspace },
|
||||
{ NSTabCharacter, Qt::Key_Tab },
|
||||
{ NSNewlineCharacter, Qt::Key_Return },
|
||||
{ NSCarriageReturnCharacter, Qt::Key_Return },
|
||||
{ NSBackTabCharacter, Qt::Key_Backtab },
|
||||
{ kEscapeCharCode, Qt::Key_Escape },
|
||||
// Cocoa sends us delete when pressing backspace!
|
||||
// (NB when we reverse this list in qtKey2CocoaKey, there
|
||||
// will be two indices of Qt::Key_Backspace. But is seems to work
|
||||
// ok for menu shortcuts (which uses that function):
|
||||
{ NSDeleteCharacter, Qt::Key_Backspace },
|
||||
{ NSUpArrowFunctionKey, Qt::Key_Up },
|
||||
{ NSDownArrowFunctionKey, Qt::Key_Down },
|
||||
{ NSLeftArrowFunctionKey, Qt::Key_Left },
|
||||
{ NSRightArrowFunctionKey, Qt::Key_Right },
|
||||
{ NSF1FunctionKey, Qt::Key_F1 },
|
||||
{ NSF2FunctionKey, Qt::Key_F2 },
|
||||
{ NSF3FunctionKey, Qt::Key_F3 },
|
||||
{ NSF4FunctionKey, Qt::Key_F4 },
|
||||
{ NSF5FunctionKey, Qt::Key_F5 },
|
||||
{ NSF6FunctionKey, Qt::Key_F6 },
|
||||
{ NSF7FunctionKey, Qt::Key_F7 },
|
||||
{ NSF8FunctionKey, Qt::Key_F8 },
|
||||
{ NSF9FunctionKey, Qt::Key_F8 },
|
||||
{ NSF10FunctionKey, Qt::Key_F10 },
|
||||
{ NSF11FunctionKey, Qt::Key_F11 },
|
||||
{ NSF12FunctionKey, Qt::Key_F12 },
|
||||
{ NSF13FunctionKey, Qt::Key_F13 },
|
||||
{ NSF14FunctionKey, Qt::Key_F14 },
|
||||
{ NSF15FunctionKey, Qt::Key_F15 },
|
||||
{ NSF16FunctionKey, Qt::Key_F16 },
|
||||
{ NSF17FunctionKey, Qt::Key_F17 },
|
||||
{ NSF18FunctionKey, Qt::Key_F18 },
|
||||
{ NSF19FunctionKey, Qt::Key_F19 },
|
||||
{ NSF20FunctionKey, Qt::Key_F20 },
|
||||
{ NSF21FunctionKey, Qt::Key_F21 },
|
||||
{ NSF22FunctionKey, Qt::Key_F22 },
|
||||
{ NSF23FunctionKey, Qt::Key_F23 },
|
||||
{ NSF24FunctionKey, Qt::Key_F24 },
|
||||
{ NSF25FunctionKey, Qt::Key_F25 },
|
||||
{ NSF26FunctionKey, Qt::Key_F26 },
|
||||
{ NSF27FunctionKey, Qt::Key_F27 },
|
||||
{ NSF28FunctionKey, Qt::Key_F28 },
|
||||
{ NSF29FunctionKey, Qt::Key_F29 },
|
||||
{ NSF30FunctionKey, Qt::Key_F30 },
|
||||
{ NSF31FunctionKey, Qt::Key_F31 },
|
||||
{ NSF32FunctionKey, Qt::Key_F32 },
|
||||
{ NSF33FunctionKey, Qt::Key_F33 },
|
||||
{ NSF34FunctionKey, Qt::Key_F34 },
|
||||
{ NSF35FunctionKey, Qt::Key_F35 },
|
||||
{ NSInsertFunctionKey, Qt::Key_Insert },
|
||||
{ NSDeleteFunctionKey, Qt::Key_Delete },
|
||||
{ NSHomeFunctionKey, Qt::Key_Home },
|
||||
{ NSEndFunctionKey, Qt::Key_End },
|
||||
{ NSPageUpFunctionKey, Qt::Key_PageUp },
|
||||
{ NSPageDownFunctionKey, Qt::Key_PageDown },
|
||||
{ NSPrintScreenFunctionKey, Qt::Key_Print },
|
||||
{ NSScrollLockFunctionKey, Qt::Key_ScrollLock },
|
||||
{ NSPauseFunctionKey, Qt::Key_Pause },
|
||||
{ NSSysReqFunctionKey, Qt::Key_SysReq },
|
||||
{ NSMenuFunctionKey, Qt::Key_Menu },
|
||||
{ NSHelpFunctionKey, Qt::Key_Help },
|
||||
};
|
||||
static const KeyPair * const end = entries + NumEntries;
|
||||
|
||||
QChar qtKey2CocoaKey(Qt::Key key)
|
||||
{
|
||||
// The first time this function is called, create a reverse
|
||||
// looup table sorted on Qt Key rather than Cocoa key:
|
||||
static QVector<KeyPair> rev_entries(NumEntries);
|
||||
static bool mustInit = true;
|
||||
if (mustInit){
|
||||
mustInit = false;
|
||||
for (int i=0; i<NumEntries; ++i)
|
||||
rev_entries[i] = entries[i];
|
||||
qSort(rev_entries.begin(), rev_entries.end(), qtKey2CocoaKeySortLessThan);
|
||||
}
|
||||
const QVector<KeyPair>::iterator i
|
||||
= qBinaryFind(rev_entries.begin(), rev_entries.end(), key);
|
||||
if (i == rev_entries.end())
|
||||
return QChar();
|
||||
return i->cocoaKey;
|
||||
}
|
||||
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
static Qt::Key cocoaKey2QtKey(QChar keyCode)
|
||||
{
|
||||
const KeyPair *i = qBinaryFind(entries, end, keyCode);
|
||||
if (i == end)
|
||||
return Qt::Key(keyCode.unicode());
|
||||
return i->qtKey;
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags)
|
||||
{
|
||||
@ -1585,50 +1453,6 @@ void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayI
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
|
||||
class CocoaPostMessageAfterEventLoopExitHelp : public QObject
|
||||
{
|
||||
id target;
|
||||
SEL selector;
|
||||
int argCount;
|
||||
id arg1;
|
||||
id arg2;
|
||||
public:
|
||||
CocoaPostMessageAfterEventLoopExitHelp(id target, SEL selector, int argCount, id arg1, id arg2)
|
||||
: target(target), selector(selector), argCount(argCount), arg1(arg1), arg2(arg2){
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
~CocoaPostMessageAfterEventLoopExitHelp()
|
||||
{
|
||||
qt_cocoaPostMessage(target, selector, argCount, arg1, arg2);
|
||||
}
|
||||
};
|
||||
|
||||
void qt_cocoaPostMessage(id target, SEL selector, int argCount, id arg1, id arg2)
|
||||
{
|
||||
// WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
|
||||
// That is why we need to split the address in two parts:
|
||||
QCocoaPostMessageArgs *args = new QCocoaPostMessageArgs(target, selector, argCount, arg1, arg2);
|
||||
quint32 lower = quintptr(args);
|
||||
quint32 upper = quintptr(args) >> 32;
|
||||
NSEvent *e = [NSEvent otherEventWithType:NSApplicationDefined
|
||||
location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0
|
||||
context:nil subtype:QtCocoaEventSubTypePostMessage data1:lower data2:upper];
|
||||
[NSApp postEvent:e atStart:NO];
|
||||
}
|
||||
|
||||
void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount, id arg1, id arg2)
|
||||
{
|
||||
if (QApplicationPrivate::instance()->threadData->eventLoops.size() <= 1)
|
||||
qt_cocoaPostMessage(target, selector, argCount, arg1, arg2);
|
||||
else
|
||||
new CocoaPostMessageAfterEventLoopExitHelp(target, selector, argCount, arg1, arg2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void qt_mac_post_retranslateAppMenu()
|
||||
{
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
|
@ -126,11 +126,6 @@ struct HIContentBorderMetrics;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
enum {
|
||||
QtCocoaEventSubTypeWakeup = SHRT_MAX,
|
||||
QtCocoaEventSubTypePostMessage = SHRT_MAX-1
|
||||
};
|
||||
|
||||
Qt::MouseButtons qt_mac_get_buttons(int buttons);
|
||||
Qt::MouseButton qt_mac_get_button(EventMouseButton button);
|
||||
void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0.15);
|
||||
@ -221,31 +216,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]; }
|
||||
|
||||
class QCocoaPostMessageArgs {
|
||||
public:
|
||||
id target;
|
||||
SEL selector;
|
||||
int argCount;
|
||||
id arg1;
|
||||
id arg2;
|
||||
QCocoaPostMessageArgs(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0)
|
||||
: target(target), selector(selector), argCount(argCount), arg1(arg1), arg2(arg2)
|
||||
{
|
||||
[target retain];
|
||||
[arg1 retain];
|
||||
[arg2 retain];
|
||||
}
|
||||
|
||||
~QCocoaPostMessageArgs()
|
||||
{
|
||||
[arg2 release];
|
||||
[arg1 release];
|
||||
[target release];
|
||||
}
|
||||
};
|
||||
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
|
||||
|
||||
class QMacScrollOptimization {
|
||||
|
@ -1,113 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
@ -164,6 +164,8 @@ void QMenuPrivate::init()
|
||||
scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
|
||||
}
|
||||
|
||||
platformMenu = QGuiApplicationPrivate::platformIntegration()->createPlatformMenu(q);
|
||||
|
||||
#ifdef QT_SOFTKEYS_ENABLED
|
||||
selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q);
|
||||
cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Back, q);
|
||||
@ -2367,10 +2369,8 @@ void QMenu::changeEvent(QEvent *e)
|
||||
if (d->tornPopup) // torn-off menu
|
||||
d->tornPopup->setEnabled(isEnabled());
|
||||
d->menuAction->setEnabled(isEnabled());
|
||||
#ifdef Q_OS_MAC
|
||||
if (d->mac_menu)
|
||||
d->setMacMenuEnabled(isEnabled());
|
||||
#endif
|
||||
if (d->platformMenu)
|
||||
d->platformMenu->setMenuEnabled(isEnabled());
|
||||
}
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
@ -2923,16 +2923,14 @@ void QMenu::actionEvent(QActionEvent *e)
|
||||
d->widgetItems.remove(e->action());
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
if (d->mac_menu) {
|
||||
if (d->platformMenu) {
|
||||
if (e->type() == QEvent::ActionAdded)
|
||||
d->mac_menu->addAction(e->action(), d->mac_menu->findAction(e->before()), d);
|
||||
d->platformMenu->addAction(e->action(), e->before());
|
||||
else if (e->type() == QEvent::ActionRemoved)
|
||||
d->mac_menu->removeAction(e->action());
|
||||
d->platformMenu->removeAction(e->action());
|
||||
else if (e->type() == QEvent::ActionChanged)
|
||||
d->mac_menu->syncAction(e->action());
|
||||
d->platformMenu->syncAction(e->action());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
|
||||
if (!d->wce_menu)
|
||||
@ -3093,6 +3091,14 @@ void QMenu::setNoReplayFor(QWidget *noReplayFor)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!\internal
|
||||
*/
|
||||
QPlatformMenu *QMenu::platformMenu()
|
||||
{
|
||||
|
||||
return d_func()->platformMenu;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMenu::separatorsCollapsible
|
||||
\since 4.2
|
||||
@ -3123,10 +3129,8 @@ void QMenu::setSeparatorsCollapsible(bool collapse)
|
||||
d->updateActionRects();
|
||||
update();
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
if (d->mac_menu)
|
||||
d->syncSeparatorsCollapsible(collapse);
|
||||
#endif
|
||||
if (d->platformMenu)
|
||||
d->platformMenu->syncSeparatorsCollapsible(collapse);
|
||||
}
|
||||
|
||||
#ifdef QT3_SUPPORT
|
||||
|
@ -46,10 +46,7 @@
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtWidgets/qicon.h>
|
||||
#include <QtWidgets/qaction.h>
|
||||
#ifdef Q_OS_MAC
|
||||
#include "QtWidgets/qmacdefines_mac.h"
|
||||
#endif
|
||||
|
||||
#include <QtWidgets/qplatformmenu_qpa.h>
|
||||
|
||||
#ifdef QT3_SUPPORT
|
||||
#include <QtGui/qpixmap.h>
|
||||
@ -145,9 +142,7 @@ public:
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
void setNoReplayFor(QWidget *widget);
|
||||
#ifdef Q_OS_MAC
|
||||
OSMenuRef macMenu(OSMenuRef merge=0);
|
||||
#endif
|
||||
QPlatformMenu *platformMenu();
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
HMENU wceMenu();
|
||||
@ -418,15 +413,8 @@ private:
|
||||
friend class QComboBox;
|
||||
friend class QAction;
|
||||
friend class QToolButtonPrivate;
|
||||
|
||||
#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 *);
|
||||
friend bool qt_mac_activate_action(OSMenuRef, uint, QAction::ActionEvent, bool);
|
||||
friend void qt_mac_emit_menuSignals(QMenu *, bool);
|
||||
friend void qt_mac_emit_menuSignals(QMenu *menu, bool show);
|
||||
friend void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // QT_NO_MENU
|
||||
|
@ -83,37 +83,6 @@ void qt_symbian_show_submenu(CEikMenuPane* menuPane, int id);
|
||||
class QTornOffMenu;
|
||||
class QEventLoop;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# ifdef __OBJC__
|
||||
QT_END_NAMESPACE
|
||||
@class NSMenuItem;
|
||||
QT_BEGIN_NAMESPACE
|
||||
# else
|
||||
typedef void NSMenuItem;
|
||||
# endif //__OBJC__
|
||||
struct QMacMenuAction {
|
||||
QMacMenuAction()
|
||||
: menuItem(0)
|
||||
, ignore_accel(0), merged(0), menu(0)
|
||||
{
|
||||
}
|
||||
~QMacMenuAction();
|
||||
NSMenuItem *menuItem;
|
||||
uchar ignore_accel : 1;
|
||||
uchar merged : 1;
|
||||
QPointer<QAction> action;
|
||||
OSMenuRef menu;
|
||||
};
|
||||
|
||||
struct QMenuMergeItem
|
||||
{
|
||||
inline QMenuMergeItem(NSMenuItem *c, QMacMenuAction *a) : menuItem(c), action(a) { }
|
||||
NSMenuItem *menuItem;
|
||||
QMacMenuAction *action;
|
||||
};
|
||||
typedef QList<QMenuMergeItem> QMenuMergeList;
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
struct QWceMenuAction {
|
||||
uint command;
|
||||
@ -144,13 +113,8 @@ public:
|
||||
cancelAction(0),
|
||||
#endif
|
||||
scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0),
|
||||
hasCheckableItems(0), sloppyAction(0), doChildEffects(false)
|
||||
#ifdef QT3_SUPPORT
|
||||
,emitHighlighted(false)
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
,mac_menu(0)
|
||||
#endif
|
||||
hasCheckableItems(0), sloppyAction(0), doChildEffects(false), platformMenu(0)
|
||||
|
||||
#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
|
||||
,wce_menu(0)
|
||||
#endif
|
||||
@ -161,9 +125,7 @@ public:
|
||||
~QMenuPrivate()
|
||||
{
|
||||
delete scroll;
|
||||
#ifdef Q_OS_MAC
|
||||
delete mac_menu;
|
||||
#endif
|
||||
delete platformMenu;
|
||||
#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
|
||||
delete wce_menu;
|
||||
#endif
|
||||
@ -293,36 +255,7 @@ public:
|
||||
//menu fading/scrolling effects
|
||||
bool doChildEffects;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
//mac menu binding
|
||||
struct QMacMenuPrivate {
|
||||
QList<QMacMenuAction*> actionItems;
|
||||
OSMenuRef menu;
|
||||
QMacMenuPrivate();
|
||||
~QMacMenuPrivate();
|
||||
|
||||
bool merged(const QAction *action) const;
|
||||
void addAction(QAction *, QMacMenuAction* =0, QMenuPrivate *qmenu = 0);
|
||||
void addAction(QMacMenuAction *, QMacMenuAction* =0, QMenuPrivate *qmenu = 0);
|
||||
void syncAction(QMacMenuAction *);
|
||||
inline void syncAction(QAction *a) { syncAction(findAction(a)); }
|
||||
void removeAction(QMacMenuAction *);
|
||||
inline void removeAction(QAction *a) { removeAction(findAction(a)); }
|
||||
inline QMacMenuAction *findAction(QAction *a) {
|
||||
for(int i = 0; i < actionItems.size(); i++) {
|
||||
QMacMenuAction *act = actionItems[i];
|
||||
if(a == act->action)
|
||||
return act;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} *mac_menu;
|
||||
OSMenuRef macMenu(OSMenuRef merge);
|
||||
void setMacMenuEnabled(bool enable = true);
|
||||
void syncSeparatorsCollapsible(bool collapsible);
|
||||
static QHash<OSMenuRef, OSMenuRef> mergeMenuHash;
|
||||
static QHash<OSMenuRef, QMenuMergeList*> mergeMenuItemsHash;
|
||||
#endif
|
||||
QPlatformMenu *platformMenu;
|
||||
|
||||
QPointer<QAction> actionAboutToTrigger;
|
||||
#ifdef QT3_SUPPORT
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qwhatsthis.h>
|
||||
#include "private/qguiapplication_p.h"
|
||||
|
||||
#ifndef QT_NO_MENUBAR
|
||||
|
||||
@ -728,11 +729,11 @@ void QMenuBarPrivate::init()
|
||||
Q_Q(QMenuBar);
|
||||
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
||||
q->setAttribute(Qt::WA_CustomWhatsThis);
|
||||
#ifdef Q_OS_MAC
|
||||
macCreateMenuBar(q->parentWidget());
|
||||
if(mac_menubar)
|
||||
|
||||
platformMenuBar = QGuiApplicationPrivate::platformIntegration()->createPlatformMenuBar(q);
|
||||
|
||||
if (platformMenuBar)
|
||||
q->hide();
|
||||
#endif
|
||||
#ifdef Q_WS_WINCE
|
||||
if (qt_wince_is_mobile()) {
|
||||
wceCreateMenuBar(q->parentWidget());
|
||||
@ -808,10 +809,10 @@ QMenuBar::QMenuBar(QWidget *parent, const char *name) : QWidget(*new QMenuBarPri
|
||||
*/
|
||||
QMenuBar::~QMenuBar()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
Q_D(QMenuBar);
|
||||
d->macDestroyMenuBar();
|
||||
#endif
|
||||
delete d->platformMenuBar;
|
||||
d->platformMenuBar = 0;
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
Q_D(QMenuBar);
|
||||
if (qt_wince_is_mobile())
|
||||
@ -1275,25 +1276,23 @@ void QMenuBar::actionEvent(QActionEvent *e)
|
||||
{
|
||||
Q_D(QMenuBar);
|
||||
d->itemsDirty = true;
|
||||
#if defined (Q_OS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60)
|
||||
if (isNativeMenuBar()) {
|
||||
#ifdef Q_OS_MAC
|
||||
QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar;
|
||||
#elif defined(Q_WS_S60)
|
||||
|
||||
if (d->platformMenuBar) {
|
||||
QPlatformMenuBar *nativeMenuBar = d->platformMenuBar;
|
||||
#if defined(Q_WS_S60)
|
||||
QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar;
|
||||
#else
|
||||
#elif defined(Q_WS_WINCE)
|
||||
QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar;
|
||||
#endif
|
||||
if (!nativeMenuBar)
|
||||
return;
|
||||
if(e->type() == QEvent::ActionAdded)
|
||||
nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before()));
|
||||
nativeMenuBar->addAction(e->action(), e->before());
|
||||
else if(e->type() == QEvent::ActionRemoved)
|
||||
nativeMenuBar->removeAction(e->action());
|
||||
else if(e->type() == QEvent::ActionChanged)
|
||||
nativeMenuBar->syncAction(e->action());
|
||||
}
|
||||
#endif
|
||||
|
||||
if(e->type() == QEvent::ActionAdded) {
|
||||
connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
|
||||
@ -1372,15 +1371,8 @@ void QMenuBarPrivate::handleReparent()
|
||||
oldParent = newParent;
|
||||
oldWindow = newWindow;
|
||||
|
||||
#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
|
||||
// menubar has precedence over children menubars).
|
||||
macDestroyMenuBar();
|
||||
macCreateMenuBar(newParent);
|
||||
}
|
||||
#endif
|
||||
if (platformMenuBar)
|
||||
platformMenuBar->handleReparent(newParent);
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
if (qt_wince_is_mobile() && wce_menubar)
|
||||
@ -1925,27 +1917,18 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
|
||||
Q_D(QMenuBar);
|
||||
if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) {
|
||||
d->nativeMenuBar = nativeMenuBar;
|
||||
#ifdef Q_OS_MAC
|
||||
|
||||
if (!d->nativeMenuBar) {
|
||||
extern void qt_mac_clear_menubar();
|
||||
qt_mac_clear_menubar();
|
||||
d->macDestroyMenuBar();
|
||||
const QList<QAction *> &menubarActions = actions();
|
||||
for (int i = 0; i < menubarActions.size(); ++i) {
|
||||
const QAction *action = menubarActions.at(i);
|
||||
if (QMenu *menu = action->menu()) {
|
||||
delete menu->d_func()->mac_menu;
|
||||
menu->d_func()->mac_menu = 0;
|
||||
}
|
||||
}
|
||||
delete d->platformMenuBar;
|
||||
d->platformMenuBar = 0;
|
||||
} else {
|
||||
d->macCreateMenuBar(parentWidget());
|
||||
if (!d->platformMenuBar)
|
||||
d->platformMenuBar = QGuiApplicationPrivate::platformIntegration()->createPlatformMenuBar(this);
|
||||
}
|
||||
macUpdateMenuBar();
|
||||
|
||||
updateGeometry();
|
||||
if (!d->nativeMenuBar && parentWidget())
|
||||
setVisible(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1958,6 +1941,12 @@ bool QMenuBar::isNativeMenuBar() const
|
||||
return d->nativeMenuBar;
|
||||
}
|
||||
|
||||
QPlatformMenuBar *QMenuBar::platformMenuBar()
|
||||
{
|
||||
Q_D(const QMenuBar);
|
||||
return d->platformMenuBar;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 4.4
|
||||
|
||||
|
@ -110,11 +110,6 @@ public:
|
||||
void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
|
||||
QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
OSMenuRef macMenu();
|
||||
static bool macUpdateMenuBar();
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
void setDefaultAction(QAction *);
|
||||
QAction *defaultAction() const;
|
||||
@ -125,7 +120,7 @@ public:
|
||||
|
||||
bool isNativeMenuBar() const;
|
||||
void setNativeMenuBar(bool nativeMenuBar);
|
||||
|
||||
QPlatformMenuBar *platformMenuBar();
|
||||
public Q_SLOTS:
|
||||
virtual void setVisible(bool visible);
|
||||
|
||||
|
@ -78,13 +78,10 @@ class QMenuBarPrivate : public QWidgetPrivate
|
||||
public:
|
||||
QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0),
|
||||
closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0),
|
||||
nativeMenuBar(-1), doChildEffects(false)
|
||||
nativeMenuBar(-1), doChildEffects(false), platformMenuBar(0)
|
||||
#ifdef QT3_SUPPORT
|
||||
, doAutoResize(false)
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
, mac_menubar(0)
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_WINCE
|
||||
, wce_menubar(0), wceClassicMenu(false)
|
||||
@ -96,9 +93,7 @@ public:
|
||||
{ }
|
||||
~QMenuBarPrivate()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
delete mac_menubar;
|
||||
#endif
|
||||
delete platformMenuBar;
|
||||
#ifdef Q_WS_WINCE
|
||||
delete wce_menubar;
|
||||
#endif
|
||||
@ -173,35 +168,8 @@ public:
|
||||
#ifdef QT3_SUPPORT
|
||||
bool doAutoResize;
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
//mac menubar binding
|
||||
struct QMacMenuBarPrivate {
|
||||
QList<QMacMenuAction*> actionItems;
|
||||
OSMenuRef menu, apple_menu;
|
||||
QMacMenuBarPrivate();
|
||||
~QMacMenuBarPrivate();
|
||||
QPlatformMenuBar *platformMenuBar;
|
||||
|
||||
void addAction(QAction *, QMacMenuAction* =0);
|
||||
void addAction(QMacMenuAction *, QMacMenuAction* =0);
|
||||
void syncAction(QMacMenuAction *);
|
||||
inline void syncAction(QAction *a) { syncAction(findAction(a)); }
|
||||
void removeAction(QMacMenuAction *);
|
||||
inline void removeAction(QAction *a) { removeAction(findAction(a)); }
|
||||
inline QMacMenuAction *findAction(QAction *a) {
|
||||
for(int i = 0; i < actionItems.size(); i++) {
|
||||
QMacMenuAction *act = actionItems[i];
|
||||
if(a == act->action)
|
||||
return act;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} *mac_menubar;
|
||||
static bool macUpdateMenuBarImmediatly();
|
||||
bool macWidgetHasNativeMenubar(QWidget *widget);
|
||||
void macCreateMenuBar(QWidget *);
|
||||
void macDestroyMenuBar();
|
||||
OSMenuRef macMenu();
|
||||
#endif
|
||||
#ifdef Q_WS_WINCE
|
||||
void wceCreateMenuBar(QWidget *);
|
||||
void wceDestroyMenuBar();
|
||||
|
@ -155,12 +155,6 @@ SOURCES += \
|
||||
widgets/qmacnativewidget_mac.mm \
|
||||
}
|
||||
|
||||
mac {
|
||||
OBJECTIVE_SOURCES += widgets/qmenu_mac.mm \
|
||||
widgets/qcocoamenu_mac.mm \
|
||||
platforms/mac/qt_widget_helpers_mac.mm
|
||||
}
|
||||
|
||||
wince*: {
|
||||
SOURCES += widgets/qmenu_wince.cpp
|
||||
HEADERS += widgets/qmenu_wince_resource_p.h
|
||||
|
Loading…
Reference in New Issue
Block a user