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) {
44 int MathFracInset::getArgumentIdx() const
50 int MathFracInset::getMaxArgumentIdx() const
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 const & n, MathedArray const & d)
68 MathParInset::setData(n);
72 void MathFracInset::setData(MathedArray const & 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 MathedArray const & MathFracInset::GetData() const
105 return den_.GetData();
109 bool MathFracInset::Inside(int x, int y)
111 int const xx = xo() - (width - w0_) / 2;
115 && y <= yo() + descent
116 && y >= yo() - ascent;
120 void MathFracInset::SetFocus(int /*x*/, int y)
122 // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
123 idx_ = (y > yo()) ? 1 : 0;
127 void MathFracInset::draw(Painter & pain, int x, int y)
129 int const idxp = idx_;
130 int const sizex = size();
133 if (size() == LM_ST_DISPLAY) incSize();
134 MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
135 den_.draw(pain, x + (width - w1_) / 2, y + den_.Ascent() + 2 - dh_);
137 if (objtype == LM_OT_FRAC)
138 pain.line(x + 2, y - dh_,
139 x + width - 4, y - dh_, LColor::mathline);
144 void MathFracInset::Metrics()
149 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
151 int const idxp = idx_;
152 int const sizex = size();
154 if (size() == LM_ST_DISPLAY) incSize();
155 MathParInset::Metrics();
158 int const as = Height() + 2 + dh_;
159 des0_ = Descent() + 2 + dh_;
162 width = ((w0_ > w1_) ? w0_: w1_) + 12;
164 descent = den_.Height()+ 2 - dh_;
168 MathParInset * MathFracInset::denom()
174 void MathFracInset::Write(ostream & os, bool fragile)
176 os << '\\' << name << '{';
177 MathParInset::Write(os, fragile);
179 den_.Write(os, fragile);
184 void MathFracInset::WriteNormal(ostream & os)
186 os << '[' << name << ' ';
187 MathParInset::WriteNormal(os);
189 den_.WriteNormal(os);