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(*this);
36 // this cast will go again...
37 p->den_ = static_cast<MathParInset*>(p->den_->Clone());
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;
103 && y <= yo() + descent
104 && 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)
118 int const idxp = idx_;
119 int const sizex = size();
122 if (size() == LM_ST_DISPLAY) incSize();
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_,
128 x + width - 4, y - dh_, LColor::mathline);
134 MathFracInset::Metrics()
139 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
141 int const idxp = idx_;
142 int const sizex = size();
144 if (size() == LM_ST_DISPLAY) incSize();
145 MathParInset::Metrics();
148 int const as = Height() + 2 + dh_;
149 des0_ = Descent() + 2 + dh_;
152 width = ((w0_ > w1_) ? w0_: w1_) + 12;
154 descent = den_->Height()+ 2 - dh_;
159 void MathFracInset::Write(ostream & os, bool fragile)
161 os << '\\' << name << '{';
162 MathParInset::Write(os, fragile);
164 den_->Write(os, fragile);