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