]> git.lyx.org Git - lyx.git/blob - src/mathed/math_accentinset.C
first go at mathed file cleanup
[lyx.git] / src / mathed / math_accentinset.C
1 #include <config.h>
2
3 #include "math_accentinset.h"
4 #include "support.h"
5 #include "math_parser.h"
6
7
8 MathAccentInset::MathAccentInset(byte cx, MathedTextCodes f, int cd, short st)
9         : MathedInset("", LM_OT_ACCENT, st), c(cx), fn(f), code(cd)
10 {
11         inset = 0;
12 }
13
14
15 MathAccentInset::MathAccentInset(MathedInset *ins, int cd, short st)
16         : MathedInset("", LM_OT_ACCENT, st),
17           c(0), fn(LM_TC_MIN), code(cd), inset(ins) {}
18
19
20 MathAccentInset::~MathAccentInset()
21 {
22         delete inset;
23 }
24
25
26 MathedInset * MathAccentInset::Clone()
27 {   
28         MathAccentInset * p;
29         
30         if (inset) 
31                 p = new MathAccentInset(inset->Clone(), code, GetStyle());
32         else
33                 p = new MathAccentInset(c, fn, code, GetStyle());
34         
35         return p;
36 }
37
38
39 void
40 MathAccentInset::draw(Painter & pain, int x, int y)
41 {
42         int dw = width - 2;
43         
44         if (inset) 
45                 inset->draw(pain, x, y);
46         else {
47                 string s;
48                 s += c;
49                 drawStr(pain, fn, size, x, y, s);
50         }
51         x += (code == LM_not) ? (width-dw) / 2 : 2;
52         mathed_draw_deco(pain, x, y - dy, dw, dh, code);
53 }
54
55
56 void
57 MathAccentInset::Metrics()
58 {
59         if (inset) {
60                 inset->Metrics();
61                 ascent = inset->Ascent();
62                 descent = inset->Descent();
63                 width = inset->Width();
64                 dh = ascent;
65         } else {
66                 mathed_char_height(fn, size, c, ascent, descent);
67                 width = mathed_char_width(fn, size, c);
68                 dh = (width-2)/2; 
69         }
70         if (code == LM_not) {
71                 ascent += dh;
72                 descent += dh;
73                 dh = Height();
74         } else 
75                 ascent += dh+2;
76         
77         dy = ascent;
78 //    if (MathIsBinary(fn))
79 //      width += 2*mathed_char_width(fn, size, ' ');    
80 }
81
82
83 void MathAccentInset::Write(ostream & os, bool fragile)
84 {
85         latexkeys * l = lm_get_key_by_id(code, LM_TK_ACCENT);
86         os << '\\' << l->name;
87         if (code!= LM_not)
88                 os << '{';
89         else
90                 os << ' ';
91         
92         if (inset) {
93                 inset->Write(os, fragile);
94         } else {
95                 if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) {
96                         os << '\\'
97                            << math_font_name[fn - LM_TC_RM]
98                            << '{';
99                 }
100                 if (MathIsSymbol(fn)) {
101                         latexkeys * l = lm_get_key_by_id(c, LM_TK_SYM);
102                         if (l) {
103                                 os << '\\' << l->name << ' ';
104                         }
105                 } else
106                         os << char(c);
107                 
108                 if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
109                         os << '}';
110         }
111         
112         if (code!= LM_not)
113                 os << '}';
114 }