]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
rework of MathDelimInset almost finished... did that break anything?
[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 MathInset * MathDelimInset::clone() const
18 {   
19         return new MathDelimInset(*this);
20 }
21
22
23 string MathDelimInset::latexName(latexkeys const * l)
24 {
25         //static const string vdelim("(){}[]./|");
26         string name = l->name;
27         if (name == "(")
28                 return name;
29         if (name == "[")
30                 return name;
31         if (name == ".")
32                 return name;
33         if (name == ")")
34                 return name;
35         if (name == "]")
36                 return name;
37         if (name == "/")
38                 return name;
39         if (name == "|")
40                 return name;
41         return "\\" + name + " ";
42 }
43
44
45 void MathDelimInset::write(std::ostream & os, bool fragile) const
46 {
47         os << "\\left" << latexName(left_);
48         cell(0).write(os, fragile);
49         os << "\\right" << latexName(right_);
50 }
51
52
53 void MathDelimInset::draw(Painter & pain, int x, int y) const
54
55         xo(x);
56         yo(y); 
57
58         int w = dw();
59         xcell(0).draw(pain, x + w, y);
60         
61         if (latexName(left_) == ".") {
62                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
63                           LColor::mathcursor, Painter::line_onoffdash);
64         } else
65                 mathed_draw_deco(pain, x, y - ascent_, w, height(), left_);
66
67         x += width() - w - 2;
68
69         if (latexName(right_) == ".") {
70                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
71                           LColor::mathcursor, Painter::line_onoffdash);
72         } else
73                 mathed_draw_deco(pain, x, y - ascent_, w, height(), right_);
74 }
75
76
77 int MathDelimInset::dw() const
78 {
79         int w = height()/5;
80         if (w > 15)
81                 w = 15;
82         if (w < 6)
83                 w = 6;
84         return w;
85 }
86
87
88 void MathDelimInset::metrics(MathStyles st) const
89 {
90         xcell(0).metrics(st);
91         size_    = st;
92         ascent_  = xcell(0).ascent() + 2;
93         descent_ = xcell(0).descent() + 2;
94         width_   = xcell(0).width() + 2 * dw() + 4;
95 }