7 #include "math_xyarrowinset.h"
8 #include "math_xymatrixinset.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "math_cursor.h"
12 #include "math_support.h"
17 MathXYArrowInset::MathXYArrowInset()
22 MathInset * MathXYArrowInset::clone() const
24 return new MathXYArrowInset(*this);
28 bool MathXYArrowInset::editing() const
30 return mathcursor && mathcursor->isInside(this);
34 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
36 return mi_.inset ? mi_.inset->asXYMatrixInset() : 0;
40 MathXArray const & MathXYArrowInset::targetCell() const
42 MathXYMatrixInset const * p = targetMatrix();
45 MathArray const & t = cell(0);
46 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
47 switch ((*it)->getChar()) {
54 //lyxerr << "target: x: " << x << " y: " << y << "\n";
55 int n = mi_.idx + p->ncols() * y + x;
56 if (n < 0 || n >= int(p->nargs())) {
57 lyxerr << "source: n: " << mi_.idx << "\n";
58 lyxerr << "target: n: " << n << " out of range\n";
65 MathXArray const & MathXYArrowInset::sourceCell() const
67 return targetMatrix()->xcell(mi_.idx);
71 void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
74 MathNestInset::metrics(mi);
77 int w = mathed_string_width(LM_TC_TEXTRM, mi_, "target: ");
78 width_ = w + std::max(xcell(0).width(), xcell(1).width());
79 ascent_ = xcell(0).ascent();
80 descent_ = xcell(0).descent() + xcell(1).height() + 10;
85 //mathed_string_dim(LM_TC_TEXTRM, mi_, "X", ascent_, descent_, width_);
90 void MathXYArrowInset::draw(Painter & pain, int x, int y) const
99 mathed_string_dim(LM_TC_TEXTRM, mi_, "target: ", lasc, ldes, lwid);
101 xcell(0).draw(pain, x + lwid, y);
102 drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "target");
103 y += std::max(xcell(0).descent(), ldes) + 5;
105 y += std::max(xcell(1).ascent(), lasc) + 5;
106 xcell(1).draw(pain, x + lwid, y);
107 drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "label");
111 //drawStr(pain, LM_TC_TEXTRM, mi_, x, y, "X");
112 MathXArray const & s = sourceCell();
113 MathXArray const & t = targetCell();
114 pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
115 xcell(1).draw(pain, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
121 void MathXYArrowInset::write(WriteStream & os) const
125 os << "[" << cell(0) << "]";
127 os << (up_ ? "^" : "_") << "{" << cell(1) << "}";
132 void MathXYArrowInset::normalize(NormalStream & os) const
135 MathNestInset::normalize(os);