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 "MathStream.h"
15 #include "MathSupport.h"
16 #include "frontends/Painter.h"
26 InsetMathXYArrow::InsetMathXYArrow()
31 std::auto_ptr<InsetBase> InsetMathXYArrow::clone() const
33 return std::auto_ptr<InsetBase>(new InsetMathXYArrow(*this));
37 InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
43 MathArray const & InsetMathXYArrow::targetCell() const
46 InsetMathXYMatrix const * p = targetMatrix();
49 MathArray const & t = cell(0);
50 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
51 switch ((*it)->getChar()) {
58 //lyxerr << "target: x: " << x << " y: " << y << endl;
59 InsetMath::idx_type n = mi_.idx + p->ncols() * y + x;
60 if (n >= p->nargs()) {
61 lyxerr << "source: n: " << mi_.idx << "\n"
62 << "target: n: " << n << " out of range" << endl;
67 static MathArray dummy;
73 MathArray const & InsetMathXYArrow::sourceCell() const
76 return targetMatrix()->cell(mi_.idx);
78 static MathArray dummy;
84 void InsetMathXYArrow::metrics(MetricsInfo & mi) const
86 InsetMathNest::metrics(mi);
88 FontSetChanger dummy(mi.base, "textrm");
90 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
93 int w = mathed_string_width(mi.base.font, from_ascii("target: "));
94 width_ = w + max(cell(0).width(), cell(1).width());
95 ascent_ = cell(0).ascent();
96 descent_ = cell(0).descent() + cell(1).height() + 10;
101 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
107 void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
110 FontSetChanger dummy(pi.base, "textrm");
119 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
121 cell(0).draw(pi, x + lwid, y);
122 pi.base.text(x + 3, y, "target");
123 y += max(cell(0).descent(), ldes) + 5;
125 y += max(cell(1).ascent(), lasc) + 5;
126 cell(1).draw(pi, x + lwid, y);
127 pi.base.text(x + 3, y, "label");
133 pi.pain.text(x, y, "X");
134 MathArray const & s = sourceCell();
135 MathArray const & t = targetCell();
136 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
137 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
143 void InsetMathXYArrow::write(WriteStream & os) const
147 os << '[' << cell(0) << ']';
149 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
154 void InsetMathXYArrow::normalize(NormalStream & os) const
157 InsetMathNest::normalize(os);