2 * \file InsetMathXYArrow.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathXYArrow.h"
14 #include "MathMLStream.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "frontends/Painter.h"
24 InsetMathXYArrow::InsetMathXYArrow()
29 std::auto_ptr<InsetBase> InsetMathXYArrow::clone() const
31 return std::auto_ptr<InsetBase>(new InsetMathXYArrow(*this));
35 InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
41 MathArray const & InsetMathXYArrow::targetCell() const
44 InsetMathXYMatrix const * p = targetMatrix();
47 MathArray const & t = cell(0);
48 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
49 switch ((*it)->getChar()) {
56 //lyxerr << "target: x: " << x << " y: " << y << endl;
57 InsetMath::idx_type n = mi_.idx + p->ncols() * y + x;
58 if (n >= p->nargs()) {
59 lyxerr << "source: n: " << mi_.idx << "\n"
60 << "target: n: " << n << " out of range" << endl;
65 static MathArray dummy;
71 MathArray const & InsetMathXYArrow::sourceCell() const
74 return targetMatrix()->cell(mi_.idx);
76 static MathArray dummy;
82 void InsetMathXYArrow::metrics(MetricsInfo & mi) const
84 InsetMathNest::metrics(mi);
86 FontSetChanger dummy(mi.base, "textrm");
88 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
91 int w = mathed_string_width(mi.base.font, "target: ");
92 width_ = w + max(cell(0).width(), cell(1).width());
93 ascent_ = cell(0).ascent();
94 descent_ = cell(0).descent() + cell(1).height() + 10;
99 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
105 void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
108 FontSetChanger dummy(pi.base, "textrm");
117 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
119 cell(0).draw(pi, x + lwid, y);
120 pi.base.text(x + 3, y, "target");
121 y += max(cell(0).descent(), ldes) + 5;
123 y += max(cell(1).ascent(), lasc) + 5;
124 cell(1).draw(pi, x + lwid, y);
125 pi.base.text(x + 3, y, "label");
131 pi.pain.text(x, y, "X");
132 MathArray const & s = sourceCell();
133 MathArray const & t = targetCell();
134 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
135 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
141 void InsetMathXYArrow::write(WriteStream & os) const
145 os << '[' << cell(0) << ']';
147 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
152 void InsetMathXYArrow::normalize(NormalStream & os) const
155 InsetMathNest::normalize(os);