]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
small cleanup, doxygen, formatting changes
[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         MathDelimInset * p = new MathDelimInset(left_, right_, GetStyle());
21         MathedIter it(array);
22         p->setData(it.Copy());
23         return p;
24 }
25
26
27 void MathDelimInset::Write(ostream & os, bool fragile)
28 {
29         latexkeys const * l = (left_ != '|') ?
30                 lm_get_key_by_id(left_, LM_TK_SYM) : 0;
31         latexkeys const * r = (right_ != '|') ?
32                 lm_get_key_by_id(right_, LM_TK_SYM) : 0;
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         MathParInset::Write(os, fragile);
44         os << "\\right";
45         if (r) {
46                 os << '\\' << r->name << ' ';
47         } else {
48                 if (right_ == '{' || right_ == '}') {
49                         os << '\\' << char(right_) << ' ';
50                 } else {
51                         os << char(right_) << ' ';
52                 }
53         }
54 }
55
56
57 void
58 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
81 MathDelimInset::Metrics()
82 {
83         MathParInset::Metrics();
84         int d;
85         
86         mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
87         dh_ /= 2;
88         ascent += 2 + dh_;
89         descent += 2 - dh_;
90         dw_ = Height()/5;
91         if (dw_ > 15) dw_ = 15;
92         if (dw_ < 6) dw_ = 6;
93         width += 2 * dw_ + 4;
94 }