Andre Poenitz wrote:

>> Can I prepare a patch with those changes?
> 
> I would think so.

This is it. Now LyXText::init(bv) does a metrics-lite (i.e. puts width_ =
textwidth_ = bv->workWidth() for the top-level LyXText), and there is no
access to textwidth_ (now maxwidth) from outside. You set maxwidth with
init or metrics, and you get width() with the provided method. 

[this explanation is obviously not for you who has designed the mechanism,
just a confirmation for the rest of us. :-) ]

I've renamed prepareToPrint to computeRowMetrics also.

Alfredo
? ChangeLog-old
? PosIterator.C-save
? PosIterator.h-save
? bfri.C
? textcursor.C-save
? textcursor.h-save
? insets/insetcollapsable-save.C
? insets/insettext-save.C
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.514
diff -u -p -u -r1.514 BufferView_pimpl.C
--- BufferView_pimpl.C	27 Feb 2004 14:20:59 -0000	1.514
+++ BufferView_pimpl.C	1 Mar 2004 15:02:06 -0000
@@ -319,8 +319,6 @@ void BufferView::Pimpl::buffer(Buffer * 
 		connectBuffer(*buffer_);
 
 		buffer_->text().init(bv_);
-		buffer_->text().textwidth_ = workarea().workWidth();
-		buffer_->text().fullRebreak();
 
 		// If we don't have a text object for this, we make one
 		if (bv_->text() == 0)
@@ -404,8 +402,7 @@ void BufferView::Pimpl::resizeCurrentBuf
 	selendpos = cur.selEnd().pos();
 	sel = cur.selection();
 	mark_set = cur.mark();
-	text->textwidth_ = bv_->workWidth();
-	text->fullRebreak();
+	text->init(bv_);
 	update();
 
 	if (par != -1) {
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.298
diff -u -p -u -r1.298 lyxtext.h
--- lyxtext.h	1 Mar 2004 12:23:16 -0000	1.298
+++ lyxtext.h	1 Mar 2004 15:02:07 -0000
@@ -290,8 +290,8 @@ public:
 	///
 	void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
 
-	/// current max text width
-	int textWidth() const;
+	/// current text width
+	int width() const;
 
 	/// updates all counters
 	void updateCounters();
@@ -321,7 +321,7 @@ public:
 	/** this calculates the specified parameters. needed when setting
 	 * the cursor and when creating a visible row */
 	RowMetrics
-	prepareToPrint(ParagraphList::iterator pit, Row const & row) const;
+	computeRowMetrics(ParagraphList::iterator pit, Row const & row) const;
 
 	/// access to our paragraphs
 	ParagraphList & paragraphs() const;
@@ -380,9 +380,9 @@ public:
 	///
 	int height;
 	///
-	unsigned int width;
+	unsigned int width_;
 	///
-	int textwidth_;
+	int maxwidth_;
 	/// the current font settings
 	LyXFont current_font;
 	/// the current font
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.121
diff -u -p -u -r1.121 rowpainter.C
--- rowpainter.C	1 Mar 2004 12:23:16 -0000	1.121
+++ rowpainter.C	1 Mar 2004 15:02:08 -0000
@@ -120,12 +120,12 @@ RowPainter::RowPainter(BufferView const 
      ParagraphList::iterator pit, RowList::iterator rit,
      int xo, int yo)
 	: bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
-	  pit_(pit), xo_(xo), yo_(yo), width_(text_.width)
+	  pit_(pit), xo_(xo), yo_(yo), width_(text_.width())
 {
 	//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
 	//	<< " pit->y: " << pit_->y
 	//	<< " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl;
-	RowMetrics m = text_.prepareToPrint(pit, row_);
+	RowMetrics m = text_.computeRowMetrics(pit, row_);
 	x_ = m.x + xo_;
 	separator_ = m.separator;
 	hfill_ = m.hfill;
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.545
diff -u -p -u -r1.545 text.C
--- text.C	1 Mar 2004 12:23:16 -0000	1.545
+++ text.C	1 Mar 2004 15:02:09 -0000
@@ -184,9 +184,9 @@ void LyXText::updateParPositions()
 }
 
 
-int LyXText::textWidth() const
+int LyXText::width() const
 {
-	return textwidth_;
+	return width_;
 }
 
 
@@ -355,7 +355,7 @@ int LyXText::leftMargin(ParagraphList::i
 		RowList::iterator rit = pit->rows.begin();
 		RowList::iterator end = pit->rows.end();
 #warning This is wrong.
-		int minfill = textwidth_;
+		int minfill = maxwidth_;
 		for ( ; rit != end; ++rit)
 			if (rit->fill() < minfill)
 				minfill = rit->fill();
@@ -364,14 +364,14 @@ int LyXText::leftMargin(ParagraphList::i
 		x += minfill;
 #endif
 		// also wrong, but much shorter.
-		x += textwidth_ / 2;
+		x += maxwidth_ / 2;
 		break;
 	}
 	}
 	
 
 	if (!pit->params().leftIndent().zero())
-		x += pit->params().leftIndent().inPixels(textWidth());
+		x += pit->params().leftIndent().inPixels(maxwidth_);
 
 	LyXAlignment align;
 
@@ -457,7 +457,7 @@ void LyXText::rowBreakPoint(ParagraphLis
 	}
 
 	// maximum pixel width of a row
-	int width = textWidth() - rightMargin(*pit); // - leftMargin(pit, row);
+	int width = maxwidth_ - rightMargin(*pit); // - leftMargin(pit, row);
 	if (width < 0) {
 		row.endpos(end);
 		return;
@@ -1007,11 +1007,11 @@ void LyXText::charInserted()
 
 
 RowMetrics
-LyXText::prepareToPrint(ParagraphList::iterator pit, Row const & row) const
+LyXText::computeRowMetrics(ParagraphList::iterator pit, Row const & row) const
 {
 	RowMetrics result;
 
-	double w = width - row.width();
+	double w = width_ - row.width();
 
 	bool const is_rtl = isRTL(*pit);
 	if (is_rtl)
@@ -1048,7 +1048,7 @@ LyXText::prepareToPrint(ParagraphList::i
 	// we don't have to look at the alignment if it is ALIGN_LEFT and
 	// if the row is already larger then the permitted width as then
 	// we force the LEFT_ALIGN'edness!
-	} else if (int(row.width()) < textWidth()) {
+	} else if (int(row.width()) < maxwidth_) {
 		// is it block, flushleft or flushright?
 		// set x how you need it
 		int align;
@@ -1563,7 +1563,7 @@ void LyXText::redoParagraphInternal(Para
 	InsetList::iterator iend = pit->insetlist.end();
 	for (; ii != iend; ++ii) {
 		Dimension dim;
-		int const w = textWidth() - leftMargin(pit) - rightMargin(*pit);
+		int const w = maxwidth_ - leftMargin(pit) - rightMargin(*pit);
 		MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
 		ii->inset->metrics(mi, dim);
 	}
@@ -1615,19 +1615,20 @@ void LyXText::metrics(MetricsInfo & mi, 
 {
 	//BOOST_ASSERT(mi.base.textwidth);
 	if (mi.base.textwidth)
-		textwidth_ = mi.base.textwidth;
+		maxwidth_ = mi.base.textwidth;
 	//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
-	//	<< " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl;
+	//<< " maxWidth: " << maxwidth << "\nfont: " << mi.base.font
+	//<< endl;
 
 	// Rebuild row cache. This recomputes height as well.
 	redoParagraphs(paragraphs().begin(), paragraphs().end());
 
-	width = maxParagraphWidth(paragraphs());
+	width_ = maxParagraphWidth(paragraphs());
 
 	// final dimension
 	dim.asc = firstRow()->ascent_of_text();
 	dim.des = height - dim.asc;
-	dim.wid = width;
+	dim.wid = width_;
 }
 
 
@@ -1819,7 +1820,7 @@ int LyXText::cursorX(CursorSlice const &
 	pos_type pos = cur.pos();
 	pos_type cursor_vpos = 0;
 
-	RowMetrics const m = prepareToPrint(pit, row);
+	RowMetrics const m = computeRowMetrics(pit, row);
 	double x = m.x;
 
 	pos_type const row_pos  = row.pos();
@@ -2040,8 +2041,8 @@ int LyXText::dist(int x, int y) const
 
 	if (x < xo_)
 		xx = xo_ - x;
-	else if (x > xo_ + width)
-		xx = x - xo_ - width;
+	else if (x > xo_ + width_)
+		xx = x - xo_ - width_;
 
 	if (y < yo_ - ascent())
 		yy = yo_ - ascent() - y;
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.551
diff -u -p -u -r1.551 text2.C
--- text2.C	1 Mar 2004 12:23:17 -0000	1.551
+++ text2.C	1 Mar 2004 15:02:10 -0000
@@ -72,8 +72,8 @@ using std::string;
 
 
 LyXText::LyXText(BufferView * bv, bool in_inset)
-	: height(0), width(0), textwidth_(bv ? bv->workWidth() : 100),
-		background_color_(LColor::background),
+	: height(0), width_(0), maxwidth_(bv ? bv->workWidth() : 100),
+	  background_color_(LColor::background),
 	  bv_owner(bv), in_inset_(in_inset), xo_(0), yo_(0)
 {}
 
@@ -87,7 +87,8 @@ void LyXText::init(BufferView * bv)
 	for (ParagraphList::iterator pit = beg; pit != end; ++pit)
 		pit->rows.clear();
 
-	width = bv->workWidth();
+	maxwidth_ = bv->workWidth();
+	width_ = maxwidth_;
 	height = 0;
 
 	current_font = getFont(beg, 0);
@@ -1197,7 +1198,7 @@ pos_type LyXText::getColumnNearX(Paragra
 	Row const & row, int & x, bool & boundary) const
 {
 	x -= xo_;
-	RowMetrics const r = prepareToPrint(pit, row);
+	RowMetrics const r = computeRowMetrics(pit, row);
 	
 	pos_type vc = row.pos();
 	pos_type end = row.endpos();

Reply via email to