]> git.lyx.org Git - lyx.git/blobdiff - src/rowpainter.cpp
Add empty InsetLayout for undefined cases. Should avoid possible bugs caused by empty...
[lyx.git] / src / rowpainter.cpp
index cd19b72389b3d7903cb01be77046c11e6ed2422c..9f20f65b7d3b278dfb2f80adcbcc12198b979ff8 100644 (file)
@@ -17,7 +17,6 @@
 #include "Buffer.h"
 #include "CoordCache.h"
 #include "Cursor.h"
-#include "support/debug.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Changes.h"
@@ -40,6 +39,7 @@
 
 #include "insets/InsetText.h"
 
+#include "support/debug.h"
 #include "support/textutils.h"
 
 #include <boost/crc.hpp>
@@ -96,6 +96,10 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos)
        Font const font = text_metrics_.getDisplayFont(pit_, pos);
 
        BOOST_ASSERT(inset);
+       // Backup full_repaint status because some insets (InsetTabular)
+       // requires a full repaint
+       bool pi_full_repaint = pi_.full_repaint;
+
        // FIXME: We should always use font, see documentation of
        // noFontChange() in Inset.h.
        pi_.base.font = inset->noFontChange() ?
@@ -114,6 +118,9 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos)
 
        x_ += dim.width();
 
+       // Restore full_repaint status.
+       pi_.full_repaint = pi_full_repaint;
+
 #ifdef DEBUG_METRICS
        int const x1 = int(x_ - dim.width());
        Dimension dim2;
@@ -603,10 +610,14 @@ void RowPainter::paintLast()
                FontMetrics const & fm = theFontMetrics(font);
                int const size = int(0.75 * fm.maxAscent());
                int const y = yo_ - size;
-               int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
+               int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET;
+               int x = is_rtl ? nestMargin() + changebarMargin()
+                       : max_row_width - text_metrics_.rightMargin(pm_);
 
-               if (width_ - int(row_.width()) <= size)
-                       x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
+               // If needed, move the box a bit to avoid overlapping with text.
+               int const rem = max_row_width - row_.width();
+               if (rem <= 0)
+                       x += is_rtl ? rem : - rem;
 
                if (endlabel == END_LABEL_BOX)
                        pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
@@ -636,15 +647,12 @@ void RowPainter::paintOnlyInsets()
 {
        pos_type const end = row_.endpos();
        for (pos_type pos = row_.pos(); pos != end; ++pos) {
-               if (!par_.isInset(pos))
-                       continue;
-
                // If outer row has changed, nested insets are repaint completely.
                Inset const * inset = par_.getInset(pos);
-
+               if (!inset)
+                       continue;
                if (x_ > pi_.base.bv->workWidth())
                        continue;
-
                x_ = pi_.base.bv->coordCache().getInsets().x(inset);
                paintInset(inset, pos);
        }
@@ -719,8 +727,9 @@ void RowPainter::paintText()
                        last_strikeout_x = int(x_);
                }
 
-               bool const highly_editable_inset = par_.isInset(pos)
-                       && par_.getInset(pos)->editable() == Inset::HIGHLY_EDITABLE;
+               Inset const * inset = par_.getInset(pos);
+               bool const highly_editable_inset = inset
+                       && inset->editable() == Inset::HIGHLY_EDITABLE;
 
                // If we reach the end of a struck out range, paint it.
                // We also don't paint across things like tables
@@ -750,9 +759,8 @@ void RowPainter::paintText()
                        paintForeignMark(orig_x, orig_font.language());
                        ++vpos;
 
-               } else if (par_.isInset(pos)) {
+               } else if (inset) {
                        // If outer row has changed, nested insets are repaint completely.
-                       Inset const * inset = par_.getInset(pos);
                        pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
                        paintInset(inset, pos);
                        ++vpos;