Comments?

I can hear John's curse already.


Regards, Alfredo
? lyxrow_funcs.C-bad1
? paragraph.C-bad1
? text.C-bad1
? text.C-goood
? text3-save.C
Index: Bidi.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Bidi.C,v
retrieving revision 1.1
diff -u -p -u -r1.1 Bidi.C
--- Bidi.C	23 Oct 2003 13:28:44 -0000	1.1
+++ Bidi.C	27 Oct 2003 11:13:12 -0000
@@ -11,13 +11,13 @@
 
 #include "Bidi.h"
 #include "buffer.h"
-#include "insets/updatableinset.h"
 #include "lyxfont.h"
 #include "lyxrow.h"
 #include "lyxrow_funcs.h"
 #include "lyxrc.h"
 #include "paragraph.h"
 
+#include "insets/updatableinset.h"
 
 using lyx::pos_type;
 
@@ -68,7 +68,7 @@ void Bidi::computeTables(Paragraph const
 	}
 
 	start_ = row.pos();
-	end_ = lastPos(par, row);
+	end_ = row.endpos() - 1;
 
 	if (start_ > end_) {
 		start_ = -1;
Index: lyxrow_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow_funcs.C,v
retrieving revision 1.24
diff -u -p -u -r1.24 lyxrow_funcs.C
--- lyxrow_funcs.C	24 Oct 2003 15:04:14 -0000	1.24
+++ lyxrow_funcs.C	27 Oct 2003 11:13:13 -0000
@@ -24,25 +24,16 @@ using std::min;
 using std::endl;
 
 
-pos_type lastPos(Paragraph const & par, Row const & row)
-{
-	if (par.empty())
-		return 0;
-	pos_type pos = row.endpos() - 1;
-//	if (pos == par.size())
-//		--pos;
-	return pos;
-}
-
-
 int numberOfSeparators(Paragraph const & par, Row const & row)
 {
-	pos_type const last = lastPos(par, row);
+	pos_type const first = max(row.pos(), par.beginningOfBody());
+	pos_type const last = row.endpos() - 1;
 	int n = 0;
-	pos_type p = max(row.pos(), par.beginningOfBody());
-	for ( ; p < last; ++p)
+	for (pos_type p = first; p < last; ++p) {
 		if (par.isSeparator(p))
 			++n;
+	}
+
 	return n;
 }
 
@@ -51,7 +42,7 @@ int numberOfSeparators(Paragraph const &
 // an anonymous namespace there. (Lgb)
 int numberOfHfills(Paragraph const & par, Row const & row)
 {
-	pos_type const last = lastPos(par, row);
+	pos_type const last = row.endpos() - 1;
 	pos_type first = row.pos();
 
 	// hfill *DO* count at the beginning of paragraphs!
@@ -78,7 +69,7 @@ int numberOfHfills(Paragraph const & par
 // an anonymous namespace there. (Lgb)
 int numberOfLabelHfills(Paragraph const & par, Row const & row)
 {
-	pos_type last = lastPos(par, row);
+	pos_type last = row.endpos() - 1;
 	pos_type first = row.pos();
 
 	// hfill *DO* count at the beginning of paragraphs!
Index: lyxrow_funcs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow_funcs.h,v
retrieving revision 1.10
diff -u -p -u -r1.10 lyxrow_funcs.h
--- lyxrow_funcs.h	22 Oct 2003 16:30:56 -0000	1.10
+++ lyxrow_funcs.h	27 Oct 2003 11:13:13 -0000
@@ -18,8 +18,6 @@
 class Paragraph;
 class Row;
 
-lyx::pos_type lastPos(Paragraph const & par, Row const & row);
-
 int numberOfSeparators(Paragraph const & par, Row const & row);
 
 int numberOfHfills(Paragraph const & par, Row const & row);
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.246
diff -u -p -u -r1.246 lyxtext.h
--- lyxtext.h	24 Oct 2003 09:45:03 -0000	1.246
+++ lyxtext.h	27 Oct 2003 11:13:14 -0000
@@ -343,8 +343,7 @@ public:
 private:
 	///
 	float getCursorX(ParagraphList::iterator pit,
-	     Row const & row, lyx::pos_type pos,
-			 lyx::pos_type last, bool boundary) const;
+	     Row const & row, lyx::pos_type pos, bool boundary) const;
 	/// used in setlayout
 	void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
 
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.335
diff -u -p -u -r1.335 paragraph.C
--- paragraph.C	24 Oct 2003 15:04:15 -0000	1.335
+++ paragraph.C	27 Oct 2003 11:13:15 -0000
@@ -414,7 +414,7 @@ Paragraph::highestFontInRange(pos_type s
 		return def_size;
 
 	Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
-	Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+	Pimpl::FontList::const_iterator const end = pimpl_->fontlist.end();
 	for (; end_it != end; ++end_it) {
 		if (end_it->pos() >= endpos)
 			break;
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.83
diff -u -p -u -r1.83 rowpainter.C
--- rowpainter.C	24 Oct 2003 09:45:04 -0000	1.83
+++ rowpainter.C	27 Oct 2003 11:13:17 -0000
@@ -257,7 +257,7 @@ void RowPainter::paintArabicComposeChar(
 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
 {
 	pos_type pos = text_.bidi.vis2log(vpos);
-	pos_type const last = lastPos(*pit_, row_);
+	pos_type const end = row_.endpos();
 	LyXFont orig_font = getFont(pos);
 
 	// first character
@@ -274,7 +274,7 @@ void RowPainter::paintChars(pos_type & v
 	++vpos;
 
 	// collect as much similar chars as we can
-	while (vpos <= last && (pos = text_.bidi.vis2log(vpos)) >= 0) {
+	while (vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0) {
 		char c = pit_->getChar(pos);
 
 		if (!IsPrintableNonspace(c))
@@ -437,10 +437,10 @@ void RowPainter::paintSelection()
 			int(x_), row_.height(), LColor::selection);
 
 	pos_type const body_pos = pit_->beginningOfBody();
-	pos_type const last = lastPos(*pit_, row_);
+	pos_type const end = row_.endpos();
 	double tmpx = x_;
 
-	for (pos_type vpos = row_.pos(); vpos <= last; ++vpos)  {
+	for (pos_type vpos = row_.pos(); vpos < end; ++vpos)  {
 		pos_type pos = text_.bidi.vis2log(vpos);
 		double const old_tmpx = tmpx;
 		if (body_pos > 0 && pos == body_pos - 1) {
@@ -489,9 +489,9 @@ void RowPainter::paintSelection()
 void RowPainter::paintChangeBar()
 {
 	pos_type const start = row_.pos();
-	pos_type const end = lastPos(*pit_, row_);
+	pos_type const end = row_.endpos();
 
-	if (!pit_->isChanged(start, end))
+	if (start == end || !pit_->isChanged(start, end - 1))
 		return;
 
 	int const height = text_.isLastRow(pit_, row_)
@@ -906,10 +906,10 @@ void RowPainter::paintLast()
 
 void RowPainter::paintText()
 {
-	pos_type const last = lastPos(*pit_, row_);
+	pos_type const end = row_.endpos();
 	pos_type body_pos = pit_->beginningOfBody();
 	if (body_pos > 0 &&
-		(body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
+		(body_pos > end || !pit_->isLineSeparator(body_pos - 1))) {
 		body_pos = 0;
 	}
 
@@ -920,7 +920,7 @@ void RowPainter::paintText()
 	int last_strikeout_x = 0;
 
 	pos_type vpos = row_.pos();
-	while (vpos <= last) {
+	while (vpos < end) {
 		if (x_ > bv_.workWidth())
 			break;
 		pos_type pos = text_.bidi.vis2log(vpos);
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.484
diff -u -p -u -r1.484 text.C
--- text.C	27 Oct 2003 10:27:50 -0000	1.484
+++ text.C	27 Oct 2003 11:13:19 -0000
@@ -507,6 +507,7 @@ void LyXText::rowBreakPoint(ParagraphLis
 	// pixel width since last breakpoint
 	int chunkwidth = 0;
 
+
 	// We re-use the font resolution for the entire font span when possible
 	LyXFont font = getFont(pit, pos);
 	lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
@@ -534,6 +535,7 @@ void LyXText::rowBreakPoint(ParagraphLis
 		}
 
 		char const c = pit->getChar(i);
+ 
 		if (i > endPosOfFontSpan) {
 			font = getFont(pit, i);
 			endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
@@ -571,7 +573,7 @@ void LyXText::rowBreakPoint(ParagraphLis
 			}
 			// exit on last registered breakpoint:
 			if (i + 1 < end)
-				break;  
+				break;
 		}
 
 		InsetOld * in = pit->getInset(i);
@@ -608,11 +610,13 @@ void LyXText::fill(ParagraphList::iterat
 {
 	int w;
 	// get the pure distance
-	pos_type const last = lastPos(*pit, row);
+	pos_type const end = row.endpos();
 
 	LyXLayout_ptr const & layout = pit->layout();
 
 	// special handling of the right address boxes
+#if 0
+//this is not working anymore
 	if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
 		int const tmpfill = row.fill();
 		row.fill(0); // the minfill in leftMargin()
@@ -621,15 +625,18 @@ void LyXText::fill(ParagraphList::iterat
 	} else {
 		w = leftMargin(pit, row);
 	}
+#else
+	w = leftMargin(pit, row);
+#endif
 
 	pos_type const body_pos = pit->beginningOfBody();
 	pos_type i = row.pos();
 
-	if (! pit->empty() && i <= last) {
+	if (i < end) {
 		// We re-use the font resolution for the entire span when possible
 		LyXFont font = getFont(pit, i);
 		lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
-		while (i <= last) {
+		while (i < end) {
 			if (body_pos > 0 && i == body_pos) {
 				w += font_metrics::width(layout->labelsep, getLabelFont(pit));
 				if (pit->isLineSeparator(i - 1))
@@ -648,10 +655,10 @@ void LyXText::fill(ParagraphList::iterat
 			++i;
 		}
 	}
-	if (body_pos > 0 && body_pos > last) {
+	if (body_pos > 0 && body_pos >= end) {
 		w += font_metrics::width(layout->labelsep, getLabelFont(pit));
-		if (last >= 0 && pit->isLineSeparator(last))
-			w -= singleWidth(pit, last);
+		if (end > 0 && pit->isLineSeparator(end - 1))
+			w -= singleWidth(pit, end - 1);
 		int const left_margin = labelEnd(pit, row);
 		if (w < left_margin)
 			w = left_margin;
@@ -752,7 +759,7 @@ void LyXText::setHeightOfRow(ParagraphLi
 	// This is not completely correct, but we can live with the small,
 	// cosmetic error for now.
 	int labeladdon = 0;
-	pos_type const pos_end = lastPos(*pit, row);
+	pos_type const pos_end = row.endpos();
 
 	LyXFont::FONT_SIZE maxsize =
 		pit->highestFontInRange(row.pos(), pos_end, size);
@@ -1150,7 +1157,7 @@ void LyXText::insertChar(char c)
 
 void LyXText::charInserted()
 {
-	// Here we could call finishUndo for every 20 characters inserted.
+	// Here we call finishUndo for every 20 characters inserted.
 	// This is from my experience how emacs does it. (Lgb)
 	static unsigned int counter;
 	if (counter < 20) {
@@ -1193,9 +1200,8 @@ void LyXText::prepareToPrint(ParagraphLi
 		if (!pit->empty())
 			++nlh;
 
-		if (nlh && !pit->getLabelWidthString().empty()) {
+		if (nlh && !pit->getLabelWidthString().empty())
 			fill_label_hfill = labelFill(pit, row) / double(nlh);
-		}
 	}
 
 	// are there any hfills in the row?
@@ -1271,13 +1277,13 @@ void LyXText::prepareToPrint(ParagraphLi
 	bidi.computeTables(*pit, *bv()->buffer(), row);
 	if (is_rtl) {
 		pos_type body_pos = pit->beginningOfBody();
-		pos_type last = lastPos(*pit, row);
+		pos_type end = row.endpos();
 
 		if (body_pos > 0 &&
-				(body_pos - 1 > last ||
+				(body_pos > end ||
 				 !pit->isLineSeparator(body_pos - 1))) {
 			x += font_metrics::width(layout->labelsep, getLabelFont(pit));
-			if (body_pos - 1 <= last)
+			if (body_pos <= end)
 				x += fill_label_hfill;
 		}
 	}
@@ -1539,10 +1545,10 @@ void LyXText::deleteWordBackward()
 // Kill to end of line.
 void LyXText::deleteLineForward()
 {
-	if (cursorPar()->empty())
+	if (cursorPar()->empty()) {
 		// Paragraph is empty, so we just go to the right
 		cursorRight(bv());
-	else {
+	} else {
 		LyXCursor tmpcursor = cursor;
 		// We can't store the row over a regular setCursor
 		// so we set it to 0 and reset it afterwards.
@@ -1553,11 +1559,10 @@ void LyXText::deleteLineForward()
 		cursor = tmpcursor;
 		setSelection();
 		// What is this test for ??? (JMarc)
-		if (!selection.set()) {
+		if (!selection.set())
 			deleteWordForward();
-		} else {
+		else
 			cutSelection(true, false);
-		}
 	}
 }
 
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.485
diff -u -p -u -r1.485 text2.C
--- text2.C	24 Oct 2003 15:04:17 -0000	1.485
+++ text2.C	27 Oct 2003 11:13:22 -0000
@@ -1307,10 +1307,15 @@ void LyXText::setCursor(LyXCursor & cur,
 	// y is now the cursor baseline
 	cur.y(y);
 
-	pos_type last = lastPos(*pit, row);
+	pos_type const end = row.endpos();
 
 	// None of these should happen, but we're scaredy-cats
-	if (pos > pit->size()) {
+	if (pos < 0) {
+		lyxerr << "dont like -1" << endl;
+		pos = 0;
+		cur.pos(0);
+		BOOST_ASSERT(false);
+	} else if (pos > pit->size()) {
 		lyxerr << "dont like 1, pos: " << pos
 		       << " size: " << pit->size()
 		       << " row.pos():" << row.pos()
@@ -1318,10 +1323,10 @@ void LyXText::setCursor(LyXCursor & cur,
 		pos = 0;
 		cur.pos(0);
 		BOOST_ASSERT(false);
-	} else if (pos > last + 1) {
+	} else if (pos > end) {
 		lyxerr << "dont like 2 please report" << endl;
 		// This shouldn't happen.
-		pos = last + 1;
+		pos = end;
 		cur.pos(pos);
 		BOOST_ASSERT(false);
 	} else if (pos < row.pos()) {
@@ -1333,16 +1338,15 @@ void LyXText::setCursor(LyXCursor & cur,
 		cur.pos(pos);
 		BOOST_ASSERT(false);
 	}
-
 	// now get the cursors x position
-	float x = getCursorX(pit, row, pos, last, boundary);
+	float x = getCursorX(pit, row, pos, boundary);
 	cur.x(int(x));
 	cur.x_fix(cur.x());
 }
 
 
 float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
-			  pos_type pos, pos_type last, bool boundary) const
+			  pos_type pos, bool boundary) const
 {
 	pos_type cursor_vpos    = 0;
 	double x                = row.x();
@@ -1350,13 +1354,14 @@ float LyXText::getCursorX(ParagraphList:
 	double fill_hfill       = row.fill_hfill();
 	double fill_label_hfill = row.fill_label_hfill();
 	pos_type const row_pos  = row.pos();
-
-	if (last < row_pos)
+	pos_type const end = row.endpos();
+	
+	if (end <= row_pos)
 		cursor_vpos = row_pos;
-	else if (pos > last && !boundary)
+	else if (pos >= end && !boundary)
 		cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
-			? row_pos : last + 1;
-	else if (pos > row_pos && (pos > last || boundary))
+			? row_pos : end;
+	else if (pos > row_pos && (pos >= end || boundary))
 		// Place cursor after char at (logical) position pos - 1
 		cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
 			? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
@@ -1367,15 +1372,15 @@ float LyXText::getCursorX(ParagraphList:
 
 	pos_type body_pos = pit->beginningOfBody();
 	if (body_pos > 0 &&
-	    (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
+	    (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
 		body_pos = 0;
 
 	for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
 		pos_type pos = bidi.vis2log(vpos);
 		if (body_pos > 0 && pos == body_pos - 1) {
-			x += fill_label_hfill +
-				font_metrics::width(
-					pit->layout()->labelsep, getLabelFont(pit));
+			x += fill_label_hfill
+				+ font_metrics::width(pit->layout()->labelsep,
+						      getLabelFont(pit));
 			if (pit->isLineSeparator(body_pos - 1))
 				x -= singleWidth(pit, body_pos - 1);
 		}
@@ -1456,7 +1461,7 @@ pos_type LyXText::getColumnNearX(Paragra
 	double fill_label_hfill = row.fill_label_hfill();
 
 	pos_type vc = row.pos();
-	pos_type last = lastPos(*pit, row);
+	pos_type end = row.endpos();
 	pos_type c = 0;
 	LyXLayout_ptr const & layout = pit->layout();
 
@@ -1466,17 +1471,17 @@ pos_type LyXText::getColumnNearX(Paragra
 	double last_tmpx = tmpx;
 
 	if (body_pos > 0 &&
-	    (body_pos - 1 > last ||
+	    (body_pos > end ||
 	     !pit->isLineSeparator(body_pos - 1)))
 		body_pos = 0;
 
 	// check for empty row
-	if (!pit->size()) {
+	if (vc == end) {
 		x = int(tmpx);
 		return 0;
 	}
 
-	while (vc <= last && tmpx <= x) {
+	while (vc < end && tmpx <= x) {
 		c = bidi.vis2log(vc);
 		last_tmpx = tmpx;
 		if (body_pos > 0 && c == body_pos - 1) {
@@ -1507,8 +1512,7 @@ pos_type LyXText::getColumnNearX(Paragra
 		left_side = true;
 	}
 
-	if (vc > last + 1)  // This shouldn't happen.
-		vc = last + 1;
+	BOOST_ASSERT(vc <= end);  // This shouldn't happen.
 
 	boundary = false;
 	// This (rtl_support test) is not needed, but gives
@@ -1522,8 +1526,8 @@ pos_type LyXText::getColumnNearX(Paragra
 		: false;
 	if (lastrow &&
 		 ((rtl  &&  left_side && vc == row.pos() && x < tmpx - 5) ||
-		  (!rtl && !left_side && vc == last + 1  && x > tmpx + 5)))
-		c = last + 1;
+		  (!rtl && !left_side && vc == end  && x > tmpx + 5)))
+		c = end;
 	else if (vc == row.pos()) {
 		c = bidi.vis2log(vc);
 		if (bidi.level(c) % 2 == 1)
@@ -1537,12 +1541,12 @@ pos_type LyXText::getColumnNearX(Paragra
 		}
 	}
 
-	if (row.pos() <= last && c > last && pit->isNewline(last)) {
-		if (bidi.level(last) % 2 == 0)
-			tmpx -= singleWidth(pit, last);
+	if (row.pos() < end && c >= end && pit->isNewline(end - 1)) {
+		if (bidi.level(end -1) % 2 == 0)
+			tmpx -= singleWidth(pit, end - 1);
 		else
-			tmpx += singleWidth(pit, last);
-		c = last;
+			tmpx += singleWidth(pit, end - 1);
+		c = end - 1;
 	}
 
 	c -= row.pos();
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.161
diff -u -p -u -r1.161 text3.C
--- text3.C	24 Oct 2003 09:45:07 -0000	1.161
+++ text3.C	27 Oct 2003 11:13:24 -0000
@@ -76,8 +76,8 @@ namespace {
 	{
 		LyXText * lt = bv->getLyXText();
 
-		//if (!lt->selection.set())
-    //	lt->selection.cursor = lt->cursor;
+//		if (!lt->selection.set())
+//			lt->selection.cursor = lt->cursor;
 
 		if (selecting || lt->selection.mark())
 			lt->setSelection();

Reply via email to