From 3c92c2ab1307263fcde466cd81faa81c6bf7c753 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 27 Aug 2007 14:38:29 +0000 Subject: [PATCH] Remove the wide() hack. This simplifies quite a few things... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19834 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetCaption.h | 2 - src/insets/InsetFloat.h | 2 - src/insets/InsetOptArg.h | 2 - src/insets/InsetText.cpp | 24 +------- src/insets/InsetText.h | 12 +--- src/rowpainter.cpp | 125 ++++---------------------------------- 6 files changed, 15 insertions(+), 152 deletions(-) diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index 6a9d57e9b5..9a95c9f378 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -61,8 +61,6 @@ public: // Update the counters of this inset and of its contents virtual void updateLabels(Buffer const &, ParIterator const &); /// - virtual bool wide() const { return false; } - /// int latex(Buffer const & buf, odocstream & os, OutputParams const &) const; /// diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index d56ededc5d..ca18156b77 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -59,8 +59,6 @@ public: /// Inset::Code lyxCode() const { return Inset::FLOAT_CODE; } /// - virtual bool wide() const { return false; } - /// int latex(Buffer const &, odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetOptArg.h b/src/insets/InsetOptArg.h index 4f8c14ae08..2a289120d5 100644 --- a/src/insets/InsetOptArg.h +++ b/src/insets/InsetOptArg.h @@ -31,8 +31,6 @@ public: Inset::Code lyxCode() const { return Inset::OPTARG_CODE; } /// return an message upon editing virtual docstring const editMessage() const; - /// - virtual bool wide() const { return false; } /// Standard LaTeX output -- short-circuited int latex(Buffer const &, odocstream &, diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index f06869814a..dbce51b93d 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -202,7 +202,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const int const a = tm.ascent() + border_; int const h = a + tm.descent() + border_; pi.pain.rectangle(x, y - a, - ((wide() || hasFixedWidth()) ? tm.maxWidth() : w), + (hasFixedWidth() ? tm.maxWidth() : w), h, frameColor()); } } @@ -216,24 +216,12 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const int const a = tm.ascent() + border_; int const h = a + tm.descent() + border_; pi.pain.fillRectangle(x, y - a, - ((wide() || hasFixedWidth()) ? tm.maxWidth() : w), + (hasFixedWidth() ? tm.maxWidth() : w), h, backgroundColor()); text_.drawSelection(pi, x + border_, y); } -bool InsetText::covers(BufferView const & bv, int x, int y) const -{ - TextMetrics const & tm = bv.textMetrics(&text_); - - return bv.coordCache().getInsets().has(this) - && x >= xo(bv) - && x <= xo(bv) + width() + (wide() ? tm.maxWidth() : 0) - && y >= yo(bv) - ascent() - && y <= yo(bv) + descent(); -} - - docstring const InsetText::editMessage() const { return _("Opened Text Inset"); @@ -346,14 +334,6 @@ void InsetText::validate(LaTeXFeatures & features) const } -bool InsetText::notifyCursorLeaves(Cursor & cur) -{ - if (wide()) - cur.updateFlags(cur.disp_.update() | Update::Force); - return false; -} - - void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 6d72ec31f1..e99c2d56da 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -55,8 +55,6 @@ public: void draw(PainterInfo & pi, int x, int y) const; /// draw inset selection void drawSelection(PainterInfo & pi, int x, int y) const; - /// are we inside the area covered by the inset? - virtual bool covers(BufferView const & bv, int x, int y) const; /// virtual docstring const editMessage() const; /// @@ -75,9 +73,6 @@ public: int docbook(Buffer const &, odocstream &, OutputParams const &) const; /// void validate(LaTeXFeatures & features) const; - //FIXME The following should be removed when wide is. - /// Overridden to force an update if the inset was wide(). - virtual bool notifyCursorLeaves(Cursor & cur); /// return x,y of given position relative to the inset's baseline void cursorPos(BufferView const & bv, CursorSlice const & sl, @@ -137,10 +132,7 @@ public: bool neverIndent(Buffer const &) const; /// InsetText(InsetText const &); - /// - virtual bool wide() const { return wide_inset_; } - /// - void setWide(bool wide_inset) { wide_inset_ = wide_inset; } + // Update the counters of this inset and of its contents virtual void updateLabels(Buffer const &, ParIterator const &); @@ -162,8 +154,6 @@ private: int frame_color_; /// mutable pit_type old_pit; - /// - bool wide_inset_; public: /// diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index 460b373e30..0ad2f6e894 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -56,10 +56,6 @@ using std::string; namespace { -/// Flag: do a full redraw of inside text of inset -/// Working variable indicating a full screen refresh -bool refreshInside; - /** * A class used for painting an individual row of text. */ @@ -76,7 +72,6 @@ public: void paintFirst(); void paintLast(); void paintText(); - int maxWidth() { return max_width_; } private: void paintForeignMark(double orig_x, Font const & font, int desc = 0); @@ -112,7 +107,6 @@ private: pit_type const pit_; Paragraph const & par_; ParagraphMetrics const & pm_; - int max_width_; /// bidi cache, comes from outside the rowpainter because /// rowpainters are normally created in a for loop and there only @@ -140,8 +134,7 @@ RowPainter::RowPainter(PainterInfo & pi, pars_(text.paragraphs()), row_(row), pit_(pit), par_(text.paragraphs()[pit]), pm_(text_metrics_.parMetrics(pit)), - max_width_(bv_.workWidth()), - bidi_(bidi), erased_(pi.erased_), + bidi_(bidi), erased_(pi.erased_), xo_(x), yo_(y), width_(text_metrics_.width()) { RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_); @@ -168,7 +161,8 @@ Font const RowPainter::getLabelFont() const int RowPainter::leftMargin() const { - return text_.leftMargin(bv_.buffer(), max_width_, pit_, row_.pos()); + return text_.leftMargin(bv_.buffer(), text_metrics_.width(), pit_, + row_.pos()); } @@ -193,17 +187,9 @@ void RowPainter::paintInset(pos_type const pos, Font const & font) int const x1 = int(x_); #endif bv_.coordCache().insets().add(inset, int(x_), yo_); - InsetText const * const in = inset->asTextInset(); - // non-wide insets are painted completely. Recursive - bool tmp = refreshInside; - if (!in || !in->wide()) { - refreshInside = true; - LYXERR(Debug::PAINTING) << endl << "Paint inset fully" << endl; - } - if (refreshInside) - inset->drawSelection(pi, int(x_), yo_); + // insets are painted completely. Recursive + inset->drawSelection(pi, int(x_), yo_); inset->draw(pi, int(x_), yo_); - refreshInside = tmp; x_ += inset->width(); #ifdef DEBUG_METRICS Dimension dim; @@ -416,6 +402,7 @@ void RowPainter::paintFromPos(pos_type & vpos) double const orig_x = x_; if (par_.isInset(pos)) { + // If outer row has changed, nested insets are repaint completely. paintInset(pos, orig_font); ++vpos; paintForeignMark(orig_x, orig_font, @@ -890,51 +877,6 @@ bool CursorOnRow(PainterInfo & pi, pit_type const pit, } -bool innerCursorOnRow(PainterInfo & pi, pit_type pit, - RowList::const_iterator rit, Text const & text) -{ - // Is there a cursor inside an inset on this row, and is this inset - // the only "character" on this row - Cursor & cur = pi.base.bv->cursor(); - if (rit->pos() + 1 != rit->endpos()) - return false; - for (size_type d = 0; d < cur.depth(); d++) { - CursorSlice const & sl = cur[d]; - if (sl.text() == &text - && sl.pit() == pit - && sl.pos() == rit->pos()) - return d < cur.depth() - 1; - } - return false; -} - - -// FIXME: once wide() is obsolete, remove this as well! -bool inNarrowInset(PainterInfo & pi) -{ - // check whether the current inset is nested in a non-wide inset - Cursor & cur = pi.base.bv->cursor(); - Inset const * cur_in = &cur.inset(); - // check all higher nested insets - for (size_type i = 1; i < cur.depth(); ++i) { - Inset * const in = &cur[i].inset(); - if (in == cur_in) - // we reached the level of the current inset, so stop - return false; - else if (in) { - if (in->hasFixedWidth()) - return true; - InsetText * t = - const_cast(in->asTextInset()); - if (t && !t->wide()) - // OK, we are in a non-wide() inset - return true; - } - } - return false; -} - - void paintPar (PainterInfo & pi, Text const & text, pit_type pit, int x, int y, bool repaintAll) @@ -944,8 +886,8 @@ void paintPar pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y); - Paragraph const & par = text.paragraphs()[pit]; - ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit); + TextMetrics const & tm = pi.base.bv->textMetrics(&text); + ParagraphMetrics const & pm = tm.parMetrics(pit); if (pm.rows().empty()) return; @@ -958,39 +900,10 @@ void paintPar size_type rowno = 0; for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) { y += rit->ascent(); - // Allow setting of refreshInside for nested insets in - // this row only - bool tmp = refreshInside; - // Row signature; has row changed since last paint? bool row_has_changed = pm.rowChangeStatus()[rowno]; bool cursor_on_row = CursorOnRow(pi, pit, rit, text); - bool in_inset_alone_on_row = - innerCursorOnRow(pi, pit, rit, text); - bool leftEdgeFixed = - (par.getAlign() == LYX_ALIGN_LEFT || - par.getAlign() == LYX_ALIGN_BLOCK); - bool inNarrowIns = inNarrowInset(pi); - - // If this is the only object on the row, we can make it wide - // - // FIXME: there is a const_cast here because paintPar() is not supposed - // to touch the paragraph contents. So either we move this "wide" - // property out of InsetText or we localize the feature to the painting - // done here. - // JSpitzm: We should aim at removing wide() altogether while retaining - // typing speed within insets. - for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) { - Inset const * const in = par.getInset(i); - if (in) { - InsetText * t = const_cast(in->asTextInset()); - if (t) - t->setWide(in_inset_alone_on_row - && leftEdgeFixed - && !inNarrowIns); - } - } // If selection is on, the current row signature differs // from cache, or cursor is inside an inset _on this row_, @@ -1002,18 +915,9 @@ void paintPar pi.pain.setDrawingEnabled(inside); RowPainter rp(pi, text, pit, *rit, bidi, x, y); // Clear background of this row - // (if paragraph background was not cleared) - if (!repaintAll && - (!(in_inset_alone_on_row && leftEdgeFixed && !inNarrowIns) - || row_has_changed)) { - pi.pain.fillRectangle(x, y - rit->ascent(), - rp.maxWidth(), rit->height(), - text.backgroundColor()); - // If outer row has changed, force nested - // insets to repaint completely - if (row_has_changed) - refreshInside = true; - } + pi.pain.fillRectangle(x, y - rit->ascent(), + tm.width(), rit->height(), + text.backgroundColor()); // Instrumentation for testing row cache (see also // 12 lines lower): @@ -1035,8 +939,6 @@ void paintPar rp.paintLast(); } y += rit->descent(); - // Restore, see above - refreshInside = tmp; } // Re-enable screen drawing for future use of the painter. pi.pain.setDrawingEnabled(true); @@ -1074,7 +976,6 @@ void paintText(BufferView & bv, int yy = vi.y1; // draw contents for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) { - refreshInside = repaintAll; ParagraphMetrics const & pm = bv.parMetrics(&text, pit); yy += pm.ascent(); paintPar(pi, text, pit, 0, yy, repaintAll); @@ -1098,13 +999,11 @@ void paintTextInset(Text const & text, PainterInfo & pi, int x, int y) // lyxerr << " paintTextInset: y: " << y << endl; y -= pi.base.bv->parMetrics(&text, 0).ascent(); - // This flag cannot be set from within same inset: - bool repaintAll = refreshInside; for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) { ParagraphMetrics const & pmi = pi.base.bv->parMetrics(&text, pit); y += pmi.ascent(); - paintPar(pi, text, pit, x, y, repaintAll); + paintPar(pi, text, pit, x, y, true); y += pmi.descent(); } } -- 2.39.2