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)
121 int const idxp = idx_;
122 int const 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_,
131 x + width - 4, y - dh_, LColor::mathline);
137 MathFracInset::Metrics()
142 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
144 int const idxp = idx_;
145 int const sizex = size();
147 if (size() == LM_ST_DISPLAY) incSize();
148 MathParInset::Metrics();
151 int const as = Height() + 2 + dh_;
152 des0_ = Descent() + 2 + dh_;
155 width = ((w0_ > w1_) ? w0_: w1_) + 12;
157 descent = den_->Height()+ 2 - dh_;
162 void MathFracInset::Write(ostream & os, bool fragile)
164 os << '\\' << name << '{';
165 MathParInset::Write(os, fragile);
167 den_->Write(os, fragile);