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