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