The following patch tries to fix properly bug 1720. Obviously, I do
not have LyX/Mac, so I would be grateful if Andreas or Bennett could
test it for me :)

All it needs to do its magic is to introduce a new virtual method
LyXView::hasFocus, which is only meaningfully implemented for Qt right
now. Indeed, what we want to catch are cases where the menu is opened
while the LyXView does not have focus, and this can only happen on
LyX/Mac for now.

I guess an implementation for xforms should not be difficult if always
returning true makes someone nervous. The same can probably be done
for Gtk. BTW, does Gtk have a possibility of having a Mac-style
menubar on the top of the screen?

JMarc

Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2029
diff -u -p -r1.2029 ChangeLog
--- src/ChangeLog	8 Nov 2004 10:54:27 -0000	1.2029
+++ src/ChangeLog	8 Nov 2004 11:34:41 -0000
@@ -1,3 +1,9 @@
+2004-11-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* lyxfunc.C (getStatus): when the origin of the request is menu or
+	toolbar, and the LyXView does not have focus, do as if there was
+	no buffer [bug 1720]
+
 2004-11-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* lyxfunc.C (dispatch): remove the verbose argument
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.628
diff -u -p -r1.628 lyxfunc.C
--- src/lyxfunc.C	8 Nov 2004 10:54:28 -0000	1.628
+++ src/lyxfunc.C	8 Nov 2004 11:34:41 -0000
@@ -272,8 +272,18 @@ FuncStatus LyXFunc::getStatus(FuncReques
 {
 	//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
 	FuncStatus flag;
-	Buffer * buf = owner->buffer();
 	LCursor & cur = view()->cursor();
+
+	/* In LyX/Mac, when a dialog is open, the menus of the
+	   application can still be accessed without giving focus to
+	   the main window. In this case, we want to disable the menu
+	   entries that are buffer-related.
+	*/
+	Buffer * buf;
+	if (cmd.origin == FuncRequest::UI && !owner->hasFocus())
+		buf = 0;
+	else
+		buf = owner->buffer();
 
 	if (cmd.action == LFUN_NOACTION) {
 		setStatusMessage(N_("Nothing to do"));
Index: src/frontends/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/ChangeLog,v
retrieving revision 1.261
diff -u -p -r1.261 ChangeLog
--- src/frontends/ChangeLog	27 Sep 2004 20:52:39 -0000	1.261
+++ src/frontends/ChangeLog	8 Nov 2004 11:34:41 -0000
@@ -1,3 +1,7 @@
+2004-11-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* LyXView.h (hasFocus): new abstract virtual function
+
 2004-09-27  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
 	* LyXView.h: fix typo
Index: src/frontends/LyXView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/LyXView.h,v
retrieving revision 1.33
diff -u -p -r1.33 LyXView.h
--- src/frontends/LyXView.h	27 Sep 2004 20:52:39 -0000	1.33
+++ src/frontends/LyXView.h	8 Nov 2004 11:34:41 -0000
@@ -142,6 +142,9 @@ public:
 	 */
 	Buffer const * const updateInset(InsetBase const *) const;
 
+	// returns true if this view has the focus.
+	virtual bool hasFocus() const = 0;
+
 protected:
 	/// view of a buffer. Eventually there will be several.
 	boost::shared_ptr<BufferView> bufferview_;
Index: src/frontends/gtk/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.80
diff -u -p -r1.80 ChangeLog
--- src/frontends/gtk/ChangeLog	8 Nov 2004 10:54:29 -0000	1.80
+++ src/frontends/gtk/ChangeLog	8 Nov 2004 11:34:41 -0000
@@ -1,3 +1,7 @@
+2004-11-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* GView.C (hasFocus): new method, always returns true for now
+
 2004-11-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* GToolbar.C (selected, clicked): 
Index: src/frontends/gtk/GView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/GView.C,v
retrieving revision 1.19
diff -u -p -r1.19 GView.C
--- src/frontends/gtk/GView.C	10 Oct 2004 15:10:37 -0000	1.19
+++ src/frontends/gtk/GView.C	8 Nov 2004 11:34:41 -0000
@@ -171,5 +171,13 @@ void GView::clearMessage()
 	message(getLyXFunc().viewStatusMessage());
 }
 
+
+bool GView::hasFocus() const
+{
+	// No real implementation needed for now
+	return true;
+}
+
+
 } // namespace frontend
 } // namespace lyx
Index: src/frontends/gtk/GView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/GView.h,v
retrieving revision 1.9
diff -u -p -r1.9 GView.h
--- src/frontends/gtk/GView.h	26 Sep 2004 18:36:07 -0000	1.9
+++ src/frontends/gtk/GView.h	8 Nov 2004 11:34:41 -0000
@@ -51,6 +51,10 @@ public:
 	virtual void busy(bool) const;
 	/// clear any temporary message and replace with current status
 	virtual void clearMessage();
+
+	// returns true if this view has the focus.
+	virtual bool hasFocus() const;
+
 private:
 	void showViewState();
 	bool onFocusIn(GdkEventFocus * event);
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.722
diff -u -p -r1.722 ChangeLog
--- src/frontends/qt2/ChangeLog	8 Nov 2004 10:54:29 -0000	1.722
+++ src/frontends/qt2/ChangeLog	8 Nov 2004 11:34:41 -0000
@@ -1,3 +1,10 @@
+2004-11-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* QtView.C (hasFocus): new method
+
+	* QLPopupMenu.C (populate): remove a Qt/Mac hack to disable some
+	menu entries when the main window does not have focus
+
 2004-11-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* QLToolbar.C (activated, clicked): 
Index: src/frontends/qt2/QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.37
diff -u -p -r1.37 QLPopupMenu.C
--- src/frontends/qt2/QLPopupMenu.C	26 Oct 2004 21:16:43 -0000	1.37
+++ src/frontends/qt2/QLPopupMenu.C	8 Nov 2004 11:34:41 -0000
@@ -24,7 +24,6 @@
 
 #ifdef Q_WS_MACX
 #include "kbmap.h"
-#include "LyXAction.h"
 #include "QLyXKeySym.h"
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 #endif
@@ -122,26 +121,6 @@ void QLPopupMenu::populate(Menu * menu)
 
 			QString label = toqstr(getLabel(*m));
 #ifdef Q_WS_MACX
-			/* In LyX/Mac, when a dialog is open, the
-			 menus of the application can still be
-			 accessed without giving focus to the main
-			 window. In this case, we want to disable the
-			 menu entries that are buffer-related.
-			*/
-			/* This test is actually not adequate,
-			   for example "dialog-show document" is not
-			   correctly disabled. What should be done
-			   (but is maybe hackish) define a version of
-			   LyXFunc::getStatus that takes a Buffer* as
-			   argument, so that we can call it with buf=0
-			   (JMarc)
-			*/
-			if (status.enabled()
-			    && qApp->activeWindow() != qApp->mainWidget()
-			    && !lyxaction.funcHasFlag(m->func().action,
-						      LyXAction::NoBuffer))
-				status.enabled(false);
-
 			/* There are two constraints on Qt/Mac: (1)
 			   the bindings require a unicode string to be
 			   represented meaningfully and std::string
Index: src/frontends/qt2/QtView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QtView.C,v
retrieving revision 1.47
diff -u -p -r1.47 QtView.C
--- src/frontends/qt2/QtView.C	8 Nov 2004 10:54:29 -0000	1.47
+++ src/frontends/qt2/QtView.C	8 Nov 2004 11:34:41 -0000
@@ -144,6 +144,12 @@ void QtView::activated(FuncRequest const
 }
 
 
+bool QtView::hasFocus() const
+{
+	return qApp->activeWindow() == this;
+}
+
+
 void QtView::closeEvent(QCloseEvent *)
 {
 	QuitLyX();
Index: src/frontends/qt2/QtView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QtView.h,v
retrieving revision 1.19
diff -u -p -r1.19 QtView.h
--- src/frontends/qt2/QtView.h	19 May 2004 15:11:34 -0000	1.19
+++ src/frontends/qt2/QtView.h	8 Nov 2004 11:34:41 -0000
@@ -59,6 +59,9 @@ public:
 	/// menu item has been selected
 	void activated(FuncRequest const &);
 
+	// returns true if this view has the focus.
+	virtual bool hasFocus() const;
+
 public slots:
 	/// idle timeout
 	void update_view_state_qt();
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.943
diff -u -p -r1.943 ChangeLog
--- src/frontends/xforms/ChangeLog	8 Nov 2004 10:56:02 -0000	1.943
+++ src/frontends/xforms/ChangeLog	8 Nov 2004 11:34:41 -0000
@@ -1,5 +1,7 @@
 2004-11-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
+	* XFormsView.C (hasFocus): new method, always returns true for now
+
 	* forms/Makefile.am (SUFFIXES): use +=, since SUFFIXES is already
 	set in config/common.am
 
Index: src/frontends/xforms/XFormsView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XFormsView.C,v
retrieving revision 1.47
diff -u -p -r1.47 XFormsView.C
--- src/frontends/xforms/XFormsView.C	19 May 2004 15:11:37 -0000	1.47
+++ src/frontends/xforms/XFormsView.C	8 Nov 2004 11:34:41 -0000
@@ -218,6 +218,13 @@ void XFormsView::updateMetrics(bool resi
 }
 
 
+bool XFormsView::hasFocus() const
+{
+	// No real implementation needed for now
+	return true;
+}
+
+
 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
 {
 	fl_set_form_title(getForm(), title.c_str());
Index: src/frontends/xforms/XFormsView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XFormsView.h,v
retrieving revision 1.24
diff -u -p -r1.24 XFormsView.h
--- src/frontends/xforms/XFormsView.h	26 Sep 2004 14:19:46 -0000	1.24
+++ src/frontends/xforms/XFormsView.h	8 Nov 2004 11:34:41 -0000
@@ -79,6 +79,9 @@ public:
 	///
 	boost::signal<void()> metricsUpdated;
 
+	// returns true if this view has the focus.
+	virtual bool hasFocus() const;
+
 private:
 	/**
 	 * setWindowTitle - set title of window

Reply via email to