Abdelrazak Younes wrote:
Martin Vermeer wrote:
I expect you will have to do the rowpainter cleanup
at the same time.

I'd like to do it in three steps: first remove the hack, then put in place a better design, then optimize if need be.

When I say better design, I mean that the rowpainter use should be progressively erased. The drawing code will be transfered to TextMetrics, ParagraphMetrics and Row in that order. I've made some experiment before the summer and I am confident that this is doable.

First step done. Will proceed to second step now.

Abdel.

Author: younes
Date: Mon Aug 27 16:38:29 2007
New Revision: 19834

URL: http://www.lyx.org/trac/changeset/19834
Log:
Remove the wide() hack. This simplifies quite a few things...

Modified:
    lyx-devel/trunk/src/insets/InsetCaption.h
    lyx-devel/trunk/src/insets/InsetFloat.h
    lyx-devel/trunk/src/insets/InsetOptArg.h
    lyx-devel/trunk/src/insets/InsetText.cpp
    lyx-devel/trunk/src/insets/InsetText.h
    lyx-devel/trunk/src/rowpainter.cpp

Modified: lyx-devel/trunk/src/insets/InsetCaption.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetCaption.h?rev=19834
==============================================================================
--- lyx-devel/trunk/src/insets/InsetCaption.h (original)
+++ lyx-devel/trunk/src/insets/InsetCaption.h Mon Aug 27 16:38:29 2007
@@ -61,8 +61,6 @@
        // 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;
        ///

Modified: lyx-devel/trunk/src/insets/InsetFloat.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetFloat.h?rev=19834
==============================================================================
--- lyx-devel/trunk/src/insets/InsetFloat.h (original)
+++ lyx-devel/trunk/src/insets/InsetFloat.h Mon Aug 27 16:38:29 2007
@@ -58,8 +58,6 @@
        void validate(LaTeXFeatures & features) const;
        ///
        Inset::Code lyxCode() const { return Inset::FLOAT_CODE; }
-       ///
-       virtual bool wide() const { return false; }
        ///
        int latex(Buffer const &, odocstream &,
                  OutputParams const &) const;

Modified: lyx-devel/trunk/src/insets/InsetOptArg.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetOptArg.h?rev=19834
==============================================================================
--- lyx-devel/trunk/src/insets/InsetOptArg.h (original)
+++ lyx-devel/trunk/src/insets/InsetOptArg.h Mon Aug 27 16:38:29 2007
@@ -31,8 +31,6 @@
        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 &,

Modified: lyx-devel/trunk/src/insets/InsetText.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetText.cpp?rev=19834
==============================================================================
--- lyx-devel/trunk/src/insets/InsetText.cpp (original)
+++ lyx-devel/trunk/src/insets/InsetText.cpp Mon Aug 27 16:38:29 2007
@@ -202,7 +202,7 @@
                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,21 +216,9 @@
        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();
 }


@@ -346,14 +334,6 @@
 }


-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
 {

Modified: lyx-devel/trunk/src/insets/InsetText.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetText.h?rev=19834
==============================================================================
--- lyx-devel/trunk/src/insets/InsetText.h (original)
+++ lyx-devel/trunk/src/insets/InsetText.h Mon Aug 27 16:38:29 2007
@@ -55,8 +55,6 @@
        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 @@
        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 @@
        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 @@
        int frame_color_;
        ///
        mutable pit_type old_pit;
-       ///
-       bool wide_inset_;

 public:
        ///

Modified: lyx-devel/trunk/src/rowpainter.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/rowpainter.cpp?rev=19834
==============================================================================
--- lyx-devel/trunk/src/rowpainter.cpp (original)
+++ lyx-devel/trunk/src/rowpainter.cpp Mon Aug 27 16:38:29 2007
@@ -56,10 +56,6 @@

 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 @@
        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 @@
        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 @@
          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 @@

 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 @@
        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 @@
        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 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<InsetText *>(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 @@

        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 @@
        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<InsetText 
*>(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 @@
                        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 @@
                                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 @@
        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 @@
 //     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();
        }
 }



Reply via email to