2001-08-03 17:10:22 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_nestinset.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2001-10-24 18:10:21 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathNestInset::MathNestInset(idx_type nargs)
|
2001-08-03 17:55:10 +00:00
|
|
|
: MathDimInset(), cells_(nargs)
|
2001-08-08 17:26:30 +00:00
|
|
|
{}
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathInset::idx_type MathNestInset::nargs() const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return cells_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathXArray & MathNestInset::xcell(idx_type i)
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return cells_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathXArray const & MathNestInset::xcell(idx_type i) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return cells_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathArray & MathNestInset::cell(idx_type i)
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return cells_[i].data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathArray const & MathNestInset::cell(idx_type i) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return cells_[i].data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 15:46:51 +00:00
|
|
|
void MathNestInset::substitute(MathMacro const & m)
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-09-11 15:46:51 +00:00
|
|
|
cell(i).substitute(m);
|
2001-08-03 17:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathNestInset::metrics(MathMetricsInfo const & mi) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-10-22 15:37:49 +00:00
|
|
|
xcell(i).metrics(mi);
|
2001-08-03 17:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathNestInset::draw(Painter & pain, int x, int y) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-08-03 17:10:22 +00:00
|
|
|
xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (idx + 1 >= nargs())
|
|
|
|
return false;
|
|
|
|
++idx;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return idxNext(idx, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
return false;
|
|
|
|
--idx;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
return idxPrev(idx, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (nargs() == 0)
|
|
|
|
return false;
|
|
|
|
i = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (nargs() == 0)
|
|
|
|
return false;
|
|
|
|
i = nargs() - 1;
|
|
|
|
pos = cell(i).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (pos == 0)
|
|
|
|
return false;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
pos_type n = cell(idx).size();
|
2001-09-14 14:05:57 +00:00
|
|
|
if (pos == n)
|
2001-08-03 17:10:22 +00:00
|
|
|
return false;
|
2001-09-14 14:05:57 +00:00
|
|
|
pos = n;
|
2001-08-03 17:10:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::dump() const
|
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
MathWriteInfo os(lyxerr);
|
|
|
|
os << "---------------------------------------------\n";
|
|
|
|
write(os);
|
|
|
|
os << "\n";
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-10-19 11:25:48 +00:00
|
|
|
os << cell(i) << "\n";
|
|
|
|
os << "---------------------------------------------\n";
|
2001-08-03 17:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathNestInset::push_back(MathAtom const & t)
|
2001-08-03 17:10:22 +00:00
|
|
|
{
|
|
|
|
if (nargs())
|
2001-10-12 12:02:49 +00:00
|
|
|
cells_.back().data_.push_back(t);
|
2001-08-03 17:10:22 +00:00
|
|
|
else
|
|
|
|
lyxerr << "can't push without a cell\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-08-03 17:10:22 +00:00
|
|
|
cell(i).validate(features);
|
|
|
|
}
|
2001-10-24 09:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool MathNestInset::covers(int x, int y) const
|
|
|
|
{
|
|
|
|
if (!nargs())
|
|
|
|
return false;
|
|
|
|
int x0 = xcell(0).xo();
|
|
|
|
int y0 = xcell(0).yo() - xcell(0).ascent();
|
|
|
|
int x1 = xcell(0).xo() + xcell(0).width();
|
|
|
|
int y1 = xcell(0).yo() + xcell(0).descent();
|
|
|
|
for (idx_type i = 1; i < nargs(); ++i) {
|
|
|
|
x0 = min(x0, xcell(i).xo());
|
|
|
|
y0 = min(y0, xcell(i).yo() - xcell(i).ascent());
|
|
|
|
x1 = max(x1, xcell(i).xo() + xcell(i).width());
|
|
|
|
y1 = max(y1, xcell(i).yo() + xcell(i).descent());
|
|
|
|
}
|
|
|
|
return x >= x0 && x <= x1 && y >= y0 && y <= y1;
|
|
|
|
}
|