7 #include "math_xyarrowinset.h"
8 #include "math_xymatrixinset.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "math_support.h"
12 #include "frontends/Painter.h"
19 MathXYArrowInset::MathXYArrowInset()
24 MathInset * MathXYArrowInset::clone() const
26 return new MathXYArrowInset(*this);
30 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
36 MathArray const & MathXYArrowInset::targetCell() const
39 MathXYMatrixInset const * p = targetMatrix();
42 MathArray const & t = cell(0);
43 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
44 switch ((*it)->getChar()) {
51 //lyxerr << "target: x: " << x << " y: " << y << "\n";
52 MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
53 if (n >= p->nargs()) {
54 lyxerr << "source: n: " << mi_.idx << "\n";
55 lyxerr << "target: n: " << n << " out of range\n";
60 static MathArray dummy;
66 MathArray const & MathXYArrowInset::sourceCell() const
69 return targetMatrix()->cell(mi_.idx);
71 static MathArray dummy;
77 void MathXYArrowInset::metrics(MathMetricsInfo & mi) const
79 MathNestInset::metrics(mi);
81 MathFontSetChanger dummy(mi.base, "textrm");
83 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
86 int w = mathed_string_width(mi.base.font, "target: ");
87 width_ = w + max(cell(0).width(), cell(1).width());
88 ascent_ = cell(0).ascent();
89 descent_ = cell(0).descent() + cell(1).height() + 10;
94 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
100 void MathXYArrowInset::draw(MathPainterInfo & pi, int x, int y) const
103 MathFontSetChanger dummy(pi.base, "textrm");
112 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
114 cell(0).draw(pi, x + lwid, y);
115 drawStr(pi, pi.base.font, x + 3, y, "target");
116 y += max(cell(0).descent(), ldes) + 5;
118 y += max(cell(1).ascent(), lasc) + 5;
119 cell(1).draw(pi, x + lwid, y);
120 drawStr(pi, pi.base.font, x + 3, y, "label");
126 drawStr(pi, font_, x, y, "X");
127 MathArray const & s = sourceCell();
128 MathArray const & t = targetCell();
129 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
130 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
136 void MathXYArrowInset::write(WriteStream & os) const
140 os << '[' << cell(0) << ']';
142 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
147 void MathXYArrowInset::normalize(NormalStream & os) const
150 MathNestInset::normalize(os);