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