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