#include "MacroTable.h"
#include "MathMacro.h"
#include "MathMacroTemplate.h"
+#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParIterator.h"
size_t firstRelOp(MathData const & ar)
{
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
- if ((*it)->isRelOp())
+ if ((*it)->isMathRel())
return it - ar.begin();
return ar.size();
}
}
-docstring InsetMathHull::standardFont() const
+string InsetMathHull::standardFont() const
{
switch (type_) {
case hullRegexp:
- return from_ascii("texttt");
+ return "texttt";
case hullNone:
- return from_ascii("lyxnochange");
+ return "lyxnochange";
default:
- return from_ascii("mathnormal");
+ return "mathnormal";
}
}
return;
}
- FontSetChanger dummy1(mi.base, standardFont());
- StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ // FIXME: Changing the same object repeatedly is inefficient.
+ Changer dummy1 = mi.base.changeFontSet(standardFont());
+ Changer dummy2 = mi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
// let the cells adjust themselves
InsetMathGrid::metrics(mi, dim);
}
if (numberedType()) {
- FontSetChanger dummy(mi.base, from_ascii("mathbf"));
+ Changer dummy = mi.base.changeFontSet("mathbf");
int l = 0;
for (row_type row = 0; row < nrows(); ++row)
l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
ColorCode color = pi.selected && lyxrc.use_system_colors
? Color_selectiontext : standardColor();
bool const really_change_color = pi.base.font.color() == Color_none;
- ColorChanger dummy0(pi.base.font, color, really_change_color);
- FontSetChanger dummy1(pi.base, standardFont());
- StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ Changer dummy0 = pi.base.font.changeColor(color, really_change_color);
+ Changer dummy1 = pi.base.changeFontSet(standardFont());
+ Changer dummy2 = pi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
InsetMathGrid::draw(pi, x + 1, y);
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
for (row_type row = 0; row < nrows(); ++row) {
int const yy = y + rowinfo_[row].offset_;
- FontSetChanger dummy(pi.base, from_ascii("mathrm"));
+ Changer dummy = pi.base.changeFontSet("mathrm");
docstring const nl = nicelabel(row);
pi.draw(xx, yy, nl);
}
}
+namespace {
+
+bool allowDisplayMath(Cursor const & cur)
+{
+ LATTEST(cur.depth() > 1);
+ Cursor tmpcur = cur;
+ tmpcur.pop();
+ FuncStatus status;
+ FuncRequest cmd(LFUN_MATH_DISPLAY);
+ return tmpcur.getStatus(cmd, status) && status.enabled();
+}
+
+}
+
+
bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
status.setOnOff(type_ == ht);
status.setEnabled(isMutable(ht) && isMutable(type_));
- if (ht != hullSimple && status.enabled()) {
- Cursor tmpcur = cur;
- while (!tmpcur.empty()) {
- InsetCode code = tmpcur.inset().lyxCode();
- if (code == BOX_CODE) {
- return true;
- } else if (code == TABULAR_CODE) {
- FuncRequest tmpcmd(LFUN_MATH_DISPLAY);
- if (tmpcur.getStatus(tmpcmd, status) && !status.enabled())
- return true;
- }
- tmpcur.pop_back();
- }
- }
+ if (ht != hullSimple && status.enabled())
+ status.setEnabled(allowDisplayMath(cur));
return true;
}
case LFUN_MATH_DISPLAY: {
- bool enable = true;
- if (cur.depth() > 1) {
- Inset const & in = cur[cur.depth()-2].inset();
- if (in.lyxCode() == SCRIPT_CODE)
- enable = display() != Inline;
- }
- status.setEnabled(enable);
+ status.setEnabled(display() != Inline || allowDisplayMath(cur));
status.setOnOff(display() != Inline);
return true;
}