From edb4e66f5f81f2b62ed0664bf9654c36ebbf315c Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 30 Nov 2012 11:27:34 +0100 Subject: Mac: fix regression to make dialog resizable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-28254 Change-Id: I8623a68d589bec17042935ad308f85ddc953540d Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoawindow.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index f786e6969f..8ef489e28e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -372,9 +372,9 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags) if (flags == Qt::Window) { styleMask = (NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask); } else if ((flags & Qt::Dialog) && (window()->modality() != Qt::NonModal)) { - styleMask = NSTitledWindowMask; + styleMask = NSResizableWindowMask | NSTitledWindowMask; } else if (!(flags & Qt::FramelessWindowHint)) { - if (flags & Qt::WindowMaximizeButtonHint) + if ((flags & Qt::Dialog) || (flags & Qt::WindowMaximizeButtonHint)) styleMask |= NSResizableWindowMask; if (flags & Qt::WindowTitleHint) styleMask |= NSTitledWindowMask; -- cgit v1.2.3 From f6cc1f3aeae795e7ed67338b17b860df9f5146a7 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 3 Dec 2012 22:03:53 +0100 Subject: Ensure ctrl + click sends a right mouse button press in Cocoa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Mac's typically just have one button for their mice then pressing Control then clicking the button should end it as a right mouse button event. Task-number: QTBUG-28350 Change-Id: Iabcac5b315c36cb8cd062c27d7b1506bc066f5bb Reviewed-by: Liang Qi Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview.h | 1 + src/plugins/platforms/cocoa/qnsview.mm | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index f93fd86205..9cdfe6f5bb 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -66,6 +66,7 @@ QT_END_NAMESPACE QString m_composingText; bool m_sendKeyEvent; QStringList *currentCustomDragTypes; + bool m_sendUpAsRightButton; Qt::KeyboardModifiers currentWheelModifiers; bool m_subscribesForGlobalFrameNotifications; } diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index b608989e43..eea65cf8c0 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -84,6 +84,7 @@ static QTouchDevice *touchDevice = 0; m_sendKeyEvent = false; m_subscribesForGlobalFrameNotifications = false; currentCustomDragTypes = 0; + m_sendUpAsRightButton = false; if (!touchDevice) { touchDevice = new QTouchDevice; @@ -427,6 +428,7 @@ static QTouchDevice *touchDevice = 0; - (void)mouseDown:(NSEvent *)theEvent { + m_sendUpAsRightButton = false; if (m_platformWindow->m_activePopupWindow) { QWindowSystemInterface::handleCloseEvent(m_platformWindow->m_activePopupWindow); QWindowSystemInterface::flushWindowSystemEvents(); @@ -438,7 +440,12 @@ static QTouchDevice *touchDevice = 0; [inputManager handleMouseEvent:theEvent]; } } else { - m_buttons |= Qt::LeftButton; + if ([self convertKeyModifiers:[theEvent modifierFlags]] & Qt::MetaModifier) { + m_buttons |= Qt::RightButton; + m_sendUpAsRightButton = true; + } else { + m_buttons |= Qt::LeftButton; + } [self handleMouseEvent:theEvent]; } } @@ -452,7 +459,12 @@ static QTouchDevice *touchDevice = 0; - (void)mouseUp:(NSEvent *)theEvent { - m_buttons &= QFlag(~int(Qt::LeftButton)); + if (m_sendUpAsRightButton) { + m_buttons &= QFlag(~int(Qt::RightButton)); + m_sendUpAsRightButton = false; + } else { + m_buttons &= QFlag(~int(Qt::LeftButton)); + } [self handleMouseEvent:theEvent]; } -- cgit v1.2.3 From fd4106e2d110a361208a6289cee18c5847377cb1 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 5 Dec 2012 11:36:25 +0100 Subject: Cocoa: fix unresponsive dialogs causes application to hang The reason for this bug seems to be related to how we wait for more events in the event dispatcher. We use the nextEventMatchingMask function, which already in Qt4 showed to have problems when telling it to not dequeue the event. The solution back then was to tell it to dequeue the event, and instead repost in front again. Why this was changed in Qt5 is uncertain (other than it being tempting) but moving the same code back in will solve the bug. Note that this bug might also stem from the fact that the run loop sources we add in the event dispatcher fires before the application is really ready to show modal dialogs. E.g refusing to execute a modal dialog before NSAppDelegate applicationWillFinishLaunching is called will also fix the problem. But this code change is to big atm, and can easily introduce other unforeseen regressions. Task-number: QTBUG-28283 Change-Id: I07cd109568c2b9c782cf5120a9eb2ac71128cada Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 7aa365df67..80c9e227d2 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -510,14 +510,16 @@ static bool IsMouseOrKeyEvent( NSEvent* event ) static inline void qt_mac_waitForMoreEvents(NSString *runLoopMode = NSDefaultRunLoopMode) { - // If no event exist in the cocoa event que, wait - // (and free up cpu time) until at least one event occur. - // This implementation is a bit on the edge, but seems to - // work fine: - [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] - inMode:runLoopMode - dequeue:NO]; + // If no event exist in the cocoa event que, wait (and free up cpu time) until + // at least one event occur. Setting 'dequeuing' to 'no' in the following call + // causes it to hang under certain circumstances (QTBUG-28283), so we tell it + // to dequeue instead, just to repost the event again: + NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantFuture] + inMode:runLoopMode + dequeue:YES]; + if (event) + [NSApp postEvent:event atStart:YES]; } bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) -- cgit v1.2.3 From e84e86dc8cdab602ed19c18829e57230687a427c Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Thu, 6 Dec 2012 17:46:07 +0100 Subject: Update QNSView geometry on window resize. Ideally this should not be required since NSWindow should resize the content view automatically. However, in the case of modal QDialogs this does not happen. Add call to updateGeometry in windowDidResize as a workaround, and remove code which called QNSView::setFrameSize with the current size. This will cause duplicate handleGeometryChange calls in the non-qdialog case, add a test to see if the geometry really has changed to prevent that. Change-Id: I29bea23b2ab72f923aeadf8db8cb9131ae177a28 Reviewed-by: Liang Qi --- src/plugins/platforms/cocoa/qcocoawindow.mm | 4 +--- src/plugins/platforms/cocoa/qnsview.mm | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 8ef489e28e..ffee8528f0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -590,9 +590,7 @@ void QCocoaWindow::windowDidResize() if (!m_nsWindow) return; - NSRect rect = [[m_nsWindow contentView]frame]; - // Call setFrameSize which will trigger a frameDidChangeNotification on QNSView. - [[m_nsWindow contentView] setFrameSize:rect.size]; + [m_contentView updateGeometry]; } void QCocoaWindow::windowWillClose() diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index eea65cf8c0..1f19b07904 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -185,6 +185,9 @@ static QTouchDevice *touchDevice = 0; geometry = qt_mac_toQRect([self frame]); } + if (geometry == m_platformWindow->geometry()) + return; + #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG qDebug() << "QNSView::udpateGeometry" << m_platformWindow << geometry; #endif -- cgit v1.2.3 From 9650a5aa25b5750c571326380490c191c62fd6a1 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Tue, 4 Dec 2012 15:19:27 +0100 Subject: Avoid backing store color space conversions. We want the Qt backing store to be in the device color space by default. This will avoid colour space conversions when blitting it to screen, at the cost of a potential loss in color accuracy. As it turns out, CGColorSpaceCreateDeviceRGB no longer crates a device color space but rather a generic color space. (Since 10.4). Create the color space with a system profile instead. Accurate color representation needs to be supported at some point, but this fast path should be the default. Change-Id: I7ebb77b36f81f66119d8c2ef464723401ec1d1e8 Reviewed-by: Gabriel de Dietrich Reviewed-by: Gunnar Sletta --- src/plugins/platforms/cocoa/qcocoahelpers.mm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 008d9da2cf..0d0d2eb106 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -789,7 +789,21 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy) NULL, false); } else { - CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB(); + // Try get a device color space. Using the device color space means + // that the CGImage can be drawn to screen without per-pixel color + // space conversion, at the cost of less color accuracy. + CGColorSpaceRef cgColourSpaceRef = 0; + CMProfileRef sysProfile; + if (CMGetSystemProfile(&sysProfile) == noErr) + { + cgColourSpaceRef = CGColorSpaceCreateWithPlatformColorSpace(sysProfile); + CMCloseProfile(sysProfile); + } + + // Fall back to Generic RGB if a profile was not found. + if (!cgColourSpaceRef) + cgColourSpaceRef = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + cgImage = CGImageCreate(width, height, colorBufferSize, -- cgit v1.2.3 From 2e142143579c0db098d966d40ddc871c9c7119f9 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Tue, 4 Dec 2012 15:26:02 +0100 Subject: Use the "copy" blend mode for backingstore drawing The default is a "source over", but we want to completely replace the destination pixels. (Which is slightly faster). Change-Id: I4916765258a2236f70f58a8e20b06f80739183c1 Reviewed-by: Gabriel de Dietrich Reviewed-by: Gunnar Sletta --- src/plugins/platforms/cocoa/qnsview.mm | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 1f19b07904..f0ece54d20 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -316,6 +316,7 @@ static QTouchDevice *touchDevice = 0; ); CGImageRef bsCGImage = m_backingStore->getBackingStoreCGImage(); CGImageRef cleanImg = CGImageCreateWithImageInRect(bsCGImage, backingStoreRect); + CGContextSetBlendMode(cgContext, kCGBlendModeCopy); CGContextDrawImage(cgContext, dirtyWindowRect, cleanImg); // Clean-up: -- cgit v1.2.3 From 13fcd1c342b7d60640fb82956149d00f1ee2f3c7 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Tue, 4 Dec 2012 17:02:59 +0100 Subject: Set CGImage format when converting from QImage. Set the CGImage format based on QImage::format(). Handle8-bit per component (A)RGB. Change-Id: I041b0ee53d3943a0aaf9e813eb0a235c4de619dd Reviewed-by: Gabriel de Dietrich Reviewed-by: Gunnar Sletta --- src/plugins/platforms/cocoa/qcocoahelpers.mm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 0d0d2eb106..c1146612a6 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -804,13 +804,34 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy) if (!cgColourSpaceRef) cgColourSpaceRef = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + // Create a CGBitmapInfo contiaining the image format. + // Support the 8-bit per component (A)RGB formats. + CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Little; + switch (qImage.format()) { + case QImage::Format_ARGB32_Premultiplied : + bitmapInfo |= kCGImageAlphaPremultipliedFirst; + break; + case QImage::Format_ARGB32 : + bitmapInfo |= kCGImageAlphaFirst; + break; + case QImage::Format_RGB32 : + bitmapInfo |= kCGImageAlphaNoneSkipFirst; + break; + case QImage::Format_RGB888 : + bitmapInfo |= kCGImageAlphaNone; + break; + default: + qWarning() << "qt_mac_toCGImage: Unsupported image format" << qImage.format(); + break; + } + cgImage = CGImageCreate(width, height, colorBufferSize, bitDepth, bytesPrLine, cgColourSpaceRef, - kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, + bitmapInfo, cgDataProviderRef, NULL, false, -- cgit v1.2.3 From b9321a1a5f1b255e5e5860edb42c63a4e4da6804 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Mon, 22 Oct 2012 10:41:28 +0200 Subject: Implement Cocoa KeyMapper. Port Qt 4 implementation. Shortcuts such as shift-5 should now work. Change-Id: I1d8c4c6c4a903142361996b558ee31c8549fcef6 Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff Reviewed-by: Lars Knoll --- src/plugins/platforms/cocoa/cocoa.pro | 2 + src/plugins/platforms/cocoa/qcocoaintegration.h | 4 + src/plugins/platforms/cocoa/qcocoaintegration.mm | 6 + src/plugins/platforms/cocoa/qcocoakeymapper.h | 111 ++++++ src/plugins/platforms/cocoa/qcocoakeymapper.mm | 468 +++++++++++++++++++++++ src/plugins/platforms/cocoa/qnsview.mm | 15 +- 6 files changed, 604 insertions(+), 2 deletions(-) create mode 100644 src/plugins/platforms/cocoa/qcocoakeymapper.h create mode 100644 src/plugins/platforms/cocoa/qcocoakeymapper.mm (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 78fcf20afc..f709bef633 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -38,6 +38,7 @@ OBJECTIVE_SOURCES += main.mm \ qcocoaservices.mm \ qcocoasystemtrayicon.mm \ qcocoaintrospection.mm \ + qcocoakeymapper.mm \ HEADERS += qcocoaintegration.h \ qcocoatheme.h \ @@ -72,6 +73,7 @@ HEADERS += qcocoaintegration.h \ qcocoaservices.h \ qcocoasystemtrayicon.h \ qcocoaintrospection.h \ + qcocoakeymapper.h \ RESOURCES += qcocoaresources.qrc diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 1bb46ea3ea..e455a3552e 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -49,6 +49,7 @@ #include "qcocoaclipboard.h" #include "qcocoadrag.h" #include "qcocoaservices.h" +#include "qcocoakeymapper.h" #include #include @@ -121,6 +122,8 @@ public: QPlatformServices *services() const; QVariant styleHint(StyleHint hint) const; + QList possibleKeys(const QKeyEvent *event) const; + void updateScreens(); private: @@ -138,6 +141,7 @@ private: QScopedPointer mCocoaDrag; QScopedPointer mNativeInterface; QScopedPointer mServices; + QScopedPointer mKeyboardMapper; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 393c471c25..e096096e99 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -199,6 +199,7 @@ QCocoaIntegration::QCocoaIntegration() , mCocoaDrag(new QCocoaDrag) , mNativeInterface(new QCocoaNativeInterface) , mServices(new QCocoaServices) + , mKeyboardMapper(new QCocoaKeyMapper) { initResources(); QCocoaAutoReleasePool pool; @@ -414,4 +415,9 @@ QVariant QCocoaIntegration::styleHint(StyleHint hint) const return QPlatformIntegration::styleHint(hint); } +QList QCocoaIntegration::possibleKeys(const QKeyEvent *event) const +{ + return mKeyboardMapper->possibleKeys(event); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.h b/src/plugins/platforms/cocoa/qcocoakeymapper.h new file mode 100644 index 0000000000..693539dd4e --- /dev/null +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOCOAKEYMAPPER_H +#define QCOCOAKEYMAPPER_H + +#include + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \internal + A Mac KeyboardLayoutItem has 8 possible states: + 1. Unmodified + 2. Shift + 3. Control + 4. Control + Shift + 5. Alt + 6. Alt + Shift + 7. Alt + Control + 8. Alt + Control + Shift + 9. Meta + 10. Meta + Shift + 11. Meta + Control + 12. Meta + Control + Shift + 13. Meta + Alt + 14. Meta + Alt + Shift + 15. Meta + Alt + Control + 16. Meta + Alt + Control + Shift +*/ +struct KeyboardLayoutItem { + bool dirty; + quint32 qtKey[16]; // Can by any Qt::Key_, or unicode character +}; + + +class QCocoaKeyMapper +{ +public: + QCocoaKeyMapper(); + ~QCocoaKeyMapper(); + QList possibleKeys(const QKeyEvent *event) const; + bool updateKeyboard(); + void deleteLayouts(); + void updateKeyMap(unsigned short macVirtualKey, QChar unicodeKey); + void clearMappings(); + +private: + QCFType currentInputSource; + + QLocale keyboardInputLocale; + Qt::LayoutDirection keyboardInputDirection; + enum { NullMode, UnicodeMode, OtherMode } keyboard_mode; + union { + const UCKeyboardLayout *unicode; + void *other; + } keyboard_layout_format; + KeyboardLayoutRef currentKeyboardLayout; + KeyboardLayoutKind keyboard_kind; + UInt32 keyboard_dead; + KeyboardLayoutItem *keyLayout[256]; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm new file mode 100644 index 0000000000..6df0466355 --- /dev/null +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm @@ -0,0 +1,468 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcocoakeymapper.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +// QCocoaKeyMapper debug facilities +//#define DEBUG_KEY_BINDINGS +//#define DEBUG_KEY_BINDINGS_MODIFIERS +//#define DEBUG_KEY_MAPS + +// Possible modifier states. +// NOTE: The order of these states match the order in updatePossibleKeyCodes()! +static const Qt::KeyboardModifiers ModsTbl[] = { + Qt::NoModifier, // 0 + Qt::ShiftModifier, // 1 + Qt::ControlModifier, // 2 + Qt::ControlModifier | Qt::ShiftModifier, // 3 + Qt::AltModifier, // 4 + Qt::AltModifier | Qt::ShiftModifier, // 5 + Qt::AltModifier | Qt::ControlModifier, // 6 + Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 7 + Qt::MetaModifier, // 8 + Qt::MetaModifier | Qt::ShiftModifier, // 9 + Qt::MetaModifier | Qt::ControlModifier, // 10 + Qt::MetaModifier | Qt::ControlModifier | Qt::ShiftModifier,// 11 + Qt::MetaModifier | Qt::AltModifier, // 12 + Qt::MetaModifier | Qt::AltModifier | Qt::ShiftModifier, // 13 + Qt::MetaModifier | Qt::AltModifier | Qt::ControlModifier, // 14 + Qt::MetaModifier | Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 15 +}; + +bool qt_mac_eat_unicode_key = false; + +Q_GUI_EXPORT void qt_mac_secure_keyboard(bool b) +{ + static bool secure = false; + if (b != secure){ + b ? EnableSecureEventInput() : DisableSecureEventInput(); + secure = b; + } +} + +/* key maps */ +struct qt_mac_enum_mapper +{ + int mac_code; + int qt_code; +#if defined(DEBUG_KEY_BINDINGS) +# define QT_MAC_MAP_ENUM(x) x, #x + const char *desc; +#else +# define QT_MAC_MAP_ENUM(x) x +#endif +}; + +//modifiers +static qt_mac_enum_mapper qt_mac_modifier_symbols[] = { + { shiftKey, QT_MAC_MAP_ENUM(Qt::ShiftModifier) }, + { rightShiftKey, QT_MAC_MAP_ENUM(Qt::ShiftModifier) }, + { controlKey, QT_MAC_MAP_ENUM(Qt::MetaModifier) }, + { rightControlKey, QT_MAC_MAP_ENUM(Qt::MetaModifier) }, + { cmdKey, QT_MAC_MAP_ENUM(Qt::ControlModifier) }, + { optionKey, QT_MAC_MAP_ENUM(Qt::AltModifier) }, + { rightOptionKey, QT_MAC_MAP_ENUM(Qt::AltModifier) }, + { kEventKeyModifierNumLockMask, QT_MAC_MAP_ENUM(Qt::KeypadModifier) }, + { 0, QT_MAC_MAP_ENUM(0) } +}; +Qt::KeyboardModifiers qt_mac_get_modifiers(int keys) +{ +#ifdef DEBUG_KEY_BINDINGS_MODIFIERS + qDebug("Qt: internal: **Mapping modifiers: %d (0x%04x)", keys, keys); +#endif + Qt::KeyboardModifiers ret = Qt::NoModifier; + for (int i = 0; qt_mac_modifier_symbols[i].qt_code; i++) { + if (keys & qt_mac_modifier_symbols[i].mac_code) { +#ifdef DEBUG_KEY_BINDINGS_MODIFIERS + qDebug("Qt: internal: got modifier: %s", qt_mac_modifier_symbols[i].desc); +#endif + ret |= Qt::KeyboardModifier(qt_mac_modifier_symbols[i].qt_code); + } + } + if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { + Qt::KeyboardModifiers oldModifiers = ret; + ret &= ~(Qt::MetaModifier | Qt::ControlModifier); + if (oldModifiers & Qt::ControlModifier) + ret |= Qt::MetaModifier; + if (oldModifiers & Qt::MetaModifier) + ret |= Qt::ControlModifier; + } + return ret; +} +static int qt_mac_get_mac_modifiers(Qt::KeyboardModifiers keys) +{ +#ifdef DEBUG_KEY_BINDINGS_MODIFIERS + qDebug("Qt: internal: **Mapping modifiers: %d (0x%04x)", (int)keys, (int)keys); +#endif + int ret = 0; + for (int i = 0; qt_mac_modifier_symbols[i].qt_code; i++) { + if (keys & qt_mac_modifier_symbols[i].qt_code) { +#ifdef DEBUG_KEY_BINDINGS_MODIFIERS + qDebug("Qt: internal: got modifier: %s", qt_mac_modifier_symbols[i].desc); +#endif + ret |= qt_mac_modifier_symbols[i].mac_code; + } + } + + if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { + int oldModifiers = ret; + ret &= ~(controlKeyBit | cmdKeyBit); + if (oldModifiers & controlKeyBit) + ret |= cmdKeyBit; + if (oldModifiers & cmdKeyBit) + ret |= controlKeyBit; + } + return ret; +} + +//keyboard keys (non-modifiers) +static qt_mac_enum_mapper qt_mac_keyboard_symbols[] = { + { kHomeCharCode, QT_MAC_MAP_ENUM(Qt::Key_Home) }, + { kEnterCharCode, QT_MAC_MAP_ENUM(Qt::Key_Enter) }, + { kEndCharCode, QT_MAC_MAP_ENUM(Qt::Key_End) }, + { kBackspaceCharCode, QT_MAC_MAP_ENUM(Qt::Key_Backspace) }, + { kTabCharCode, QT_MAC_MAP_ENUM(Qt::Key_Tab) }, + { kPageUpCharCode, QT_MAC_MAP_ENUM(Qt::Key_PageUp) }, + { kPageDownCharCode, QT_MAC_MAP_ENUM(Qt::Key_PageDown) }, + { kReturnCharCode, QT_MAC_MAP_ENUM(Qt::Key_Return) }, + { kEscapeCharCode, QT_MAC_MAP_ENUM(Qt::Key_Escape) }, + { kLeftArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Left) }, + { kRightArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Right) }, + { kUpArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Up) }, + { kDownArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Down) }, + { kHelpCharCode, QT_MAC_MAP_ENUM(Qt::Key_Help) }, + { kDeleteCharCode, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, +//ascii maps, for debug + { ':', QT_MAC_MAP_ENUM(Qt::Key_Colon) }, + { ';', QT_MAC_MAP_ENUM(Qt::Key_Semicolon) }, + { '<', QT_MAC_MAP_ENUM(Qt::Key_Less) }, + { '=', QT_MAC_MAP_ENUM(Qt::Key_Equal) }, + { '>', QT_MAC_MAP_ENUM(Qt::Key_Greater) }, + { '?', QT_MAC_MAP_ENUM(Qt::Key_Question) }, + { '@', QT_MAC_MAP_ENUM(Qt::Key_At) }, + { ' ', QT_MAC_MAP_ENUM(Qt::Key_Space) }, + { '!', QT_MAC_MAP_ENUM(Qt::Key_Exclam) }, + { '"', QT_MAC_MAP_ENUM(Qt::Key_QuoteDbl) }, + { '#', QT_MAC_MAP_ENUM(Qt::Key_NumberSign) }, + { '$', QT_MAC_MAP_ENUM(Qt::Key_Dollar) }, + { '%', QT_MAC_MAP_ENUM(Qt::Key_Percent) }, + { '&', QT_MAC_MAP_ENUM(Qt::Key_Ampersand) }, + { '\'', QT_MAC_MAP_ENUM(Qt::Key_Apostrophe) }, + { '(', QT_MAC_MAP_ENUM(Qt::Key_ParenLeft) }, + { ')', QT_MAC_MAP_ENUM(Qt::Key_ParenRight) }, + { '*', QT_MAC_MAP_ENUM(Qt::Key_Asterisk) }, + { '+', QT_MAC_MAP_ENUM(Qt::Key_Plus) }, + { ',', QT_MAC_MAP_ENUM(Qt::Key_Comma) }, + { '-', QT_MAC_MAP_ENUM(Qt::Key_Minus) }, + { '.', QT_MAC_MAP_ENUM(Qt::Key_Period) }, + { '/', QT_MAC_MAP_ENUM(Qt::Key_Slash) }, + { '[', QT_MAC_MAP_ENUM(Qt::Key_BracketLeft) }, + { ']', QT_MAC_MAP_ENUM(Qt::Key_BracketRight) }, + { '\\', QT_MAC_MAP_ENUM(Qt::Key_Backslash) }, + { '_', QT_MAC_MAP_ENUM(Qt::Key_Underscore) }, + { '`', QT_MAC_MAP_ENUM(Qt::Key_QuoteLeft) }, + { '{', QT_MAC_MAP_ENUM(Qt::Key_BraceLeft) }, + { '}', QT_MAC_MAP_ENUM(Qt::Key_BraceRight) }, + { '|', QT_MAC_MAP_ENUM(Qt::Key_Bar) }, + { '~', QT_MAC_MAP_ENUM(Qt::Key_AsciiTilde) }, + { '^', QT_MAC_MAP_ENUM(Qt::Key_AsciiCircum) }, + { 0, QT_MAC_MAP_ENUM(0) } +}; + +static qt_mac_enum_mapper qt_mac_keyvkey_symbols[] = { //real scan codes + { 122, QT_MAC_MAP_ENUM(Qt::Key_F1) }, + { 120, QT_MAC_MAP_ENUM(Qt::Key_F2) }, + { 99, QT_MAC_MAP_ENUM(Qt::Key_F3) }, + { 118, QT_MAC_MAP_ENUM(Qt::Key_F4) }, + { 96, QT_MAC_MAP_ENUM(Qt::Key_F5) }, + { 97, QT_MAC_MAP_ENUM(Qt::Key_F6) }, + { 98, QT_MAC_MAP_ENUM(Qt::Key_F7) }, + { 100, QT_MAC_MAP_ENUM(Qt::Key_F8) }, + { 101, QT_MAC_MAP_ENUM(Qt::Key_F9) }, + { 109, QT_MAC_MAP_ENUM(Qt::Key_F10) }, + { 103, QT_MAC_MAP_ENUM(Qt::Key_F11) }, + { 111, QT_MAC_MAP_ENUM(Qt::Key_F12) }, + { 105, QT_MAC_MAP_ENUM(Qt::Key_F13) }, + { 107, QT_MAC_MAP_ENUM(Qt::Key_F14) }, + { 113, QT_MAC_MAP_ENUM(Qt::Key_F15) }, + { 106, QT_MAC_MAP_ENUM(Qt::Key_F16) }, + { 0, QT_MAC_MAP_ENUM(0) } +}; + +static qt_mac_enum_mapper qt_mac_private_unicode[] = { + { 0xF700, QT_MAC_MAP_ENUM(Qt::Key_Up) }, //NSUpArrowFunctionKey + { 0xF701, QT_MAC_MAP_ENUM(Qt::Key_Down) }, //NSDownArrowFunctionKey + { 0xF702, QT_MAC_MAP_ENUM(Qt::Key_Left) }, //NSLeftArrowFunctionKey + { 0xF703, QT_MAC_MAP_ENUM(Qt::Key_Right) }, //NSRightArrowFunctionKey + { 0xF727, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertFunctionKey + { 0xF728, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteFunctionKey + { 0xF729, QT_MAC_MAP_ENUM(Qt::Key_Home) }, //NSHomeFunctionKey + { 0xF72B, QT_MAC_MAP_ENUM(Qt::Key_End) }, //NSEndFunctionKey + { 0xF72C, QT_MAC_MAP_ENUM(Qt::Key_PageUp) }, //NSPageUpFunctionKey + { 0xF72D, QT_MAC_MAP_ENUM(Qt::Key_PageDown) }, //NSPageDownFunctionKey + { 0xF72F, QT_MAC_MAP_ENUM(Qt::Key_ScrollLock) }, //NSScrollLockFunctionKey + { 0xF730, QT_MAC_MAP_ENUM(Qt::Key_Pause) }, //NSPauseFunctionKey + { 0xF731, QT_MAC_MAP_ENUM(Qt::Key_SysReq) }, //NSSysReqFunctionKey + { 0xF735, QT_MAC_MAP_ENUM(Qt::Key_Menu) }, //NSMenuFunctionKey + { 0xF738, QT_MAC_MAP_ENUM(Qt::Key_Print) }, //NSPrintFunctionKey + { 0xF73A, QT_MAC_MAP_ENUM(Qt::Key_Clear) }, //NSClearDisplayFunctionKey + { 0xF73D, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertCharFunctionKey + { 0xF73E, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteCharFunctionKey + { 0xF741, QT_MAC_MAP_ENUM(Qt::Key_Select) }, //NSSelectFunctionKey + { 0xF742, QT_MAC_MAP_ENUM(Qt::Key_Execute) }, //NSExecuteFunctionKey + { 0xF746, QT_MAC_MAP_ENUM(Qt::Key_Help) }, //NSHelpFunctionKey + { 0xF747, QT_MAC_MAP_ENUM(Qt::Key_Mode_switch) }, //NSModeSwitchFunctionKey + { 0, QT_MAC_MAP_ENUM(0) } +}; + +static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) +{ +#ifdef DEBUG_KEY_BINDINGS + qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); +#endif + + if (key == kClearCharCode && virtualKey == 0x47) + return Qt::Key_Clear; + + if (key.isDigit()) { +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: %d", __LINE__, key.digitValue()); +#endif + return key.digitValue() + Qt::Key_0; + } + + if (key.isLetter()) { +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: %d", __LINE__, (key.toUpper().unicode() - 'A')); +#endif + return (key.toUpper().unicode() - 'A') + Qt::Key_A; + } + if (key.isSymbol()) { +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: %d", __LINE__, (key.unicode())); +#endif + return key.unicode(); + } + + for (int i = 0; qt_mac_keyboard_symbols[i].qt_code; i++) { + if (qt_mac_keyboard_symbols[i].mac_code == key) { + /* To work like Qt for X11 we issue Backtab when Shift + Tab are pressed */ + if (qt_mac_keyboard_symbols[i].qt_code == Qt::Key_Tab && (modif & Qt::ShiftModifier)) { +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: Qt::Key_Backtab", __LINE__); +#endif + return Qt::Key_Backtab; + } + +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: %s", __LINE__, qt_mac_keyboard_symbols[i].desc); +#endif + return qt_mac_keyboard_symbols[i].qt_code; + } + } + + //last ditch try to match the scan code + for (int i = 0; qt_mac_keyvkey_symbols[i].qt_code; i++) { + if (qt_mac_keyvkey_symbols[i].mac_code == virtualKey) { +#ifdef DEBUG_KEY_BINDINGS + qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); +#endif + return qt_mac_keyvkey_symbols[i].qt_code; + } + } + + // check if they belong to key codes in private unicode range + if (key >= 0xf700 && key <= 0xf747) { + if (key >= 0xf704 && key <= 0xf726) { + return Qt::Key_F1 + (key.unicode() - 0xf704) ; + } + for (int i = 0; qt_mac_private_unicode[i].qt_code; i++) { + if (qt_mac_private_unicode[i].mac_code == key) { + return qt_mac_private_unicode[i].qt_code; + } + } + + } + + //oh well +#ifdef DEBUG_KEY_BINDINGS + qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); +#endif + return Qt::Key_unknown; +} + +QCocoaKeyMapper::QCocoaKeyMapper() +{ + memset(keyLayout, 0, sizeof(keyLayout)); + keyboard_layout_format.unicode = 0; + currentInputSource = 0; +} + +QCocoaKeyMapper::~QCocoaKeyMapper() +{ + deleteLayouts(); +} + +bool QCocoaKeyMapper::updateKeyboard() +{ + const UCKeyboardLayout *uchrData = 0; + QCFType source = TISCopyCurrentKeyboardInputSource(); + if (keyboard_mode != NullMode && source == currentInputSource) { + return false; + } + Q_ASSERT(source != 0); + CFDataRef data = static_cast(TISGetInputSourceProperty(source, + kTISPropertyUnicodeKeyLayoutData)); + uchrData = data ? reinterpret_cast(CFDataGetBytePtr(data)) : 0; + + keyboard_kind = LMGetKbdType(); + if (uchrData) { + keyboard_layout_format.unicode = uchrData; + keyboard_mode = UnicodeMode; + } + currentInputSource = source; + keyboard_dead = 0; + CFStringRef iso639Code; + + CFArrayRef array = static_cast(TISGetInputSourceProperty(currentInputSource, kTISPropertyInputSourceLanguages)); + iso639Code = static_cast(CFArrayGetValueAtIndex(array, 0)); // Actually a RFC3066bis, but it's close enough + + if (iso639Code) { + keyboardInputLocale = QLocale(QCFString::toQString(iso639Code)); + keyboardInputDirection = keyboardInputLocale.textDirection(); + } else { + keyboardInputLocale = QLocale::c(); + keyboardInputDirection = Qt::LeftToRight; + } + return true; +} + +void QCocoaKeyMapper::deleteLayouts() +{ + keyboard_mode = NullMode; + for (int i = 0; i < 255; ++i) { + if (keyLayout[i]) { + delete keyLayout[i]; + keyLayout[i] = 0; + } + } +} + +void QCocoaKeyMapper::clearMappings() +{ + deleteLayouts(); + updateKeyboard(); +} + +void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKey) +{ + if (updateKeyboard()) { + // ### Qt 4 did this: + // QKeyMapper::changeKeyboard(); + } + if (keyLayout[macVirtualKey]) + return; + + UniCharCount buffer_size = 10; + UniChar buffer[buffer_size]; + keyLayout[macVirtualKey] = new KeyboardLayoutItem; + for (int i = 0; i < 16; ++i) { + UniCharCount out_buffer_size = 0; + keyLayout[macVirtualKey]->qtKey[i] = 0; + + const UInt32 keyModifier = ((qt_mac_get_mac_modifiers(ModsTbl[i]) >> 8) & 0xFF); + OSStatus err = UCKeyTranslate(keyboard_layout_format.unicode, macVirtualKey, kUCKeyActionDown, keyModifier, + keyboard_kind, 0, &keyboard_dead, buffer_size, &out_buffer_size, buffer); + if (err == noErr && out_buffer_size) { + const QChar unicode(buffer[0]); + int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); + if (qtkey == Qt::Key_unknown) + qtkey = unicode.unicode(); + keyLayout[macVirtualKey]->qtKey[i] = qtkey; + } else { + int qtkey = qt_mac_get_key(keyModifier, unicodeKey, macVirtualKey); + if (qtkey == Qt::Key_unknown) + qtkey = unicodeKey.unicode(); + keyLayout[macVirtualKey]->qtKey[i] = qtkey; + } + } +#ifdef DEBUG_KEY_MAPS + qDebug("updateKeyMap for virtual key = 0x%02x!", (uint)macVirtualKey); + for (int i = 0; i < 16; ++i) { + qDebug(" [%d] (%d,0x%02x,'%c')", i, + keyLayout[macVirtualKey]->qtKey[i], + keyLayout[macVirtualKey]->qtKey[i], + keyLayout[macVirtualKey]->qtKey[i]); + } +#endif +} + +QList QCocoaKeyMapper::possibleKeys(const QKeyEvent *event) const +{ + QList ret; + const_cast(this)->updateKeyMap(event->nativeVirtualKey(), QChar(event->key())); + + KeyboardLayoutItem *kbItem = keyLayout[event->nativeVirtualKey()]; + + if (!kbItem) // Key is not in any keyboard layout (e.g. eisu-key on Japanese keyboard) + return ret; + + int baseKey = kbItem->qtKey[0]; + Qt::KeyboardModifiers keyMods = event->modifiers(); + + ret << int(baseKey + keyMods); // The base key is _always_ valid, of course + + for (int i = 1; i < 8; ++i) { + Qt::KeyboardModifiers neededMods = ModsTbl[i]; + int key = kbItem->qtKey[i]; + if (key && key != baseKey && ((keyMods & neededMods) == neededMods)) { + ret << int(key + (keyMods & ~neededMods)); + } + } + return ret; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index f0ece54d20..cfd12cfb61 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -756,9 +756,19 @@ static QTouchDevice *touchDevice = 0; - (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType { ulong timestamp = [nsevent timestamp] * 1000; - Qt::KeyboardModifiers modifiers = [self convertKeyModifiers:[nsevent modifierFlags]]; + ulong nativeModifiers = [nsevent modifierFlags]; + Qt::KeyboardModifiers modifiers = [self convertKeyModifiers: nativeModifiers]; NSString *charactersIgnoringModifiers = [nsevent charactersIgnoringModifiers]; + // [from Qt 4 impl] There is no way to get the scan code from carbon. But we cannot + // use the value 0, since it indicates that the event originates from somewhere + // else than the keyboard. + quint32 nativeScanCode = 1; + + UInt32 nativeVirtualKey = 0; + EventRef eventRef = EventRef([nsevent eventRef]); + GetEventParameter(eventRef, kEventParamKeyCode, typeUInt32, 0, sizeof(nativeVirtualKey), 0, &nativeVirtualKey); + QChar ch; int keyCode; if ([charactersIgnoringModifiers length] > 0) { @@ -799,7 +809,8 @@ static QTouchDevice *touchDevice = 0; } if (m_sendKeyEvent && m_composingText.isEmpty()) - QWindowSystemInterface::handleKeyEvent(m_window, timestamp, QEvent::Type(eventType), keyCode, modifiers, text); + QWindowSystemInterface::handleExtendedKeyEvent(m_window, timestamp, QEvent::Type(eventType), keyCode, modifiers, + nativeScanCode, nativeVirtualKey, nativeModifiers, text); m_sendKeyEvent = false; } -- cgit v1.2.3 From c9d40ef2c1ff9e701cd052dadfc0e515ff6b523f Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 10 Dec 2012 11:49:09 +0200 Subject: Add PLUGIN_CLASS_NAME to qtbase plugins Needed for automating static plugin loading. Task-number: QTBUG-28131 Change-Id: Icd993c0fc8335f29aeec30e853a408d888069399 Reviewed-by: Oswald Buddenhagen --- src/plugins/platforms/cocoa/cocoa.pro | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index f709bef633..5533650809 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -1,6 +1,7 @@ TARGET = qcocoa PLUGIN_TYPE = platforms +PLUGIN_CLASS_NAME = QCocoaIntegrationPlugin load(qt_plugin) OBJECTIVE_SOURCES += main.mm \ -- cgit v1.2.3 From 4afc88b381128302c383a1d82ed93e6274bac9f1 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Tue, 11 Dec 2012 13:37:40 +0100 Subject: Partially revert e84e86dc. Make tst_qquickview::resizemodeitem pass. Returning on equal geometry breaks for non-top-level windows. Change-Id: I3b361655e25b6cf2d5e29410dc1f3567ab8f54d9 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qnsview.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index cfd12cfb61..678f88baa0 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -185,7 +185,7 @@ static QTouchDevice *touchDevice = 0; geometry = qt_mac_toQRect([self frame]); } - if (geometry == m_platformWindow->geometry()) + if (m_platformWindow->m_nsWindow && geometry == m_platformWindow->geometry()) return; #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG -- cgit v1.2.3 From 968b11737564572ef5939400ed70f281556d167b Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Mon, 10 Dec 2012 11:29:54 +0100 Subject: Improve Cocoa platform plugin loading. Loading both the debug and release version of the cocoa plugins causes the objective-c runtime to print "duplicate class definitions" warnings. Fix this by directing the plugin loader to only load one of the cocoa plugins if both are available. Implement this as a special case directly in QFactoryLoader. Define QT_NO_DEBUG_PLUGIN_CHECK to allow mixing debug and release builds. Task-number: QTBUG-28155 Change-Id: Ie1927b219cc501a821f91b7e4b56f0589e0acbf5 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/plugins/platforms/cocoa/cocoa.pro | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 5533650809..85e3f0007c 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -98,13 +98,6 @@ QT += core-private gui-private platformsupport-private OTHER_FILES += cocoa.json -# Build the release libqcocoa.dylib only, skip the debug version. -# The Qt plugin loader will dlopen both if found, causing duplicate -# Objective-c class definitions for the classes defined in the plugin. -contains(QT_CONFIG,release):CONFIG -= debug -contains(QT_CONFIG,debug_and_release):CONFIG -= debug_and_release -contains(QT_CONFIG,build_all):CONFIG -= build_all - # Acccessibility debug support # DEFINES += QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR # include ($$PWD/../../../../util/accessibilityinspector/accessibilityinspector.pri) -- cgit v1.2.3 From 76ce3e6419f9b816359c0995ac7f1828e9291d7e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 12 Dec 2012 17:16:54 +0100 Subject: Fix QWidget::setWindowOpacity() when called before show(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass opacity from the QWidget to QWindow and to the platform windows. Task-number: QTBUG-28477 Change-Id: If5a85d9183bd1ca33dac2052936ecd1e6c0b5f6c Reviewed-by: Samuel Rødal --- src/plugins/platforms/cocoa/qcocoawindow.mm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index ffee8528f0..b545844a24 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -649,6 +650,10 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow) NSRect frame = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()); [m_contentView setFrame:frame]; } + + const qreal opacity = qt_window_private(window())->opacity; + if (!qFuzzyCompare(opacity, qreal(1.0))) + setOpacity(opacity); } NSWindow * QCocoaWindow::createNSWindow() -- cgit v1.2.3 From 3c09f6bc9aee0c97427fe8da6efdc73b4ac473aa Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 30 Oct 2012 14:01:12 +0100 Subject: Mac: fix bugs for font selection in QFontDialog Use localized family name and style name when selecting font with non-English locale Task-number: QTBUG-27415 Change-Id: Ie81507ed011fc096e0f5edad146e97c392e86494 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 5ccd019a9b..ff3ba63931 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -92,20 +92,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QFont newFont; if (cocoaFont) { int pSize = qRound([cocoaFont pointSize]); - QString family(QCFString::toQString([cocoaFont familyName])); - QString typeface(QCFString::toQString([cocoaFont fontName])); - - int hyphenPos = typeface.indexOf(QLatin1Char('-')); - if (hyphenPos != -1) { - typeface.remove(0, hyphenPos + 1); - } else { - typeface = QLatin1String("Normal"); - } + CTFontDescriptorRef font = CTFontCopyFontDescriptor((CTFontRef)cocoaFont); + // QCoreTextFontDatabase::populateFontDatabase() is using localized names + QString family = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL)); + QString style = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL)); - newFont = QFontDatabase().font(family, typeface, pSize); + newFont = QFontDatabase().font(family, style, pSize); newFont.setUnderline(resolveFont.underline()); newFont.setStrikeOut(resolveFont.strikeOut()); + CFRelease(font); } return newFont; } -- cgit v1.2.3 From 9a6366cead1c787f0c29b721bdbf07585199e9ca Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Fri, 14 Dec 2012 14:05:08 +0100 Subject: Don't use NSAccessibilityUnignoredChildren. The function is massively ineffective on deep hierarchies and not strictly needed. (It's supposed to filter out "Ignored" children - VoiceOver will do that anyway based on accessibilityIsIgnored()) Change-Id: I9a74b5f5e9b7880e0d46d5330f7192472eac7a36 Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm | 2 +- src/plugins/platforms/cocoa/qnsviewaccessibility.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index df6b64443d..7d46ad5cde 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -139,7 +139,7 @@ static QAccessibleInterface *acast(void *ptr) [kids addObject:[QCocoaAccessibleElement elementWithInterface:(void*)childInterface parent:self]]; } - return NSAccessibilityUnignoredChildren(kids); + return kids; } else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) { // Just check if the app thinks we're focused. id focusedElement = [NSApp accessibilityAttributeValue:NSAccessibilityFocusedUIElementAttribute]; diff --git a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm index 6824f19489..da714d3326 100644 --- a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm +++ b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm @@ -80,7 +80,7 @@ [kids addObject:[QCocoaAccessibleElement elementWithInterface: m_accessibleRoot->child(i) parent:self ]]; } - return NSAccessibilityUnignoredChildren(kids); + return kids; } else { return [super accessibilityAttributeValue:attribute]; } -- cgit v1.2.3 From 457829da52183d406164f8e8f13c4a35b3caf8d8 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Thu, 13 Dec 2012 11:37:19 +0100 Subject: Fix memory leak in cocoa accessibility. Autorelease ("delete later") the created attribute name array. Change-Id: I2d7af9eb1fd899f04c8acb90204600a2dd43fa20 Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 7d46ad5cde..c722ffb3bf 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -122,7 +122,7 @@ static QAccessibleInterface *acast(void *ptr) [attributes addObject : NSAccessibilityValueAttribute]; } - return attributes; + return [attributes autorelease]; } - (id)accessibilityAttributeValue:(NSString *)attribute { -- cgit v1.2.3 From d75d86190bca85841db2040d50184f4c6886ef89 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Sat, 8 Dec 2012 01:55:11 +0100 Subject: Ensure the native filedialog starts up with the right directory On Mac it was not starting the dialog with the specified directory when one was present. If a filename was given as well then it would start up fine. Task-number: QTBUG-28161 Change-Id: I7cce0d065dd57e6433ce62380d4263d6e20b6e7c Reviewed-by: Liang Qi --- src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index f9122f56d1..5747cc01e9 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -223,7 +223,7 @@ static QString strippedText(QString s) - (void)showModelessPanel { if (mOpenPanel){ - QFileInfo info(*mCurrentSelection); + QFileInfo info(!mCurrentSelection->isEmpty() ? *mCurrentSelection : QT_PREPEND_NAMESPACE(QCFString::toQString)(mCurrentDir)); NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; @@ -241,7 +241,7 @@ static QString strippedText(QString s) - (BOOL)runApplicationModalPanel { - QFileInfo info(*mCurrentSelection); + QFileInfo info(!mCurrentSelection->isEmpty() ? *mCurrentSelection : QT_PREPEND_NAMESPACE(QCFString::toQString)(mCurrentDir)); NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; @@ -266,7 +266,7 @@ static QString strippedText(QString s) - (void)showWindowModalSheet:(QWindow *)parent { - QFileInfo info(*mCurrentSelection); + QFileInfo info(!mCurrentSelection->isEmpty() ? *mCurrentSelection : QT_PREPEND_NAMESPACE(QCFString::toQString)(mCurrentDir)); NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; -- cgit v1.2.3 From f55ce226282ce1ff1c7c998b6d5552b908897d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 28 Nov 2012 13:22:54 +0100 Subject: Cocoa: make accessibility hit test not crash Check if the accessibility element is valid before calling childAt. Change-Id: Id63c11f18b262c3c3a839db8ee2d11c0d7adc822 Reviewed-by: J-P Nurmi Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index c722ffb3bf..d5841c1983 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -239,6 +239,10 @@ static QAccessibleInterface *acast(void *ptr) if (!accessibleInterface) return NSAccessibilityUnignoredAncestor(self); + + if (!acast(accessibleInterface)->isValid()) + return NSAccessibilityUnignoredAncestor(self); + QAccessibleInterface *childInterface = acast(accessibleInterface)->childAt(point.x, qt_mac_flipYCoordinate(point.y)); // No child found, meaning we hit this element. -- cgit v1.2.3 From dde9569d389b4382e8869ac48f942adb3c51ade7 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 17 Dec 2012 22:46:45 +0100 Subject: Initalize the printinfo on Mac if it requests and it needs initalizing When the print panel was closed then it would clean up the printinfo and if it was requested for the same QPrinter then it would not be recreated in time. Therefore we check if it is initalized and if not we re-initalize it. Task-number: QTBUG-28657 Change-Id: I7dc9011b80e03cfa3eae8fee2fcf6cc8021a8566 Reviewed-by: Lars Knoll --- src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index f0b1bd330a..271c9d2894 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -107,8 +107,10 @@ QPlatformPrinterSupport *QCocoaNativeInterface::createPlatformPrinterSupport() void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine) { #ifndef QT_NO_WIDGETS - QMacPrintEngine *macPrintEngine = static_cast(printEngine); - return macPrintEngine->d_func()->printInfo; + QMacPrintEnginePrivate *macPrintEnginePriv = static_cast(printEngine)->d_func(); + if (macPrintEnginePriv->state == QPrinter::Idle && !macPrintEnginePriv->isPrintSessionInitialized()) + macPrintEnginePriv->initialize(); + return macPrintEnginePriv->printInfo; #else qFatal("Printing is not supported when Qt is configured with -no-widgets"); return 0; -- cgit v1.2.3 From 9f28f8bcbbf72d737616bcf57820c1e4bef3be95 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 17 Dec 2012 11:53:55 +0100 Subject: Prevent a crash if the pixmap passed in is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the pixmap passed in is null then we should not try to create a NSImage for it, so we just return 0 instead. Change-Id: Idae7ba304c97878e0aa8ae1eead5f4bb644a73de Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoahelpers.mm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index c1146612a6..e242b4e366 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -138,6 +138,8 @@ NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image) NSImage *qt_mac_create_nsimage(const QPixmap &pm) { + if (pm.isNull()) + return 0; QImage image = pm.toImage(); CGImageRef cgImage = qt_mac_image_to_cgimage(image); NSImage *nsImage = qt_mac_cgimage_to_nsimage(cgImage); -- cgit v1.2.3 From 586adeabe4d58a7c8a71bbb1be79c3533ab858ff Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 21 Dec 2012 12:09:56 +0100 Subject: add and use qtHaveModule() function this is much more elegant than the so far propagated !isEmpty(QT.foo.name). also replace feature-specific tests (no-gui and no-widgets) and the obsolete contains(QT_CONFIG, foo) syntax. Change-Id: Ia4b3c8febcabf9eeca67b1f9173a523820b1038b Reviewed-by: Sergio Ahumada Reviewed-by: Tasuku Suzuki Reviewed-by: Oswald Buddenhagen --- src/plugins/platforms/cocoa/cocoa.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 85e3f0007c..83e2a88e6a 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -82,7 +82,7 @@ LIBS += -framework Cocoa -framework IOKit QT += core-private gui-private platformsupport-private -!contains(QT_CONFIG, no-widgets) { +qtHaveModule(widgets) { OBJECTIVE_SOURCES += \ qpaintengine_mac.mm \ qprintengine_mac.mm \ -- cgit v1.2.3 From 3262ba8de68a4af7169e884f36f3ba26ad00806f Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 11 Dec 2012 12:34:46 +0100 Subject: Cocoa: Re-enable per class palette on QPA plugin Task-number: QTBUG-28443 Change-Id: If66604e8d002be6cf4c308378199c96be7422e06 Reviewed-by: Jake Petroules Reviewed-by: Jens Bache-Wiig --- .../platforms/cocoa/qcocoasystemsettings.mm | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index aacf47ec43..692e504432 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -96,6 +96,8 @@ QColor qt_mac_colorForThemeTextColor(ThemeTextColor themeColor) case kThemeTextColorTabFrontInactive: case kThemeTextColorBevelButtonInactive: return QColor(127, 127, 127, 255); + case kThemeTextColorMenuItemSelected: + return Qt::white; default: return QColor(0, 0, 0, 255); // ### TODO: Sample color like Qt 4. } @@ -153,21 +155,19 @@ struct QMacPaletteMap { }; static QMacPaletteMap mac_widget_colors[] = { -// TODO (msorvig): Fix/match palette behavior with Qt 4 and enable. -// -// QMacPaletteMap(QPlatformTheme::ToolButtonPalette, kThemeTextColorBevelButtonActive, kThemeTextColorBevelButtonInactive), -// QMacPaletteMap(QPlatformTheme::ButtonPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), -// QMacPaletteMap(QPlatformTheme::HeaderPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), -// QMacPaletteMap(QPlatformTheme::ComboBoxPalette, kThemeTextColorPopupButtonActive, kThemeTextColorPopupButtonInactive), -// QMacPaletteMap(QPlatformTheme::ItemViewPalette, kThemeTextColorListView, kThemeTextColorDialogInactive), -// QMacPaletteMap(QPlatformTheme::MessageBoxLabelPelette, kThemeTextColorAlertActive, kThemeTextColorAlertInactive), -// QMacPaletteMap(QPlatformTheme::TabBarPalette, kThemeTextColorTabFrontActive, kThemeTextColorTabFrontInactive), -// QMacPaletteMap(QPlatformTheme::LabelPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), -// QMacPaletteMap(QPlatformTheme::GroupBoxPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), -// QMacPaletteMap(QPlatformTheme::MenuPalette, kThemeTextColorPopupLabelActive, kThemeTextColorPopupLabelInactive), -// ### TODO: The zeros below gives white-on-black text. -// QMacPaletteMap(QPlatformTheme::TextEditPalette, 0, 0), -// QMacPaletteMap(QPlatformTheme::TextLineEditPalette, 0, 0), + QMacPaletteMap(QPlatformTheme::ToolButtonPalette, kThemeTextColorBevelButtonActive, kThemeTextColorBevelButtonInactive), + QMacPaletteMap(QPlatformTheme::ButtonPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), + QMacPaletteMap(QPlatformTheme::HeaderPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), + QMacPaletteMap(QPlatformTheme::ComboBoxPalette, kThemeTextColorPopupButtonActive, kThemeTextColorPopupButtonInactive), + QMacPaletteMap(QPlatformTheme::ItemViewPalette, kThemeTextColorListView, kThemeTextColorDialogInactive), + QMacPaletteMap(QPlatformTheme::MessageBoxLabelPelette, kThemeTextColorAlertActive, kThemeTextColorAlertInactive), + QMacPaletteMap(QPlatformTheme::TabBarPalette, kThemeTextColorTabFrontActive, kThemeTextColorTabFrontInactive), + QMacPaletteMap(QPlatformTheme::LabelPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), + QMacPaletteMap(QPlatformTheme::GroupBoxPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), + QMacPaletteMap(QPlatformTheme::MenuPalette, kThemeTextColorPopupLabelActive, kThemeTextColorPopupLabelInactive), + //### TODO: The zeros below gives white-on-black text. + QMacPaletteMap(QPlatformTheme::TextEditPalette, 0, 0), + QMacPaletteMap(QPlatformTheme::TextLineEditPalette, 0, 0), QMacPaletteMap(QPlatformTheme::NPalettes, 0, 0) }; QHash qt_mac_createRolePalettes() @@ -175,7 +175,7 @@ QHash qt_mac_createRolePalettes() QHash palettes; QColor qc; for (int i = 0; mac_widget_colors[i].paletteRole != QPlatformTheme::NPalettes; i++) { - QPalette pal; + QPalette pal = *qt_mac_createSystemPalette(); if (mac_widget_colors[i].active != 0) { qc = qt_mac_colorForThemeTextColor(mac_widget_colors[i].active); pal.setColor(QPalette::Active, QPalette::Text, qc); -- cgit v1.2.3