]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetLine.cpp
Fix InsetLine metrics and drawing.
[lyx.git] / src / insets / InsetLine.cpp
index dcec5c7530eb290aab92a0b45170d47745af6a1d..fa3395bac42d09d190e1e7c2070c08eccd973e85 100644 (file)
@@ -14,6 +14,8 @@
 #include "InsetLine.h"
 
 #include "Buffer.h"
+#include "BufferView.h"
+#include "CoordCache.h"
 #include "Dimension.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
@@ -33,8 +35,6 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-#include <cstdlib>
-
 using namespace std;
 
 namespace lyx {
@@ -109,10 +109,9 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = fm.maxAscent();
        dim.des = fm.maxDescent();
 
-       Length width = Length(to_ascii(getParam("width")));
-       int w =
-               width.inPixels(mi.base.textwidth,
-               fm.width(char_type('M')));
+       Length const width(to_ascii(getParam("width")));
+       int w = width.inPixels(mi.base.textwidth,
+                              fm.width(char_type('M')));
 
        // assure that the line inset is not outside of the window
        // check that it doesn't exceed the outer boundary
@@ -120,7 +119,7 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
                w = mi.base.textwidth;
 
        // set a minimal width
-       int const minw = (w < 0) ? 3 * 8 : 4;
+       int const minw = (w < 0) ? 24 : 4;
        dim.wid = max(minw, max(w, -w));
 
        // Cache the inset dimension
@@ -130,22 +129,22 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetLine::draw(PainterInfo & pi, int x, int y) const
 {
-       Dimension const dim = dimension(*pi.base.bv);
+       // We cannot use InsetCommand::dimension() as this returns the dimension
+       // of the button, which is not used here!
+       Dimension const dim = pi.base.bv->coordCache().getInsets().dim(this);
+       int const max_width = dim.width();
 
        frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
 
        // get the length of the parameters in pixels
        Length offset = Length(to_ascii(getParam("offset")));
-       int o =
-               offset.inPixels(pi.base.textwidth,
-               fm.width(char_type('M')));
-       Length width = Length(to_ascii(getParam("width")));
-       int w =
-               width.inPixels(pi.base.textwidth,
+       int o = offset.inPixels(max_width,
+                               fm.width(char_type('M')));
+       Length const width(to_ascii(getParam("width")));
+       int w = width.inPixels(max_width,
                fm.width(char_type('M')));
        Length height = Length(to_ascii(getParam("height")));
-       int h =
-               height.inPixels(pi.base.textwidth,
+       int h = height.inPixels(max_width,
                fm.width(char_type('M')));
 
        // get the surrounding text color
@@ -154,14 +153,14 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const
 
        // assure that the drawn line is not outside of the window
        // check that it doesn't exceed the outer boundary
-       if (x + w - h/2 - 2 > pi.base.textwidth)
-               w = pi.base.textwidth - x + h/2 + 2;
+       if (w > max_width)
+               w = max_width;
        // check that it doesn't exceed the upper boundary
        if (y - o - h/2 < 0)
                o = y - h/2 - 2;
 
        // the offset is a vertical one
-       pi.pain.line(x + h/2 + 1, y - o - h/2, x + w - h/2 - 2, y - o - h/2,
+       pi.pain.line(x, y - o - h/2, x + w, y - o - h/2,
                Line_color, Painter::line_solid, float(h));
 }