#include "Buffer.h"
#include "BufferView.h"
+#include "CoordCache.h"
#include "Cursor.h"
#include "support/debug.h"
#include "LaTeXFeatures.h"
///
void metrics(MetricsInfo & mi, Dimension & dim) const {
mathMacro_.macro()->unlock();
- mathMacro_.cell(idx_).metrics(mi, dim);
- if (!mathMacro_.editMetrics(mi.base.bv) && !def_.empty())
+ if (!mathMacro_.editMetrics(mi.base.bv)
+ && mathMacro_.cell(idx_).empty())
def_.metrics(mi, dim);
+ else {
+ CoordCache & coords = mi.base.bv->coordCache();
+ dim = coords.arrays().dim(&mathMacro_.cell(idx_));
+ }
mathMacro_.macro()->lock();
}
///
pi.pain.leaveMonochromeMode();
mathMacro_.cell(idx_).draw(pi, x, y);
pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
- } else {
- if (def_.empty())
- mathMacro_.cell(idx_).draw(pi, x, y);
- else {
- mathMacro_.cell(idx_).setXY(*pi.base.bv, x, y);
- def_.draw(pi, x, y);
- }
- }
+ } else if (mathMacro_.cell(idx_).empty()) {
+ mathMacro_.cell(idx_).setXY(*pi.base.bv, x, y);
+ def_.draw(pi, x, y);
+ } else
+ mathMacro_.cell(idx_).draw(pi, x, y);
}
///
size_t idx() const { return idx_; }
///
int kerning(BufferView const * bv) const
{
- if (mathMacro_.editMetrics(bv) || def_.empty())
+ if (mathMacro_.editMetrics(bv)
+ || !mathMacro_.cell(idx_).empty())
return mathMacro_.cell(idx_).kerning(bv);
else
return def_.kerning(bv);
}
-int MathMacro::cursorIdx(Cursor const & cur) const {
- for (size_t i = 0; i != cur.depth(); ++i)
- if (&cur[i].inset() == this)
- return cur[i].idx();
- return -1;
-}
-
-
bool MathMacro::editMode(BufferView const * bv) const {
// find this in cursor trace
Cursor const & cur = bv->cursor();
} else {
BOOST_ASSERT(macro_ != 0);
+ // metrics are computed here for the cells,
+ // in the proxy we will then use the dim from the cache
+ InsetMathNest::metrics(mi);
+
// calculate metrics finally
macro_->lock();
expanded_.cell(0).metrics(mi, dim);
void MathMacro::updateRepresentation(Cursor const * bvCur)
{
- // index of child where the cursor is (or -1 if none is edited)
- int curIdx = -1;
- if (bvCur) {
- curIdx = cursorIdx(*bvCur);
- previousCurIdx_[&bvCur->bv()] = curIdx;
- }
-
// known macro?
if (macro_ == 0)
return;
vector<MathData> values(nargs());
for (size_t i = 0; i < nargs(); ++i) {
ArgumentProxy * proxy;
- if (!cell(i).empty()
- || i >= defaults.size()
- || defaults[i].empty()
- || curIdx == (int)i)
- proxy = new ArgumentProxy(*this, i);
- else
+ if (i < defaults.size())
proxy = new ArgumentProxy(*this, i, defaults[i]);
+ else
+ proxy = new ArgumentProxy(*this, i);
values[i].insert(0, MathAtom(proxy));
}
// expanding macro with the values
macro_->expand(values, expanded_.cell(0));
- }
+ }
}
pi.pain.rectangle(x, y - dim.asc, dim.wid, dim.height(), Color_mathmacroframe);
}
- // another argument selected or edit mode changed?
- idx_type curIdx = cursorIdx(pi.base.bv->cursor());
- if (previousCurIdx_[pi.base.bv] != curIdx
- || editing_[pi.base.bv] != editMode(pi.base.bv))
+ // edit mode changed?
+ if (editing_[pi.base.bv] != editMode(pi.base.bv))
pi.base.bv->cursor().updateFlags(Update::Force);
}