summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-10-20 08:11:00 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-10-20 12:31:22 (GMT)
commitce03601e522ab10381f375c7bfd8862938d6955a (patch)
tree54f36b1aac1fd36640b6ddb3d321548d9e99fb6e /src/gui/widgets
parentc238f7b7e299e742e71fdb043a7bc81bbfd6c419 (diff)
downloadQt-ce03601e522ab10381f375c7bfd8862938d6955a.zip
Qt-ce03601e522ab10381f375c7bfd8862938d6955a.tar.gz
Qt-ce03601e522ab10381f375c7bfd8862938d6955a.tar.bz2
Mac: fix bug when reparenting non-native menu bars
If we reparent a naive menu bar inside a widget that has a menu bar from before, the old menu bar is lost. This patch makes sure that we don't set the new menu bar in this case, but let it remain as-is in case the widget is reparanted out again later. Rev-By: MortenS
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qmenu_mac.mm20
-rw-r--r--src/gui/widgets/qmenubar.cpp9
-rw-r--r--src/gui/widgets/qmenubar_p.h1
3 files changed, 26 insertions, 4 deletions
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index cee38ee..b238faf 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -1771,6 +1771,16 @@ QMenuBarPrivate::QMacMenuBarPrivate::removeAction(QMacMenuAction *action)
actionItems.removeAll(action);
}
+bool QMenuBarPrivate::macWidgetHasNativeMenubar(QWidget *widget)
+{
+ // This function is different from q->isNativeMenuBar(), as
+ // it returns true only if a native menu bar is actually
+ // _created_.
+ if (!widget)
+ return false;
+ return menubars()->contains(widget->window());
+}
+
void
QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
{
@@ -1778,16 +1788,22 @@ QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
static int dontUseNativeMenuBar = -1;
// We call the isNativeMenuBar function here
// because that will make sure that local overrides
- // are dealt with correctly.
+ // 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();
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.
+ // As a result, Qt::AA_DontUseNativeMenuBar is set. NB: the application
+ // might still choose to not respect, or change, this flag.
bool isPlugin = QApplication::testAttribute(Qt::AA_MacPluginApplication);
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();
}
- if (!qt_mac_no_native_menubar) {
+ if (qt_mac_no_native_menubar == false) {
+ // INVARIANT: Use native menubar.
extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp
qt_event_request_menubarupdate();
if (!parent && !fallback) {
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index 13e7de4..f2f0722 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -1370,8 +1370,13 @@ void QMenuBarPrivate::handleReparent()
oldWindow = newWindow;
#ifdef Q_WS_MAC
- macDestroyMenuBar();
- macCreateMenuBar(newParent);
+ 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
#ifdef Q_WS_WINCE
diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h
index 0b27b97..7815969 100644
--- a/src/gui/widgets/qmenubar_p.h
+++ b/src/gui/widgets/qmenubar_p.h
@@ -196,6 +196,7 @@ public:
return 0;
}
} *mac_menubar;
+ bool macWidgetHasNativeMenubar(QWidget *widget);
void macCreateMenuBar(QWidget *);
void macDestroyMenuBar();
OSMenuRef macMenu();