]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
mathed34.diff
[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         return new MathDelimInset(*this);
21 }
22
23
24 void MathDelimInset::Write(ostream & os, bool fragile)
25 {
26         latexkeys const * l = (left_ != '|') ?
27                 lm_get_key_by_id(left_, LM_TK_SYM) : 0;
28         latexkeys const * r = (right_ != '|') ?
29                 lm_get_key_by_id(right_, LM_TK_SYM) : 0;
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         MathParInset::Write(os, fragile);
41         os << "\\right";
42         if (r) {
43                 os << '\\' << r->name << ' ';
44         } else {
45                 if (right_ == '{' || right_ == '}') {
46                         os << '\\' << char(right_) << ' ';
47                 } else {
48                         os << char(right_) << ' ';
49                 }
50         }
51 }
52
53
54 void
55 MathDelimInset::draw(Painter & pain, int x, int y)
56
57         xo(x);
58         yo(y); 
59         MathParInset::draw(pain, x + dw_ + 2, y - dh_); 
60         
61         if (left_ == '.') {
62                 pain.line(x + 4, yo() - ascent,
63                           x + 4, yo() + descent,
64                           LColor::mathcursor, Painter::line_onoffdash);
65         } else
66                 mathed_draw_deco(pain, x, y - ascent, dw_, Height(), left_);
67         x += Width() - dw_ - 2;
68         if (right_ == '.') {
69                 pain.line(x + 4, yo() - ascent,
70                           x + 4, yo() + descent,
71                           LColor::mathcursor, Painter::line_onoffdash);
72         } else
73                 mathed_draw_deco(pain, x, y - ascent, dw_, Height(), right_);
74 }
75
76
77 void
78 MathDelimInset::Metrics()
79 {
80         MathParInset::Metrics();
81         int d;
82         
83         mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
84         dh_ /= 2;
85         ascent += 2 + dh_;
86         descent += 2 - dh_;
87         dw_ = Height()/5;
88         if (dw_ > 15) dw_ = 15;
89         if (dw_ < 6) dw_ = 6;
90         width += 2 * dw_ + 4;
91 }