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