The following patch is a first attempt at fixing menu merging problems
in LyX/Mac. It requires to at least Qt/Mac 3.2.2 (the undocumented
function we use appeared at this time).

I would appreciate heavy testing of this (I think that it compiles,
but cannot go further). Bennett, Nirmal, that means you!

If the approach works, it seems much less complicated than what I
envisioned at first. In any case, this patch does not have support
for localization, so more work is needed.

JMarc

Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.697
diff -u -p -r1.697 ChangeLog
--- ChangeLog	7 Jul 2004 09:32:18 -0000	1.697
+++ ChangeLog	7 Jul 2004 15:21:52 -0000
@@ -1,3 +1,14 @@
+2004-07-07  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* QLMenubar.C (QLMenubar): remove special code to work around
+	Qt/Mac menu merging madness.
+
+	* QLPopupMenu.C (QLPopupMenu): add dummy entries to toplevel menus
+	(so that Qt/Mac moves them to the LyX menu)
+	(fire): recognize special values of index under Qt/Mac
+	(populate): under Qt/Mac, skip entries corresponding to About,
+	Preferences and Quit (which are handled by the dummy entries above)
+
 2004-07-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* QLyXKeySym.C (qprint): like print, but return a QString
Index: QLMenubar.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLMenubar.C,v
retrieving revision 1.9
diff -u -p -r1.9 QLMenubar.C
--- QLMenubar.C	9 Jun 2004 14:10:27 -0000	1.9
+++ QLMenubar.C	7 Jul 2004 15:21:52 -0000
@@ -22,7 +22,6 @@
 #include <qmenubar.h>
 #include <qcursor.h>
 
-
 using std::pair;
 using std::string;
 
@@ -41,17 +40,6 @@ QLMenubar::QLMenubar(LyXView * view, Men
 		pair<int, QLPopupMenu *> menu =
 			createMenu(menuBar(), &(*m), this, true);
 		name_map_[m->submenuname()] = menu.second;
-#ifdef Q_WS_MACX
-		/* The qt/mac menu code has a very silly hack that
-		   moves some menu entries that it recognizes by name
-		   (ex: "Preferences...") to the "LyX" menu. This
-		   feature can only work if the menu entries are
-		   always available. Since we build menus on demand,
-		   we have to have a reasonable default value before
-		   the menus have been explicitely opened. (JMarc)
-		*/
-		menu.second->showing();
-#endif
 	}
 }
 
Index: QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.32
diff -u -p -r1.32 QLPopupMenu.C
--- QLPopupMenu.C	7 Jul 2004 09:32:19 -0000	1.32
+++ QLPopupMenu.C	7 Jul 2004 15:21:52 -0000
@@ -26,6 +26,8 @@
 #include "kbmap.h"
 #include "QLyXKeySym.h"
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
+// this is an undocumented Qt/Mac function (Qt >= 3.2.2)
+extern void qt_mac_set_no_menubar_merge(bool b)
 #endif
 
 using std::distance;
@@ -55,6 +57,14 @@ string const getLabel(MenuItem const & m
 	return label;
 }
 
+#ifdef Q_WS_MACX
+// some constants needed for special handling of Mac menus
+// They are chosen to be large enough to avoid clashes with real menu indices.
+const int aboutIndex = 5001;
+const int prefsIndex = 5002;
+const int quitIndex = 5003;
+#endif
+
 } // namespace anon
 
 
@@ -77,12 +87,46 @@ QLPopupMenu::QLPopupMenu(QLMenubar * own
 		connect(this, SIGNAL(aboutToShow()), this, SLOT(showing()));
 	connect(this, SIGNAL(activated(int)),
 		this, SLOT(fire(int)));
+#ifdef Q_WS_MACX
+	/* The qt/mac menu code has a very silly hack that
+	   moves some menu entries that it recognizes by name
+	   (e.g. "Preferences...") to the "LyX" menu. This
+	   feature can only work if the menu entries are
+	   always available. Since we build menus on demand,
+	   we add some dummy contents to each menu (JMarc)
+	*/
+	if (toplevel) {
+		// allow menu merging functionality
+		qt_mac_set_no_menubar_merge(false);
+		insertItem("About LyX", aboutIndex);
+		insertItem("Preferences...", prefsIndex);
+		insertItem("Quit LyX", quitIndex);
+		// no menu merging functionality
+		qt_mac_set_no_menubar_merge(true);
+	}
+#endif
 }
 
 
 void QLPopupMenu::fire(int index)
 {
+#ifdef Q_WS_MACX
+	switch (index) {
+	case aboutIndex:
+		owner_->view()->activated(FuncRequest(LFUN_DIALOG_SHOW, "aboutlyx"));
+		break;
+	case prefsIndex:
+		owner_->view()->activated(FuncRequest(LFUN_DIALOG_SHOW, "prefs"));
+		break;
+	case quitIndex:
+		owner_->view()->activated(FuncRequest(LFUN_QUIT));
+		break;
+	default:
+		owner_->view()->activated(funcs_[index]);
+	}
+#else
 	owner_->view()->activated(funcs_[index]);
+#endif
 }
 
 
@@ -99,7 +143,22 @@ void QLPopupMenu::populate(Menu * menu)
 			pair<int, QLPopupMenu *> res = createMenu(this, &(*m), owner_);
 			setItemEnabled(res.first, m->status().enabled());
 			res.second->populate(m->submenu());
-		} else {
+		} else { // we have a MenuItem::Command
+#ifdef Q_WS_MACX
+			// we skip the About, Preferences and Quit
+			// actions, because they are handled in
+			// QLMenubar. (JMarc)
+			switch (m->func().action) {
+			case LFUN_QUIT:
+				continue;
+			case LFUN_DIALOG_SHOW:
+				if (m->func().argument == "aboutlyx"
+				    || m->func().argument == "prefs");
+				continue;
+			default:
+				break;
+			}
+#endif
 			FuncStatus const status = m->status();
 
 			Funcs::iterator fit =

Reply via email to