]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXYMatrix.cpp
5e3bdb5057e6333ed7a43774b285f580eee5712f
[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 dummy = mi.base.changeArray();
53         InsetMathGrid::metrics(mi, dim);
54 }
55
56
57 void InsetMathXYMatrix::draw(PainterInfo & pi, int x, int y) const
58 {
59         setPosCache(pi, x, y);
60         Changer dummy = pi.base.changeArray();
61         InsetMathGrid::draw(pi, x, y);
62 }
63
64
65 void InsetMathXYMatrix::write(WriteStream & os) const
66 {
67         MathEnsurer ensurer(os);
68         os << "\\xymatrix";
69         bool open = os.startOuterRow();
70         if (equal_spacing_) {
71                 os << "@!";
72                 switch (spacing_code_) {
73                 case '0':
74                 case 'R':
75                 case 'C':
76                         os << spacing_code_;
77                 }
78         } else {
79                 switch (spacing_code_) {
80                 case 'R':
81                 case 'C':
82                 case 'M':
83                 case 'W':
84                 case 'H':
85                 case 'L':
86                         os << '@' << spacing_code_ << '='
87                            << from_ascii(spacing_.asLatexString());
88                         break;
89                 default:
90                         if (!spacing_.empty())
91                                 os << "@=" << from_ascii(spacing_.asLatexString());
92                 }
93         }
94         os << '{';
95         InsetMathGrid::write(os);
96         os << "}";
97         if (open)
98                 os.startOuterRow();
99         os << "\n";
100 }
101
102
103 void InsetMathXYMatrix::infoize(odocstream & os) const
104 {
105         os << "xymatrix ";
106         if (equal_spacing_) {
107                 switch (spacing_code_) {
108                 case '0':
109                 case 'R':
110                 case 'C':
111                         os << '!' << spacing_code_ << ' ';
112                 }
113         } else {
114                 switch (spacing_code_) {
115                 case 'R':
116                 case 'C':
117                 case 'M':
118                 case 'W':
119                 case 'H':
120                 case 'L':
121                         os << spacing_code_ << ' '
122                            << from_ascii(spacing_.asLatexString()) << ' ';
123                         break;
124                 default:
125                         if (!spacing_.empty())
126                                 os << from_ascii(spacing_.asLatexString()) << ' ';
127                 }
128         }
129         InsetMathGrid::infoize(os);
130 }
131
132
133 void InsetMathXYMatrix::normalize(NormalStream & os) const
134 {
135         os << "[xymatrix ";
136         InsetMathGrid::normalize(os);
137         os << ']';
138 }
139
140
141 void InsetMathXYMatrix::maple(MapleStream & os) const
142 {
143         os << "xymatrix(";
144         InsetMathGrid::maple(os);
145         os << ')';
146 }
147
148
149 void InsetMathXYMatrix::validate(LaTeXFeatures & features) const
150 {
151         features.require("xy");
152         InsetMathGrid::validate(features);
153 }
154
155
156 void InsetMathXYMatrix::mathmlize(MathStream &) const
157 {
158         throw MathExportException();
159 }
160
161
162 void InsetMathXYMatrix::htmlize(HtmlStream &) const 
163 {
164         throw MathExportException(); 
165 }
166
167
168 } // namespace lyx