]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
bd5eda375d5f6ff7f69e25b1e7d7af2d847980e8
[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_iter.h"
9 #include "math_parser.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "mathed/support.h"
13 #include "support/LOstream.h"
14
15 using std::ostream;
16
17
18 MathDelimInset::MathDelimInset(int l, int r, short st)
19         : MathParInset(st, "", LM_OT_DELIM), left_(l), right_(r) {}
20
21
22 MathedInset * MathDelimInset::Clone()
23 {   
24         return new MathDelimInset(*this);
25 }
26
27
28 void MathDelimInset::Write(ostream & os, bool fragile)
29 {
30         latexkeys const * l = (left_ != '|') ?
31                 lm_get_key_by_id(left_, LM_TK_SYM) : 0;
32         latexkeys const * r = (right_ != '|') ?
33                 lm_get_key_by_id(right_, LM_TK_SYM) : 0;
34         os << "\\left";
35         if (l) {
36                 os << '\\' << l->name << ' ';
37         } else {
38                 if (left_ == '{' || left_ == '}') {
39                         os << '\\' << char(left_) << ' ';
40                 } else {
41                         os << char(left_) << ' ';
42                 }
43         }
44         MathParInset::Write(os, fragile);
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
58 void 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 MathDelimInset::Metrics()
81 {
82         MathParInset::Metrics();
83
84         int d;
85         mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
86         dh_ /= 2;
87         ascent += 2 + dh_;
88         descent += 2 - dh_;
89         dw_ = Height()/5;
90         if (dw_ > 15) dw_ = 15;
91         if (dw_ < 6) dw_ = 6;
92         width += 2 * dw_ + 4;
93 }