]> git.lyx.org Git - lyx.git/blob - src/mathed/math_accentinset.C
2c12be4ad877d25d98abaa7e996d85ae44f72897
[lyx.git] / src / mathed / math_accentinset.C
1 #include <config.h>
2
3 #include "math_accentinset.h"
4 #include "mathed/support.h"
5 #include "math_parser.h"
6 #include "support/LOstream.h"
7
8 using std::ostream;
9
10 MathAccentInset::MathAccentInset(int f)
11         : MathInset(1), code(f)
12 {}
13
14
15 MathInset * MathAccentInset::clone() const
16 {   
17         return new MathAccentInset(*this);
18 }
19
20 void MathAccentInset::Metrics(MathStyles st, int, int)
21 {
22         xcell(0).Metrics(st);
23         ascent_  = xcell(0).ascent();
24         descent_ = xcell(0).descent();
25         width_   = xcell(0).width();
26         dh = 5;
27
28         if (code == LM_not) {
29                 ascent_  += dh;
30                 descent_ += dh;
31                 dh = height();
32         } else 
33                 ascent_ += dh + 2;
34         
35         dy = ascent_;
36 }
37
38 void MathAccentInset::draw(Painter & pain, int x, int y)
39 {
40         int const dw = width() - 2;
41         xcell(0).draw(pain, x, y);
42         x += (code == LM_not) ? (width() - dw) / 2 : 2;
43         mathed_draw_deco(pain, x, y - dy, dw, dh, code);
44 }
45
46
47 void MathAccentInset::Write(ostream & os, bool fragile) const
48 {
49         latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
50         os << '\\' << l->name;
51         if (code == LM_not)
52                 os << ' ';
53         else
54                 os << '{';
55         
56         cell(0).Write(os, fragile);
57         
58         if (code != LM_not)
59                 os << '}';
60 }
61
62
63 void MathAccentInset::WriteNormal(ostream & os) const
64 {
65         latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
66         os << "[accent " << l->name << " ";
67
68         cell(0).WriteNormal(os);
69
70         os << "] ";
71 }