3 #include "math_fracinset.h"
7 #include "mathed/support.h"
8 #include "support/LOstream.h"
13 MathFracInset::MathFracInset(short ot)
14 : MathParInset(LM_ST_TEXT, "frac", ot)
17 den = new MathParInset(LM_ST_TEXT); // this leaks
20 if (objtype == LM_OT_STACKREL) {
27 MathFracInset::~MathFracInset()
33 MathedInset * MathFracInset::Clone()
35 MathFracInset * p = new MathFracInset(GetType());
36 MathedIter itn(array);
37 MathedIter itd(den->GetData());
38 p->SetData(itn.Copy(), itd.Copy());
45 bool MathFracInset::setArgumentIdx(int i)
47 if (i == 0 || i == 1) {
55 void MathFracInset::SetStyle(short st)
57 MathParInset::SetStyle(st);
59 den->SetStyle((size == LM_ST_DISPLAY) ?
60 static_cast<short>(LM_ST_TEXT)
65 void MathFracInset::SetData(MathedArray * n, MathedArray * d)
68 MathParInset::SetData(n);
72 void MathFracInset::SetData(MathedArray * d)
75 MathParInset::SetData(d);
82 void MathFracInset::GetXY(int & x, int & y) const
85 MathParInset::GetXY(x, y);
91 MathedArray * MathFracInset::GetData()
96 return den->GetData();
100 bool MathFracInset::Inside(int x, int y)
102 int xx = xo - (width - w0) / 2;
104 return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent;
108 void MathFracInset::SetFocus(int /*x*/, int y)
110 // lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
111 idx = (y > yo) ? 1: 0;
116 MathFracInset::draw(Painter & pain, int x, int y)
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);
126 if (objtype == LM_OT_FRAC)
127 pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
133 MathFracInset::Metrics()
137 dh = mathed_char_height(LM_TC_CONST, size, 'I', a, b)/2;
142 if (size == LM_ST_DISPLAY) ++size;
143 MathParInset::Metrics();
146 int as = Height() + 2 + dh;
147 des0 = Descent() + 2 + dh;
150 width = ((w0 > w1) ? w0: w1) + 12;
152 descent = den->Height()+ 2 - dh;
157 void MathFracInset::Write(ostream & os, bool fragile)
159 os << '\\' << name << '{';
160 MathParInset::Write(os, fragile);
162 den->Write(os, fragile);