dummy patch to allow extending a word/row selection with the mouse.

Ok?

Alfredo
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.465
diff -u -p -u -r1.465 BufferView_pimpl.C
--- BufferView_pimpl.C	17 Nov 2003 20:28:08 -0000	1.465
+++ BufferView_pimpl.C	20 Nov 2003 10:30:07 -0000
@@ -486,7 +486,7 @@ void BufferView::Pimpl::scroll(int lines
 	// Restrict to a valid value
 	new_top_y = std::min(t->height - 4 * line_height, new_top_y);
 	new_top_y = std::max(0, new_top_y);
-
+	
 	scrollDocView(new_top_y);
 
 	// Update the scrollbar.
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1708
diff -u -p -u -r1.1708 ChangeLog
--- ChangeLog	18 Nov 2003 11:39:28 -0000	1.1708
+++ ChangeLog	20 Nov 2003 10:30:26 -0000
@@ -1,3 +1,9 @@
+2003-11-20  Alfredo Braunstein  <[EMAIL PROTECTED]>
+
+	* lyxtext.h: add x0_, y0_
+	* text3.C (cursorPrevious, cursorNext): rewrite (using x0_, y0_)
+	* text2.C (cursorDown, cursorUp): rewrite (using x0_, y0_)
+
 2003-11-18  Alfredo Braunstein  <[EMAIL PROTECTED]>
 
 	* text2.C (setCursorIntern): move the x_target update here *
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.542
diff -u -p -u -r1.542 lyxfunc.C
--- lyxfunc.C	17 Nov 2003 20:20:55 -0000	1.542
+++ lyxfunc.C	20 Nov 2003 10:30:29 -0000
@@ -1409,6 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const
 	if (view()->available()) {
 		view()->fitCursor();
 		view()->update();
+		
 		view()->cursor().updatePos();
 		// if we executed a mutating lfun, mark the buffer as dirty
 		if (!getStatus(func).disabled()
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.255
diff -u -p -u -r1.255 lyxtext.h
--- lyxtext.h	17 Nov 2003 14:28:17 -0000	1.255
+++ lyxtext.h	20 Nov 2003 10:30:30 -0000
@@ -461,19 +461,19 @@ public:
 	///
 	bool checkAndActivateInset(bool front);
 
-
 private:
-	/** Cursor related data.
-	  Later this variable has to be removed. There should be now internal
-	  cursor in a text */
-	///
-	///TextCursor cursor_;
+	
 	/// prohibit this as long as there are back pointers...
 	LyXText(LyXText const &);
 
 	// cache for cursorPar()
 	mutable ParagraphList::iterator cache_par_;
 	mutable int cache_pos_;
+
+public:
+	/// absolute document pixel coordinates of this LyXText
+	int x0_;
+	int y0_;
 };
 
 /// return the default height of a row in pixels, considering font zoom
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.503
diff -u -p -u -r1.503 text2.C
--- text2.C	18 Nov 2003 11:39:29 -0000	1.503
+++ text2.C	20 Nov 2003 10:30:32 -0000
@@ -74,7 +74,7 @@ LyXText::LyXText(BufferView * bv, InsetT
 	  ParagraphList & paragraphs)
 	: height(0), width(0), inset_owner(inset), bv_owner(bv),
 	  in_inset_(ininset), paragraphs_(&paragraphs),
-		cache_pos_(-1)
+	  cache_pos_(-1), x0_(0), y0_(0)
 {}
 
 
@@ -1404,7 +1404,7 @@ void LyXText::setCursorIntern(paroffset_
 			      pos_type pos, bool setfont, bool boundary)
 {
 	setCursor(cursor, par, pos, boundary);
-	bv()->x_target(cursor.x());
+	bv()->x_target(cursor.x() + x0_);
 	if (setfont)
 		setCurrentFont();
 }
@@ -1562,7 +1562,7 @@ void LyXText::setCursorFromCoordinates(i
 	deleteEmptyParagraphMechanism(old_cursor);
 }
 
-
+//gets LyXText coordinates
 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
 {
 	// Get the row first.
@@ -1710,24 +1710,16 @@ void LyXText::cursorUp(bool selecting)
 {
 	ParagraphList::iterator cpit = cursorPar();
 	Row const & crow = *cpit->getRow(cursor.pos());
-#if 1
-	int x = bv()->x_target();
+	int x = bv()->x_target() - x0_;
 	int y = cursor.y() - crow.baseline() - 1;
 	setCursorFromCoordinates(x, y);
 	if (!selecting) {
-		int topy = bv()->top_y();
-		int y1 = cursor.y() - topy;
-		y -= topy;
-		InsetOld * inset_hit = checkInsetHit(x, y1);
+		y += y0_ - bv()->top_y();
+		lyxerr << "y:" << y << " y0: " << y0_ << endl;
+		InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y);
 		if (inset_hit && isHighlyEditableInset(inset_hit))
 			inset_hit->edit(bv(), x, y);
 	}
-#else
-	lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
-		crow.baseline() << endl;
-	setCursorFromCoordinates(bv()->x_target(),
-		cursor.y() - crow.baseline() - 1);
-#endif
 }
 
 
@@ -1735,22 +1727,15 @@ void LyXText::cursorDown(bool selecting)
 {
 	ParagraphList::iterator cpit = cursorPar();
 	Row const & crow = *cpit->getRow(cursor.pos());
-#if 1
-	int x = bv()->x_target();
+	int x = bv()->x_target() - x0_;
 	int y = cursor.y() - crow.baseline() + crow.height() + 1;
 	setCursorFromCoordinates(x, y);
 	if (!selecting) {
-		int topy = bv()->top_y();
-		int y1 = cursor.y() - topy;
-		y -= topy;
-		InsetOld * inset_hit = checkInsetHit(x, y1);
+		y += y0_ - bv()->top_y();
+		InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y);
 		if (inset_hit && isHighlyEditableInset(inset_hit))
 			inset_hit->edit(bv(), x, y);
 	}
-#else
-	setCursorFromCoordinates(bv()->x_target(),
-		 cursor.y() - crow.baseline() + crow.height() + 1);
-#endif
 }
 
 
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.183
diff -u -p -u -r1.183 text3.C
--- text3.C	18 Nov 2003 11:39:30 -0000	1.183
+++ text3.C	20 Nov 2003 10:30:34 -0000
@@ -362,103 +362,40 @@ void LyXText::gotoInset(InsetOld::Code c
 
 void LyXText::cursorPrevious()
 {
-	int y = bv()->top_y();
 
-	ParagraphList::iterator cpit = cursorPar();
-	RowList::iterator crit = cpit->getRow(cursor.pos());
+	RowList::iterator crit = cursorRow();
 
-	if (isFirstRow(cpit, *crit)) {
-		if (y > 0)
-			bv()->updateScrollbar();
-		return;
-	}
-
-	setCursorFromCoordinates(bv()->x_target(), y);
-	finishUndo();
+	int x = bv()->x_target() - x0_;
+	int y = bv()->top_y() - y0_;
+	setCursorFromCoordinates(x, y);
 
-	if (crit == bv()->text->cursorRow()) {
+	if (crit == cursorRow()) {
 		// we have a row which is taller than the workarea. The
 		// simplest solution is to move to the previous row instead.
 		cursorUp(true);
-		return;
 	}
 
-	int new_y = + crit->height() - bv()->workHeight() + 1;
-
-	if (inset_owner) {
-		new_y += bv()->text->cursor.y()
-			+ bv()->cursor().innerInset()->insetInInsetY()
-			+ y;
-	} else {
-		new_y += cursor.y() - crit->baseline();
-	}
-
-	previousRow(cpit, crit);
-	LyXCursor cur;
-	setCursor(cur, parOffset(cpit), crit->pos(), false);
-	if (cur.y() > bv()->top_y())
-		cursorUp(true);
 	bv()->updateScrollbar();
+	finishUndo();
 }
 
 
 void LyXText::cursorNext()
 {
-	int topy = bv()->top_y();
-
-	ParagraphList::iterator cpit = cursorPar();
-	RowList::iterator crit = cpit->getRow(cursor.pos());
-
-	if (isLastRow(cpit, *crit)) {
-		int y = cursor.y() - crit->baseline() + crit->height();
-		if (y > topy + bv()->workHeight())
-			bv()->updateScrollbar();
-		return;
-	}
-
-	int y = topy + bv()->workHeight();
-	if (inset_owner && !topy) {
-		y += - bv()->text->cursor.y()
-			   + bv()->top_y()
-			   - bv()->cursor().innerInset()->insetInInsetY();
-	}
+	RowList::iterator crit = cursorRow();
 
-	ParagraphList::iterator dummypit;
-	Row const & row = *getRowNearY(y, dummypit);
-	y = dummypit->y + row.y_offset();
+	int x = bv()->x_target() - x0_;
+	int y = bv()->top_y() + bv()->workHeight() - y0_;
+	setCursorFromCoordinates(x, y);
 
-	setCursorFromCoordinates(bv()->x_target(), y);
-	// + bv->workHeight());
-	finishUndo();
-
-	int new_y;
-	if (crit == bv()->text->cursorRow()) {
+	if (crit == cursorRow()) {
 		// we have a row which is taller than the workarea. The
 		// simplest solution is to move to the next row instead.
 		cursorDown(true);
-		return;
-		// This is what we used to do, so we wouldn't skip right past
-		// tall rows, but it's not working right now.
-#if 0
-		new_y = bv->top_y() + bv->workHeight();
-#endif
 	}
-
-	if (inset_owner) {
-		new_y = bv()->text->cursor.y()
-			+ bv()->cursor().innerInset()->insetInInsetY()
-			+ y - crit->baseline();
-	} else {
-		new_y = cursor.y() - crit->baseline();
-	}
-
-
-	nextRow(cpit, crit);
-	LyXCursor cur;
-	setCursor(cur, parOffset(cpit), crit->pos(), false);
-	if (cur.y() < bv()->top_y() + bv()->workHeight())
-		cursorDown(true);
+	
 	bv()->updateScrollbar();
+	finishUndo();
 }
 
 
@@ -1355,7 +1292,7 @@ DispatchResult LyXText::dispatch(FuncReq
 		setCursorFromCoordinates(cmd.x, cmd.y);
 		selection.cursor = cursor;
 		finishUndo();
-		bv->x_target(cursor.x());
+		bv->x_target(cursor.x() + x0_);
 
 		if (bv->fitCursor())
 			selection_possible = false;
@@ -1596,11 +1533,12 @@ DispatchResult LyXText::dispatch(FuncReq
 
 	case LFUN_FINISHED_UP:
 		lyxerr << "swallow LFUN_FINISHED_UP" << endl;
+		cursorUp(true);
 		break;
 
 	case LFUN_FINISHED_DOWN:
 		lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
-		cursorRight(true);
+		cursorDown(true);
 		break;
 
 	default:
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.210
diff -u -p -u -r1.210 insetcollapsable.C
--- insets/insetcollapsable.C	20 Nov 2003 01:22:50 -0000	1.210
+++ insets/insetcollapsable.C	20 Nov 2003 10:30:37 -0000
@@ -283,6 +283,7 @@ void InsetCollapsable::edit(BufferView *
 		else
 			inset.edit(bv, x, ascent() + y - height_collapsed() + inset.ascent());
 	}
+	
 	bv->cursor().push(this);
 }
 
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.546
diff -u -p -u -r1.546 insettext.C
--- insets/insettext.C	17 Nov 2003 20:28:10 -0000	1.546
+++ insets/insettext.C	20 Nov 2003 10:30:38 -0000
@@ -38,6 +38,7 @@
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "rowpainter.h"
+#include "lyxrow.h"
 #include "sgml.h"
 #include "texrow.h"
 #include "undo.h"
@@ -257,6 +258,9 @@ void InsetText::draw(PainterInfo & pi, i
 
 	x += TEXT_TO_INSET_OFFSET;
 
+	text_.x0_ = x;
+	text_.y0_ = y - text_.firstRow()->ascent_of_text() + bv->top_y();
+	
 	paintTextInset(*bv, text_, x, y);
 
 	if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
@@ -340,10 +344,8 @@ void InsetText::edit(BufferView * bv, in
 	lyxerr << "InsetText::edit xy" << endl;
 	old_par = -1;
 	sanitizeEmptyText(bv);
-	text_.setCursorFromCoordinates(x, y + dim_.asc);
-	text_.cursor.x(text_.cursor.x());
-	bv->x_target(text_.cursor.x());
-
+	text_.setCursorFromCoordinates(x - text_.x0_, y + bv->top_y()
+				       - text_.y0_);
 	text_.clearSelection();
 	finishUndo();
 

Reply via email to