2 * \file math_xyarrowinset.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 "math_xyarrowinset.h"
14 #include "math_xymatrixinset.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17 #include "math_support.h"
18 #include "frontends/Painter.h"
25 MathXYArrowInset::MathXYArrowInset()
30 auto_ptr<InsetBase> MathXYArrowInset::clone() const
32 return auto_ptr<InsetBase>(new MathXYArrowInset(*this));
36 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
42 MathArray const & MathXYArrowInset::targetCell() const
45 MathXYMatrixInset const * p = targetMatrix();
48 MathArray const & t = cell(0);
49 for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
50 switch ((*it)->getChar()) {
57 //lyxerr << "target: x: " << x << " y: " << y << endl;
58 MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
59 if (n >= p->nargs()) {
60 lyxerr << "source: n: " << mi_.idx << "\n"
61 << "target: n: " << n << " out of range" << endl;
66 static MathArray dummy;
72 MathArray const & MathXYArrowInset::sourceCell() const
75 return targetMatrix()->cell(mi_.idx);
77 static MathArray dummy;
83 void MathXYArrowInset::metrics(MetricsInfo & mi) const
85 MathNestInset::metrics(mi);
87 FontSetChanger dummy(mi.base, "textrm");
89 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
92 int w = mathed_string_width(mi.base.font, "target: ");
93 width_ = w + max(cell(0).width(), cell(1).width());
94 ascent_ = cell(0).ascent();
95 descent_ = cell(0).descent() + cell(1).height() + 10;
100 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
106 void MathXYArrowInset::draw(PainterInfo & pi, int x, int y) const
109 FontSetChanger dummy(pi.base, "textrm");
118 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
120 cell(0).draw(pi, x + lwid, y);
121 drawStr(pi, pi.base.font, x + 3, y, "target");
122 y += max(cell(0).descent(), ldes) + 5;
124 y += max(cell(1).ascent(), lasc) + 5;
125 cell(1).draw(pi, x + lwid, y);
126 drawStr(pi, pi.base.font, x + 3, y, "label");
132 drawStr(pi, font_, x, y, "X");
133 MathArray const & s = sourceCell();
134 MathArray const & t = targetCell();
135 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
136 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
142 void MathXYArrowInset::write(WriteStream & os) const
146 os << '[' << cell(0) << ']';
148 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
153 void MathXYArrowInset::normalize(NormalStream & os) const
156 MathNestInset::normalize(os);