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