Here's another idea. Basically, what I've done is added an optional
"setFont" argument to editXY, so we can call it with setFont = false
during mere mouse movements and still take advantage of its recursion
without messing up the font. setFont then has to be carried through the
whole editXY hierarchy. This seems like of silly, but it's probably just
a consequence of what Abdel suggested earlier: that editXY and
checkInsetHit may need re-factoring. editXY is doing two very different
things.

Anyway, it can be made pretty later. The behavior ought to be the same
as before the previous patch. But I'm not entirely sure I understand
what behavior is wanted here. The insets look very different from how
they looked in the 1.4.x series.

Richard

-- 
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: insets/insetbase.h
===================================================================
--- insets/insetbase.h	(revision 17593)
+++ insets/insetbase.h	(working copy)
@@ -102,7 +102,7 @@
 	/// cursor enters
 	virtual void edit(LCursor & cur, bool left);
 	/// cursor enters
-	virtual InsetBase * editXY(LCursor & cur, int x, int y);
+	virtual InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 
 	/// compute the size of the object returned in dim
 	/// \retval true if metrics changed.
Index: insets/insetcollapsable.C
===================================================================
--- insets/insetcollapsable.C	(revision 17593)
+++ insets/insetcollapsable.C	(working copy)
@@ -303,13 +303,13 @@
 }
 
 
-InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y, bool setFont)
 {
 	//lyxerr << "InsetCollapsable: edit xy" << endl;
 	if (status() == Collapsed || (button_dim.contains(x, y) && status() != Inlined))
 		return this;
 	cur.push(*this);
-	return InsetText::editXY(cur, x, y);
+	return InsetText::editXY(cur, x, y, setFont);
 }
 
 
Index: insets/insettext.h
===================================================================
--- insets/insettext.h	(revision 17593)
+++ insets/insettext.h	(working copy)
@@ -119,7 +119,7 @@
 	///
 	void edit(LCursor & cur, bool left);
 	///
-	InsetBase * editXY(LCursor & cur, int x, int y);
+	InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 
 	/// number of cells in this inset
 	size_t nargs() const { return 1; }
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C	(revision 17593)
+++ insets/insettabular.C	(working copy)
@@ -1221,14 +1221,14 @@
 }
 
 
-InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y, bool setFont)
 {
 	//lyxerr << "InsetTabular::editXY: " << this << endl;
 	cur.selection() = false;
 	cur.push(*this);
 	cur.idx() = getNearestCell(cur.bv(), x, y);
 	resetPos(cur);
-	return cell(cur.idx())->text_.editXY(cur, x, y);
+	return cell(cur.idx())->text_.editXY(cur, x, y, setFont);
 }
 
 
Index: insets/insetcollapsable.h
===================================================================
--- insets/insetcollapsable.h	(revision 17593)
+++ insets/insetcollapsable.h	(working copy)
@@ -95,7 +95,7 @@
 	///
 	void edit(LCursor & cur, bool left);
 	///
-	InsetBase * editXY(LCursor & cur, int x, int y);
+	InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 	///
 	void setInlined() { status_ = Inlined; }
 	/// Is the width forced to some value?
Index: insets/insetcaption.C
===================================================================
--- insets/insetcaption.C	(revision 17593)
+++ insets/insetcaption.C	(working copy)
@@ -181,10 +181,10 @@
 }
 
 
-InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y, bool setFont)
 {
 	cur.push(*this);
-	return InsetText::editXY(cur, x, y);
+	return InsetText::editXY(cur, x, y, setFont);
 }
 
 
Index: insets/insettabular.h
===================================================================
--- insets/insettabular.h	(revision 17593)
+++ insets/insettabular.h	(working copy)
@@ -138,7 +138,7 @@
 	/// lock cell with given index
 	void edit(LCursor & cur, bool left);
 	///
-	InsetBase * editXY(LCursor & cur, int x, int y);
+	InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 	/// can we go further down on mouse click?
 	bool descendable() const { return true; }
 
Index: insets/insetcaption.h
===================================================================
--- insets/insetcaption.h	(revision 17593)
+++ insets/insetcaption.h	(working copy)
@@ -52,7 +52,7 @@
 	///
 	virtual void edit(LCursor & cur, bool left);
 	///
-	virtual InsetBase * editXY(LCursor & cur, int x, int y);
+	virtual InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 	///
 	bool insetAllowed(InsetBase::Code code) const;
 	///
Index: insets/insetbase.C
===================================================================
--- insets/insetbase.C	(revision 17593)
+++ insets/insetbase.C	(working copy)
@@ -179,7 +179,7 @@
 }
 
 
-InsetBase * InsetBase::editXY(LCursor &, int x, int y)
+InsetBase * InsetBase::editXY(LCursor &, int x, int y, bool setFont /*for compatibility*/)
 {
 	lyxerr[Debug::INSETS] << BOOST_CURRENT_FUNCTION
 			      << ": x=" << x << " y= " << y
Index: insets/insettext.C
===================================================================
--- insets/insettext.C	(revision 17593)
+++ insets/insettext.C	(working copy)
@@ -246,9 +246,9 @@
 }
 
 
-InsetBase * InsetText::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetText::editXY(LCursor & cur, int x, int y, bool setFont)
 {
-	return text_.editXY(cur, x, y);
+	return text_.editXY(cur, x, y, setFont);
 }
 
 
Index: text2.C
===================================================================
--- text2.C	(revision 17593)
+++ text2.C	(working copy)
@@ -846,10 +846,10 @@
 
 // x,y are absolute screen coordinates
 // sets cursor recursively descending into nested editable insets
-InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
+InsetBase * LyXText::editXY(LCursor & cur, int x, int y, bool setFont)
 {
 	if (lyxerr.debugging(Debug::WORKAREA)) {
-		lyxerr << "LyXText::editXY(cur, " << x << ", " << y << ")" << std::endl;
+		lyxerr << "LyXText::editXY(cur, " << x << ", " << y << ", " << setFont << ")" << std::endl;
 		cur.bv().coordCache().dump();
 	}
 	pit_type pit = getPitNearY(cur.bv(), y);
@@ -873,7 +873,8 @@
 	if (!inset) {
 		// Either we deconst editXY or better we move current_font
 		// and real_current_font to LCursor
-		setCurrentFont(cur);
+		if (setFont) 
+			setCurrentFont(cur);
 		return 0;
 	}
 
@@ -891,9 +892,9 @@
 		--cur.pos();
 
 	// Try to descend recursively inside the inset.
-	inset = inset->editXY(cur, x, y);
+	inset = inset->editXY(cur, x, y, setFont);
 
-	if (cur.top().text() == this)
+	if (setFont && (cur.top().text() == this))
 		setCurrentFont(cur);
 	return inset;
 }
Index: lyxtext.h
===================================================================
--- lyxtext.h	(revision 17593)
+++ lyxtext.h	(working copy)
@@ -189,10 +189,11 @@
 	/**
 	\return the inset pointer if x,y is covering that inset
 	\param x,y are absolute screen coordinates.
+	\param setFont is whether to change the font for the new cursor
 	\retval inset is non-null if the cursor is positionned inside
 	*/
 	/// FIXME: move to TextMetrics.
-	InsetBase * editXY(LCursor & cur, int x, int y);
+	InsetBase * editXY(LCursor & cur, int x, int y, bool setFont = true);
 	
 	/// Move cursor one line up.
 	/**
Index: BufferView.C
===================================================================
--- BufferView.C	(revision 17593)
+++ BufferView.C	(working copy)
@@ -1105,11 +1105,7 @@
 		bool need_redraw = false;
 		
 		//Get inset under mouse, if there is one
-		// NOTE: checkInsetHit returns the top level inset of nested insets. 
-		// If you happen to move from a text (inset=0) to a text inside an inset 
-		// (e.g. an opened footnote inset, again inset=0), that inset will not 
-		// be redrawn.
-		InsetBase * inset = buffer_->text().checkInsetHit(cur.bv(), cmd.x, cmd.y);
+		InsetBase * inset = buffer_->text().editXY(cur, cmd.x, cmd.y, false);
 		if (inset != last_inset_) {
 			if (last_inset_)
 				need_redraw |= last_inset_->setMouseHover(false);

Reply via email to