]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCancelto.cpp
RefChanger
[lyx.git] / src / mathed / InsetMathCancelto.cpp
1 /**
2  * \file InsetMathCancelto.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Uwe Stöhr
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathCancelto.h"
14
15 #include "Cursor.h"
16 #include "LaTeXFeatures.h"
17 #include "MathData.h"
18 #include "MathStream.h"
19
20 #include "frontends/Painter.h"
21
22 #include <ostream>
23
24 using namespace std;
25
26 namespace lyx {
27
28
29 InsetMathCancelto::InsetMathCancelto(Buffer * buf)
30         : InsetMathNest(buf, 2)
31 {}
32
33
34 Inset * InsetMathCancelto::clone() const
35 {
36         return new InsetMathCancelto(*this);
37 }
38
39
40 void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
41 {
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;
48         metricsMarkers(dim);
49 }
50
51
52 void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
53 {
54         ColorCode const origcol = pi.base.font.color();
55
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);
60                 
61         //Dimension const dim = dimension(*pi.base.bv);
62         
63         // y3____ ___
64         //          /|
65         // y2_     / |
66         //        /
67         //       /
68         //      /
69         //     /
70         // y1 /    | |
71         //    x1  x2 x3
72
73         int const x2 = x + dim0.wid;
74         int const x3 = x2 + 8;
75         int const x1 = x;
76         int const y1 = y + dim0.des;
77         int const y2 = y - dim0.asc;
78         int const y3 = y2 - 8;
79
80         // the main line
81         pi.pain.line(x3, y3, x1, y1, origcol);
82         // the arrow bars
83         pi.pain.line(x3, y3, x2 + 2, y3, origcol);
84         pi.pain.line(x3, y3, x3 - 2, y2 - 2, origcol);
85
86         drawMarkers(pi, x, y);
87 }
88
89
90 void InsetMathCancelto::write(WriteStream & os) const
91 {
92         MathEnsurer ensurer(os);
93         os << "\\cancelto{" << cell(1) << "}{" << cell(0) << '}';
94 }
95
96
97 void InsetMathCancelto::normalize(NormalStream & os) const
98 {
99         os << "[cancelto " << cell(1) << ' ' << cell(0) << ']';
100 }
101
102 bool InsetMathCancelto::idxUpDown(Cursor & cur, bool up) const
103 {
104         Cursor::idx_type const target = up ? 1 : 0;
105         if (cur.idx() == target)
106                 return false;
107         cur.idx() = target;
108         cur.pos() = up ? cur.lastpos() : 0;
109         return true;
110 }
111
112 void InsetMathCancelto::infoize(odocstream & os) const
113 {
114         os << "Cancelto";
115 }
116
117 void InsetMathCancelto::validate(LaTeXFeatures & features) const
118 {
119         InsetMathNest::validate(features);
120         if (features.runparams().isLaTeX())
121                 features.require("cancel");
122         InsetMathNest::validate(features);
123 }
124
125
126 } // namespace lyx