]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathPhantom.C
rename mathed/math_xinset into mathed/InsetMathX
[lyx.git] / src / mathed / InsetMathPhantom.C
1 /**
2  * \file InsetMathPhantom.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Georg Baum
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathPhantom.h"
14 #include "MathMLStream.h"
15 #include "MathStream.h"
16
17 #include "LColor.h"
18
19 #include "frontends/Painter.h"
20
21 #include "support/std_ostream.h"
22
23
24 InsetMathPhantom::InsetMathPhantom(Kind k)
25         : InsetMathNest(1), kind_(k)
26 {}
27
28
29 std::auto_ptr<InsetBase> InsetMathPhantom::doClone() const
30 {
31         return std::auto_ptr<InsetBase>(new InsetMathPhantom(*this));
32 }
33
34
35 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
36 {
37         cell(0).metrics(mi, dim);
38         metricsMarkers(dim);
39         dim_ = dim;
40 }
41
42
43 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
44 {
45         static int const arrow_size = 4;
46
47         // We first draw the text and then an arrow
48         LColor_color const origcol = pi.base.font.color();
49         pi.base.font.setColor(LColor::special);
50         cell(0).draw(pi, x + 1, y);
51         pi.base.font.setColor(origcol);
52
53         if (kind_ == phantom || kind_ == vphantom) {
54                 // y1---------
55                 //           / \.
56                 // y2-----  / | \.
57                 //            |
58                 //            |
59                 // y3-----  \ | /
60                 //           \ /
61                 // y4---------
62                 //          | | |
63                 //         /  |  \.
64                 //        x1  x2 x3
65
66                 int const x2 = x + dim_.wid / 2;
67                 int const x1 = x2 - arrow_size;
68                 int const x3 = x2 + arrow_size;
69
70                 int const y1 = y - dim_.asc;
71                 int const y2 = y1 + arrow_size;
72                 int const y4 = y + dim_.des;
73                 int const y3 = y4 - arrow_size;
74
75                 // top arrow
76                 pi.pain.line(x2, y1, x1, y2, LColor::added_space);
77                 pi.pain.line(x2, y1, x3, y2, LColor::added_space);
78
79                 // bottom arrow
80                 pi.pain.line(x2, y4, x1, y3, LColor::added_space);
81                 pi.pain.line(x2, y4, x3, y3, LColor::added_space);
82
83                 // joining line
84                 pi.pain.line(x2, y1, x2, y4, LColor::added_space);
85         }
86
87         if (kind_ == phantom || kind_ == hphantom) {
88                 // y1----   /          \.
89                 //        /              \.
90                 // y2--- <---------------->
91                 //        \              /
92                 // y3----   \          /
93                 //       |   |        |   |
94                 //      x1  x2       x3  x4
95
96                 int const x1 = x;
97                 int const x2 = x + arrow_size;
98                 int const x4 = x + dim_.wid;
99                 int const x3 = x4 - arrow_size;
100
101                 int const y2 = y + (dim_.des - dim_.asc) / 2;
102                 int const y1 = y2 - arrow_size;
103                 int const y3 = y2 + arrow_size;
104
105                 // left arrow
106                 pi.pain.line(x1, y2, x2, y3, LColor::added_space);
107                 pi.pain.line(x1, y2, x2, y1, LColor::added_space);
108
109                 // right arrow
110                 pi.pain.line(x4, y2, x3, y3, LColor::added_space);
111                 pi.pain.line(x4, y2, x3, y1, LColor::added_space);
112
113                 // joining line
114                 pi.pain.line(x1, y2, x4, y2, LColor::added_space);
115         }
116
117         drawMarkers(pi, x, y);
118 }
119
120
121 void InsetMathPhantom::write(WriteStream & os) const
122 {
123         switch (kind_) {
124         case phantom:
125                 os << "\\phantom{";
126                 break;
127         case vphantom:
128                 os << "\\vphantom{";
129                 break;
130         case hphantom:
131                 os << "\\hphantom{";
132                 break;
133         }
134         os << cell(0) << '}';
135 }
136
137
138 void InsetMathPhantom::normalize(NormalStream & os) const
139 {
140         switch (kind_) {
141         case phantom:
142                 os << "[phantom ";
143                 break;
144         case vphantom:
145                 os << "[vphantom ";
146                 break;
147         case hphantom:
148                 os << "[hphantom ";
149                 break;
150         }
151         os << cell(0) << ']';
152 }
153
154
155 void InsetMathPhantom::infoize(std::ostream & os) const
156 {
157         switch (kind_) {
158         case phantom:
159                 os << "Phantom";
160                 break;
161         case vphantom:
162                 os << "Vphantom";
163                 break;
164         case hphantom:
165                 os << "Hphantom";
166                 break;
167         }
168 }