]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
get rid of several friends small cleanup
[lyx.git] / src / mathed / math_deliminset.C
1 #include <config.h>
2
3 #include "math_deliminset.h"
4 #include "math_iter.h"
5 #include "math_parser.h"
6 #include "LColor.h"
7 #include "Painter.h"
8 #include "mathed/support.h"
9 #include "support/LOstream.h"
10
11 using std::ostream;
12
13
14 MathDelimInset::MathDelimInset(int l, int r, short st)
15         : MathParInset(st, "", LM_OT_DELIM), left(l), right(r) {}
16
17
18 MathedInset * MathDelimInset::Clone()
19 {   
20         MathDelimInset * p = new MathDelimInset(left, right, GetStyle());
21         MathedIter it(array);
22         p->SetData(it.Copy());
23         return p;
24 }
25
26
27
28 void MathDelimInset::Write(ostream & os, bool fragile)
29 {
30         latexkeys * l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
31         latexkeys * r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
32         os << "\\left";
33         if (l) {
34                 os << '\\' << l->name << ' ';
35         } else {
36                 if (left == '{' || left == '}') {
37                         os << '\\' << char(left) << ' ';
38                 } else {
39                         os << char(left) << ' ';
40                 }
41         }
42         MathParInset::Write(os, fragile);
43         os << "\\right";
44         if (r) {
45                 os << '\\' << r->name << ' ';
46         } else {
47                 if (right == '{' || right == '}') {
48                         os << '\\' << char(right) << ' ';
49                 } else {
50                         os << char(right) << ' ';
51                 }
52         }
53 }
54
55
56
57 void
58 MathDelimInset::draw(Painter & pain, int x, int y)
59
60         xo(x);
61         yo(y); 
62         MathParInset::draw(pain, x + dw + 2, y - dh); 
63         
64         if (left == '.') {
65                 pain.line(x + 4, yo() - ascent,
66                           x + 4, yo() + descent,
67                           LColor::mathcursor, Painter::line_onoffdash);
68         } else
69                 mathed_draw_deco(pain, x, y - ascent, dw, Height(), left);
70         x += Width() - dw - 2;
71         if (right == '.') {
72                 pain.line(x + 4, yo() - ascent,
73                           x + 4, yo() + descent,
74                           LColor::mathcursor, Painter::line_onoffdash);
75         } else
76                 mathed_draw_deco(pain, x, y - ascent, dw, Height(), right);
77 }
78
79
80 void
81 MathDelimInset::Metrics()
82 {
83         MathParInset::Metrics();
84         int d;
85         
86         mathed_char_height(LM_TC_CONST, size(), 'I', d, dh);
87         dh /= 2;
88         ascent += 2 + dh;
89         descent += 2 - dh;
90         dw = Height()/5;
91         if (dw > 15) dw = 15;
92         if (dw < 6) dw = 6;
93         width += 2 * dw + 4;
94 }