]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
remove more forms.h cruft
[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 "LColor.h"
10 #include "Painter.h"
11 #include "mathed/support.h"
12 #include "support/LOstream.h"
13
14
15 MathDelimInset::MathDelimInset(int l, int r)
16         : MathInset("", LM_OT_DELIM, 1), left_(l), right_(r)
17 {}
18
19
20 MathInset * MathDelimInset::clone() const
21 {   
22         return new MathDelimInset(*this);
23 }
24
25
26 void MathDelimInset::Write(std::ostream & os, bool fragile) const
27 {
28         latexkeys const * l = (left_ != '|') ?
29                 lm_get_key_by_id(left_, LM_TK_SYM) : 0;
30         latexkeys const * r = (right_ != '|') ?
31                 lm_get_key_by_id(right_, LM_TK_SYM) : 0;
32
33         os << "\\left";
34         if (l)
35                 os << '\\' << l->name << ' ';
36         else {
37                 if (left_ == '{' || left_ == '}')
38                         os << '\\' << char(left_) << ' ';
39                 else
40                         os << char(left_) << ' ';
41         }
42
43         cell(0).Write(os, fragile);
44
45         os << "\\right";
46         if (r)
47                 os << '\\' << r->name << ' ';
48         else {
49                 if (right_ == '{' || right_ == '}')
50                         os << '\\' << char(right_) << ' ';
51                 else
52                         os << char(right_) << ' ';
53         }
54 }
55
56
57 void MathDelimInset::draw(Painter & pain, int x, int y)
58
59         xo(x);
60         yo(y); 
61
62         int w = dw();
63         xcell(0).draw(pain, x + w, y);
64         
65         if (left_ == '.') {
66                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
67                           LColor::mathcursor, Painter::line_onoffdash);
68         } else
69                 mathed_draw_deco(pain, x, y - ascent_, w, height(), left_);
70
71         x += width() - w - 2;
72
73         if (right_ == '.') {
74                 pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
75                           LColor::mathcursor, Painter::line_onoffdash);
76         } else
77                 mathed_draw_deco(pain, x, y - ascent_, w, height(), right_);
78 }
79
80
81 int MathDelimInset::dw() const
82 {
83         int w = height()/5;
84         if (w > 15)
85                 w = 15;
86         if (w < 6)
87                 w = 6;
88         return w;
89 }
90
91
92 void MathDelimInset::Metrics(MathStyles st)
93 {
94         xcell(0).Metrics(st);
95         size_    = st;
96         ascent_  = xcell(0).ascent() + 2;
97         descent_ = xcell(0).descent() + 2;
98         width_   = xcell(0).width() + 2 * dw() + 4;
99 }