]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXYArrow.C
fix reading UTF8 encoded symbol file
[lyx.git] / src / mathed / InsetMathXYArrow.C
1 /**
2  * \file InsetMathXYArrow.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathXYArrow.h"
14 #include "MathMLStream.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "frontends/Painter.h"
18 #include "debug.h"
19
20
21 namespace lyx {
22
23
24 using std::max;
25
26
27 InsetMathXYArrow::InsetMathXYArrow()
28         : InsetMathNest(2)
29 {}
30
31
32 std::auto_ptr<InsetBase> InsetMathXYArrow::clone() const
33 {
34         return std::auto_ptr<InsetBase>(new InsetMathXYArrow(*this));
35 }
36
37
38 InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
39 {
40         return target_;
41 }
42
43
44 MathArray const & InsetMathXYArrow::targetCell() const
45 {
46 #if 0
47         InsetMathXYMatrix const * p = targetMatrix();
48         int x = 0;
49         int y = 0;
50         MathArray const & t = cell(0);
51         for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
52                 switch ((*it)->getChar()) {
53                         case 'l': --x; break;
54                         case 'r': ++x; break;
55                         case 'u': --y; break;
56                         case 'd': ++y; break;
57                 }
58         }
59         //lyxerr << "target: x: " << x << " y: " << y << endl;
60         InsetMath::idx_type n = mi_.idx + p->ncols() * y + x;
61         if (n >= p->nargs()) {
62                 lyxerr << "source: n: " << mi_.idx << "\n"
63                        << "target: n: " << n << " out of range" << endl;
64                 n = 0;
65         }
66         return p->cell(n);
67 #else
68         static MathArray dummy;
69         return dummy;
70 #endif
71 }
72
73
74 MathArray const & InsetMathXYArrow::sourceCell() const
75 {
76 #if 0
77         return targetMatrix()->cell(mi_.idx);
78 #else
79         static MathArray dummy;
80         return dummy;
81 #endif
82 }
83
84
85 void InsetMathXYArrow::metrics(MetricsInfo & mi) const
86 {
87         InsetMathNest::metrics(mi);
88         mi_   = mi;
89         FontSetChanger dummy(mi.base, "textrm");
90 #if 0
91         target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
92
93         if (editing()) {
94                 int w    = mathed_string_width(mi.base.font, from_ascii("target: "));
95                 width_   = w + max(cell(0).width(), cell(1).width());
96                 ascent_  = cell(0).ascent();
97                 descent_ = cell(0).descent() + cell(1).height() + 10;
98         } else {
99                 width_   = 0;
100                 ascent_  = 0;
101                 descent_ = 0;
102                 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
103         }
104 #endif
105 }
106
107
108 void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
109 {
110         metrics(mi_);
111         FontSetChanger dummy(pi.base, "textrm");
112
113         if (editing()) {
114
115 #if 0
116
117                 int lasc;
118                 int ldes;
119                 int lwid;
120                 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
121
122                 cell(0).draw(pi, x + lwid, y);
123                 pi.base.text(x + 3, y, "target");
124                 y += max(cell(0).descent(), ldes) + 5;
125
126                 y += max(cell(1).ascent(), lasc) + 5;
127                 cell(1).draw(pi, x + lwid, y);
128                 pi.base.text(x + 3, y, "label");
129
130 #endif
131
132         } else {
133
134                 pi.pain.text(x, y, "X");
135                 MathArray const & s = sourceCell();
136                 MathArray const & t = targetCell();
137                 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
138                 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
139
140         }
141 }
142
143
144 void InsetMathXYArrow::write(WriteStream & os) const
145 {
146         os << "\\ar";
147         if (cell(0).size())
148                 os << '[' << cell(0) << ']';
149         if (cell(1).size())
150                 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
151         os << " ";
152 }
153
154
155 void InsetMathXYArrow::normalize(NormalStream & os) const
156 {
157         os << "[xyarrow ";
158         InsetMathNest::normalize(os);
159         os << ']';
160 }
161
162
163 } // namespace lyx