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"
16 MathXYArrowInset::MathXYArrowInset()
21 MathInset * MathXYArrowInset::clone() const
23 return new MathXYArrowInset(*this);
27 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
29 return mi_.inset ? mi_.inset->asXYMatrixInset() : 0;
33 MathXArray const & MathXYArrowInset::targetCell() const
35 MathXYMatrixInset const * p = targetMatrix();
38 MathArray const & t = cell(0);
39 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
40 switch ((*it)->getChar()) {
47 //lyxerr << "target: x: " << x << " y: " << y << "\n";
48 int n = mi_.idx + p->ncols() * y + x;
49 if (n < 0 || n >= int(p->nargs())) {
50 lyxerr << "source: n: " << mi_.idx << "\n";
51 lyxerr << "target: n: " << n << " out of range\n";
58 MathXArray const & MathXYArrowInset::sourceCell() const
60 return targetMatrix()->xcell(mi_.idx);
64 void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
67 MathNestInset::metrics(mi);
70 int w = mathed_string_width(LM_TC_TEXTRM, mi_, "target: ");
71 width_ = w + std::max(xcell(0).width(), xcell(1).width());
72 ascent_ = xcell(0).ascent();
73 descent_ = xcell(0).descent() + xcell(1).height() + 10;
78 //mathed_string_dim(LM_TC_TEXTRM, mi_, "X", ascent_, descent_, width_);
83 void MathXYArrowInset::draw(Painter & pain, int x, int y) const
92 mathed_string_dim(LM_TC_TEXTRM, mi_, "target: ", lasc, ldes, lwid);
94 xcell(0).draw(pain, x + lwid, y);
95 drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "target");
96 y += std::max(xcell(0).descent(), ldes) + 5;
98 y += std::max(xcell(1).ascent(), lasc) + 5;
99 xcell(1).draw(pain, x + lwid, y);
100 drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "label");
104 //drawStr(pain, LM_TC_TEXTRM, mi_, x, y, "X");
105 MathXArray const & s = sourceCell();
106 MathXArray const & t = targetCell();
107 pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
108 xcell(1).draw(pain, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
114 void MathXYArrowInset::write(WriteStream & os) const
118 os << "[" << cell(0) << "]";
120 os << (up_ ? "^" : "_") << "{" << cell(1) << "}";
125 void MathXYArrowInset::normalize(NormalStream & os) const
128 MathNestInset::normalize(os);