7 #include "math_fracinset.h"
11 #include "mathed/support.h"
12 #include "support/LOstream.h"
17 MathFracInset::MathFracInset(short ot)
18 : MathParInset(LM_ST_TEXT, "frac", ot)
21 den_ = new MathParInset(LM_ST_TEXT); // this leaks
24 if (objtype == LM_OT_STACKREL) {
31 MathFracInset::~MathFracInset()
37 MathedInset * MathFracInset::Clone()
39 MathFracInset * p = new MathFracInset(*this);
40 // this cast will go again...
41 p->den_ = static_cast<MathParInset*>(p->den_->Clone());
46 bool MathFracInset::setArgumentIdx(int i)
48 if (i == 0 || i == 1) {
56 void MathFracInset::SetStyle(short st)
58 MathParInset::SetStyle(st);
60 den_->SetStyle((size() == LM_ST_DISPLAY) ?
61 static_cast<short>(LM_ST_TEXT)
66 void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
69 MathParInset::setData(n);
73 void MathFracInset::setData(MathedArray const & d)
76 MathParInset::setData(d);
83 void MathFracInset::GetXY(int & x, int & y) const
86 MathParInset::GetXY(x, y);
92 MathedArray & MathFracInset::GetData()
97 return den_->GetData();
101 bool MathFracInset::Inside(int x, int y)
103 int const xx = xo() - (width - w0_) / 2;
107 && y <= yo() + descent
108 && y >= yo() - ascent;
112 void MathFracInset::SetFocus(int /*x*/, int y)
114 // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
115 idx_ = (y > yo()) ? 1 : 0;
120 MathFracInset::draw(Painter & pain, int x, int y)
122 int const idxp = idx_;
123 int const sizex = size();
126 if (size() == LM_ST_DISPLAY) incSize();
127 MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
128 den_->draw(pain, x + (width - w1_) / 2, y + den_->Ascent() + 2 - dh_);
130 if (objtype == LM_OT_FRAC)
131 pain.line(x + 2, y - dh_,
132 x + width - 4, y - dh_, LColor::mathline);
138 MathFracInset::Metrics()
143 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
145 int const idxp = idx_;
146 int const sizex = size();
148 if (size() == LM_ST_DISPLAY) incSize();
149 MathParInset::Metrics();
152 int const as = Height() + 2 + dh_;
153 des0_ = Descent() + 2 + dh_;
156 width = ((w0_ > w1_) ? w0_: w1_) + 12;
158 descent = den_->Height()+ 2 - dh_;
163 void MathFracInset::Write(ostream & os, bool fragile)
165 os << '\\' << name << '{';
166 MathParInset::Write(os, fragile);
168 den_->Write(os, fragile);