diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 942fc8db21..0fc1bff325 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -197,6 +197,8 @@ void QCocoaMenuItem::setEnabled(bool enabled) void QCocoaMenuItem::setNativeContents(WId item) { NSView *itemView = (NSView *)item; + if (m_itemView == itemView) + return; [m_itemView release]; m_itemView = [itemView retain]; [m_itemView setAutoresizesSubviews:YES]; @@ -301,8 +303,8 @@ NSMenuItem *QCocoaMenuItem::sync() if (!m_native) { m_native = [[NSMenuItem alloc] initWithTitle:QCFString::toNSString(m_text) - action:nil - keyEquivalent:@""]; + action:nil + keyEquivalent:@""]; [m_native setTag:reinterpret_cast(this)]; } diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index 028a34af1c..a2890d9b4a 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -77,6 +77,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); bool m_scrolling; bool m_exposedOnMoveToWindow; NSEvent *m_currentlyInterpretedKeyEvent; + bool m_isMenuView; } - (id)init; diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 8c22e51fe2..6e6e128aed 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -160,6 +160,8 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::NormalizedPosition | QTouchDevice::MouseEmulation); QWindowSystemInterface::registerTouchDevice(touchDevice); } + + m_isMenuView = false; } return self; } @@ -269,11 +271,11 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; - (void)viewDidMoveToWindow { + m_isMenuView = [self.window.className isEqualToString:@"NSCarbonMenuWindow"]; if (self.window) { // This is the case of QWidgetAction's generated QWidget inserted in an NSMenu. // 10.9 and newer get the NSWindowDidChangeOcclusionStateNotification - if ((!_q_NSWindowDidChangeOcclusionStateNotification - && [self.window.className isEqualToString:@"NSCarbonMenuWindow"])) { + if (!_q_NSWindowDidChangeOcclusionStateNotification && m_isMenuView) { m_exposedOnMoveToWindow = true; m_platformWindow->exposeWindow(); } @@ -402,7 +404,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; NSString *notificationName = [windowNotification name]; if (notificationName == NSWindowDidBecomeKeyNotification) { - if (!m_platformWindow->windowIsPopupType()) + if (!m_platformWindow->windowIsPopupType() && !m_isMenuView) QWindowSystemInterface::handleWindowActivated(m_window); } else if (notificationName == NSWindowDidResignKeyNotification) { // key window will be non-nil if another window became key... do not @@ -411,7 +413,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; NSWindow *keyWindow = [NSApp keyWindow]; if (!keyWindow) { // no new key window, go ahead and set the active window to zero - if (!m_platformWindow->windowIsPopupType()) + if (!m_platformWindow->windowIsPopupType() && !m_isMenuView) QWindowSystemInterface::handleWindowActivated(0); } } else if (notificationName == NSWindowDidMiniaturizeNotification @@ -621,13 +623,15 @@ QT_WARNING_POP { if (m_window && (m_window->flags() & Qt::WindowTransparentForInput) ) return NO; - if (!m_platformWindow->windowIsPopupType()) + if (!m_platformWindow->windowIsPopupType() && !m_isMenuView) QWindowSystemInterface::handleWindowActivated([self topLevelWindow]); return YES; } - (BOOL)acceptsFirstResponder { + if (m_isMenuView) + return NO; if (m_platformWindow->shouldRefuseKeyWindowAndFirstResponder()) return NO; if (m_window && (m_window->flags() & Qt::WindowTransparentForInput) ) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 6e37f91197..5453d9d64f 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1265,7 +1265,7 @@ void QMenuPrivate::_q_platformMenuAboutToShow() #ifdef Q_OS_OSX if (platformMenu) Q_FOREACH (QAction *action, q->actions()) - if (QWidget *widget = widgetItems.value(const_cast(action))) + if (QWidget *widget = widgetItems.value(action)) if (widget->parent() == q) { QPlatformMenuItem *menuItem = platformMenu->menuItemForTag(reinterpret_cast(action)); moveWidgetToPlatformItem(widget, menuItem); diff --git a/src/widgets/widgets/qmenu_mac.mm b/src/widgets/widgets/qmenu_mac.mm index a42879fc73..8b29011178 100644 --- a/src/widgets/widgets/qmenu_mac.mm +++ b/src/widgets/widgets/qmenu_mac.mm @@ -115,6 +115,7 @@ void QMenuPrivate::moveWidgetToPlatformItem(QWidget *widget, QPlatformMenuItem* QObject::connect(platformMenu, SIGNAL(destroyed()), container, SLOT(deleteLater())); container->resize(widget->sizeHint()); widget->setParent(container); + widget->setVisible(true); NSView *containerView = container->nativeView(); QWindow *containerWindow = container->windowHandle();