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