]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
Fix working of the spellchecker dialog with ispell when there are no
[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 "mathed/support.h"
10 #include "support/LOstream.h"
11
12 using std::max;
13
14 MathDelimInset::MathDelimInset(string const & l, string const & r)
15         : MathNestInset(1), left_(l), right_(r)
16 {}
17
18
19 MathInset * MathDelimInset::clone() const
20 {   
21         return new MathDelimInset(*this);
22 }
23
24
25 string MathDelimInset::latexName(string const & name)
26 {
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 int MathDelimInset::dw() const
54 {
55         int w = height() / 5;
56         if (w > 15)
57                 w = 15;
58         if (w < 4)
59                 w = 4;
60         return w;
61 }
62
63
64 void MathDelimInset::metrics(MathStyles st) const
65 {
66         xcell(0).metrics(st);
67         size_    = st;
68         int a, d, w;
69         mathed_char_dim(LM_TC_VAR, st,'I', a, d, w);
70         int h0   = (a + d) / 2;
71         int a0   = std::max(xcell(0).ascent(), a)   - h0;
72         int d0   = std::max(xcell(0).descent(), d)  + h0;
73         ascent_  = max(a0, d0) + h0;
74         descent_ = max(a0, d0) - h0;
75         width_   = xcell(0).width() + 2 * dw() + 4;
76 }
77
78
79 void MathDelimInset::draw(Painter & pain, int x, int y) const
80
81         xo(x);
82         yo(y); 
83
84         int const w = dw();
85         int const b = y - ascent_ - 2;
86         xcell(0).draw(pain, x + w + 2, y);
87         mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_);
88         mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_);
89 }