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),
19 idx_(0), den_(LM_ST_TEXT), dh_(0)
21 if (objtype == LM_OT_STACKREL) {
28 MathedInset * MathFracInset::Clone()
30 MathFracInset * p = new MathFracInset(*this);
35 bool MathFracInset::setArgumentIdx(int i)
37 if (i == 0 || i == 1) {
45 void MathFracInset::SetStyle(short st)
47 MathParInset::SetStyle(st);
49 den_.SetStyle((size() == LM_ST_DISPLAY) ?
50 static_cast<short>(LM_ST_TEXT)
55 void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
58 MathParInset::setData(n);
62 void MathFracInset::setData(MathedArray const & d)
65 MathParInset::setData(d);
72 void MathFracInset::GetXY(int & x, int & y) const
75 MathParInset::GetXY(x, y);
81 MathedArray & MathFracInset::GetData()
86 return den_.GetData();
90 MathedArray const & MathFracInset::GetData() const
95 return den_.GetData();
99 bool MathFracInset::Inside(int x, int y)
101 int const xx = xo() - (width - w0_) / 2;
105 && y <= yo() + descent
106 && y >= yo() - ascent;
110 void MathFracInset::SetFocus(int /*x*/, int y)
112 // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
113 idx_ = (y > yo()) ? 1 : 0;
118 MathFracInset::draw(Painter & pain, int x, int y)
120 int const idxp = idx_;
121 int const sizex = size();
124 if (size() == LM_ST_DISPLAY) incSize();
125 MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
126 den_.draw(pain, x + (width - w1_) / 2, y + den_.Ascent() + 2 - dh_);
128 if (objtype == LM_OT_FRAC)
129 pain.line(x + 2, y - dh_,
130 x + width - 4, y - dh_, LColor::mathline);
136 MathFracInset::Metrics()
141 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
143 int const idxp = idx_;
144 int const sizex = size();
146 if (size() == LM_ST_DISPLAY) incSize();
147 MathParInset::Metrics();
150 int const as = Height() + 2 + dh_;
151 des0_ = Descent() + 2 + dh_;
154 width = ((w0_ > w1_) ? w0_: w1_) + 12;
156 descent = den_.Height()+ 2 - dh_;
161 void MathFracInset::Write(ostream & os, bool fragile)
163 os << '\\' << name << '{';
164 MathParInset::Write(os, fragile);
166 den_.Write(os, fragile);