]> git.lyx.org Git - lyx.git/blob - src/mathed/math_xyarrowinset.C
macro rework
[lyx.git] / src / mathed / math_xyarrowinset.C
1 /**
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.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
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"
19 #include "debug.h"
20
21
22 using std::max;
23
24
25 MathXYArrowInset::MathXYArrowInset()
26         : MathNestInset(2)
27 {}
28
29
30 auto_ptr<InsetBase> MathXYArrowInset::clone() const
31 {
32         return auto_ptr<InsetBase>(new MathXYArrowInset(*this));
33 }
34
35
36 MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
37 {
38         return target_;
39 }
40
41
42 MathArray const & MathXYArrowInset::targetCell() const
43 {
44 #if 0
45         MathXYMatrixInset const * p = targetMatrix();
46         int x = 0;
47         int y = 0;
48         MathArray const & t = cell(0);
49         for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
50                 switch ((*it)->getChar()) {
51                         case 'l': --x; break;
52                         case 'r': ++x; break;
53                         case 'u': --y; break;
54                         case 'd': ++y; break;
55                 }
56         }
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;
62                 n = 0;
63         }
64   return p->cell(n);
65 #else
66         static MathArray dummy;
67         return dummy;
68 #endif
69 }
70
71
72 MathArray const & MathXYArrowInset::sourceCell() const
73 {
74 #if 0
75   return targetMatrix()->cell(mi_.idx);
76 #else
77         static MathArray dummy;
78         return dummy;
79 #endif
80 }
81
82
83 void MathXYArrowInset::metrics(MetricsInfo & mi) const
84 {
85         MathNestInset::metrics(mi);
86         mi_   = mi;
87         FontSetChanger dummy(mi.base, "textrm");
88 #if 0
89         target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
90
91         if (editing()) {
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;
96         } else {
97                 width_   = 0;
98                 ascent_  = 0;
99                 descent_ = 0;
100                 //mathed_string_dim(font_, "X", ascent_, descent_, width_);
101         }
102 #endif
103 }
104
105
106 void MathXYArrowInset::draw(PainterInfo & pi, int x, int y) const
107 {
108         metrics(mi_);
109         FontSetChanger dummy(pi.base, "textrm");
110
111         if (editing()) {
112
113 #if 0
114
115                 int lasc;
116                 int ldes;
117                 int lwid;
118                 mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
119
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;
123
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");
127
128 #endif
129
130         } else {
131
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);
137
138         }
139 }
140
141
142 void MathXYArrowInset::write(WriteStream & os) const
143 {
144         os << "\\ar";
145         if (cell(0).size())
146                 os << '[' << cell(0) << ']';
147         if (cell(1).size())
148                 os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
149         os << " ";
150 }
151
152
153 void MathXYArrowInset::normalize(NormalStream & os) const
154 {
155         os << "[xyarrow ";
156         MathNestInset::normalize(os);
157         os << ']';
158 }