]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
mathed compilation fixes
[lyx.git] / src / mathed / math_fracinset.C
1 #include <config.h>
2
3 #include "math_fracinset.h"
4 #include "math_iter.h"
5 #include "LColor.h"
6 #include "Painter.h"
7 #include "mathed/support.h"
8 #include "support/LOstream.h"
9
10 using std::ostream;
11
12
13 MathFracInset::MathFracInset(short ot)
14         : MathParInset(LM_ST_TEXT, "frac", ot)
15 {
16         
17         den = new MathParInset(LM_ST_TEXT); // this leaks
18         dh = 0;
19         idx = 0;
20         if (objtype == LM_OT_STACKREL) {
21                 flag |= LMPF_SCRIPT;
22                 SetName("stackrel");
23         }
24 }
25
26
27 MathFracInset::~MathFracInset()
28 {
29         delete den;
30 }
31
32
33 MathedInset * MathFracInset::Clone()
34 {   
35         MathFracInset * p = new MathFracInset(GetType());
36         MathedIter itn(array);
37         MathedIter itd(den->GetData());
38         p->SetData(itn.Copy(), itd.Copy());
39         p->idx = idx;
40         p->dh = dh;
41         return p;
42 }
43
44
45 bool MathFracInset::setArgumentIdx(int i)
46 {
47         if (i == 0 || i == 1) {
48                 idx = i;
49                 return true;
50         } else 
51                 return false;
52 }
53
54
55 void MathFracInset::SetStyle(short st)
56 {
57         MathParInset::SetStyle(st);
58         dh = 0;
59         den->SetStyle((size == LM_ST_DISPLAY) ?
60                       static_cast<short>(LM_ST_TEXT)
61                       : size);
62 }
63
64
65 void MathFracInset::SetData(MathedArray * n, MathedArray * d)
66 {
67         den->SetData(d);
68         MathParInset::SetData(n);
69 }
70
71
72 void MathFracInset::SetData(MathedArray * d)
73 {
74         if (idx == 0)
75                 MathParInset::SetData(d);
76         else {
77                 den->SetData(d);
78         }
79 }
80
81
82 void MathFracInset::GetXY(int & x, int & y) const
83 {  
84         if (idx == 0)
85                 MathParInset::GetXY(x, y);
86         else
87                 den->GetXY(x, y);
88 }
89
90
91 MathedArray * MathFracInset::GetData()
92 {
93         if (idx == 0)
94                 return array;
95         else
96                 return den->GetData();
97 }
98
99
100 bool MathFracInset::Inside(int x, int y) 
101 {
102         int xx = xo - (width - w0) / 2;
103         
104         return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent;
105 }
106
107
108 void MathFracInset::SetFocus(int /*x*/, int y)
109 {  
110 //    lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
111         idx = (y > yo) ? 1: 0;
112 }
113
114
115 void
116 MathFracInset::draw(Painter & pain, int x, int y)
117
118         short idxp = idx;
119         short sizex = size;
120         
121         idx = 0;
122         if (size == LM_ST_DISPLAY) ++size;
123         MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
124         den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
125         size = sizex;
126         if (objtype == LM_OT_FRAC)
127                 pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
128         idx = idxp;
129 }
130
131
132 void
133 MathFracInset::Metrics()
134 {
135         if (!dh) {
136                 int a, b;
137                 dh = mathed_char_height(LM_TC_CONST, size, 'I', a, b)/2;
138         }
139         short idxp = idx;
140         short sizex = size; 
141         idx = 0;
142         if (size == LM_ST_DISPLAY) ++size; 
143         MathParInset::Metrics();
144         size = sizex;
145         w0 = width;
146         int as = Height() + 2 + dh;
147         des0 = Descent() + 2 + dh;
148         den->Metrics();  
149         w1 = den->Width();   
150         width = ((w0 > w1) ? w0: w1) + 12;
151         ascent = as; 
152         descent = den->Height()+ 2 - dh;
153         idx = idxp;
154 }
155
156
157 void MathFracInset::Write(ostream & os, bool fragile)
158 {
159         os << '\\' << name << '{';
160         MathParInset::Write(os, fragile);
161         os << "}{";
162         den->Write(os, fragile);
163         os << '}';
164 }