]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathPhantom.cpp
f070e5505350041ab7e5b6681593a0616cc148fa
[lyx.git] / src / mathed / InsetMathPhantom.cpp
1 /**
2  * \file InsetMathPhantom.cpp
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
15 #include "MathStream.h"
16 #include "frontends/Painter.h"
17
18 #include <ostream>
19
20 namespace lyx {
21
22
23 InsetMathPhantom::InsetMathPhantom(Kind k)
24         : InsetMathNest(1), kind_(k)
25 {}
26
27
28 Inset * InsetMathPhantom::clone() const
29 {
30         return new InsetMathPhantom(*this);
31 }
32
33
34 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         cell(0).metrics(mi, dim);
37         metricsMarkers(dim);
38 }
39
40
41 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
42 {
43         static int const arrow_size = 4;
44
45         // We first draw the text and then an arrow
46         ColorCode const origcol = pi.base.font.color();
47         pi.base.font.setColor(Color_special);
48         cell(0).draw(pi, x + 1, y);
49         pi.base.font.setColor(origcol);
50         Dimension const dim = dimension(*pi.base.bv);
51
52         if (kind_ == phantom || kind_ == vphantom) {
53                 // y1---------
54                 //           / \.
55                 // y2-----  / | \.
56                 //            |
57                 //            |
58                 // y3-----  \ | /
59                 //           \ /
60                 // y4---------
61                 //          | | |
62                 //         /  |  \.
63                 //        x1  x2 x3
64
65                 int const x2 = x + dim.wid / 2;
66                 int const x1 = x2 - arrow_size;
67                 int const x3 = x2 + arrow_size;
68
69                 int const y1 = y - dim.asc;
70                 int const y2 = y1 + arrow_size;
71                 int const y4 = y + dim.des;
72                 int const y3 = y4 - arrow_size;
73
74                 // top arrow
75                 pi.pain.line(x2, y1, x1, y2, Color_added_space);
76                 pi.pain.line(x2, y1, x3, y2, Color_added_space);
77
78                 // bottom arrow
79                 pi.pain.line(x2, y4, x1, y3, Color_added_space);
80                 pi.pain.line(x2, y4, x3, y3, Color_added_space);
81
82                 // joining line
83                 pi.pain.line(x2, y1, x2, y4, Color_added_space);
84         }
85
86         if (kind_ == phantom || kind_ == hphantom) {
87                 // y1----   /          \.
88                 //        /              \.
89                 // y2--- <---------------->
90                 //        \              /
91                 // y3----   \          /
92                 //       |   |        |   |
93                 //      x1  x2       x3  x4
94
95                 int const x1 = x;
96                 int const x2 = x + arrow_size;
97                 int const x4 = x + dim.wid;
98                 int const x3 = x4 - arrow_size;
99
100                 int const y2 = y + (dim.des - dim.asc) / 2;
101                 int const y1 = y2 - arrow_size;
102                 int const y3 = y2 + arrow_size;
103
104                 // left arrow
105                 pi.pain.line(x1, y2, x2, y3, Color_added_space);
106                 pi.pain.line(x1, y2, x2, y1, Color_added_space);
107
108                 // right arrow
109                 pi.pain.line(x4, y2, x3, y3, Color_added_space);
110                 pi.pain.line(x4, y2, x3, y1, Color_added_space);
111
112                 // joining line
113                 pi.pain.line(x1, y2, x4, y2, Color_added_space);
114         }
115
116         drawMarkers(pi, x, y);
117 }
118
119
120 void InsetMathPhantom::write(WriteStream & os) const
121 {
122         MathEnsurer ensurer(os);
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(odocstream & 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 }
169
170
171 } // namespace lyx