]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
gcc 3.0 fixes
[lyx.git] / src / mathed / math_fracinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <functional>
8
9 #include "math_fracinset.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "mathed/support.h"
13 #include "support/LOstream.h"
14
15
16 MathFracInset::MathFracInset(MathInsetTypes ot)
17         : MathInset("frac", ot, 2)
18 {
19         if (objtype == LM_OT_STACKREL) 
20                 SetName("stackrel");
21 }
22
23
24 MathInset * MathFracInset::Clone() const
25 {   
26         return new MathFracInset(*this);
27 }
28
29
30 void MathFracInset::Metrics(MathStyles st)
31 {
32         xcell(0).Metrics(st);
33         xcell(1).Metrics(st);
34         size_    = st;
35         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
36         ascent_  = xcell(0).height() + 4 + 5;
37         descent_ = xcell(1).height() + 4 - 5; 
38 }
39
40
41 void MathFracInset::draw(Painter & pain, int x, int y)
42 {
43         xo(x);
44         yo(y);
45         int m = x + width() / 2;
46         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
47         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
48         
49         if (objtype == LM_OT_FRAC)
50                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
51 }
52
53
54 void MathFracInset::Write(std::ostream & os, bool fragile) const
55 {
56         os << '\\' << name() << '{';
57         cell(0).Write(os, fragile);
58         os << "}{";
59         cell(1).Write(os, fragile);
60         os << '}';
61 }
62
63
64 void MathFracInset::WriteNormal(std::ostream & os) const
65 {
66         os << '[' << name() << ' ';
67         cell(0).WriteNormal(os);
68         os << " ";
69         cell(1).WriteNormal(os);
70         os << "] ";
71 }
72
73
74 bool MathFracInset::idxRight(int &, int &) const
75 {
76         return false;
77 }
78
79 bool MathFracInset::idxLeft(int &, int &) const
80 {
81         return false;
82 }
83
84
85 bool MathFracInset::idxUp(int & idx, int &) const
86 {
87         if (idx == 0)
88                 return false;
89         idx = 0;
90         return true;
91 }
92
93 bool MathFracInset::idxDown(int & idx, int &) const
94 {
95         if (idx == 1)
96                 return false;
97         idx = 1;
98         return true;
99 }
100
101 bool MathFracInset::idxFirstUp(int & idx, int & pos) const
102 {
103         idx = 0;
104         pos = 0;
105         return true;
106 }
107
108 bool MathFracInset::idxFirstDown(int & idx, int & pos) const
109 {
110         idx = 1;
111         pos = 0;
112         return true;
113 }
114
115 bool MathFracInset::idxLastUp(int & idx, int & pos) const
116 {
117         idx = 0;
118         pos = cell(idx).size();
119         return true;
120 }
121
122 bool MathFracInset::idxLastDown(int & idx, int & pos) const
123 {
124         idx = 1;
125         pos = cell(idx).size();
126         return true;
127 }
128