+void MathHullInset::infoize(std::ostream & os) const
+{
+ os << "Type: " << type_;
+}
+
+
+void MathHullInset::check() const
+{
+ BOOST_ASSERT(nonum_.size() == nrows());
+ BOOST_ASSERT(label_.size() == nrows());
+}
+
+
+void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
+{
+ string lang;
+ string extra;
+ istringstream iss(func.argument.c_str());
+ iss >> lang >> extra;
+ if (extra.empty())
+ extra = "noextra";
+
+#ifdef WITH_WARNINGS
+#warning temporarily disabled
+ //if (selection()) {
+ // MathArray ar;
+ // selGet(ar);
+ // lyxerr << "use selection: " << ar << endl;
+ // insert(pipeThroughExtern(lang, extra, ar));
+ // return;
+ //}
+#endif
+
+ MathArray eq;
+ eq.push_back(MathAtom(new MathCharInset('=')));
+
+ // go to first item in line
+ cur.idx() -= cur.idx() % ncols();
+ cur.pos() = 0;
+
+ if (getType() == "simple") {
+ size_type pos = cur.cell().find_last(eq);
+ MathArray ar;
+ if (mathcursor && mathcursor->selection()) {
+ asArray(mathcursor->grabAndEraseSelection(cur), ar);
+ } else if (pos == cur.cell().size()) {
+ ar = cur.cell();
+ lyxerr << "use whole cell: " << ar << endl;
+ } else {
+ ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end());
+ lyxerr << "use partial cell form pos: " << pos << endl;
+ }
+ cur.cell().append(eq);
+ cur.cell().append(pipeThroughExtern(lang, extra, ar));
+ cur.pos() = cur.lastpos();
+ return;
+ }
+
+ if (getType() == "equation") {
+ lyxerr << "use equation inset" << endl;
+ mutate("eqnarray");
+ MathArray & ar = cur.cell();
+ lyxerr << "use cell: " << ar << endl;
+ ++cur.idx();
+ cur.cell() = eq;
+ ++cur.idx();
+ cur.cell() = pipeThroughExtern(lang, extra, ar);
+ // move to end of line
+ cur.pos() = cur.lastpos();
+ return;
+ }
+
+ {
+ lyxerr << "use eqnarray" << endl;
+ cur.idx() += 2 - cur.idx() % ncols();
+ cur.pos() = 0;
+ MathArray ar = cur.cell();
+ lyxerr << "use cell: " << ar << endl;
+#ifdef WITH_WARNINGS
+#warning temporarily disabled
+#endif
+ addRow(cur.row());
+ ++cur.idx();
+ ++cur.idx();
+ cur.cell() = eq;
+ ++cur.idx();
+ cur.cell() = pipeThroughExtern(lang, extra, ar);
+ cur.pos() = cur.lastpos();
+ }
+}
+
+
+DispatchResult
+MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+{
+ CursorSlice & cur = cursorTip(bv);
+ switch (cmd.action) {
+
+ case LFUN_BREAKLINE:
+ if (type_ == "simple" || type_ == "equation") {
+ mutate("eqnarray");
+ cur.idx() = 1;
+ cur.pos() = 0;
+ return DispatchResult(true, FINISHED);
+ }
+ return MathGridInset::priv_dispatch(bv, cmd);
+
+ case LFUN_MATH_NUMBER:
+ //lyxerr << "toggling all numbers" << endl;
+ if (display()) {
+ //recordUndo(bv, Undo::INSERT);
+ bool old = numberedType();
+ if (type_ == "multline")
+ numbered(nrows() - 1, !old);
+ else
+ for (row_type row = 0; row < nrows(); ++row)
+ numbered(row, !old);
+ //bv->owner()->message(old ? _("No number") : _("Number"));
+ }
+ return DispatchResult(true, true);
+
+ case LFUN_MATH_NONUMBER:
+ if (display()) {
+ row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+ //recordUndo(bv, Undo::INSERT);
+ bool old = numbered(r);
+ //bv->owner()->message(old ? _("No number") : _("Number"));
+ numbered(r, !old);
+ }
+ return DispatchResult(true, true);
+
+ case LFUN_INSERT_LABEL: {
+ row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+ string old_label = label(r);
+ string new_label = cmd.argument;
+
+ if (new_label.empty()) {
+ string const default_label =
+ (lyxrc.label_init_length >= 0) ? "eq:" : "";
+ pair<bool, string> const res = old_label.empty()
+ ? Alert::askForText(_("Enter new label to insert:"), default_label)
+ : Alert::askForText(_("Enter label:"), old_label);
+ if (!res.first)
+ return DispatchResult(false);
+ new_label = trim(res.second);
+ }
+
+ //if (new_label == old_label)
+ // break; // Nothing to do
+
+ if (!new_label.empty())
+ numbered(r, true);
+ label(r, new_label);
+ return DispatchResult(true, true);
+ }
+
+ case LFUN_MATH_EXTERN:
+ doExtern(bv.fullCursor(), cmd);
+ return DispatchResult(true, FINISHED);
+
+ case LFUN_MATH_MUTATE: {
+ lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
+ row_type r = cur.row();
+ col_type c = cur.col();
+ mutate(cmd.argument);
+ cur.idx() = r * ncols() + c;
+ if (cur.idx() >= nargs())
+ cur.idx() = nargs() - 1;
+ if (cur.pos() > cur.lastpos())
+ cur.pos() = cur.lastpos();
+ return DispatchResult(true, FINISHED);
+ }
+
+ case LFUN_MATH_DISPLAY: {
+ mutate(type_ == "simple" ? "equation" : "simple");
+ cur.idx() = 0;
+ cur.pos() = cur.lastpos();
+ return DispatchResult(true, FINISHED);
+ }
+
+ default:
+ return MathGridInset::priv_dispatch(bv, cmd);
+ }
+}
+
+
+string MathHullInset::fileInsetLabel() const
+{
+ return "Formula";
+}