]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
FindAdv: Amend b21c8b21: Expand the list for handled latin characters
[lyx.git] / src / TextMetrics.cpp
index 89f8d92075d5cd99a89a43a37456a921015200f7..88ffa6f874bef6aa8f9badab41a9615235081d01 100644 (file)
@@ -130,13 +130,6 @@ bool TextMetrics::contains(pit_type pit) const
 }
 
 
-ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
-{
-       return const_cast<TextMetrics *>(this)->parMetrics(pit, true);
-}
-
-
-
 pair<pit_type, ParagraphMetrics const *> TextMetrics::first() const
 {
        ParMetricsCache::const_iterator it = par_metrics_.begin();
@@ -152,6 +145,30 @@ pair<pit_type, ParagraphMetrics const *> TextMetrics::last() const
 }
 
 
+bool TextMetrics::isLastRow(Row const & row) const
+{
+       ParagraphList const & pars = text_->paragraphs();
+       return row.endpos() >= pars[row.pit()].size()
+               && row.pit() + 1 == pit_type(pars.size());
+}
+
+
+bool TextMetrics::isFirstRow(Row const & row) const
+{
+       return row.pos() == 0 && row.pit() == 0;
+}
+
+
+void TextMetrics::setRowChanged(pit_type pit, pos_type pos)
+{
+       for (auto & pm_pair : par_metrics_)
+               if (pm_pair.first == pit)
+                       for (Row & row : pm_pair.second.rows())
+                               if (row.pos() == pos)
+                                       row.changed(true);
+}
+
+
 ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 {
        ParMetricsCache::iterator pmc_it = par_metrics_.find(pit);
@@ -165,6 +182,42 @@ ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 }
 
 
+ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
+{
+       return const_cast<TextMetrics *>(this)->parMetrics(pit, true);
+}
+
+
+void TextMetrics::newParMetricsDown()
+{
+       pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
+       pit_type const pit = last.first + 1;
+       if (pit == int(text_->paragraphs().size()))
+               return;
+
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(last.second.position()
+               + last.second.descent() + par_metrics_[pit].ascent());
+       updatePosCache(pit);
+}
+
+
+void TextMetrics::newParMetricsUp()
+{
+       pair<pit_type, ParagraphMetrics> const & first = *par_metrics_.begin();
+       if (first.first == 0)
+               return;
+
+       pit_type const pit = first.first - 1;
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(first.second.position()
+               - first.second.ascent() - par_metrics_[pit].descent());
+       updatePosCache(pit);
+}
+
+
 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width,
                          bool const expand_on_multipars)
 {
@@ -1204,35 +1257,6 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
 }
 
 
-void TextMetrics::newParMetricsDown()
-{
-       pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
-       pit_type const pit = last.first + 1;
-       if (pit == int(text_->paragraphs().size()))
-               return;
-
-       // do it and update its position.
-       redoParagraph(pit);
-       par_metrics_[pit].setPosition(last.second.position()
-               + last.second.descent() + par_metrics_[pit].ascent());
-       updatePosCache(pit);
-}
-
-
-void TextMetrics::newParMetricsUp()
-{
-       pair<pit_type, ParagraphMetrics> const & first = *par_metrics_.begin();
-       if (first.first == 0)
-               return;
-
-       pit_type const pit = first.first - 1;
-       // do it and update its position.
-       redoParagraph(pit);
-       par_metrics_[pit].setPosition(first.second.position()
-               - first.second.ascent() - par_metrics_[pit].descent());
-       updatePosCache(pit);
-}
-
 // y is screen coordinate
 pit_type TextMetrics::getPitNearY(int y)
 {
@@ -1566,20 +1590,6 @@ void TextMetrics::deleteLineForward(Cursor & cur)
 }
 
 
-bool TextMetrics::isLastRow(Row const & row) const
-{
-       ParagraphList const & pars = text_->paragraphs();
-       return row.endpos() >= pars[row.pit()].size()
-               && row.pit() + 1 == pit_type(pars.size());
-}
-
-
-bool TextMetrics::isFirstRow(Row const & row) const
-{
-       return row.pos() == 0 && row.pit() == 0;
-}
-
-
 int TextMetrics::leftMargin(pit_type pit) const
 {
        return leftMargin(pit, text_->paragraphs()[pit].size());
@@ -1872,12 +1882,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                                row.change(row.end_margin_sel, sel_end.pit() > pit);
                }
 
-               // has row changed since last paint?
-               bool row_has_changed = row.changed()
-                       || bv_->hadHorizScrollOffset(text_, pit, row.pos());
-
                // Take this opportunity to spellcheck the row contents.
-               if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
+               if (row.changed() && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
                        text_->getPar(pit).spellCheck();
                }
 
@@ -1885,7 +1891,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
 
                // Don't paint the row if a full repaint has not been requested
                // and if it has not changed.
-               if (!pi.full_repaint && !row_has_changed) {
+               if (!pi.full_repaint && !row.changed()) {
                        // Paint only the insets if the text itself is
                        // unchanged.
                        rp.paintOnlyInsets();
@@ -1896,7 +1902,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
 
                // Clear background of this row if paragraph background was not
                // already cleared because of a full repaint.
-               if (!pi.full_repaint && row_has_changed) {
+               if (!pi.full_repaint && row.changed()) {
                        LYXERR(Debug::PAINTING, "Clear rect@("
                               << max(row_x, 0) << ", " << y - row.ascent() << ")="
                               << width() << " x " << row.height());
@@ -1915,13 +1921,13 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                // Instrumentation for testing row cache (see also
                // 12 lines lower):
                if (lyxerr.debugging(Debug::PAINTING)
-                   && (row.selection() || pi.full_repaint || row_has_changed)) {
+                   && (row.selection() || pi.full_repaint || row.changed())) {
                        string const foreword = text_->isMainText() ? "main text redraw "
                                : "inset text redraw: ";
                        LYXERR0(foreword << "pit=" << pit << " row=" << i
                                << (row.selection() ? " row_selection": "")
                                << (pi.full_repaint ? " full_repaint" : "")
-                               << (row_has_changed ? " row_has_changed" : ""));
+                               << (row.changed() ? " row.changed" : ""));
                }
 
                // Backup full_repaint status and force full repaint