]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetvspace.C
The speed patch: redraw only rows that have changed
[lyx.git] / src / insets / insetvspace.C
index c6596972fa2e4d9d0f2df6470e75a931e18fe2e4..e089fc94e4408910ada3043eb9c0d95765b16a74 100644 (file)
@@ -74,7 +74,7 @@ void InsetVSpace::doDispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               InsetOld::doDispatch(cur, cmd);
+               InsetBase::doDispatch(cur, cmd);
                break;
        }
 }
@@ -102,57 +102,63 @@ void InsetVSpace::write(Buffer const &, ostream & os) const
 }
 
 
+string const InsetVSpace::label() const
+{
+       static string const label = _("Vertical Space");
+       return label + " (" + space_.asGUIName() + ')';
+}
+
+
+namespace {
+int const arrow_size = 4;
+}
+
+
 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       int size = 10;
-       int const arrow_size = 4;
-       int const space_size = space_.inPixels(*mi.base.bv);
+       int height = 3 * arrow_size;
+       if (space_.length().len().value() >= 0.0)
+               height = max(height, space_.inPixels(*mi.base.bv));
 
        LyXFont font;
        font.decSize();
-       int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+       font.decSize();
 
-       if (space_.length().len().value() < 0.0)
-               size = min_size;
-       else
-               size = max(min_size, space_size);
+       int w = 0;
+       int a = 0;
+       int d = 0;
+       font_metrics::rectText(label(), font, w, a, d);
 
-       dim.asc = size / 2;
-       dim.des = size / 2;
-       dim.wid = 10 + 2 * ADD_TO_VSPACE_WIDTH;
+       height = max(height, a + d);
 
+       dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+       dim.des = height - dim.asc;         // label text
+       dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
        dim_ = dim;
 }
 
 
 void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
 {
-       static std::string const label = _("Vertical Space");
-
        setPosCache(pi, x, y);
 
        x += ADD_TO_VSPACE_WIDTH;
 
-       int const arrow_size = 4;
        int const start = y - dim_.asc;
        int const end   = y + dim_.des;
 
-       // the label to display (if any)
-       string str;
        // y-values for top arrow
        int ty1, ty2;
        // y-values for bottom arrow
        int by1, by2;
 
-       str = label + " (" + space_.asLyXCommand() + ")";
-
        if (space_.kind() == VSpace::VFILL) {
                ty1 = ty2 = start;
                by1 = by2 = end;
        } else {
                // adding or removing space
                bool const added = space_.kind() != VSpace::LENGTH ||
-                                  space_.length().len().value() > 0.0;
+                                  space_.length().len().value() >= 0.0;
                ty1 = added ? (start + arrow_size) : start;
                ty2 = added ? start : (start + arrow_size);
                by1 = added ? (end - arrow_size) : end;
@@ -171,10 +177,11 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
        font.setColor(LColor::added_space);
        font.decSize();
        font.decSize();
-       font_metrics::rectText(str, font, w, a, d);
+       font_metrics::rectText(label(), font, w, a, d);
 
-       pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
-                      str, font, LColor::none, LColor::none);
+       pi.pain.rectText(x + 2 * arrow_size + 5, 
+                        start + (end - start) / 2 + (a - d) / 2,
+                        label(), font, LColor::none, LColor::none);
 
        // top arrow
        pi.pain.line(x, ty1, midx, ty2, LColor::added_space);