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 bool MathFracInset::Inside(int x, int y)
92 int const xx = xo() - (width - w0_) / 2;
96 && y <= yo() + descent
97 && y >= yo() - ascent;
101 void MathFracInset::SetFocus(int /*x*/, int y)
103 // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
104 idx_ = (y > yo()) ? 1 : 0;
109 MathFracInset::draw(Painter & pain, int x, int y)
111 int const idxp = idx_;
112 int const sizex = size();
115 if (size() == LM_ST_DISPLAY) incSize();
116 MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
117 den_.draw(pain, x + (width - w1_) / 2, y + den_.Ascent() + 2 - dh_);
119 if (objtype == LM_OT_FRAC)
120 pain.line(x + 2, y - dh_,
121 x + width - 4, y - dh_, LColor::mathline);
127 MathFracInset::Metrics()
132 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
134 int const idxp = idx_;
135 int const sizex = size();
137 if (size() == LM_ST_DISPLAY) incSize();
138 MathParInset::Metrics();
141 int const as = Height() + 2 + dh_;
142 des0_ = Descent() + 2 + dh_;
145 width = ((w0_ > w1_) ? w0_: w1_) + 12;
147 descent = den_.Height()+ 2 - dh_;
152 void MathFracInset::Write(ostream & os, bool fragile)
154 os << '\\' << name << '{';
155 MathParInset::Write(os, fragile);
157 den_.Write(os, fragile);