Juergen Spitzmueller wrote:

> Martin Vermeer wrote:
>> I think I know where the problem is, not how to fix it :-(
> 
> Me too. It seems that MOUSE_MOTION moves inside nested insets despite of
> 
> // only accept motions to places not deeper nested than the real anchor
> if (bvcur.anchor_.hasPart(cur)) {
> 
> No idea why.

Nice spot. I had a look.

The problem is the following: the MOTION event is indeed ignored in the
inner table, but when it is handled in the outer one InsetTabular::setPos
is called to positionate the cursor in the right cell, but setPos wrongly
descends into insets.

I attach a tentative solution (make setPos not descend), tested only
once ;-). Feedback greatly appreciated.

Alfredo
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.457
diff -u -p -u -r1.457 insettabular.C
--- insets/insettabular.C	17 Mar 2005 15:57:41 -0000	1.457
+++ insets/insettabular.C	20 Mar 2005 12:29:47 -0000
@@ -425,16 +425,6 @@ void InsetTabular::edit(LCursor & cur, b
 }
 
 
-InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
-{
-	//lyxerr << "InsetTabular::editXY: " << this << endl;
-	cur.selection() = false;
-	cur.push(const_cast<InsetTabular&>(*this));
-	return setPos(cur, x, y);
-	//int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
-}
-
-
 void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
 	lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
@@ -1129,7 +1119,28 @@ int dist(InsetOld const & inset, int x, 
 } //namespace anon
 
 
-InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
+InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
+{
+	//lyxerr << "InsetTabular::editXY: " << this << endl;
+	cur.selection() = false;
+	cur.push(const_cast<InsetTabular&>(*this));
+	cur.idx() = getNearestCell(x, y);
+	resetPos(cur);
+	return cell(cur.idx())->text_.editXY(cur, x, y);
+	//int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
+}
+
+
+void InsetTabular::setPos(LCursor & cur, int x, int y) const
+{
+	//lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
+	cur.idx() = getNearestCell(x, y);
+	resetPos(cur);
+	return cell(cur.idx())->text_.setCursorFromCoordinates(cur, x, y);
+}
+
+
+InsetTabular::idx_type InsetTabular::getNearestCell(int x, int y) const
 {
 	lyxerr << "# InsetTabular::setPos()  x=" << x << " y=" << y << endl;
 	idx_type idx_min = 0;
@@ -1143,10 +1154,7 @@ InsetBase * InsetTabular::setPos(LCursor
 			}
 		}
 	}
-	cur.idx() = idx_min;
-	//lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
-	resetPos(cur);
-	return cell(cur.idx())->text_.editXY(cur, x, y);
+	return idx_min;
 }
 
 
Index: insets/insettabular.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v
retrieving revision 1.199
diff -u -p -u -r1.199 insettabular.h
--- insets/insettabular.h	3 Dec 2004 13:57:50 -0000	1.199
+++ insets/insettabular.h	20 Mar 2005 12:29:47 -0000
@@ -153,7 +153,7 @@ private:
 	void drawCellLines(Painter &, int x, int y, row_type row,
 	                   idx_type cell) const;
 	///
-	InsetBase * setPos(LCursor & cur, int x, int y) const;
+	void setPos(LCursor & cur, int x, int y) const;
 
 	///
 	void moveNextCell(LCursor & cur);
@@ -183,6 +183,9 @@ private:
 	/// are we operating on several cells?
 	bool tablemode(LCursor & cur) const;
 
+	/// return the cell nearest to x, y
+	idx_type getNearestCell(int x, int y) const;
+	
 	///
 	Buffer const * buffer_;
 	///

Reply via email to