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