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"
27 InsetMathXYArrow::InsetMathXYArrow()
32 std::auto_ptr<InsetBase> InsetMathXYArrow::clone() const
34 return std::auto_ptr<InsetBase>(new InsetMathXYArrow(*this));
38 InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
44 MathArray const & InsetMathXYArrow::targetCell() const
47 InsetMathXYMatrix const * p = targetMatrix();
50 MathArray const & t = cell(0);
51 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
52 switch ((*it)->getChar()) {
59 //lyxerr << "target: x: " << x << " y: " << y << endl;
60 InsetMath::idx_type n = mi_.idx + p->ncols() * y + x;
61 if (n >= p->nargs()) {
62 lyxerr << "source: n: " << mi_.idx << "\n"
63 << "target: n: " << n << " out of range" << endl;
68 static MathArray dummy;
74 MathArray const & InsetMathXYArrow::sourceCell() const
77 return targetMatrix()->cell(mi_.idx);
79 static MathArray dummy;
85 void InsetMathXYArrow::metrics(MetricsInfo & mi) const
87 InsetMathNest::metrics(mi);
89 FontSetChanger dummy(mi.base, "textrm");
91 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
94 int w = mathed_string_width(mi.base.font, from_ascii("target: "));
95 width_ = w + max(cell(0).width(), cell(1).width());
96 ascent_ = cell(0).ascent();
97 descent_ = cell(0).descent() + cell(1).height() + 10;
102 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
108 void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
111 FontSetChanger dummy(pi.base, "textrm");
120 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
122 cell(0).draw(pi, x + lwid, y);
123 pi.base.text(x + 3, y, "target");
124 y += max(cell(0).descent(), ldes) + 5;
126 y += max(cell(1).ascent(), lasc) + 5;
127 cell(1).draw(pi, x + lwid, y);
128 pi.base.text(x + 3, y, "label");
134 pi.pain.text(x, y, "X");
135 MathArray const & s = sourceCell();
136 MathArray const & t = targetCell();
137 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
138 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
144 void InsetMathXYArrow::write(WriteStream & os) const
148 os << '[' << cell(0) << ']';
150 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
155 void InsetMathXYArrow::normalize(NormalStream & os) const
158 InsetMathNest::normalize(os);