]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathPhantom.cpp
0000175ad0e43f3acaf350834954aa1da343fbf4
[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
21 namespace lyx {
22
23
24 InsetMathPhantom::InsetMathPhantom(Kind k)
25         : InsetMathNest(1), kind_(k)
26 {}
27
28
29 Inset * InsetMathPhantom::clone() const
30 {
31         return 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         // Cache the inset dimension. 
40         setDimCache(mi, dim);
41 }
42
43
44 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
45 {
46         static int const arrow_size = 4;
47
48         // We first draw the text and then an arrow
49         ColorCode const origcol = pi.base.font.color();
50         pi.base.font.setColor(Color_special);
51         cell(0).draw(pi, x + 1, y);
52         pi.base.font.setColor(origcol);
53         Dimension const dim = dimension(*pi.base.bv);
54
55         if (kind_ == phantom || kind_ == vphantom) {
56                 // y1---------
57                 //           / \.
58                 // y2-----  / | \.
59                 //            |
60                 //            |
61                 // y3-----  \ | /
62                 //           \ /
63                 // y4---------
64                 //          | | |
65                 //         /  |  \.
66                 //        x1  x2 x3
67
68                 int const x2 = x + dim.wid / 2;
69                 int const x1 = x2 - arrow_size;
70                 int const x3 = x2 + arrow_size;
71
72                 int const y1 = y - dim.asc;
73                 int const y2 = y1 + arrow_size;
74                 int const y4 = y + dim.des;
75                 int const y3 = y4 - arrow_size;
76
77                 // top arrow
78                 pi.pain.line(x2, y1, x1, y2, Color_added_space);
79                 pi.pain.line(x2, y1, x3, y2, Color_added_space);
80
81                 // bottom arrow
82                 pi.pain.line(x2, y4, x1, y3, Color_added_space);
83                 pi.pain.line(x2, y4, x3, y3, Color_added_space);
84
85                 // joining line
86                 pi.pain.line(x2, y1, x2, y4, Color_added_space);
87         }
88
89         if (kind_ == phantom || kind_ == hphantom) {
90                 // y1----   /          \.
91                 //        /              \.
92                 // y2--- <---------------->
93                 //        \              /
94                 // y3----   \          /
95                 //       |   |        |   |
96                 //      x1  x2       x3  x4
97
98                 int const x1 = x;
99                 int const x2 = x + arrow_size;
100                 int const x4 = x + dim.wid;
101                 int const x3 = x4 - arrow_size;
102
103                 int const y2 = y + (dim.des - dim.asc) / 2;
104                 int const y1 = y2 - arrow_size;
105                 int const y3 = y2 + arrow_size;
106
107                 // left arrow
108                 pi.pain.line(x1, y2, x2, y3, Color_added_space);
109                 pi.pain.line(x1, y2, x2, y1, Color_added_space);
110
111                 // right arrow
112                 pi.pain.line(x4, y2, x3, y3, Color_added_space);
113                 pi.pain.line(x4, y2, x3, y1, Color_added_space);
114
115                 // joining line
116                 pi.pain.line(x1, y2, x4, y2, Color_added_space);
117         }
118
119         drawMarkers(pi, x, y);
120 }
121
122
123 void InsetMathPhantom::write(WriteStream & os) const
124 {
125         switch (kind_) {
126         case phantom:
127                 os << "\\phantom{";
128                 break;
129         case vphantom:
130                 os << "\\vphantom{";
131                 break;
132         case hphantom:
133                 os << "\\hphantom{";
134                 break;
135         }
136         os << cell(0) << '}';
137 }
138
139
140 void InsetMathPhantom::normalize(NormalStream & os) const
141 {
142         switch (kind_) {
143         case phantom:
144                 os << "[phantom ";
145                 break;
146         case vphantom:
147                 os << "[vphantom ";
148                 break;
149         case hphantom:
150                 os << "[hphantom ";
151                 break;
152         }
153         os << cell(0) << ']';
154 }
155
156
157 void InsetMathPhantom::infoize(odocstream & os) const
158 {
159         switch (kind_) {
160         case phantom:
161                 os << "Phantom";
162                 break;
163         case vphantom:
164                 os << "Vphantom";
165                 break;
166         case hphantom:
167                 os << "Hphantom";
168                 break;
169         }
170 }
171
172
173 } // namespace lyx