3 #include "math_fracinset.h"
7 #include "mathed/support.h"
10 MathFracInset::MathFracInset(short ot)
11 : MathParInset(LM_ST_TEXT, "frac", ot)
14 den = new MathParInset(LM_ST_TEXT); // this leaks
17 if (objtype == LM_OT_STACKREL) {
24 MathFracInset::~MathFracInset()
30 MathedInset * MathFracInset::Clone()
32 MathFracInset * p = new MathFracInset(GetType());
33 MathedIter itn(array);
34 MathedIter itd(den->GetData());
35 p->SetData(itn.Copy(), itd.Copy());
42 bool MathFracInset::setArgumentIdx(int i)
44 if (i == 0 || i == 1) {
52 void MathFracInset::SetStyle(short st)
54 MathParInset::SetStyle(st);
56 den->SetStyle((size == LM_ST_DISPLAY) ?
57 static_cast<short>(LM_ST_TEXT)
62 void MathFracInset::SetData(MathedArray * n, MathedArray * d)
65 MathParInset::SetData(n);
69 void MathFracInset::SetData(MathedArray * d)
72 MathParInset::SetData(d);
79 void MathFracInset::GetXY(int & x, int & y) const
82 MathParInset::GetXY(x, y);
88 MathedArray * MathFracInset::GetData()
93 return den->GetData();
97 bool MathFracInset::Inside(int x, int y)
99 int xx = xo - (width - w0) / 2;
101 return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent;
105 void MathFracInset::SetFocus(int /*x*/, int y)
107 // lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
108 idx = (y > yo) ? 1: 0;
113 MathFracInset::draw(Painter & pain, int x, int y)
119 if (size == LM_ST_DISPLAY) ++size;
120 MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
121 den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
123 if (objtype == LM_OT_FRAC)
124 pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
130 MathFracInset::Metrics()
134 dh = mathed_char_height(LM_TC_CONST, size, 'I', a, b)/2;
139 if (size == LM_ST_DISPLAY) ++size;
140 MathParInset::Metrics();
143 int as = Height() + 2 + dh;
144 des0 = Descent() + 2 + dh;
147 width = ((w0 > w1) ? w0: w1) + 12;
149 descent = den->Height()+ 2 - dh;
154 void MathFracInset::Write(ostream & os, bool fragile)
156 os << '\\' << name << '{';
157 MathParInset::Write(os, fragile);
159 den->Write(os, fragile);