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"
19 MathXYArrowInset::MathXYArrowInset()
24 MathInset * MathXYArrowInset::clone() const
26 return new MathXYArrowInset(*this);
30 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
36 MathXArray const & MathXYArrowInset::targetCell() const
38 MathXYMatrixInset const * p = targetMatrix();
41 MathArray const & t = cell(0);
42 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
43 switch ((*it)->getChar()) {
50 //lyxerr << "target: x: " << x << " y: " << y << "\n";
51 int n = mi_.idx + p->ncols() * y + x;
52 if (n < 0 || n >= int(p->nargs())) {
53 lyxerr << "source: n: " << mi_.idx << "\n";
54 lyxerr << "target: n: " << n << " out of range\n";
61 MathXArray const & MathXYArrowInset::sourceCell() const
63 return targetMatrix()->xcell(mi_.idx);
67 void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
69 MathNestInset::metrics(mi);
71 whichFont(font_, LM_TC_TEXTRM, mi);
72 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
75 int w = mathed_string_width(font_, "target: ");
76 width_ = w + max(xcell(0).width(), xcell(1).width());
77 ascent_ = xcell(0).ascent();
78 descent_ = xcell(0).descent() + xcell(1).height() + 10;
83 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
88 void MathXYArrowInset::draw(Painter & pain, int x, int y) const
97 mathed_string_dim(font_, "target: ", lasc, ldes, lwid);
99 xcell(0).draw(pain, x + lwid, y);
100 drawStr(pain, font_, x + 3, y, "target");
101 y += max(xcell(0).descent(), ldes) + 5;
103 y += max(xcell(1).ascent(), lasc) + 5;
104 xcell(1).draw(pain, x + lwid, y);
105 drawStr(pain, font_, x + 3, y, "label");
109 //drawStr(pain, font_, x, y, "X");
110 MathXArray const & s = sourceCell();
111 MathXArray const & t = targetCell();
112 pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
113 xcell(1).draw(pain, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
119 void MathXYArrowInset::write(WriteStream & os) const
123 os << "[" << cell(0) << "]";
125 os << (up_ ? "^" : "_") << "{" << cell(1) << "}";
130 void MathXYArrowInset::normalize(NormalStream & os) const
133 MathNestInset::normalize(os);