]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXYMatrix.cpp
Fix bug 1527
[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(Length const & s, char c)
24         : InsetMathGrid(1, 1), spacing_(s), spacing_code_(c)
25 {}
26
27
28 Inset * InsetMathXYMatrix::clone() const
29 {
30         return new InsetMathXYMatrix(*this);
31 }
32
33
34 int InsetMathXYMatrix::colsep() const
35 {
36         return 40;
37 }
38
39
40 int InsetMathXYMatrix::rowsep() const
41 {
42         return 40;
43 }
44
45
46 void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         if (mi.base.style == LM_ST_DISPLAY)
49                 mi.base.style = LM_ST_TEXT;
50         InsetMathGrid::metrics(mi, dim);
51 }
52
53
54 void InsetMathXYMatrix::write(WriteStream & os) const
55 {
56         bool brace = os.pendingBrace();
57         os.pendingBrace(false);
58         if (os.latex() && os.textMode()) {
59                 os << "\\ensuremath{";
60                 os.textMode(false);
61                 brace = true;
62         }
63         os << "\\xymatrix";
64         switch (spacing_code_) {
65         case 'R':
66         case 'C':
67         case 'M':
68         case 'W':
69         case 'H':
70         case 'L':
71                 os << '@' << spacing_code_ << '='
72                    << from_ascii(spacing_.asLatexString());
73                 break;
74         default:
75                 if (!spacing_.empty())
76                         os << "@=" << from_ascii(spacing_.asLatexString());
77         }
78         os << '{';
79         InsetMathGrid::write(os);
80         os << "}\n";
81         os.pendingBrace(brace);
82 }
83
84
85 void InsetMathXYMatrix::infoize(odocstream & os) const
86 {
87         os << "xymatrix ";
88         switch (spacing_code_) {
89         case 'R':
90         case 'C':
91         case 'M':
92         case 'W':
93         case 'H':
94         case 'L':
95                 os << spacing_code_ << ' '
96                    << from_ascii(spacing_.asLatexString()) << ' ';
97                 break;
98         default:
99                 if (!spacing_.empty())
100                         os << from_ascii(spacing_.asLatexString()) << ' ';
101         }
102         InsetMathGrid::infoize(os);
103 }
104
105
106 void InsetMathXYMatrix::normalize(NormalStream & os) const
107 {
108         os << "[xymatrix ";
109         InsetMathGrid::normalize(os);
110         os << ']';
111 }
112
113
114 void InsetMathXYMatrix::maple(MapleStream & os) const
115 {
116         os << "xymatrix(";
117         InsetMathGrid::maple(os);
118         os << ')';
119 }
120
121
122 void InsetMathXYMatrix::validate(LaTeXFeatures & features) const
123 {
124         features.require("xy");
125         InsetMathGrid::validate(features);
126 }
127
128
129 } // namespace lyx