From c3ad479d449375ca4b600d62e4c72b34a36736d7 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 22 Sep 2010 10:18:16 +0200 Subject: QTBUG-13301: The menubar does now work when no window is showing The reason is that actions from the menu bar have no target, and is therefore sendt down the responder chain. This is sometimes neccessary to make it work with modal dialogs. But this also means that there will be no first responder window to catch the action if no window is showing on screen. Luckily, in 4.8, we added our own QNSApplication. And this will also be the last resort in the responder chaing. Hence, we add code to handle the menu bar action here. Rev-by: carlos --- src/gui/kernel/qcocoaapplication_mac.mm | 11 +++++++++++ src/gui/kernel/qcocoasharedwindowmethods_mac_p.h | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qcocoaapplication_mac.mm b/src/gui/kernel/qcocoaapplication_mac.mm index 9270213..1b30efd 100644 --- a/src/gui/kernel/qcocoaapplication_mac.mm +++ b/src/gui/kernel/qcocoaapplication_mac.mm @@ -183,6 +183,17 @@ QT_USE_NAMESPACE [super sendEvent:event]; } +- (void)qtDispatcherToQAction:(id)sender +{ + // Forward actions sendt from the menu bar (e.g. quit) to the menu loader. + // Having this method here means that we are the last stop in the responder + // chain, and that we are able to handle menu actions even when no window is + // visible on screen. Note: If Qt is used as a plugin, Qt will not use a + // native menu bar. Hence, we will also not need to do any redirection etc. as + // we do with sendEvent. + [[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender]; +} + @end QT_BEGIN_NAMESPACE diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index 970bc0a..efe045c 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -136,16 +136,6 @@ QT_END_NAMESPACE qt_dispatchTabletProximityEvent(tabletEvent); } -- (void)qtDispatcherToQAction:(id)sender -{ - // If this window is modal, the menu bar will be modally shaddowed. - // In that case, since the window will be in the first responder chain, - // we can still catch the trigger here and forward it to the menu bar. - // This is needed as a single modal dialog on Qt should be able to access - // the application menu (e.g. quit). - [[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender]; -} - - (void)terminate:(id)sender { // This function is called from the quit item in the menubar when this window -- cgit v0.12