]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Revert "Do not modify the changed() status of rows when no drawing has taken place"
[lyx.git] / src / TextMetrics.cpp
index 874cb17607f716e9551e53720237300f57c1f699..f29202c668644dc6dada33af211f7fd25ac7435b 100644 (file)
@@ -565,7 +565,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
 
        Paragraph const & par = text_->getPar(pit);
 
-       double const w = width - row.right_margin - row.width();
+       int const w = width - row.right_margin - row.width();
        // FIXME: put back this assertion when the crash on new doc is solved.
        //LASSERT(w >= 0, /**/);
 
@@ -600,7 +600,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
        // are there any hfills in the row?
        if (int const nh = numberOfHfills(row, par.beginOfBody())) {
                if (w > 0)
-                       hfill = w / double(nh);
+                       hfill = double(w) / nh;
        // we don't have to look at the alignment if it is ALIGN_LEFT and
        // if the row is already larger then the permitted width as then
        // we force the LEFT_ALIGN'edness!
@@ -615,7 +615,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
                         * or newline, then stretch it */
                        if (ns && !row.right_boundary()
                            && row.endpos() != par.size()) {
-                               setSeparatorWidth(row, w / ns);
+                               setSeparatorWidth(row, double(w) / ns);
                                row.dimension().wid = width;
                        } else if (is_rtl) {
                                row.dimension().wid = width;
@@ -627,7 +627,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
                        row.left_margin += w;
                        break;
                case LYX_ALIGN_CENTER:
-                       row.dimension().wid = width - int(w / 2);
+                       row.dimension().wid = width - w / 2;
                        row.left_margin += w / 2;
                        break;
                case LYX_ALIGN_LEFT:
@@ -1803,7 +1803,7 @@ void TextMetrics::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) const
+void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const x, int y) const
 {
        BufferParams const & bparams = bv_->buffer().params();
        ParagraphMetrics const & pm = par_metrics_[pit];
@@ -1843,14 +1843,25 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
        for (size_t i = 0; i != nrows; ++i) {
 
                Row const & row = pm.rows()[i];
+               int row_x = x;
                if (i)
                        y += row.ascent();
 
+               CursorSlice rowSlice(const_cast<InsetText &>(text_->inset()));
+               rowSlice.pit() = pit;
+               rowSlice.pos() = row.pos();
+
                bool const inside = (y + row.descent() >= 0
                        && y - row.ascent() < ww);
+
+               // Adapt to cursor row scroll offset if applicable.
+               if (bv_->currentRowSlice() == rowSlice)
+                       row_x -= bv_->horizScrollOffset();
+
                // It is not needed to draw on screen if we are not inside.
                pi.pain.setDrawingEnabled(inside && original_drawing_state);
-               RowPainter rp(pi, *text_, pit, row, x, y);
+
+               RowPainter rp(pi, *text_, pit, row, row_x, y);
 
                if (selection)
                        row.setSelectionAndMargins(sel_beg_par, sel_end_par);
@@ -1868,7 +1879,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
 
                // Row signature; has row changed since last paint?
                row.setCrc(pm.computeRowSignature(row, bparams));
-               bool row_has_changed = row.changed();
+               bool row_has_changed = row.changed()
+                       || rowSlice == bv_->lastRowSlice();
 
                // Take this opportunity to spellcheck the row contents.
                if (row_has_changed && lyxrc.spellcheck_continuously) {
@@ -1888,7 +1900,10 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
                // Clear background of this row if paragraph background was not
                // already cleared because of a full repaint.
                if (!pi.full_repaint && row_has_changed) {
-                       pi.pain.fillRectangle(x, y - row.ascent(),
+                       LYXERR(Debug::PAINTING, "Clear rect@("
+                              << max(row_x, 0) << ", " << y - row.ascent() << ")="
+                              << width() << " x " << row.height());
+                       pi.pain.fillRectangle(max(row_x, 0), y - row.ascent(),
                                width(), row.height(), pi.background_color);
                }
 
@@ -1923,6 +1938,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
                        rp.paintLast();
                if (i == 0 && is_rtl)
                        rp.paintFirst();
+               rp.paintTooLargeMarks(row_x < 0,
+                                     row_x + row.width() > bv_->workWidth());
                y += row.descent();
 
                // Restore full_repaint status.