On Mon, Jul 21, 2003 at 08:39:49PM +0100, John Levon wrote: >
OK, a better version. This has two obvious remaining problems: o minipage - we need to add another width meaning "total width" for the benefit of the 50% page width calculation etc. o inlined ERT - tougher. We need to know the actual width of the lyxtext. Currently LyXText::width just expands to fill the containing inset. Changing this seems non-trivial. Instead we could add a LyXText::actualWidth() or something. There's quite a few cursor position bugs around, btw. regards john Index: lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.193 diff -u -p -r1.193 lyxtext.h --- lyxtext.h 18 Jul 2003 07:47:03 -0000 1.193 +++ lyxtext.h 21 Jul 2003 23:10:58 -0000 @@ -52,7 +52,7 @@ public: void init(BufferView *); /// int height; - /// + /// current width of text unsigned int width; /// the current font settings LyXFont current_font; @@ -194,6 +194,9 @@ private: // do we need a refresh? bool need_refresh_; + /// maximum width of text + unsigned int maxwidth; + public: /// only the top-level LyXText has this non-zero BufferView * bv_owner; @@ -398,10 +401,12 @@ public: bool updateInset(Inset *); /// void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos); - /// + /// this should go in favour of maxWidth() int workWidth() const; /// returns width of row containing inset int workWidth(Inset const * inset) const; + /// return the maximum width for this text + unsigned int maxWidth() const; /// void computeBidiTables(Buffer const *, RowList::iterator row) const; Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.383 diff -u -p -r1.383 text.C --- text.C 18 Jul 2003 12:05:48 -0000 1.383 +++ text.C 21 Jul 2003 23:11:02 -0000 @@ -142,6 +142,14 @@ void LyXText::anchor_row(RowList::iterat } +unsigned int LyXText::maxWidth() const +{ + if (inset_owner) + return maxwidth; + return bv()->workWidth(); +} + + int LyXText::workWidth() const { return inset_owner ? inset_owner->textWidth() : bv()->workWidth(); @@ -311,19 +319,8 @@ int LyXText::singleWidth(ParagraphList:: // Because of the representation as vertical lines return 3; } -#if 1 -#warning inset->update FIXME - // this IS needed otherwise on initialitation we don't get the fill - // of the row right (ONLY on initialization if we read a file!) - // should be changed! (Jug 20011204) - //tmpinset->update(bv()); - Dimension dim; - MetricsInfo mi(bv(), font, workWidth()); - tmpinset->metrics(mi, dim); - return dim.wid; -#else + return tmpinset->width(); -#endif } return 0; } @@ -786,7 +783,7 @@ pos_type LyXText::rowBreakPoint(Row cons ParagraphList::iterator pit = row.par(); // maximum pixel width of a row. - int width = workWidth() - rightMargin(*bv()->buffer(), row); + int width = maxWidth() - rightMargin(*bv()->buffer(), row); // inset->textWidth() returns -1 via workWidth(), // but why ? @@ -826,26 +823,38 @@ pos_type LyXText::rowBreakPoint(Row cons char const c = pit->getChar(i); - int thiswidth; + int labeladdwidth = 0; // add the auto-hfill from label end to the body if (body_pos && i == body_pos) { - thiswidth = font_metrics::width(layout->labelsep, + labeladdwidth = font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit)); if (pit->isLineSeparator(i - 1)) - thiswidth -= singleWidth(pit, i - 1); + labeladdwidth -= singleWidth(pit, i - 1); int left_margin = labelEnd(row); - if (thiswidth + x < left_margin) - thiswidth = left_margin - x; - thiswidth += singleWidth(pit, i, c); + if (labeladdwidth + x < left_margin) + labeladdwidth = left_margin - x; + } + + int thiswidth; + + Inset * in = pit->isInset(i) ? pit->getInset(i) : 0; + /* update the metrics */ + if (in) { + LyXFont const font = getFont(bv()->buffer(), pit, pos); + Dimension dim; + MetricsInfo mi(bv(), font, maxWidth() - (x + labeladdwidth)); + in->metrics(mi, dim); + thiswidth = dim.wid; } else { thiswidth = singleWidth(pit, i, c); } + thiswidth += labeladdwidth; + x += thiswidth; chunkwidth += thiswidth; - Inset * in = pit->isInset(i) ? pit->getInset(i) : 0; fullrow = (in && (in->display() || in->needFullRow())); // break before a character that will fall off @@ -1070,7 +1079,7 @@ void LyXText::setHeightOfRow(RowList::it pos_type const pos_end = lastPos(*this, rit); int labeladdon = 0; - int maxwidth = 0; + int max = 0; if (!pit->empty()) { // Check if any insets are larger @@ -1085,17 +1094,17 @@ void LyXText::setHeightOfRow(RowList::it Dimension dim; MetricsInfo mi(bv(), tmpfont, workWidth()); tmpinset->metrics(mi, dim); - maxwidth += dim.wid; + max += dim.wid; maxasc = max(maxasc, dim.asc); maxdesc = max(maxdesc, dim.des); #else - maxwidth += tmpinset->width(); + max += tmpinset->width(); maxasc = max(maxasc, tmpinset->ascent()); maxdesc = max(maxdesc, tmpinset->descent()); #endif } } else { - maxwidth += singleWidth(pit, pos); + max += singleWidth(pit, pos); } } } @@ -1318,12 +1327,12 @@ void LyXText::setHeightOfRow(RowList::it if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) { int dummy; // this IS needed - rit->width(maxwidth); + rit->width(max); prepareToPrint(rit, x, dummy, dummy, dummy, false); } - rit->width(int(maxwidth + x)); + rit->width(int(max + x)); if (inset_owner) { - width = max(0, workWidth()); + width = maxWidth(); RowList::iterator it = rows().begin(); RowList::iterator end = rows().end(); for (; it != end; ++it) { Index: text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.393 diff -u -p -r1.393 text2.C --- text2.C 21 Jul 2003 11:01:28 -0000 1.393 +++ text2.C 21 Jul 2003 23:11:06 -0000 @@ -58,22 +58,20 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) - : height(0), width(0), anchor_row_offset_(0), - inset_owner(0), the_locking_inset(0), bv_owner(bv) + : height(0), width(0), anchor_row_offset_(0), inset_owner(0), + the_locking_inset(0), need_refresh_(true), maxwidth(0), bv_owner(bv) { anchor_row_ = rows().end(); need_break_row = rows().end(); - need_refresh_ = true; } LyXText::LyXText(BufferView * bv, InsetText * inset) - : height(0), width(0), anchor_row_offset_(0), - inset_owner(inset), the_locking_inset(0), bv_owner(bv) + : height(0), width(0), anchor_row_offset_(0), inset_owner(inset), + the_locking_inset(0), need_refresh_(true), maxwidth(0), bv_owner(bv) { anchor_row_ = rows().end(); need_break_row = rows().end(); - need_refresh_ = true; } @@ -692,8 +690,10 @@ void LyXText::fullRebreak() } -void LyXText::rebuild(int maxwidth) +void LyXText::rebuild(int max) { + maxwidth = max; + rowlist_.clear(); need_break_row = rows().end(); width = height = 0; Index: insets/insetcollapsable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v retrieving revision 1.155 diff -u -p -r1.155 insetcollapsable.C --- insets/insetcollapsable.C 18 Jul 2003 16:13:33 -0000 1.155 +++ insets/insetcollapsable.C 21 Jul 2003 23:11:10 -0000 @@ -136,6 +136,8 @@ void InsetCollapsable::metrics(MetricsIn inset.metrics(mi, insetdim); dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET; dim.wid = max(dim.wid, insetdim.wid); + lyxerr << "collapse wid" << dim.wid << endl; + lyxerr << "insetdim wid" << insetdim.wid << endl; } dim_ = dim; } Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.442 diff -u -p -r1.442 insettext.C --- insets/insettext.C 21 Jul 2003 11:01:29 -0000 1.442 +++ insets/insettext.C 21 Jul 2003 23:11:13 -0000 @@ -275,17 +275,21 @@ void InsetText::read(Buffer const * buf, void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const { - //lyxerr << "InsetText::metrics: " << getInsetName() - // << " width: " << mi.base.textwidth << "\n"; + lyxerr << "InsetText::metrics: " << getInsetName() + << " mi.base.textwidth: " << mi.base.textwidth << "\n"; if (mi.base.textwidth) textwidth_ = mi.base.textwidth; BufferView * bv = mi.base.bv; setViewCache(bv); - text_.rebuild(mi.base.textwidth); + text_.rebuild(mi.base.textwidth - 2 * TEXT_TO_INSET_OFFSET); + lyxerr << "text wid" << text_.width << endl; dim.asc = text_.rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET; dim.des = text_.height - dim.asc + TEXT_TO_INSET_OFFSET; - dim.wid = max(textwidth_, int(text_.width)) + 2 * TEXT_TO_INSET_OFFSET; + dim.wid = int(text_.width) + 2 * TEXT_TO_INSET_OFFSET; + if (dim.wid > textwidth_ || needFullRow()) + dim.wid = textwidth_; dim.wid = max(dim.wid, 10); + lyxerr << "insettext width is now " << dim.wid << endl; dim_ = dim; }