]> git.lyx.org Git - lyx.git/blob - src/mathed/math_xyarrowinset.C
Jean-Marc's fix for wrong descent
[lyx.git] / src / mathed / math_xyarrowinset.C
1 #include <config.h>
2
3
4 #include "math_xyarrowinset.h"
5 #include "math_xymatrixinset.h"
6 #include "math_mathmlstream.h"
7 #include "math_streamstr.h"
8 #include "math_support.h"
9 #include "frontends/Painter.h"
10 #include "debug.h"
11
12
13 using std::max;
14
15
16 MathXYArrowInset::MathXYArrowInset()
17         : MathNestInset(2)
18 {}
19
20
21 MathInset * MathXYArrowInset::clone() const
22 {
23         return new MathXYArrowInset(*this);
24 }
25
26
27 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
28 {
29         return target_;
30 }
31
32
33 MathArray const & MathXYArrowInset::targetCell() const
34 {
35 #if 0
36         MathXYMatrixInset const * p = targetMatrix();
37         int x = 0;
38         int y = 0;
39         MathArray const & t = cell(0);
40         for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
41                 switch ((*it)->getChar()) {
42                         case 'l': --x; break;
43                         case 'r': ++x; break;
44                         case 'u': --y; break;
45                         case 'd': ++y; break;
46                 }
47         }
48         //lyxerr << "target: x: " << x << " y: " << y << "\n";
49         MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
50         if (n >= p->nargs()) {
51                 lyxerr << "source: n: " << mi_.idx << "\n";
52                 lyxerr << "target: n: " << n << " out of range\n";
53                 n = 0;
54         }
55   return p->cell(n);
56 #else
57         static MathArray dummy;
58         return dummy;
59 #endif
60 }
61
62
63 MathArray const & MathXYArrowInset::sourceCell() const
64 {
65 #if 0
66   return targetMatrix()->cell(mi_.idx);
67 #else
68         static MathArray dummy;
69         return dummy;
70 #endif
71 }
72
73
74 void MathXYArrowInset::metrics(MathMetricsInfo & mi) const
75 {
76         MathNestInset::metrics(mi);
77         mi_   = mi;
78         MathFontSetChanger dummy(mi.base, "textrm");
79 #if 0
80         target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
81
82         if (editing()) {
83                 int w    = mathed_string_width(mi.base.font, "target: ");
84                 width_   = w + max(cell(0).width(), cell(1).width());
85                 ascent_  = cell(0).ascent();
86                 descent_ = cell(0).descent() + cell(1).height() + 10;
87         } else {
88                 width_   = 0;
89                 ascent_  = 0;
90                 descent_ = 0;
91                 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
92         }
93 #endif
94 }
95
96
97 void MathXYArrowInset::draw(MathPainterInfo & pi, int x, int y) const
98 {
99         metrics(mi_);
100         MathFontSetChanger dummy(pi.base, "textrm");
101
102         if (editing()) {
103
104 #if 0
105
106                 int lasc;
107                 int ldes;
108                 int lwid;
109                 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
110
111                 cell(0).draw(pi, x + lwid, y);
112                 drawStr(pi, pi.base.font, x + 3, y, "target");
113                 y += max(cell(0).descent(), ldes) + 5;
114
115                 y += max(cell(1).ascent(), lasc) + 5;
116                 cell(1).draw(pi, x + lwid, y);
117                 drawStr(pi, pi.base.font, x + 3, y, "label");
118
119 #endif
120
121         } else {
122
123                 drawStr(pi, font_, x, y, "X");
124                 MathArray const & s = sourceCell();
125                 MathArray const & t = targetCell();
126                 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
127                 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
128
129         }
130 }
131
132
133 void MathXYArrowInset::write(WriteStream & os) const
134 {
135         os << "\\ar";
136         if (cell(0).size())
137                 os << '[' << cell(0) << ']';
138         if (cell(1).size())
139                 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
140         os << " ";
141 }
142
143
144 void MathXYArrowInset::normalize(NormalStream & os) const
145 {
146         os << "[xyarrow ";
147         MathNestInset::normalize(os);
148         os << ']';
149 }