]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Take right margin into account for text inset width
[lyx.git] / src / TextMetrics.cpp
index cacf2e7ea65326ff73312eebe12b97e01d4df631..3769627f68d32c768c4a89da73ddd7f3caaf5bcd 100644 (file)
@@ -369,8 +369,9 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        // FIXME: This check ought to be done somewhere else. It is the reason
        // why text_ is not const. But then, where else to do it?
        // Well, how can you end up with either (a) a biblio environment that
-       // has no InsetBibitem or (b) a biblio environment with more than one
-       // InsetBibitem? I think the answer is: when paragraphs are merged;
+       // has no InsetBibitem, (b) a biblio environment with more than one
+       // InsetBibitem or (c) a paragraph that has a bib item but is no biblio
+       // environment? I think the answer is: when paragraphs are merged;
        // when layout is set; when material is pasted.
        if (par.brokenBiblio()) {
                Cursor & cur = const_cast<Cursor &>(bv_->cursor());
@@ -489,7 +490,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                first = row.endpos();
                ++row_index;
 
-               pm.dim().wid = max(pm.dim().wid, row.width());
+               pm.dim().wid = max(pm.dim().wid, row.width() + row.right_margin);
                pm.dim().des += row.height();
        } while (first < par.size() || need_new_row);
 
@@ -536,7 +537,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
 
 LyXAlignment TextMetrics::getAlign(Paragraph const & par, Row const & row) const
 {
-       LyXAlignment align = par.getAlign();
+       LyXAlignment align = par.getAlign(bv_->buffer().params());
 
        // handle alignment inside tabular cells
        Inset const & owner = text_->inset();
@@ -836,6 +837,7 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
        row.clear();
        row.left_margin = leftMargin(row.pit(), pos);
        row.right_margin = right_margin;
+       row.needsChangeBar(false);
        if (is_rtl)
                swap(row.left_margin, row.right_margin);
        // Remember that the row width takes into account the left_margin
@@ -1747,7 +1749,7 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
        if (!par.params().leftIndent().zero())
                l_margin += par.params().leftIndent().inPixels(max_width_, lfm.em());
 
-       LyXAlignment align = par.getAlign();
+       LyXAlignment align = par.getAlign(bv_->buffer().params());
 
        // set the correct parindent
        if (pos == 0
@@ -1917,15 +1919,15 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                        LYXERR(Debug::PAINTING, "Clear rect@("
                               << max(row_x, 0) << ", " << y - row.ascent() << ")="
                               << width() << " x " << row.height());
-                       // FIXME: this is a hack. We know that at least this
-                       // amount of pixels can be cleared on right and left.
-                       // Doing so gets rid of caret ghosts when the cursor is at
-                       // the begining/end of row. However, it will not work if
-                       // the caret has a ridiculous width like 6. (see ticket
-                       // #10797)
-                       pi.pain.fillRectangle(max(row_x, 0) - Inset::TEXT_TO_INSET_OFFSET,
-                                             y - row.ascent(),
-                                             width() + 2 * Inset::TEXT_TO_INSET_OFFSET,
+                       // FIXME: this is a hack. We clear an amount equal to
+                       // cursor width. This will not work if the caret has a
+                       // ridiculous width like 6. (see ticket #10797)
+                       // This is the same formula as in GuiWorkArea.
+                       int const caret_width = lyxrc.cursor_width
+                               ? lyxrc.cursor_width
+                               : 1 + int((lyxrc.currentZoom + 50) / 200.0);
+                       pi.pain.fillRectangle(max(row_x, 0), y - row.ascent(),
+                                             width() + caret_width,
                                              row.height(), pi.background_color);
                }