#include <boost/assert.hpp>
#include <boost/next_prior.hpp>
+#include <cstdlib>
+
using namespace std;
namespace lyx {
dim.asc = 0;
dim.wid = 0;
Dimension d;
- atom_dims_.clear();
+ CoordCacheBase<Inset> & coords = mi.base.bv->coordCache().insets();
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
at->metrics(mi, d);
- atom_dims_.push_back(d);
+ coords.add(at.nucleus(), d);
dim += d;
if (i == n - 1)
- kerning_ = at->kerning();
+ kerning_ = at->kerning(mi.base.bv);
}
// Cache the dimension.
mi.base.bv->coordCache().arrays().add(this, dim);
|| x >= bv. workWidth())
return;
+ CoordCacheBase<Inset> & coords = pi.base.bv->coordCache().insets();
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
- bv.coordCache().insets().add(at.nucleus(), x, y);
+ coords.add(at.nucleus(), x, y);
at->drawSelection(pi, x, y);
at->draw(pi, x, y);
- x += atom_dims_[i].wid;
+ x += coords.dim(at.nucleus()).wid;
}
}
// find arguments behind the macro
if (!interactiveInit) {
collectOptionalParameters(cur, macroOptionals, detachedArgs, p,
- macroPos, thisPos, thisSlice);
+ scriptToPutAround, macroPos, thisPos, thisSlice);
collectParameters(cur, macroNumArgs, detachedArgs, p,
scriptToPutAround, macroPos, thisPos, thisSlice);
}
void MathData::collectOptionalParameters(Cursor * cur,
const size_type numOptionalParams, vector<MathData> & params,
- size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice)
+ size_t & pos, MathAtom & scriptToPutAround,
+ const pos_type macroPos, const int thisPos, const int thisSlice)
{
// insert optional arguments?
- while (params.size() < numOptionalParams && pos < size()) {
+ while (params.size() < numOptionalParams
+ && pos < size()
+ && !scriptToPutAround.nucleus()) {
// is a [] block following which could be an optional parameter?
if (operator[](pos)->getChar() != '[')
break;
// found possible optional argument, look for "]"
size_t right = pos + 1;
for (; right < size(); ++right) {
- if (operator[](right)->getChar() == ']')
+ MathAtom & cell = operator[](right);
+
+ if (cell->getChar() == ']')
// found right end
break;
+
+ // maybe "]" with a script around?
+ InsetMathScript * script = cell.nucleus()->asScriptInset();
+ if (!script)
+ continue;
+ if (script->nuc().size() != 1)
+ continue;
+ if (script->nuc()[0]->getChar() == ']') {
+ // script will be put around the macro later
+ scriptToPutAround = cell;
+ break;
+ }
}
// found?
const pos_type macroPos, const int thisPos, const int thisSlice)
{
// insert normal arguments
- for (; params.size() < numParams && pos < size();) {
+ while (params.size() < numParams
+ && pos < size()
+ && !scriptToPutAround.nucleus()) {
MathAtom & cell = operator[](pos);
// fix cursor
}
-int MathData::pos2x(size_type pos) const
+int MathData::pos2x(BufferView const * bv, size_type pos) const
{
- return pos2x(pos, 0);
+ return pos2x(bv, pos, 0);
}
-int MathData::pos2x(size_type pos, int glue) const
+int MathData::pos2x(BufferView const * bv, size_type pos, int glue) const
{
int x = 0;
size_type target = min(pos, size());
+ CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
for (size_type i = 0; i < target; ++i) {
const_iterator it = begin() + i;
if ((*it)->getChar() == ' ')
x += glue;
//lyxerr << "char: " << (*it)->getChar()
// << "width: " << (*it)->width() << endl;
- x += atom_dims_[i].wid;
+ x += coords.dim((*it).nucleus()).wid;
}
return x;
}
-MathData::size_type MathData::x2pos(int targetx) const
+MathData::size_type MathData::x2pos(BufferView const * bv, int targetx) const
{
- return x2pos(targetx, 0);
+ return x2pos(bv, targetx, 0);
}
-MathData::size_type MathData::x2pos(int targetx, int glue) const
+MathData::size_type MathData::x2pos(BufferView const * bv, int targetx, int glue) const
{
const_iterator it = begin();
int lastx = 0;
int currx = 0;
+ CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
// find first position after targetx
for (; currx < targetx && it < end(); ++it) {
lastx = currx;
if ((*it)->getChar() == ' ')
currx += glue;
- currx += atom_dims_[it - begin()].wid;
+ currx += coords.dim((*it).nucleus()).wid;
}
/**