A bit more re-organization.
[lyx.git] / src / mathed / InsetMathXYArrow.cpp
blobb0e20499036ed2f9767b12631a7d6ba0b8763ce5
1 /**
2 * \file InsetMathXYArrow.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathXYArrow.h"
14 #include "MathStream.h"
15 #include "MathSupport.h"
16 #include "frontends/Painter.h"
17 #include "support/debug.h"
19 using namespace std;
21 namespace lyx {
24 InsetMathXYArrow::InsetMathXYArrow()
25 : InsetMathNest(2)
29 Inset * InsetMathXYArrow::clone() const
31 return new InsetMathXYArrow(*this);
35 InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
37 return target_;
41 MathData const & InsetMathXYArrow::targetCell() const
43 #if 0
44 InsetMathXYMatrix const * p = targetMatrix();
45 int x = 0;
46 int y = 0;
47 MathData const & t = cell(0);
48 for (MathData::const_iterator it = t.begin(); it != t.end(); ++it) {
49 switch ((*it)->getChar()) {
50 case 'l': --x; break;
51 case 'r': ++x; break;
52 case 'u': --y; break;
53 case 'd': ++y; break;
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;
61 n = 0;
63 return p->cell(n);
64 #else
65 static MathData dummy;
66 return dummy;
67 #endif
71 MathData const & InsetMathXYArrow::sourceCell() const
73 #if 0
74 return targetMatrix()->cell(mi_.idx);
75 #else
76 static MathData dummy;
77 return dummy;
78 #endif
82 bool InsetMathXYArrow::metrics(MetricsInfo & mi) const
84 InsetMathNest::metrics(mi);
85 mi_ = mi;
86 FontSetChanger dummy(mi.base, "textrm");
87 #if 0
88 target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
90 if (editing()) {
91 int w = mathed_string_width(mi.base.font, from_ascii("target: "));
92 width_ = w + max(dim0.width(), dim1.wid);
93 ascent_ = dim0.asc;
94 descent_ = dim0.des + dim1.height() + 10;
95 } else {
96 width_ = 0;
97 ascent_ = 0;
98 descent_ = 0;
99 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
101 #endif
105 void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
107 metrics(mi_);
108 FontSetChanger dummy(pi.base, "textrm");
110 if (editing()) {
112 #if 0
114 int lasc;
115 int ldes;
116 int lwid;
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(dim0.des, ldes) + 5;
123 y += max(dim1.asc, lasc) + 5;
124 cell(1).draw(pi, x + lwid, y);
125 pi.base.text(x + 3, y, "label");
127 #endif
129 } else {
131 pi.pain.text(x, y, "X");
132 MathData const & s = sourceCell();
133 MathData const & t = targetCell();
134 pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), Color_math);
135 cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
141 void InsetMathXYArrow::write(WriteStream & os) const
143 MathEnsurer ensurer(os);
144 os << "\\ar";
145 if (cell(0).size())
146 os << '[' << cell(0) << ']';
147 if (cell(1).size())
148 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
149 os << " ";
153 void InsetMathXYArrow::normalize(NormalStream & os) const
155 os << "[xyarrow ";
156 InsetMathNest::normalize(os);
157 os << ']';
161 } // namespace lyx