]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
inactive new stuff to re-sync my tree before going on holyday
[lyx.git] / src / mathed / math_deliminset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_deliminset.h"
8 #include "math_parser.h"
9 #include "math_support.h"
10 #include "math_mathmlstream.h"
11 #include "math_streamstr.h"
12 #include "math_extern.h"
13
14
15 MathDelimInset::MathDelimInset(string const & l, string const & r)
16         : MathNestInset(1), left_(l), right_(r)
17 {}
18
19
20 MathInset * MathDelimInset::clone() const
21 {   
22         return new MathDelimInset(*this);
23 }
24
25
26 void MathDelimInset::write(WriteStream & os) const
27 {
28         os << "\\left" << convertDelimToLatexName(left_) << cell(0)
29            << "\\right" << convertDelimToLatexName(right_);
30 }
31
32
33 void MathDelimInset::normalize(NormalStream & os) const
34 {
35         os << "[delim " << convertDelimToLatexName(left_) << ' '
36            << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
37 }
38
39
40 int MathDelimInset::dw() const
41 {
42         int w = height() / 5;
43         if (w > 12)
44                 w = 12;
45         if (w < 4)
46                 w = 4;
47         return w;
48 }
49
50
51 void MathDelimInset::metrics(MathMetricsInfo const & mi) const
52 {
53         xcell(0).metrics(mi);
54         int a, d, w;
55         mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
56         int h0   = (a + d) / 2;
57         int a0   = std::max(xcell(0).ascent(), a)   - h0;
58         int d0   = std::max(xcell(0).descent(), d)  + h0;
59         ascent_  = std::max(a0, d0) + h0;
60         descent_ = std::max(a0, d0) - h0;
61         width_   = xcell(0).width() + 2 * dw() + 4;
62 }
63
64
65 void MathDelimInset::draw(Painter & pain, int x, int y) const
66
67         int const w = dw();
68         int const b = y - ascent_;
69         xcell(0).draw(pain, x + w + 2, y);
70         mathed_draw_deco(pain, x + 1, b, w, height(), left_);
71         mathed_draw_deco(pain, x + width() - w - 1, b, w, height(), right_);
72 }
73
74
75 bool MathDelimInset::isParanthesis() const
76 {
77         return left_ == "(" && right_ == ")";
78 }
79
80
81 bool MathDelimInset::isBrackets() const
82 {
83         return left_ == "[" && right_ == "]";
84 }
85
86
87 bool MathDelimInset::isAbs() const
88 {
89         return left_ == "|" && right_ == "|";
90 }
91
92
93 void MathDelimInset::maplize(MapleStream & os) const
94 {
95         if (isAbs()) {
96                 bool mat =
97                         cell(0).size() == 1 && cell(0).begin()->nucleus()
98                                         && cell(0).begin()->nucleus()->asMatrixInset();
99                 if (mat)        
100                         os << "linalg[det](" << cell(0) << ")";
101                 else
102                         os << "abs(" << cell(0) << ")";
103         }
104         else
105                 os << left_ << cell(0) << right_;
106 }
107
108
109 void MathDelimInset::mathmlize(MathMLStream & os) const
110 {
111         os << "<fenced open=\"" << left_ << "\" close=\""
112                 << right_ << "\">" << cell(0) << "</fenced>";
113 }
114
115
116 void MathDelimInset::octavize(OctaveStream & os) const
117 {
118         if (isAbs())
119                 os << "det(" << cell(0) << ")";
120         else
121                 os << left_ << cell(0) << right_;
122 }