This is basically update 7 with the LyXTabular::curr_cell speed up hack _not_ removed.
So optically it is update 7, speed wise 'state of the art'. This is about the thing I want to commit once John doesn't find really serious problems. Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Index: lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.175 diff -u -p -r1.175 lyxtext.h --- lyxtext.h 17 Jun 2003 15:33:45 -0000 1.175 +++ lyxtext.h 18 Jun 2003 14:57:38 -0000 @@ -67,7 +67,6 @@ public: /// Constructor LyXText(BufferView *); - /// sets inset as owner LyXText(BufferView *, InsetText *); void init(BufferView *, bool reinit = false); @@ -97,9 +96,9 @@ public: /// set the anchoring row. top_y will be computed relative to this void anchor_row(RowList::iterator rit); /// - InsetText * inset_owner; - /// UpdatableInset * the_locking_inset; + /// + InsetText * inset_owner; /// int getRealCursorX() const; @@ -232,10 +231,10 @@ private: refresh_status refresh_status_; +public: /// only the top-level LyXText has this non-zero BufferView * bv_owner; -public: /** returns a pointer to the row near the specified y-coordinate (relative to the whole text). y is set to the real beginning of this row Index: rowpainter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v retrieving revision 1.18 diff -u -p -r1.18 rowpainter.C --- rowpainter.C 30 May 2003 06:48:20 -0000 1.18 +++ rowpainter.C 18 Jun 2003 14:57:38 -0000 @@ -100,18 +100,27 @@ int RowPainter::leftMargin() const void RowPainter::paintInset(pos_type const pos) { - Inset * inset = const_cast<Inset*>(pit_->getInset(pos)); + Inset * inset = const_cast<Inset *>(pit_->getInset(pos)); lyx::Assert(inset); -#warning inset->update FIXME - inset->update(perv(bv_), false); + //bv_.buffer()->resizeInsets(perv(bv_)); + + MetricsInfo mi; + mi.base.bv = perv(bv_); + mi.base.font = getFont(pos); + mi.base.restrictwidth = true; + mi.base.textwidth = text_.isInInset() + ? text_.inset_owner->textWidth(perv(bv_), true) : bv_.workWidth(); + + Dimension dim; + inset->metrics(mi, dim); PainterInfo pi(perv(bv_)); - pi.base.font = getFont(pos); - int const w = inset->width(perv(bv_), pi.base.font); + //pi.base.font = getFont(pos); + //int const w = inset->width(perv(bv_), pi.base.font); inset->draw(pi, int(x_), yo_ + row_->baseline()); - x_ += w; + x_ += dim.wid; } @@ -570,7 +579,7 @@ int RowPainter::paintPageBreak(string co int d = 0; font_metrics::rectText(label, pb_font, w, a, d); - int const text_start = xo_ + ((width_ - w) / 2); + int const text_start = xo_ + (width_ - w) / 2; int const text_end = text_start + w; pain_.rectText(text_start, y + d, label, pb_font); @@ -595,7 +604,7 @@ int RowPainter::paintAppendixStart(int y int d = 0; font_metrics::rectText(label, pb_font, w, a, d); - int const text_start = xo_ + ((width_ - w) / 2); + int const text_start = xo_ + (width_ - w) / 2; int const text_end = text_start + w; pain_.rectText(text_start, y + d, label, pb_font); @@ -661,12 +670,13 @@ void RowPainter::paintFirst() int const asc = font_metrics::ascent('x', getFont(0)); y_top += asc; - +/* int const w = (text_.isInInset() ? text_.inset_owner->width(perv(bv_), font) : ww); int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0); pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top, LColor::topline, Painter::line_solid, Painter::line_thick); +*/ y_top += asc; } @@ -790,11 +800,13 @@ void RowPainter::paintLast() y_bottom -= asc; +/* int const w = (text_.isInInset() ? text_.inset_owner->width(perv(bv_), font) : ww); int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0); int const y = yo_ + y_bottom; pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid, Painter::line_thick); +*/ y_bottom -= asc; } @@ -969,9 +981,6 @@ void RowPainter::paint(int y_offset, int // belonging to row metrics ? text_.prepareToPrint(row_, x_, separator_, hfill_, label_hfill_); - // FIXME: what is this fixing ? - if (text_.isInInset() && (x_ < 0)) - x_ = 0; x_ += xo_; // If we're *not* at the top-level of rows, then the @@ -980,9 +989,8 @@ void RowPainter::paint(int y_offset, int paintBackground(); // paint the selection background - if (text_.selection.set()) { + if (text_.selection.set()) paintSelection(); - } // vertical lines for appendix paintAppendix(); @@ -993,13 +1001,11 @@ void RowPainter::paint(int y_offset, int // changebar paintChangeBar(); - if (row_->isParStart()) { + if (row_->isParStart()) paintFirst(); - } - if (isParEnd(text_, row_)) { + if (isParEnd(text_, row_)) paintLast(); - } // paint text paintText(); Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.367 diff -u -p -r1.367 text.C --- text.C 12 Jun 2003 11:09:53 -0000 1.367 +++ text.C 18 Jun 2003 14:57:38 -0000 @@ -33,6 +33,7 @@ #include "WordLangTuple.h" #include "paragraph_funcs.h" #include "rowpainter.h" +#include "metricsinfo.h" #include "lyxrow_funcs.h" #include "insets/insettext.h" @@ -300,21 +301,11 @@ int LyXText::singleWidth(ParagraphList:: if (c == Paragraph::META_INSET) { Inset * tmpinset = pit->getInset(pos); - if (tmpinset) { - if (tmpinset->lyxCode() == Inset::HFILL_CODE) { - // 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()); -#endif - return tmpinset->width(bv(), font); - } - return 0; + if (!tmpinset) + return 0; + if (tmpinset->lyxCode() == Inset::HFILL_CODE) + return 3; // Because of the representation as vertical lines + return tmpinset->dim_.wid; } if (IsSeparatorChar(c)) @@ -1070,13 +1061,29 @@ void LyXText::setHeightOfRow(RowList::it if (tmpinset) { #if 1 // this is needed for deep update on initialitation #warning inset->update FIXME - tmpinset->update(bv()); + //tmpinset->update(bv()); +#endif + //maxwidth += tmpinset->width(bv(), tmpfont); + //maxasc = max(maxasc, + // tmpinset->ascent(bv(), tmpfont)); + //maxdesc = max(maxdesc, + // tmpinset->descent(bv(), tmpfont)); + +#if 1 + MetricsInfo mi; + mi.base.bv = bv(); + mi.base.font = tmpfont; + mi.base.restrictwidth = true; + mi.base.textwidth = inset_owner ? + inset_owner->textWidth(bv(), true) : bv()->workWidth(); + Dimension dim; + tmpinset->metrics(mi, dim); +#else + Dimension dim = tmpinset->dim_; #endif - maxwidth += tmpinset->width(bv(), tmpfont); - maxasc = max(maxasc, - tmpinset->ascent(bv(), tmpfont)); - maxdesc = max(maxdesc, - tmpinset->descent(bv(), tmpfont)); + maxwidth += dim.wid; + maxasc = max(maxasc, dim.asc); + maxdesc = max(maxdesc, dim.des); } } else { maxwidth += singleWidth(pit, pos); Index: text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.371 diff -u -p -r1.371 text2.C --- text2.C 17 Jun 2003 15:33:46 -0000 1.371 +++ text2.C 18 Jun 2003 14:57:38 -0000 @@ -104,6 +104,7 @@ void LyXText::init(BufferView * bview, b } + // Gets the fully instantiated font at a given position in a paragraph // Basically the same routine as Paragraph::getFont() in paragraph.C. // The difference is that this one is used for displaying, and thus we @@ -165,9 +166,8 @@ LyXFont const LyXText::getLayoutFont(Buf { LyXLayout_ptr const & layout = pit->layout(); - if (!pit->getDepth()) { + if (!pit->getDepth()) return layout->resfont; - } LyXFont font(layout->font); // Realize with the fonts of lesser depth. @@ -182,9 +182,8 @@ LyXFont const LyXText::getLabelFont(Buff { LyXLayout_ptr const & layout = pit->layout(); - if (!pit->getDepth()) { + if (!pit->getDepth()) return layout->reslabelfont; - } LyXFont font(layout->labelfont); // Realize with the fonts of lesser depth. @@ -352,7 +351,7 @@ void LyXText::toggleInset() } -/* used in setlayout */ +// used in setlayout // Asger is not sure we want to do this... void LyXText::makeFontEntriesLayoutSpecific(Buffer const & buf, Paragraph & par) @@ -1740,8 +1739,8 @@ float LyXText::getCursorX(RowList::itera ? log2vis(pos) : log2vis(pos) + 1; pos_type body_pos = rit_par->beginningOfBody(); - if ((body_pos > 0) && - ((body_pos - 1 > last) || !rit_par->isLineSeparator(body_pos - 1))) + if (body_pos > 0 && + (body_pos - 1 > last || !rit_par->isLineSeparator(body_pos - 1))) body_pos = 0; for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) { Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.81 diff -u -p -r1.81 text3.C --- text3.C 17 Jun 2003 15:33:47 -0000 1.81 +++ text3.C 18 Jun 2003 14:57:39 -0000 @@ -39,6 +39,7 @@ #include "undo_funcs.h" #include "text_funcs.h" #include "Lsstream.h" +#include "metricsinfo.h" #include <ctime> #include <clocale> @@ -111,15 +112,28 @@ namespace { LyXFont const & font = text.getFont(bv->buffer(), par, pos); - int const width = inset->width(bv, font); +#if 1 + MetricsInfo mi; + mi.base.bv = bv; + mi.base.font = font; + //mi.base.restrictwidth = true; + //mi.base.textwidth = inset_owner + // ? inset_owner->textWidth(bv, true) : bv->workWidth(); + Dimension dim; + inset->metrics(mi, dim); +#else + Dimension dim = inset->dim_; +#endif + + int const width = dim.wid; int const inset_x = font.isVisibleRightToLeft() ? (cur.ix() - width) : cur.ix(); Box b( inset_x + inset->scroll(), inset_x + width, - cur.iy() - inset->ascent(bv, font), - cur.iy() + inset->descent(bv, font) + cur.iy() - dim.asc, + cur.iy() + dim.des ); if (!b.contained(x, y)) { @@ -1290,7 +1304,7 @@ Inset::RESULT LyXText::dispatch(FuncRequ LyXCursor cursor = bv->text->cursor; LyXFont font = bv->text->getFont(bv->buffer(), cursor.par(), cursor.pos()); - int width = tli->width(bv, font); + int width = tli->dim_.wid; int inset_x = font.isVisibleRightToLeft() ? cursor.ix() - width : cursor.ix(); int start_x = inset_x + tli->scroll(); Index: insets/Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/Makefile.am,v retrieving revision 1.63 diff -u -p -r1.63 Makefile.am --- insets/Makefile.am 12 Jun 2003 08:52:36 -0000 1.63 +++ insets/Makefile.am 18 Jun 2003 14:57:39 -0000 @@ -13,6 +13,8 @@ EXTRA_DIST = \ insettheorem.h libinsets_la_SOURCES = \ + insettext.C \ + insettext.h \ mailinset.C \ mailinset.h \ ExternalTemplate.C \ @@ -87,8 +89,6 @@ libinsets_la_SOURCES = \ insetspecialchar.h \ insettabular.C \ insettabular.h \ - insettext.C \ - insettext.h \ insettoc.C \ insettoc.h \ inseturl.C \ Index: insets/inset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v retrieving revision 1.99 diff -u -p -r1.99 inset.C --- insets/inset.C 4 Jun 2003 07:14:04 -0000 1.99 +++ insets/inset.C 18 Jun 2003 14:57:39 -0000 @@ -14,6 +14,7 @@ #include <config.h> #include "inset.h" +#include "debug.h" #include "BufferView.h" #include "funcrequest.h" #include "gettext.h" @@ -134,6 +135,7 @@ bool Inset::forceDefaultParagraphs(Inset return false; } + int Inset::latexTextWidth(BufferView * bv) const { if (owner()) @@ -141,35 +143,3 @@ int Inset::latexTextWidth(BufferView * b return bv->workWidth(); } - -int Inset::ascent(BufferView * bv, LyXFont const & font) const -{ - Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; - metrics(mi, dim); - return dim.ascent(); -} - - -int Inset::descent(BufferView * bv, LyXFont const & font) const -{ - Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; - metrics(mi, dim); - return dim.descent(); -} - - -int Inset::width(BufferView * bv, LyXFont const & font) const -{ - Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; - metrics(mi, dim); - return dim.width(); -} Index: insets/inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v retrieving revision 1.101 diff -u -p -r1.101 inset.h --- insets/inset.h 16 Jun 2003 11:49:30 -0000 1.101 +++ insets/inset.h 18 Jun 2003 14:57:39 -0000 @@ -17,6 +17,7 @@ #include "LColor.h" #include "insetbase.h" +#include "dimension.h" #include "support/types.h" #include <vector> @@ -154,15 +155,6 @@ public: Inset(); /// Inset(Inset const & in); - /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; - /// update the inset representation - virtual void update(BufferView *, bool = false) - {} /// what appears in the minibuffer when opening virtual string const editMessage() const; /// @@ -321,6 +313,8 @@ public: */ virtual void generatePreview() const {} + + mutable Dimension dim_; protected: /// mutable int top_x; Index: insets/insetbibitem.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibitem.C,v retrieving revision 1.16 diff -u -p -r1.16 insetbibitem.C --- insets/insetbibitem.C 16 Jun 2003 11:49:30 -0000 1.16 +++ insets/insetbibitem.C 18 Jun 2003 14:57:39 -0000 @@ -146,7 +146,7 @@ int bibitemMaxWidth(BufferView * bv, LyX ParagraphList::iterator end = bv->buffer()->paragraphs.end(); for (; it != end; ++it) { if (it->bibitem()) { - int const wx = it->bibitem()->width(bv, font); + int const wx = it->bibitem()->dim_.wid; if (wx > w) w = wx; } Index: insets/insetcollapsable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v retrieving revision 1.148 diff -u -p -r1.148 insetcollapsable.C --- insets/insetcollapsable.C 16 Jun 2003 11:49:30 -0000 1.148 +++ insets/insetcollapsable.C 18 Jun 2003 14:57:39 -0000 @@ -44,10 +44,7 @@ InsetCollapsable::InsetCollapsable(Buffe : UpdatableInset(), collapsed_(collapsed), inset(bp), button_length(0), button_top_y(0), button_bottom_y(0), label("Label"), -#if 0 - autocollapse(false), -#endif - oldWidth(0), in_update(false), first_after_edit(false) + first_after_edit(false) { inset.setOwner(this); inset.setAutoBreakRows(true); @@ -62,11 +59,9 @@ InsetCollapsable::InsetCollapsable(Inset framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset), button_length(0), button_top_y(0), button_bottom_y(0), label(in.label), -#if 0 - autocollapse(in.autocollapse), -#endif - oldWidth(0), in_update(false), first_after_edit(false) + first_after_edit(false) { + collapsed_ = false; inset.init(&(in.inset)); inset.setOwner(this); } @@ -126,13 +121,16 @@ int InsetCollapsable::height_collapsed() void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const { + lyxerr << "InsetCollapsable::metrics\n"; dimension_collapsed(dim); + dim_ = dim; if (collapsed_) return; Dimension insetdim; inset.metrics(mi, insetdim); dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET; dim.wid = max(dim.wid, insetdim.wid); + dim_ = dim; } @@ -153,7 +151,7 @@ void InsetCollapsable::draw(PainterInfo Dimension dim_collapsed; dimension_collapsed(dim_collapsed); - int const aa = ascent(pi.base.bv, pi.base.font); + int const aa = dim_.asc; button_length = dim_collapsed.width(); button_top_y = -aa; button_bottom_y = -aa + dim_collapsed.height(); @@ -177,8 +175,7 @@ void InsetCollapsable::draw(PainterInfo inset.draw(pi, x, y); } else { draw_collapsed(pi, old_x, bl); - int const yy = bl + dim_collapsed.descent() - + inset.ascent(pi.base.bv, pi.base.font); + int const yy = bl + dim_collapsed.descent() + inset.dim_.asc; inset.draw(pi, x, yy); } } @@ -218,10 +215,8 @@ void InsetCollapsable::insetUnlock(Buffe FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd) { - LyXFont font(LyXFont::ALL_SANE); FuncRequest cmd1 = cmd; - cmd1.y = ascent(cmd.view(), font) + cmd.y - - (height_collapsed() + inset.ascent(cmd.view(), font)); + cmd1.y = dim_.asc + cmd.y - (height_collapsed() + inset.dim_.asc); return cmd1; } @@ -286,23 +281,6 @@ int InsetCollapsable::docbook(Buffer con } -void InsetCollapsable::update(BufferView * bv, bool reinit) -{ - if (in_update) { - if (reinit && owner()) { - owner()->update(bv, true); - } - return; - } - in_update = true; - inset.update(bv, reinit); - if (reinit && owner()) { - owner()->update(bv, true); - } - in_update = false; -} - - Inset::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd) { //lyxerr << "InsetCollapsable::localDispatch: " << cmd.action << "\n"; @@ -352,9 +330,8 @@ Inset::RESULT InsetCollapsable::localDis if (cmd.y <= button_bottom_y) { cmd1.y = 0; } else { - LyXFont font(LyXFont::ALL_SANE); - cmd1.y = ascent(bv, font) + cmd.y - - (height_collapsed() + inset.ascent(bv, font)); + cmd1.y = dim_.asc + cmd.y - + (height_collapsed() + inset.dim_.asc); } inset.localDispatch(cmd); } @@ -476,8 +453,6 @@ void InsetCollapsable::deleteLyXText(Buf void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const { inset.resizeLyXText(bv, force); - LyXFont font(LyXFont::ALL_SANE); - oldWidth = width(bv, font); } Index: insets/insetcollapsable.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v retrieving revision 1.110 diff -u -p -r1.110 insetcollapsable.h --- insets/insetcollapsable.h 16 Jun 2003 11:49:30 -0000 1.110 +++ insets/insetcollapsable.h 18 Jun 2003 14:57:39 -0000 @@ -51,8 +51,6 @@ public: /// draw, either inlined (no button) or collapsed/open void draw(PainterInfo & pi, int x, int y, bool inlined) const; /// - void update(BufferView *, bool = false); - /// EDITABLE editable() const; /// bool insertInset(BufferView *, Inset * inset); @@ -216,10 +214,6 @@ private: /// bool autocollapse; #endif - /// - mutable int oldWidth; - /// - bool in_update; /// mutable bool first_after_edit; /// Index: insets/insetcommand.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcommand.C,v retrieving revision 1.77 diff -u -p -r1.77 insetcommand.C --- insets/insetcommand.C 12 Jun 2003 08:52:36 -0000 1.77 +++ insets/insetcommand.C 18 Jun 2003 14:57:39 -0000 @@ -47,6 +47,7 @@ void InsetCommand::metrics(MetricsInfo & editable() != NOT_EDITABLE); } button_.metrics(mi, dim); + dim_ = dim; } Index: insets/inseterror.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inseterror.C,v retrieving revision 1.60 diff -u -p -r1.60 inseterror.C --- insets/inseterror.C 2 Jun 2003 17:58:19 -0000 1.60 +++ insets/inseterror.C 18 Jun 2003 14:57:39 -0000 @@ -33,11 +33,6 @@ InsetError::InsetError(string const & st {} -// InsetError::InsetError(string const & str, bool) -// : contents(str) -// {} - - InsetError::~InsetError() { Dialogs::hide("error", this); @@ -64,10 +59,10 @@ void InsetError::metrics(MetricsInfo & m { LyXFont efont; efont.setSize(mi.base.font.size()).decSize(); - dim_.asc = font_metrics::maxAscent(efont) + 1; - dim_.des = font_metrics::maxDescent(efont) + 1; - dim_.wid = 6 + font_metrics::width(_("Error"), efont); - dim = dim_; + dim.asc = font_metrics::maxAscent(efont) + 1; + dim.des = font_metrics::maxDescent(efont) + 1; + dim.wid = 6 + font_metrics::width(_("Error"), efont); + dim_ = dim; } Index: insets/insetert.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v retrieving revision 1.131 diff -u -p -r1.131 insetert.C --- insets/insetert.C 16 Jun 2003 11:49:30 -0000 1.131 +++ insets/insetert.C 18 Jun 2003 14:57:39 -0000 @@ -299,7 +299,7 @@ bool InsetERT::lfunMouseRelease(FuncRequ } else { LyXFont font(LyXFont::ALL_SANE); FuncRequest cmd1 = cmd; - cmd1.y = ascent(bv, font) + cmd.y - inset.ascent(bv, font); + cmd1.y = dim_.asc + cmd.y - inset.dim_.asc; // inlined is special - the text appears above // button_bottom_y @@ -456,7 +456,7 @@ Inset::RESULT InsetERT::localDispatch(Fu t->need_break_row = t->rows().begin(); t->fullRebreak(); t->setCursorIntern(t->cursor.par(), t->cursor.pos()); - inset.update(cmd.view(), true); + //inset.update(cmd.view(), true); bv->updateInset(this); result = DISPATCHED; } @@ -554,10 +554,12 @@ bool InsetERT::checkInsertChar(LyXFont & void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const { + setButtonLabel(); if (inlined()) inset.metrics(mi, dim); else InsetCollapsable::metrics(mi, dim); + dim_ = dim; } @@ -664,17 +666,6 @@ int InsetERT::getMaxWidth(BufferView * b if (text->rows().size() == 1 && rw < w) return -1; return w; -} - - -void InsetERT::update(BufferView * bv, bool reinit) -{ - if (inset.need_update & InsetText::INIT || - inset.need_update & InsetText::FULL) { - setButtonLabel(); - } - - InsetCollapsable::update(bv, reinit); } Index: insets/insetert.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v retrieving revision 1.76 diff -u -p -r1.76 insetert.h --- insets/insetert.h 16 Jun 2003 11:49:31 -0000 1.76 +++ insets/insetert.h 18 Jun 2003 14:57:39 -0000 @@ -114,8 +114,6 @@ public: } /// int getMaxWidth(BufferView *, UpdatableInset const *) const; - /// - void update(BufferView *, bool =false); private: /// Index: insets/insetexternal.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetexternal.C,v retrieving revision 1.81 diff -u -p -r1.81 insetexternal.C --- insets/insetexternal.C 16 Jun 2003 11:49:31 -0000 1.81 +++ insets/insetexternal.C 18 Jun 2003 14:57:39 -0000 @@ -167,6 +167,7 @@ dispatch_result InsetExternal::localDisp void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const { renderer_->metrics(mi, dim); + dim_ = dim; } Index: insets/insetgraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.185 diff -u -p -r1.185 insetgraphics.C --- insets/insetgraphics.C 16 Jun 2003 11:49:31 -0000 1.185 +++ insets/insetgraphics.C 18 Jun 2003 14:57:39 -0000 @@ -202,6 +202,7 @@ dispatch_result InsetGraphics::localDisp void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const { graphic_->metrics(mi, dim); + dim_ = dim; } Index: insets/insetlatexaccent.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetlatexaccent.C,v retrieving revision 1.73 diff -u -p -r1.73 insetlatexaccent.C --- insets/insetlatexaccent.C 16 Jun 2003 11:49:31 -0000 1.73 +++ insets/insetlatexaccent.C 18 Jun 2003 14:57:39 -0000 @@ -400,11 +400,12 @@ void InsetLatexAccent::draw(PainterInfo // make the display of accent 'i' and 'j' // better. It makes the accent be written // closer to the top of the dot-less 'i' or 'j'. - char tmpic = ic; // store the ic when we - ic = 'x'; // calculates the ascent of - int asc = ascent(bv, font); // the dot-less version (here: 'x') - ic = tmpic; // set the orig ic back - y = baseline - asc; // update to new y coord. + //char tmpic = ic; // store the ic when we + //ic = 'x'; // calculates the ascent of + //int asc = ascent(bv, font);s + //// the dot-less version (here: 'x') + //ic = tmpic; // set the orig ic back + y = baseline - dim_.asc; // update to new y coord. } // now the rest - draw within (x, y, x+wid, y+hg) switch (modtype) { Index: insets/insetminipage.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetminipage.C,v retrieving revision 1.78 diff -u -p -r1.78 insetminipage.C --- insets/insetminipage.C 16 Jun 2003 11:49:31 -0000 1.78 +++ insets/insetminipage.C 18 Jun 2003 14:57:39 -0000 @@ -23,7 +23,7 @@ #include "lyxfont.h" #include "lyxlex.h" #include "lyxtext.h" -#include "Lsstream.h" +#include "metricsinfo.h" #include "frontends/LyXView.h" #include "frontends/Dialogs.h" @@ -63,7 +63,7 @@ using std::endl; // (Lgb) InsetMinipage::InsetMinipage(BufferParams const & bp) - : InsetCollapsable(bp) + : InsetCollapsable(bp), restrictwidth_(0) { setLabel(_("minipage")); LyXFont font(LyXFont::ALL_SANE); @@ -71,25 +71,13 @@ InsetMinipage::InsetMinipage(BufferParam font.decSize(); font.setColor(LColor::collapsable); setLabelFont(font); -#if 0 - setAutoCollapse(false); -#endif - -#if 0 -#ifdef WITH_WARNINGS -#warning Remove this color definitions before 1.2.0 final! -#endif - // just for experimentation :) - setBackgroundColor(LColor::green); -#endif - inset.setFrameColor(0, LColor::blue); setInsetName("Minipage"); } InsetMinipage::InsetMinipage(InsetMinipage const & in) - : InsetCollapsable(in), params_(in.params_) + : InsetCollapsable(in), params_(in.params_), restrictwidth_(0) {} @@ -101,8 +89,7 @@ InsetBase * InsetMinipage::clone() const InsetMinipage::~InsetMinipage() { - InsetMinipageMailer mailer(*this); - mailer.hideDialog(); + InsetMinipageMailer(*this).hideDialog(); } @@ -121,7 +108,7 @@ dispatch_result InsetMinipage::localDisp LyXText * t = inset.getLyXText(cmd.view()); t->need_break_row = t->rows().begin(); t->fullRebreak(); - inset.update(cmd.view(), true); + //inset.update(cmd.view(), true); t->setCursorIntern(t->cursor.par(), t->cursor.pos()); cmd.view()->updateInset(this); return DISPATCHED; @@ -220,11 +207,20 @@ void InsetMinipage::read(Buffer const * void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const { + lyxerr << "InsetMinipage: metrics: " << mi.base.textwidth << "\n"; if (collapsed_) dimension_collapsed(dim); else { + MetricsInfo m = mi; + if (!params_.width.zero()) { + m.base.restrictwidth = true; + m.base.textwidth = latexTextWidth(mi.base.bv); + restrictwidth_ = m.base.textwidth; + lyxerr << "restricting to : " << m.base.textwidth << "\n"; + } + Dimension d; - InsetCollapsable::metrics(mi, d); + InsetCollapsable::metrics(m, d); switch (params_.pos) { case top: dim.asc = d.asc; @@ -241,6 +237,7 @@ void InsetMinipage::metrics(MetricsInfo } dim.wid = d.wid; } + dim_ = dim; } @@ -288,8 +285,7 @@ bool InsetMinipage::showInsetDialog(Buff { if (!inset.showInsetDialog(bv)) { InsetMinipage * tmp = const_cast<InsetMinipage *>(this); - InsetMinipageMailer mailer(*tmp); - mailer.showDialog(bv); + InsetMinipageMailer(*tmp).showDialog(bv); } return true; @@ -299,20 +295,7 @@ bool InsetMinipage::showInsetDialog(Buff int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { - if (owner() && - static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) { - return -1; - } - if (!params_.width.zero()) { - int ww1 = latexTextWidth(bv); - int ww2 = InsetCollapsable::getMaxWidth(bv, inset); - if (ww2 > 0 && ww2 < ww1) { - return ww2; - } - return ww1; - } - // this should not happen! - return InsetCollapsable::getMaxWidth(bv, inset); + return restrictwidth_; } @@ -329,7 +312,7 @@ InsetMinipage::Params::Params() {} -string const InsetMinipageMailer:: name_("minipage"); +string const InsetMinipageMailer::name_("minipage"); InsetMinipageMailer::InsetMinipageMailer(InsetMinipage & inset) : inset_(inset) Index: insets/insetminipage.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetminipage.h,v retrieving revision 1.46 diff -u -p -r1.46 insetminipage.h --- insets/insetminipage.h 16 Jun 2003 11:49:32 -0000 1.46 +++ insets/insetminipage.h 18 Jun 2003 14:57:39 -0000 @@ -97,6 +97,8 @@ public: private: /// Params params_; + /// + mutable int restrictwidth_; }; Index: insets/insetnewline.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetnewline.C,v retrieving revision 1.10 diff -u -p -r1.10 insetnewline.C --- insets/insetnewline.C 6 Jun 2003 18:35:03 -0000 1.10 +++ insets/insetnewline.C 18 Jun 2003 14:57:39 -0000 @@ -44,6 +44,7 @@ void InsetNewline::metrics(MetricsInfo & dim.asc = font_metrics::maxAscent(font); dim.des = font_metrics::maxDescent(font); dim.wid = font_metrics::width('n', font); + dim_ = dim; } Index: insets/insetquotes.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetquotes.C,v retrieving revision 1.94 diff -u -p -r1.94 insetquotes.C --- insets/insetquotes.C 16 Jun 2003 11:49:32 -0000 1.94 +++ insets/insetquotes.C 18 Jun 2003 14:57:39 -0000 @@ -187,6 +187,7 @@ void InsetQuotes::metrics(MetricsInfo & else dim.wid += font_metrics::width(',', font); } + dim_ = dim; } Index: insets/insetspace.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspace.C,v retrieving revision 1.12 diff -u -p -r1.12 insetspace.C --- insets/insetspace.C 16 Jun 2003 11:49:32 -0000 1.12 +++ insets/insetspace.C 18 Jun 2003 14:57:39 -0000 @@ -71,12 +71,13 @@ void InsetSpace::metrics(MetricsInfo & m dim.wid = 10; break; } + dim_ = dim; } void InsetSpace::draw(PainterInfo & pi, int x, int y) const { - int const w = width(pi.base.bv, pi.base.font); + int const w = dim_.wid; int const h = font_metrics::ascent('x', pi.base.font); int xp[4], yp[4]; Index: insets/insetspace.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspace.h,v retrieving revision 1.11 diff -u -p -r1.11 insetspace.h --- insets/insetspace.h 16 Jun 2003 11:49:32 -0000 1.11 +++ insets/insetspace.h 18 Jun 2003 14:57:39 -0000 @@ -15,8 +15,8 @@ #ifndef INSET_SPACE_H #define INSET_SPACE_H - #include "inset.h" +#include "dimension.h" #include "LString.h" struct LaTeXFeatures; @@ -89,6 +89,8 @@ public: private: /// And which kind is this? Kind kind_; + /// + mutable Dimension dim_; }; #endif // INSET_SPACE_H Index: insets/insetspecialchar.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspecialchar.C,v retrieving revision 1.71 diff -u -p -r1.71 insetspecialchar.C --- insets/insetspecialchar.C 16 Jun 2003 11:49:32 -0000 1.71 +++ insets/insetspecialchar.C 18 Jun 2003 14:57:39 -0000 @@ -56,6 +56,7 @@ void InsetSpecialChar::metrics(MetricsIn dim.wid = font_metrics::width(s, font); if (kind_ == HYPHENATION && dim.wid > 5) dim.wid -= 2; // to make it look shorter + dim_ = dim; } Index: insets/insettabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v retrieving revision 1.290 diff -u -p -r1.290 insettabular.C --- insets/insettabular.C 16 Jun 2003 11:49:32 -0000 1.290 +++ insets/insettabular.C 18 Jun 2003 14:57:40 -0000 @@ -163,7 +163,6 @@ InsetTabular::InsetTabular(Buffer const actrow = actcell = 0; clearSelection(); need_update = INIT; - in_update = false; in_reset_pos = 0; inset_x = 0; inset_y = 0; @@ -182,7 +181,6 @@ InsetTabular::InsetTabular(InsetTabular actrow = actcell = 0; clearSelection(); need_update = INIT; - in_update = false; in_reset_pos = 0; inset_x = 0; inset_y = 0; @@ -245,12 +243,47 @@ void InsetTabular::read(Buffer const * b } -void InsetTabular::metrics(MetricsInfo &, - Dimension & dim) const +void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const { + int cell = -1; + int maxAsc = 0; + int maxDesc = 0; + InsetText * inset; + + // if we have a locking_inset we should have to check only this cell for + // change so I'll try this to have a boost, but who knows ;) + for (int i = 0; i < tabular.rows(); ++i) { + maxAsc = 0; + maxDesc = 0; + for (int j = 0; j < tabular.columns(); ++j) { + if (tabular.isPartOfMultiColumn(i,j)) + continue; + ++cell; + inset = tabular.getCellInset(cell); + Dimension dim; + MetricsInfo m = mi; + LyXLength len = tabular.getPWidth(cell); + if (!len.zero()) { + m.base.restrictwidth = true; + m.base.textwidth = len.inPixels(mi.base.textwidth); + //lyxerr << "InsetTabular: cell of bounded width: " + // << len.asString() << "\n"; + } + inset->metrics(m, dim); + maxAsc = max(maxAsc, dim.asc); + maxDesc = max(maxDesc, dim.des); + tabular.setWidthOfCell(cell, dim.wid); + } + tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT); + tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT); + } + tabular.reinit(); + + resetPos(mi.base.bv); dim.asc = tabular.getAscentOfRow(0); dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1; dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH; + dim_ = dim; } @@ -382,7 +415,7 @@ void InsetTabular::drawCellSelection(Pai if (rs > re) swap(rs, re); - if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) { + if (column >= cs && column <= ce && row >= rs && row <= re) { int w = tabular.getWidthOfColumn(cell); int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1; pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1, @@ -391,52 +424,6 @@ void InsetTabular::drawCellSelection(Pai } -void InsetTabular::update(BufferView * bv, bool reinit) -{ - if (in_update) { - if (reinit) { - resetPos(bv); - if (owner()) - owner()->update(bv, true); - } - return; - } - in_update = true; - if (reinit) { - need_update = INIT; - if (calculate_dimensions_of_cells(bv, true)) - resetPos(bv); - if (owner()) - owner()->update(bv, true); - in_update = false; - return; - } - if (the_locking_inset) - the_locking_inset->update(bv, reinit); - if (need_update < FULL && - bv->text->refreshStatus() == LyXText::REFRESH_AREA) - { - need_update = FULL; - } - - switch (need_update) { - case INIT: - case FULL: - case CELL: - if (calculate_dimensions_of_cells(bv, false)) { - need_update = INIT; - resetPos(bv); - } - break; - case SELECTION: - need_update = FULL; - break; - default: - break; - } - in_update = false; -} - string const InsetTabular::editMessage() const { @@ -1077,7 +1064,7 @@ Inset::RESULT InsetTabular::localDispatc ++cols; break; case '\n': - if ((p+1) < len) + if (p + 1 < len) ++rows; maxCols = max(cols, maxCols); cols = 1; @@ -1231,9 +1218,9 @@ int InsetTabular::docbook(Buffer const * // if the table is inside a float it doesn't need the informaltable // wrapper. Search for it. - for(master = owner(); - master && master->lyxCode() != Inset::FLOAT_CODE; - master = master->owner()); + for (master = owner(); + master && master->lyxCode() != Inset::FLOAT_CODE; + master = master->owner()); if (!master) { os << "<informaltable>"; @@ -1258,33 +1245,14 @@ void InsetTabular::validate(LaTeXFeature } -bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const +bool InsetTabular::calculate_dimensions_of_cells(BufferView *, bool) const { int cell = -1; int maxAsc = 0; int maxDesc = 0; - InsetText * inset; - bool changed = false; - - // FIXME: since InsetText ignores this anyway, it doesn't - // matter what we pass it. Ugly - LyXFont font; // if we have a locking_inset we should have to check only this cell for // change so I'll try this to have a boost, but who knows ;) - if ((need_update != INIT) && - (the_locking_inset == tabular.getCellInset(actcell))) { - for(int i = 0; i < tabular.columns(); ++i) { - maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font), - maxAsc); - maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font), - maxDesc); - } - changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font)); - changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed; - changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed; - return changed; - } for (int i = 0; i < tabular.rows(); ++i) { maxAsc = 0; maxDesc = 0; @@ -1292,19 +1260,16 @@ bool InsetTabular::calculate_dimensions_ if (tabular.isPartOfMultiColumn(i,j)) continue; ++cell; - inset = tabular.getCellInset(cell); - if (!reinit && !tabular.getPWidth(cell).zero()) - inset->update(bv, false); - maxAsc = max(maxAsc, inset->ascent(bv, font)); - maxDesc = max(maxDesc, inset->descent(bv, font)); - changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed; - } - changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed; - changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed; - } - if (changed) - tabular.reinit(); - return changed; + InsetText * inset = tabular.getCellInset(cell); + maxAsc = max(maxAsc, inset->dim_.asc); + maxDesc = max(maxDesc, inset->dim_.des); + tabular.setWidthOfCell(cell, inset->dim_.wid); + } + tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT); + tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT); + } + tabular.reinit(); + return true; } @@ -2064,15 +2029,13 @@ void InsetTabular::tabularFeatures(Buffe } -bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button, - bool behind) +bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, + mouse_button::state button, bool behind) { - UpdatableInset * inset = - static_cast<UpdatableInset*>(tabular.getCellInset(actcell)); - LyXFont font(LyXFont::ALL_SANE); + InsetText * inset = tabular.getCellInset(actcell); if (behind) { - x = inset->x() + inset->width(bv, font); - y = inset->descent(bv, font); + x = inset->x() + inset->dim_.wid; + y = inset->dim_.des; } //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell); //inset_y = cursor.y(); Index: insets/insettabular.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v retrieving revision 1.126 diff -u -p -r1.126 insettabular.h --- insets/insettabular.h 16 Jun 2003 11:49:33 -0000 1.126 +++ insets/insettabular.h 18 Jun 2003 14:57:40 -0000 @@ -87,8 +87,6 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - void update(BufferView *, bool = false); - /// string const editMessage() const; // void insetUnlock(BufferView *); @@ -345,8 +343,6 @@ private: mutable bool locked; /// mutable UpdateCodes need_update; - /// - bool in_update; /// mutable int in_reset_pos; }; Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.409 diff -u -p -r1.409 insettext.C --- insets/insettext.C 17 Jun 2003 15:33:48 -0000 1.409 +++ insets/insettext.C 18 Jun 2003 14:57:40 -0000 @@ -128,16 +128,9 @@ void InsetText::restoreLyXTextState(LyXT } -InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t) -{ - text = t; - remove = false; -} - - InsetText::InsetText(BufferParams const & bp) - : UpdatableInset(), lt(0), in_update(false), do_resize(0), - do_reinit(false) + : UpdatableInset(), ntext_(0), + do_reinit(false), textwidth_(-1), view_(0) { paragraphs.push_back(Paragraph()); paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout()); @@ -148,8 +141,8 @@ InsetText::InsetText(BufferParams const InsetText::InsetText(InsetText const & in) - : UpdatableInset(in), lt(0), in_update(false), do_resize(0), - do_reinit(false) + : UpdatableInset(in), ntext_(0), + do_reinit(false), textwidth_(-1), view_(0) { init(&in); } @@ -158,7 +151,7 @@ InsetText::InsetText(InsetText const & i InsetText & InsetText::operator=(InsetText const & it) { init(&it); - return * this; + return *this; } @@ -179,15 +172,12 @@ void InsetText::init(InsetText const * i autoBreakRows = false; } top_y = 0; - old_max_width = 0; no_selection = true; need_update = FULL; drawTextXOffset = 0; drawTextYOffset = 0; locked = false; old_par = paragraphs.end(); - last_drawn_width = -1; - cached_bview = 0; sstate.lpar = paragraphs.end(); in_insetAllowed = false; } @@ -289,8 +279,15 @@ void InsetText::read(Buffer const * buf, void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const { + //lyxerr << "InsetText: metrics: " << mi.base.textwidth << "\n"; BufferView * bv = mi.base.bv; LyXText * text = getLyXText(bv); + textwidth_ = -1; + if (mi.base.restrictwidth) { + textwidth_ = mi.base.textwidth; + //lyxerr << "InsetText: bounded width: " << mi.base.textwidth << "\n"; + ntext_.init(bv, false); + } 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(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET; @@ -299,25 +296,19 @@ void InsetText::metrics(MetricsInfo & mi } -int InsetText::textWidth(BufferView * bv, bool fordraw) const +int InsetText::textWidth(BufferView * bv, bool) const { - int w = autoBreakRows ? getMaxWidth(bv, this) : -1; - - if (fordraw) - return max(w - 2 * TEXT_TO_INSET_OFFSET, - (int)getLyXText(bv)->width); - - if (w < 0) - return -1; - + int w = autoBreakRows ? textwidth_ : -1; return w - 2 * TEXT_TO_INSET_OFFSET; } void InsetText::draw(PainterInfo & pi, int x, int baseline) const { - if (nodraw()) - return; + if (pi.base.bv) + view_ = pi.base.bv; + //if (nodraw()) + // return; // update our idea of where we are. Clearly, we should // not have to know this information. @@ -346,10 +337,7 @@ void InsetText::draw(PainterInfo & pi, i top_baseline = baseline; top_y = baseline - dim_.asc; - if (last_drawn_width != dim_.wid) { - need_update |= FULL; - last_drawn_width = dim_.wid; - } + need_update |= FULL; if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) { @@ -357,15 +345,10 @@ void InsetText::draw(PainterInfo & pi, i inset_y = ciy(bv) + drawTextYOffset; } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } x += TEXT_TO_INSET_OFFSET; - RowList::iterator rowit = lt->rows().begin(); - RowList::iterator end = lt->rows().end(); + RowList::iterator rowit = ntext_.rows().begin(); + RowList::iterator end = ntext_.rows().end(); int y_offset = baseline - rowit->ascent_of_text(); int ph = pain.paperHeight(); @@ -377,11 +360,11 @@ void InsetText::draw(PainterInfo & pi, i ++rowit; } if (y_offset < 0) { - lt->top_y(-y_offset); + ntext_.top_y(-y_offset); first = y; y_offset = 0; } else { - lt->top_y(first); + ntext_.top_y(first); first = 0; } @@ -390,27 +373,23 @@ void InsetText::draw(PainterInfo & pi, i bv->hideCursor(); - while ((rowit != end) && (yf < ph)) { - RowPainter rp(*bv, *lt, rowit); - rp.paint(y + y_offset + first, int(x), y + lt->top_y()); + while (rowit != end && yf < ph) { + RowPainter rp(*bv, ntext_, rowit); + rp.paint(y + y_offset + first, int(x), y + ntext_.top_y()); y += rowit->height(); yf += rowit->height(); ++rowit; } - lt->clearPaint(); + ntext_.clearPaint(); - if ((drawFrame_ == ALWAYS) || (drawFrame_ == LOCKED && locked)) { + if ((drawFrame_ == ALWAYS) || (drawFrame_ == LOCKED && locked)) drawFrame(pain, int(start_x)); - } x += dim_.wid - TEXT_TO_INSET_OFFSET; - if (need_update != INIT) { + if (need_update != INIT) need_update = NONE; - } - if (clear) - lt = 0; } @@ -426,90 +405,25 @@ void InsetText::drawFrame(Painter & pain } -void InsetText::update(BufferView * bv, bool reinit) -{ - if (in_update) { - if (reinit && owner()) { - reinitLyXText(); - owner()->update(bv, true); - } - return; - } - in_update = true; - - if (reinit || need_update == INIT) { - need_update = FULL; - // we should put this call where we set need_update to INIT! - reinitLyXText(); - if (owner()) - owner()->update(bv, true); - in_update = false; - - int nw = getMaxWidth(bv, this); - if (nw > 0 && old_max_width != nw) { - need_update |= INIT; - old_max_width = nw; - } - return; - } - - if (!autoBreakRows && - boost::next(paragraphs.begin()) != paragraphs.end()) - collapseParagraphs(bv); - - if (the_locking_inset) { - inset_x = cix(bv) - top_x + drawTextXOffset; - inset_y = ciy(bv) + drawTextYOffset; - the_locking_inset->update(bv, reinit); - } - - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - if ((need_update & CURSOR_PAR) && (lt->refreshStatus() == LyXText::REFRESH_NONE) && - the_locking_inset) { - lt->updateInset(the_locking_inset); - } - - if (lt->refreshStatus() == LyXText::REFRESH_AREA) - need_update |= FULL; - if (clear) - lt = 0; - - in_update = false; - - int nw = getMaxWidth(bv, this); - if (nw > 0 && old_max_width != nw) { - need_update |= INIT; - old_max_width = nw; - } -} - - void InsetText::setUpdateStatus(BufferView * bv, int what) const { - // this does nothing dangerous so use only a localized buffer - LyXText * llt = getLyXText(bv); - need_update |= what; // we have to redraw us full if our LyXText REFRESH_AREA or // if we don't break row so that we only have one row to update! - if ((llt->refreshStatus() == LyXText::REFRESH_AREA) || + if ((ntext_.refreshStatus() == LyXText::REFRESH_AREA) || (!autoBreakRows && - (llt->refreshStatus() == LyXText::REFRESH_ROW))) + (ntext_.refreshStatus() == LyXText::REFRESH_ROW))) { need_update |= FULL; - } else if (llt->refreshStatus() == LyXText::REFRESH_ROW) { + } else if (ntext_.refreshStatus() == LyXText::REFRESH_ROW) { need_update |= CURSOR_PAR; } // this to not draw a selection when we redraw all of it! if (need_update & CURSOR && !(need_update & SELECTION)) { - if (llt->selection.set()) + if (ntext_.selection.set()) need_update = FULL; - llt->clearSelection(); + ntext_.clearSelection(); } } @@ -525,29 +439,21 @@ void InsetText::updateLocal(BufferView * collapseParagraphs(bv); #endif - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - lt->fullRebreak(); + ntext_.fullRebreak(); setUpdateStatus(bv, what); bool flag = mark_dirty || - (((need_update != CURSOR) && (need_update != NONE)) || - (lt->refreshStatus() != LyXText::REFRESH_NONE) || lt->selection.set()); - if (!lt->selection.set()) - lt->selection.cursor = lt->cursor; + ((need_update != CURSOR && need_update != NONE) || + (ntext_.refreshStatus() != LyXText::REFRESH_NONE) || ntext_.selection.set()); + if (!ntext_.selection.set()) + ntext_.selection.cursor = ntext_.cursor; bv->fitCursor(); if (flag) { - lt->postPaint(0); + ntext_.postPaint(0); bv->updateInset(const_cast<InsetText *>(this)); } - if (clear) - lt = 0; - if (need_update == CURSOR) need_update = NONE; bv->owner()->view_state_changed(); @@ -576,14 +482,8 @@ void InsetText::insetUnlock(BufferView * no_selection = true; locked = false; int code = NONE; - bool clear = false; - - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - if (lt->selection.set()) { - lt->clearSelection(); + if (ntext_.selection.set()) { + ntext_.clearSelection(); code = FULL; } else if (owner()) { bv->owner()->setLayout(owner()->getLyXText(bv) @@ -592,12 +492,10 @@ void InsetText::insetUnlock(BufferView * bv->owner()->setLayout(bv->text->cursor.par()->layout()->name()); // hack for deleteEmptyParMech if (!paragraphs.begin()->empty()) { - lt->setCursor(paragraphs.begin(), 0); + ntext_.setCursor(paragraphs.begin(), 0); } else if (boost::next(paragraphs.begin()) != paragraphs.end()) { - lt->setCursor(boost::next(paragraphs.begin()), 0); + ntext_.setCursor(boost::next(paragraphs.begin()), 0); } - if (clear) - lt = 0; #if 0 updateLocal(bv, code, false); #else @@ -615,25 +513,18 @@ void InsetText::lockInset(BufferView * b inset_boundary = false; inset_par = paragraphs.end(); old_par = paragraphs.end(); - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - lt->setCursor(paragraphs.begin(), 0); - lt->clearSelection(); + ntext_.setCursor(paragraphs.begin(), 0); + ntext_.clearSelection(); finishUndo(); // If the inset is empty set the language of the current font to the // language to the surronding text (if different). if (paragraphs.begin()->empty() && boost::next(paragraphs.begin()) == paragraphs.end() && - bv->getParentLanguage(this) != lt->current_font.language()) { + bv->getParentLanguage(this) != ntext_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); setFont(bv, font, false); } - if (clear) - lt = 0; int code = CURSOR; if (drawFrame_ == LOCKED) code = CURSOR|DRAW_FRAME; @@ -734,11 +625,6 @@ bool InsetText::updateInsetInInset(Buffe collapseParagraphs(bv); if (inset == this) return true; - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } if (inset->owner() != this) { int ustat = CURSOR_PAR; bool found = false; @@ -755,16 +641,12 @@ bool InsetText::updateInsetInInset(Buffe ustat = FULL; } if (found) - lt->updateInset(tl_inset); - if (clear) - lt = 0; + ntext_.updateInset(tl_inset); if (found) setUpdateStatus(bv, ustat); return found; } - bool found = lt->updateInset(inset); - if (clear) - lt = 0; + bool found = ntext_.updateInset(inset); if (found) { setUpdateStatus(bv, CURSOR_PAR); if (the_locking_inset && @@ -829,30 +711,22 @@ void InsetText::lfunMousePress(FuncReque localDispatch(FuncRequest(bv, LFUN_COPY)); paste_internally = true; } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - int old_top_y = lt->top_y(); + int old_top_y = ntext_.top_y(); - lt->setCursorFromCoordinates(cmd.x - drawTextXOffset, + ntext_.setCursorFromCoordinates(cmd.x - drawTextXOffset, cmd.y + dim_.asc); // set the selection cursor! - lt->selection.cursor = lt->cursor; - lt->cursor.x_fix(lt->cursor.x()); + ntext_.selection.cursor = ntext_.cursor; + ntext_.cursor.x_fix(ntext_.cursor.x()); - if (lt->selection.set()) { - lt->clearSelection(); + if (ntext_.selection.set()) { + ntext_.clearSelection(); updateLocal(bv, FULL, false); } else { - lt->clearSelection(); + ntext_.clearSelection(); updateLocal(bv, CURSOR, false); } - if (clear) - lt = 0; - bv->owner()->setLayout(cpar(bv)->layout()->name()); // we moved the view we cannot do mouse selection in this case! @@ -930,25 +804,15 @@ void InsetText::lfunMouseMotion(FuncRequ return; BufferView * bv = cmd.view(); - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - LyXCursor cur = lt->cursor; - lt->setCursorFromCoordinates + LyXCursor cur = ntext_.cursor; + ntext_.setCursorFromCoordinates (cmd.x - drawTextXOffset, cmd.y + dim_.asc); - lt->cursor.x_fix(lt->cursor.x()); - if (cur == lt->cursor) { - if (clear) - lt = 0; + ntext_.cursor.x_fix(ntext_.cursor.x()); + if (cur == ntext_.cursor) return; - } - lt->setSelection(); - bool flag = (lt->toggle_cursor.par() != lt->toggle_end_cursor.par() || - lt->toggle_cursor.pos() != lt->toggle_end_cursor.pos()); - if (clear) - lt = 0; + ntext_.setSelection(); + bool flag = (ntext_.toggle_cursor.par() != ntext_.toggle_end_cursor.par() || + ntext_.toggle_cursor.pos() != ntext_.toggle_end_cursor.pos()); if (flag) { updateLocal(bv, SELECTION, false); } @@ -974,22 +838,16 @@ Inset::RESULT InsetText::localDispatch(F inset_par = paragraphs.end(); old_par = paragraphs.end(); - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - if (cmd.argument.size()) { if (cmd.argument == "left") - lt->setCursor(paragraphs.begin(), 0); + ntext_.setCursor(paragraphs.begin(), 0); else { ParagraphList::iterator it = paragraphs.begin(); ParagraphList::iterator end = paragraphs.end(); while (boost::next(it) != end) ++it; // int const pos = (p->size() ? p->size()-1 : p->size()); - lt->setCursor(it, it->size()); + ntext_.setCursor(it, it->size()); } } else { int tmp_y = (cmd.y < 0) ? 0 : cmd.y; @@ -998,28 +856,26 @@ Inset::RESULT InsetText::localDispatch(F // cycle hopefully (Jug 20020509) // FIXME: GUII I've changed this to none: probably WRONG if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) { - lt->setCursorFromCoordinates(cmd.x - drawTextXOffset, + ntext_.setCursorFromCoordinates(cmd.x - drawTextXOffset, cmd.y + dim_.asc); - lt->cursor.x_fix(lt->cursor.x()); + ntext_.cursor.x_fix(ntext_.cursor.x()); } } - lt->clearSelection(); + ntext_.clearSelection(); finishUndo(); // If the inset is empty set the language of the current font to the // language to the surronding text (if different). if (paragraphs.begin()->empty() && boost::next(paragraphs.begin()) == paragraphs.end()&& - bv->getParentLanguage(this) != lt->current_font.language()) + bv->getParentLanguage(this) != ntext_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); setFont(bv, font, false); } - if (clear) - lt = 0; int code = CURSOR; if (drawFrame_ == LOCKED) code = CURSOR | DRAW_FRAME; @@ -1059,10 +915,13 @@ Inset::RESULT InsetText::localDispatch(F result = the_locking_inset->localDispatch(cmd); if (result == DISPATCHED_NOUPDATE) return result; - else if (result == DISPATCHED) { + + if (result == DISPATCHED) { updateLocal(bv, CURSOR_PAR, false); return result; - } else if (result >= FINISHED) { + } + + if (result >= FINISHED) { switch (result) { case FINISHED_RIGHT: moveRightIntern(bv, false, false); @@ -1091,18 +950,13 @@ Inset::RESULT InsetText::localDispatch(F return result; } } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } int updwhat = 0; int updflag = false; // what type of update to do on a cursor movement int cursor_update = CURSOR; - if (lt->selection.set()) + if (ntext_.selection.set()) cursor_update = SELECTION; switch (cmd.action) { @@ -1121,21 +975,21 @@ Inset::RESULT InsetText::localDispatch(F * true (on). */ #if 0 // This should not be needed here and is also WRONG! - setUndo(bv, Undo::INSERT, lt->cursor.par()); + setUndo(bv, Undo::INSERT, ntext_.cursor.par()); #endif bv->switchKeyMap(); if (lyxrc.auto_region_delete) { - if (lt->selection.set()) { - lt->cutSelection(false, false); + if (ntext_.selection.set()) { + ntext_.cutSelection(false, false); } } - lt->clearSelection(); + ntext_.clearSelection(); for (string::size_type i = 0; i < cmd.argument.length(); ++i) { bv->owner()->getIntl().getTransManager(). - TranslateAndInsert(cmd.argument[i], lt); + TranslateAndInsert(cmd.argument[i], &ntext_); } } - lt->selection.cursor = lt->cursor; + ntext_.selection.cursor = ntext_.cursor; updwhat = CURSOR | CURSOR_PAR; updflag = true; result = DISPATCHED_NOUPDATE; @@ -1165,42 +1019,42 @@ Inset::RESULT InsetText::localDispatch(F break; case LFUN_PRIOR: - if (crow(bv) == lt->rows().begin()) + if (crow(bv) == ntext_.rows().begin()) result = FINISHED_UP; else { - lt->cursorPrevious(); - lt->clearSelection(); + ntext_.cursorPrevious(); + ntext_.clearSelection(); result = DISPATCHED_NOUPDATE; } updwhat = cursor_update; break; case LFUN_NEXT: - if (boost::next(crow(bv)) == lt->rows().end()) + if (boost::next(crow(bv)) == ntext_.rows().end()) result = FINISHED_DOWN; else { - lt->cursorNext(); - lt->clearSelection(); + ntext_.cursorNext(); + ntext_.clearSelection(); result = DISPATCHED_NOUPDATE; } updwhat = cursor_update; break; case LFUN_BACKSPACE: { - if (lt->selection.set()) - lt->cutSelection(true, false); + if (ntext_.selection.set()) + ntext_.cutSelection(true, false); else - lt->backspace(); + ntext_.backspace(); updwhat = CURSOR_PAR; updflag = true; break; } case LFUN_DELETE: { - if (lt->selection.set()) { - lt->cutSelection(true, false); + if (ntext_.selection.set()) { + ntext_.cutSelection(true, false); } else { - lt->Delete(); + ntext_.Delete(); } updwhat = CURSOR_PAR; updflag = true; @@ -1208,7 +1062,7 @@ Inset::RESULT InsetText::localDispatch(F } case LFUN_CUT: { - lt->cutSelection(true, true); + ntext_.cutSelection(true, true); updwhat = CURSOR_PAR; updflag = true; break; @@ -1216,7 +1070,7 @@ Inset::RESULT InsetText::localDispatch(F case LFUN_COPY: finishUndo(); - lt->copySelection(); + ntext_.copySelection(); updwhat = CURSOR_PAR; break; @@ -1227,12 +1081,12 @@ Inset::RESULT InsetText::localDispatch(F if (clip.empty()) break; if (cmd.argument == "paragraph") { - lt->insertStringAsParagraphs(clip); + ntext_.insertStringAsParagraphs(clip); } else { - lt->insertStringAsLines(clip); + ntext_.insertStringAsLines(clip); } // bug 393 - lt->clearSelection(); + ntext_.clearSelection(); updwhat = CURSOR_PAR; updflag = true; @@ -1257,9 +1111,9 @@ Inset::RESULT InsetText::localDispatch(F #warning FIXME Check if the arg is in the domain of available selections. sel_index = paste_arg; } - lt->pasteSelection(sel_index); + ntext_.pasteSelection(sel_index); // bug 393 - lt->clearSelection(); + ntext_.clearSelection(); updwhat = CURSOR_PAR; updflag = true; break; @@ -1270,7 +1124,7 @@ Inset::RESULT InsetText::localDispatch(F result = DISPATCHED; break; } - lt->breakParagraph(paragraphs, 0); + ntext_.breakParagraph(paragraphs, 0); updwhat = CURSOR | FULL; updflag = true; break; @@ -1280,7 +1134,7 @@ Inset::RESULT InsetText::localDispatch(F result = DISPATCHED; break; } - lt->breakParagraph(paragraphs, 1); + ntext_.breakParagraph(paragraphs, 1); updwhat = CURSOR | FULL; updflag = true; break; @@ -1291,7 +1145,7 @@ Inset::RESULT InsetText::localDispatch(F break; } - lt->insertInset(new InsetNewline); + ntext_.insertInset(new InsetNewline); updwhat = CURSOR | CURSOR_PAR; updflag = true; break; @@ -1326,7 +1180,7 @@ Inset::RESULT InsetText::localDispatch(F if (cur_layout != layout) { cur_layout = layout; - lt->setLayout(layout); + ntext_.setLayout(layout); bv->owner()->setLayout(cpar(bv)->layout()->name()); updwhat = CURSOR_PAR; updflag = true; @@ -1342,7 +1196,7 @@ Inset::RESULT InsetText::localDispatch(F // inherit bufferparams/paragraphparams in a strange way. (Lgb) // FIXME: how old is this comment ? ... { - ParagraphList::iterator pit = lt->cursor.par(); + ParagraphList::iterator pit = ntext_.cursor.par(); Spacing::Space cur_spacing = pit->params().spacing().getSpace(); float cur_value = 1.0; if (cur_spacing == Spacing::Other) { @@ -1418,8 +1272,6 @@ Inset::RESULT InsetText::localDispatch(F break; } - if (clear) - lt = 0; if (updwhat > 0) updateLocal(bv, updwhat, updflag); /// If the action has deleted all text in the inset, we need to change the @@ -1628,6 +1480,7 @@ void InsetText::validate(LaTeXFeatures & void InsetText::getCursor(BufferView & bv, int & x, int & y) const { + view_ = &bv; if (the_locking_inset) { the_locking_inset->getCursor(bv, x, y); return; @@ -1835,23 +1688,16 @@ void InsetText::setFont(BufferView * bv, getLyXText(bv)->setFont(font, toggleall); return; } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - if (lt->selection.set()) { - setUndo(bv, Undo::EDIT, lt->cursor.par()); + if (ntext_.selection.set()) { + setUndo(bv, Undo::EDIT, ntext_.cursor.par()); } if (selectall) selectAll(bv); - lt->toggleFree(font, toggleall); + ntext_.toggleFree(font, toggleall); if (selectall) - lt->clearSelection(); + ntext_.clearSelection(); bv->fitCursor(); - bool flag = (selectall || lt->selection.set()); - if (clear) - lt = 0; + bool flag = (selectall || ntext_.selection.set()); if (flag) updateLocal(bv, FULL, true); else @@ -1910,25 +1756,6 @@ bool InsetText::checkAndActivateInset(Bu } -int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const -{ -#if 0 - int w = UpdatableInset::getMaxWidth(bv, inset); - if (w < 0) { - return -1; - } - if (owner()) { - w = w - top_x + owner()->x(); - return w; - } - w -= (2 * TEXT_TO_INSET_OFFSET); - return w - top_x; -#else - return UpdatableInset::getMaxWidth(bv, inset); -#endif -} - - void InsetText::setParagraphData(ParagraphList const & plist) { // we have to unlock any locked inset otherwise we're in troubles @@ -2009,14 +1836,12 @@ void InsetText::setFrameColor(BufferView int InsetText::cx(BufferView * bv) const { - // we do nothing dangerous so we use a local cache - LyXText * llt = getLyXText(bv); - int x = llt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET; + int x = ntext_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET; if (the_locking_inset) { - LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(), - llt->cursor.pos()); + LyXFont font = ntext_.getFont(bv->buffer(), ntext_.cursor.par(), + ntext_.cursor.pos()); if (font.isVisibleRightToLeft()) - x -= the_locking_inset->width(bv, font); + x -= the_locking_inset->dim_.wid; } return x; } @@ -2024,14 +1849,12 @@ int InsetText::cx(BufferView * bv) const int InsetText::cix(BufferView * bv) const { - // we do nothing dangerous so we use a local cache - LyXText * llt = getLyXText(bv); - int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET; + int x = ntext_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET; if (the_locking_inset) { - LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(), - llt->cursor.pos()); + LyXFont font = ntext_.getFont(bv->buffer(), ntext_.cursor.par(), + ntext_.cursor.pos()); if (font.isVisibleRightToLeft()) - x -= the_locking_inset->width(bv, font); + x -= the_locking_inset->dim_.wid; } return x; } @@ -2039,15 +1862,13 @@ int InsetText::cix(BufferView * bv) cons int InsetText::cy(BufferView * bv) const { - LyXFont font; - return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET; + return getLyXText(bv)->cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET; } int InsetText::ciy(BufferView * bv) const { - LyXFont font; - return getLyXText(bv)->cursor.iy() - ascent(bv, font) + TEXT_TO_INSET_OFFSET; + return getLyXText(bv)->cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET; } @@ -2075,84 +1896,18 @@ RowList::iterator InsetText::crow(Buffer } -LyXText * InsetText::getLyXText(BufferView const * lbv, - bool const recursive) const +LyXText * InsetText::getLyXText(BufferView const * bv, bool) const { - if (cached_bview == lbv) { - if (recursive && the_locking_inset) - return the_locking_inset->getLyXText(lbv, true); - LyXText * lt = cached_text.get(); - lyx::Assert(lt && lt->rows().begin()->par() == const_cast<ParagraphList&>(paragraphs).begin()); - return lt; - } - // Super UGLY! (Lgb) - BufferView * bv = const_cast<BufferView *>(lbv); - - cached_bview = bv; - Cache::iterator it = cache.find(bv); - - if (it != cache.end()) { - if (do_reinit) { - reinitLyXText(); - } else if (do_resize) { - resizeLyXText(do_resize); - } else { - if (lt || !it->second.remove) { - lyx::Assert(it->second.text.get()); - cached_text = it->second.text; - if (recursive && the_locking_inset) { - return the_locking_inset->getLyXText(bv, true); - } - return cached_text.get(); - } else if (it->second.remove) { - if (locked) { - saveLyXTextState(it->second.text.get()); - } else { - sstate.lpar = const_cast<ParagraphList&>(paragraphs).end(); - } - } - // - // when we have to reinit the existing LyXText! - // - it->second.text->init(bv); - restoreLyXTextState(it->second.text.get()); - it->second.remove = false; - } - cached_text = it->second.text; - if (the_locking_inset && recursive) { - return the_locking_inset->getLyXText(bv); - } - return cached_text.get(); - } - /// - // we are here only if we don't have a BufferView * in the cache!!! - /// - cached_text.reset(new LyXText(bv, const_cast<InsetText *>(this))); - cached_text->init(bv); - restoreLyXTextState(cached_text.get()); - - cache.insert(make_pair(bv, cached_text)); - - if (the_locking_inset && recursive) { - return the_locking_inset->getLyXText(bv); - } - return cached_text.get(); + if (bv) + view_ = const_cast<BufferView *>(bv); + ntext_.inset_owner = const_cast<InsetText *>(this); + ntext_.bv_owner = view_; + return const_cast<LyXText *>(&ntext_); } void InsetText::deleteLyXText(BufferView * bv, bool recursive) const { - cached_bview = 0; - - Cache::iterator it = cache.find(bv); - - if (it == cache.end()) { - return; - } - - lyx::Assert(it->second.text.get()); - - it->second.remove = true; if (recursive) { /// then remove all LyXText in text-insets for_each(const_cast<ParagraphList&>(paragraphs).begin(), @@ -2164,13 +1919,6 @@ void InsetText::deleteLyXText(BufferView void InsetText::resizeLyXText(BufferView * bv, bool force) const { - if (lt) { - // we cannot resize this because we are in use! - // so do this on the next possible getLyXText() - do_resize = bv; - return; - } - do_resize = 0; if (boost::next(paragraphs.begin()) == paragraphs.end() && paragraphs.begin()->empty()) { // no data, resize not neccessary! // we have to do this as a fixed width may have changed! @@ -2184,13 +1932,7 @@ void InsetText::resizeLyXText(BufferView if (!force && getMaxWidth(bv, this) < 0) return; - Cache::iterator it = cache.find(bv); - if (it == cache.end()) { - return; - } - lyx::Assert(it->second.text.get()); - - LyXText * t = it->second.text.get(); + LyXText * t = &ntext_; saveLyXTextState(t); for_each(const_cast<ParagraphList&>(paragraphs).begin(), @@ -2217,40 +1959,41 @@ void InsetText::resizeLyXText(BufferView void InsetText::reinitLyXText() const { +#if 0 if (lt) { // we cannot resize this because we are in use! // so do this on the next possible getLyXText() do_reinit = true; return; } +#endif do_reinit = false; - do_resize = 0; - for (Cache::iterator it = cache.begin(); it != cache.end(); ++it) { - lyx::Assert(it->second.text.get()); - LyXText * t = it->second.text.get(); - BufferView * bv = it->first; + LyXText * t = &ntext_; + BufferView * bv = view_; - saveLyXTextState(t); + if (!bv) + return; - for_each(const_cast<ParagraphList&>(paragraphs).begin(), - const_cast<ParagraphList&>(paragraphs).end(), - boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); + saveLyXTextState(t); - t->init(bv, true); - restoreLyXTextState(t); - if (the_locking_inset) { - inset_x = cix(bv) - top_x + drawTextXOffset; - inset_y = ciy(bv) + drawTextYOffset; - } - t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y())); - if (!owner()) { - const_cast<InsetText*>(this)->updateLocal(bv, FULL, false); - // this will scroll the screen such that the cursor becomes visible - bv->updateScrollbar(); - } else { - need_update = FULL; - } + for_each(const_cast<ParagraphList&>(paragraphs).begin(), + const_cast<ParagraphList&>(paragraphs).end(), + boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); + + t->init(bv, true); + restoreLyXTextState(t); + if (the_locking_inset) { + inset_x = cix(bv) - top_x + drawTextXOffset; + inset_y = ciy(bv) + drawTextYOffset; + } + t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y())); + if (!owner()) { + const_cast<InsetText*>(this)->updateLocal(bv, FULL, false); + // this will scroll the screen such that the cursor becomes visible + bv->updateScrollbar(); + } else { + need_update = FULL; } } @@ -2319,9 +2062,9 @@ void InsetText::clearInset(BufferView * h += ty; ty = 0; } - if ((ty + h) > pain.paperHeight()) + if (ty + h > pain.paperHeight()) h = pain.paperHeight(); - if ((top_x + drawTextXOffset + w) > pain.paperWidth()) + if (top_x + drawTextXOffset + w > pain.paperWidth()) w = pain.paperWidth(); pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor()); need_update = FULL; @@ -2368,31 +2111,22 @@ WordLangTuple const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const { - bool clear = false; WordLangTuple word; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } if (the_locking_inset) { word = the_locking_inset->selectNextWordToSpellcheck(bv, value); if (!word.word().empty()) { value += cy(bv); - if (clear) - lt = 0; return word; } // we have to go on checking so move cursor to the next char - lt->cursor.pos(lt->cursor.pos() + 1); + ntext_.cursor.pos(ntext_.cursor.pos() + 1); } - word = lt->selectNextWordToSpellcheck(value); + word = ntext_.selectNextWordToSpellcheck(value); if (word.word().empty()) bv->unlockInset(const_cast<InsetText *>(this)); else value = cy(bv); - if (clear) - lt = 0; return word; } @@ -2413,19 +2147,14 @@ void InsetText::toggleSelection(BufferVi if (the_locking_inset) { the_locking_inset->toggleSelection(bv, kill_selection); } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } int x = top_x + TEXT_TO_INSET_OFFSET; - RowList::iterator rowit = lt->rows().begin(); - RowList::iterator end = lt->rows().end(); + RowList::iterator rowit = ntext_.rows().begin(); + RowList::iterator end = ntext_.rows().end(); int y_offset = top_baseline - rowit->ascent_of_text(); int y = y_offset; - while ((rowit != end) && ((y + rowit->height()) <= 0)) { + while (rowit != end && y + rowit->height() <= 0) { y += rowit->height(); ++rowit; } @@ -2434,38 +2163,29 @@ void InsetText::toggleSelection(BufferVi if (need_update & SELECTION) need_update = NONE; - bv->screen().toggleSelection(lt, bv, kill_selection, y_offset, x); - if (clear) - lt = 0; + bv->screen().toggleSelection(&ntext_, bv, kill_selection, y_offset, x); } bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length) { - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } if (the_locking_inset) { if (the_locking_inset->nextChange(bv, length)) return true; - lt->cursorRight(true); + ntext_.cursorRight(true); } lyxfind::SearchResult result = - lyxfind::findNextChange(bv, lt, length); + lyxfind::findNextChange(bv, &ntext_, length); if (result == lyxfind::SR_FOUND) { - LyXCursor cur = lt->cursor; + LyXCursor cur = ntext_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) locked = true; - lt->cursor = cur; - lt->setSelectionRange(length); + ntext_.cursor = cur; + ntext_.setSelectionRange(length); updateLocal(bv, SELECTION, false); } - if (clear) - lt = 0; return result != lyxfind::SR_NOT_FOUND; } @@ -2473,30 +2193,23 @@ bool InsetText::nextChange(BufferView * bool InsetText::searchForward(BufferView * bv, string const & str, bool cs, bool mw) { - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } if (the_locking_inset) { if (the_locking_inset->searchForward(bv, str, cs, mw)) return true; - lt->cursorRight(true); + ntext_.cursorRight(true); } lyxfind::SearchResult result = - lyxfind::LyXFind(bv, lt, str, true, cs, mw); + lyxfind::LyXFind(bv, &ntext_, str, true, cs, mw); if (result == lyxfind::SR_FOUND) { - LyXCursor cur = lt->cursor; + LyXCursor cur = ntext_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) locked = true; - lt->cursor = cur; - lt->setSelectionRange(str.length()); + ntext_.cursor = cur; + ntext_.setSelectionRange(str.length()); updateLocal(bv, SELECTION, false); } - if (clear) - lt = 0; return (result != lyxfind::SR_NOT_FOUND); } @@ -2507,11 +2220,6 @@ bool InsetText::searchBackward(BufferVie if (the_locking_inset->searchBackward(bv, str, cs, mw)) return true; } - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } if (!locked) { ParagraphList::iterator pit = paragraphs.begin(); ParagraphList::iterator pend = paragraphs.end(); @@ -2519,22 +2227,20 @@ bool InsetText::searchBackward(BufferVie while (boost::next(pit) != pend) ++pit; - lt->setCursor(pit, pit->size()); + ntext_.setCursor(pit, pit->size()); } lyxfind::SearchResult result = - lyxfind::LyXFind(bv, lt, str, false, cs, mw); + lyxfind::LyXFind(bv, &ntext_, str, false, cs, mw); if (result == lyxfind::SR_FOUND) { - LyXCursor cur = lt->cursor; + LyXCursor cur = ntext_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) locked = true; - lt->cursor = cur; - lt->setSelectionRange(str.length()); + ntext_.cursor = cur; + ntext_.setSelectionRange(str.length()); updateLocal(bv, SELECTION, false); } - if (clear) - lt = 0; return (result != lyxfind::SR_NOT_FOUND); } @@ -2549,8 +2255,6 @@ bool InsetText::checkInsertChar(LyXFont void InsetText::collapseParagraphs(BufferView * bv) { - LyXText * llt = getLyXText(bv); - while (boost::next(paragraphs.begin()) != paragraphs.end()) { if (!paragraphs.begin()->empty() && !boost::next(paragraphs.begin())->empty() && @@ -2558,16 +2262,16 @@ void InsetText::collapseParagraphs(Buffe { paragraphs.begin()->insertChar(paragraphs.begin()->size(), ' '); } - if (llt->selection.set()) { - if (llt->selection.start.par() == boost::next(paragraphs.begin())) { - llt->selection.start.par(paragraphs.begin()); - llt->selection.start.pos( - llt->selection.start.pos() + paragraphs.begin()->size()); - } - if (llt->selection.end.par() == boost::next(paragraphs.begin())) { - llt->selection.end.par(paragraphs.begin()); - llt->selection.end.pos( - llt->selection.end.pos() + paragraphs.begin()->size()); + if (ntext_.selection.set()) { + if (ntext_.selection.start.par() == boost::next(paragraphs.begin())) { + ntext_.selection.start.par(paragraphs.begin()); + ntext_.selection.start.pos( + ntext_.selection.start.pos() + paragraphs.begin()->size()); + } + if (ntext_.selection.end.par() == boost::next(paragraphs.begin())) { + ntext_.selection.end.par(paragraphs.begin()); + ntext_.selection.end.pos( + ntext_.selection.end.pos() + paragraphs.begin()->size()); } } mergeParagraph(bv->buffer()->params, paragraphs, paragraphs.begin()); Index: insets/insettext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v retrieving revision 1.168 diff -u -p -r1.168 insettext.h --- insets/insettext.h 16 Jun 2003 11:49:34 -0000 1.168 +++ insets/insettext.h 18 Jun 2003 14:57:40 -0000 @@ -18,12 +18,12 @@ #include "ParagraphList.h" #include "RowList.h" #include "dimension.h" +#include "lyxtext.h" #include "frontends/mouse_state.h" #include "support/types.h" #include <boost/shared_ptr.hpp> -#include <map> class Painter; class BufferView; @@ -90,8 +90,6 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - void update(BufferView *, bool = false); - /// void setUpdateStatus(BufferView *, int what) const; /// string const editMessage() const; @@ -142,8 +140,6 @@ public: bool toggleall = false, bool selectall = false); /// - int getMaxWidth(BufferView *, UpdatableInset const *) const; - /// void init(InsetText const * ins); /// void writeParagraphData(Buffer const *, std::ostream &) const; @@ -268,19 +264,6 @@ private: void lfunMouseMotion(FuncRequest const &); /// - struct InnerCache { - /// - InnerCache(boost::shared_ptr<LyXText>); - /// - boost::shared_ptr<LyXText> text; - /// - bool remove; - }; - /// - typedef std::map<BufferView *, InnerCache> Cache; - /// - typedef Cache::value_type value_type; - /// RESULT moveRight(BufferView *, bool activate_inset = true, bool selecting = false); @@ -343,8 +326,6 @@ private: /// mutable bool locked; /// - mutable Dimension dim_; - /// mutable int top_y; /// ParagraphList::iterator inset_par; @@ -357,21 +338,11 @@ private: /// mutable int inset_y; /// - mutable int old_max_width; - /// bool no_selection; /// UpdatableInset * the_locking_inset; /// mutable ParagraphList::iterator old_par; - /// The cache. - mutable Cache cache; - /// - mutable int last_drawn_width; - /// - mutable BufferView * cached_bview; - /// - mutable boost::shared_ptr<LyXText> cached_text; /// struct save_state { ParagraphList::iterator lpar; @@ -389,10 +360,8 @@ private: /// mutable save_state sstate; - /// - // this is needed globally so we know that we're using it actually and - // so the LyXText-Cache is not erased until used! - mutable LyXText * lt; + /// our row cache + mutable LyXText ntext_; /// // to remember old painted frame dimensions to clear it on the right spot! /// @@ -401,8 +370,6 @@ private: mutable int frame_w; mutable int frame_h; /// - bool in_update; /* as update is not reentrant! */ - mutable BufferView * do_resize; mutable bool do_reinit; mutable bool in_insetAllowed; /// @@ -410,5 +377,10 @@ private: /// int mouse_x; int mouse_y; + /// last requested fixed width + mutable int textwidth_; + /// cached BufferView + mutable BufferView * view_; }; + #endif Index: insets/updatableinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.C,v retrieving revision 1.13 diff -u -p -r1.13 updatableinset.C --- insets/updatableinset.C 30 May 2003 06:48:23 -0000 1.13 +++ insets/updatableinset.C 18 Jun 2003 14:57:40 -0000 @@ -72,22 +72,21 @@ void UpdatableInset::scroll(BufferView * int const workW = bv->workWidth(); int const tmp_top_x = top_x - scx; - if (tmp_top_x > 0 && - (tmp_top_x + width(bv, font)) < workW) + if (tmp_top_x > 0 && tmp_top_x + dim_.wid < workW) return; + if (s > 0 && top_x > 0) return; - // int mx_scx=abs((width(bv,font) - bv->workWidth())/2); + // int mx_scx=abs((dim_.wid - bv->workWidth())/2); //int const save_scx = scx; scx = int(s * workW / 2); // if (!display()) // scx += 20; - if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) { - scx += (workW / 2) - (tmp_top_x + scx + width(bv, font)); - } + if ((tmp_top_x + scx + dim_.wid) < (workW / 2)) + scx += (workW / 2) - (tmp_top_x + scx + dim_.wid); } void UpdatableInset::scroll(BufferView * bv, int offset) const @@ -95,17 +94,17 @@ void UpdatableInset::scroll(BufferView * if (offset > 0) { if (!scx && top_x >= 20) return; - if ((top_x + offset) > 20) + if (top_x + offset > 20) scx = 0; // scx += offset - (top_x - scx + offset - 20); else scx += offset; } else { LyXFont const font; - if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20)) + if (!scx && (top_x + dim_.wid) < (bv->workWidth() - 20)) return; - if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) { - scx = bv->workWidth() - width(bv, font) - top_x + scx - 20; + if ((top_x - scx + offset + dim_.wid) < (bv->workWidth() - 20)) { + scx += bv->workWidth() - dim_.wid - top_x - 20; } else { scx += offset; } Index: insets/updatableinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.h,v retrieving revision 1.9 diff -u -p -r1.9 updatableinset.h --- insets/updatableinset.h 30 May 2003 06:48:23 -0000 1.9 +++ insets/updatableinset.h 18 Jun 2003 14:57:40 -0000 @@ -17,10 +17,9 @@ // Updatable Insets. These insets can be locked and receive // directly user interaction. Currently used only for mathed. -// Note that all pure methods from Inset class are pure here too. -// [Alejandro 080596] #include "inset.h" +#include "dimension.h" /** Extracted from Matthias notes: