]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXYMatrix.cpp
InsetMath: match the screen display with the EnsureMath behaviour in output
[lyx.git] / src / mathed / InsetMathXYMatrix.cpp
1 /**
2  * \file InsetMathXYMatrix.cpp
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 "InsetMathXYMatrix.h"
14
15 #include "MathStream.h"
16
17 #include "LaTeXFeatures.h"
18 #include "MetricsInfo.h"
19
20 #include <ostream>
21
22 namespace lyx {
23
24
25 InsetMathXYMatrix::InsetMathXYMatrix(Buffer * buf, Length const & s, char c,
26         bool e) : InsetMathGrid(buf, 1, 1), spacing_(s), spacing_code_(c),
27         equal_spacing_(e)
28 {
29 }
30
31
32 Inset * InsetMathXYMatrix::clone() const
33 {
34         return new InsetMathXYMatrix(*this);
35 }
36
37
38 int InsetMathXYMatrix::colsep() const
39 {
40         return 40;
41 }
42
43
44 int InsetMathXYMatrix::rowsep() const
45 {
46         return 40;
47 }
48
49
50 void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
51 {
52         Changer dummy2 = mi.base.changeEnsureMath();
53         Changer dummy = mi.base.changeArray();
54         InsetMathGrid::metrics(mi, dim);
55 }
56
57
58 void InsetMathXYMatrix::draw(PainterInfo & pi, int x, int y) const
59 {
60         setPosCache(pi, x, y);
61         Changer dummy2 = pi.base.changeEnsureMath();
62         Changer dummy = pi.base.changeArray();
63         InsetMathGrid::draw(pi, x, y);
64 }
65
66
67 void InsetMathXYMatrix::write(WriteStream & os) const
68 {
69         MathEnsurer ensurer(os);
70         os << "\\xymatrix";
71         bool open = os.startOuterRow();
72         if (equal_spacing_) {
73                 os << "@!";
74                 switch (spacing_code_) {
75                 case '0':
76                 case 'R':
77                 case 'C':
78                         os << spacing_code_;
79                 }
80         } else {
81                 switch (spacing_code_) {
82                 case 'R':
83                 case 'C':
84                 case 'M':
85                 case 'W':
86                 case 'H':
87                 case 'L':
88                         os << '@' << spacing_code_ << '='
89                            << from_ascii(spacing_.asLatexString());
90                         break;
91                 default:
92                         if (!spacing_.empty())
93                                 os << "@=" << from_ascii(spacing_.asLatexString());
94                 }
95         }
96         os << '{';
97         InsetMathGrid::write(os);
98         os << "}";
99         if (open)
100                 os.startOuterRow();
101         os << "\n";
102 }
103
104
105 void InsetMathXYMatrix::infoize(odocstream & os) const
106 {
107         os << "xymatrix ";
108         if (equal_spacing_) {
109                 switch (spacing_code_) {
110                 case '0':
111                 case 'R':
112                 case 'C':
113                         os << '!' << spacing_code_ << ' ';
114                 }
115         } else {
116                 switch (spacing_code_) {
117                 case 'R':
118                 case 'C':
119                 case 'M':
120                 case 'W':
121                 case 'H':
122                 case 'L':
123                         os << spacing_code_ << ' '
124                            << from_ascii(spacing_.asLatexString()) << ' ';
125                         break;
126                 default:
127                         if (!spacing_.empty())
128                                 os << from_ascii(spacing_.asLatexString()) << ' ';
129                 }
130         }
131         InsetMathGrid::infoize(os);
132 }
133
134
135 void InsetMathXYMatrix::normalize(NormalStream & os) const
136 {
137         os << "[xymatrix ";
138         InsetMathGrid::normalize(os);
139         os << ']';
140 }
141
142
143 void InsetMathXYMatrix::maple(MapleStream & os) const
144 {
145         os << "xymatrix(";
146         InsetMathGrid::maple(os);
147         os << ')';
148 }
149
150
151 void InsetMathXYMatrix::validate(LaTeXFeatures & features) const
152 {
153         features.require("xy");
154         InsetMathGrid::validate(features);
155 }
156
157
158 void InsetMathXYMatrix::mathmlize(MathStream &) const
159 {
160         throw MathExportException();
161 }
162
163
164 void InsetMathXYMatrix::htmlize(HtmlStream &) const 
165 {
166         throw MathExportException(); 
167 }
168
169
170 } // namespace lyx