2 * \file InsetMathCancelto.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathCancelto.h"
16 #include "LaTeXFeatures.h"
18 #include "MathStream.h"
20 #include "frontends/Painter.h"
29 InsetMathCancelto::InsetMathCancelto(Buffer * buf)
30 : InsetMathNest(buf, 2)
34 Inset * InsetMathCancelto::clone() const
36 return new InsetMathCancelto(*this);
40 void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
42 InsetMathNest::metrics(mi);
43 Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
44 Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
45 dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8;
46 dim.des = max(dim0.descent() - 2, dim1.descent()) + 2;
47 dim.wid = dim0.width() + dim1.width() + 10;
52 void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
54 ColorCode const origcol = pi.base.font.color();
56 // We first draw the text and then an arrow
57 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
58 cell(0).draw(pi, x + 1, y);
59 cell(1).draw(pi, x + dim0.wid + 2 + 8, y - dim0.asc - 8);
61 //Dimension const dim = dimension(*pi.base.bv);
73 int const x2 = x + dim0.wid;
74 int const x3 = x2 + 8;
76 int const y1 = y + dim0.des;
77 int const y2 = y - dim0.asc;
78 int const y3 = y2 - 8;
81 pi.pain.line(x3, y3, x1, y1, origcol);
83 pi.pain.line(x3, y3, x2 + 2, y3, origcol);
84 pi.pain.line(x3, y3, x3 - 2, y2 - 2, origcol);
86 drawMarkers(pi, x, y);
90 void InsetMathCancelto::write(WriteStream & os) const
92 MathEnsurer ensurer(os);
93 os << "\\cancelto{" << cell(1) << "}{" << cell(0) << '}';
97 void InsetMathCancelto::normalize(NormalStream & os) const
99 os << "[cancelto " << cell(1) << ' ' << cell(0) << ']';
102 bool InsetMathCancelto::idxUpDown(Cursor & cur, bool up) const
104 Cursor::idx_type const target = up ? 1 : 0;
105 if (cur.idx() == target)
108 cur.pos() = up ? cur.lastpos() : 0;
112 void InsetMathCancelto::infoize(odocstream & os) const
117 void InsetMathCancelto::validate(LaTeXFeatures & features) const
119 InsetMathNest::validate(features);
120 if (features.runparams().isLaTeX())
121 features.require("cancel");
122 InsetMathNest::validate(features);