]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
6e1134f19a52be48cae9d4d12f219edb5309963c
[lyx.git] / src / mathed / math_deliminset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_deliminset.h"
6 #include "math_parser.h"
7 #include "Painter.h"
8 #include "mathed/support.h"
9 #include "support/LOstream.h"
10
11
12 MathDelimInset::MathDelimInset(latexkeys const * l, latexkeys const * r)
13         : MathNestInset(1), left_(l), right_(r)
14 {}
15
16
17 MathDelimInset::MathDelimInset(int l, int r)
18         : MathNestInset(1)
19 {
20         string ls;
21         ls += l;
22         left_ = in_word_set(ls);
23
24         string rs;
25         rs += r;
26         right_ = in_word_set(rs);
27 }
28
29
30
31 MathInset * MathDelimInset::clone() const
32 {   
33         return new MathDelimInset(*this);
34 }
35
36
37 string MathDelimInset::latexName(latexkeys const * l)
38 {
39         //static const string vdelim("(){}[]./|");
40         string name = l->name;
41         if (name == "(")
42                 return name;
43         if (name == "[")
44                 return name;
45         if (name == ".")
46                 return name;
47         if (name == ")")
48                 return name;
49         if (name == "]")
50                 return name;
51         if (name == "/")
52                 return name;
53         if (name == "|")
54                 return name;
55         return "\\" + name + " ";
56 }
57
58
59 void MathDelimInset::write(std::ostream & os, bool fragile) const
60 {
61         os << "\\left" << latexName(left_);
62         cell(0).write(os, fragile);
63         os << "\\right" << latexName(right_);
64 }
65
66
67 void MathDelimInset::draw(Painter & pain, int x, int y) const
68
69         xo(x);
70         yo(y); 
71
72         int w = dw();
73         xcell(0).draw(pain, x + w, y);
74         
75         if (latexName(left_) == ".") {
76                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
77                           LColor::mathcursor, Painter::line_onoffdash);
78         } else
79                 mathed_draw_deco(pain, x, y - ascent_, w, height(), left_);
80
81         x += width() - w - 2;
82
83         if (latexName(right_) == ".") {
84                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
85                           LColor::mathcursor, Painter::line_onoffdash);
86         } else
87                 mathed_draw_deco(pain, x, y - ascent_, w, height(), right_);
88 }
89
90
91 int MathDelimInset::dw() const
92 {
93         int w = height()/5;
94         if (w > 15)
95                 w = 15;
96         if (w < 6)
97                 w = 6;
98         return w;
99 }
100
101
102 void MathDelimInset::metrics(MathStyles st) const
103 {
104         xcell(0).metrics(st);
105         size_    = st;
106         ascent_  = xcell(0).ascent() + 2;
107         descent_ = xcell(0).descent() + 2;
108         width_   = xcell(0).width() + 2 * dw() + 4;
109 }