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;
106 && y <= yo() + descent
107 && y >= yo() - ascent;
111 void MathFracInset::SetFocus(int /*x*/, int y)
113 // lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
114 idx = (y > yo()) ? 1: 0;
119 MathFracInset::draw(Painter & pain, int x, int y)
122 short sizex = size();
125 if (size() == LM_ST_DISPLAY) incSize();
126 MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
127 den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
129 if (objtype == LM_OT_FRAC)
130 pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
136 MathFracInset::Metrics()
140 dh = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
143 short sizex = size();
145 if (size() == LM_ST_DISPLAY) incSize();
146 MathParInset::Metrics();
149 int as = Height() + 2 + dh;
150 des0 = Descent() + 2 + dh;
153 width = ((w0 > w1) ? w0: w1) + 12;
155 descent = den->Height()+ 2 - dh;
160 void MathFracInset::Write(ostream & os, bool fragile)
162 os << '\\' << name << '{';
163 MathParInset::Write(os, fragile);
165 den->Write(os, fragile);