]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.C
make it compile again (hopefully)
[lyx.git] / src / mathed / InsetMathHull.C
index ebc5f8972c499cc2fd4fe298047c7cccad78ceba..d8666be8bbd78495d8e599ca94fe1b8ed9f3706f 100644 (file)
@@ -61,6 +61,8 @@
 #include <sstream>
 
 using lyx::docstring;
+using lyx::odocstream;
+using lyx::odocstringstream;
 using lyx::cap::grabAndEraseSelection;
 using lyx::support::bformat;
 using lyx::support::subst;
@@ -347,9 +349,8 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
                for (row_type row = 0; row < nrows(); ++row) {
                        int const yy = y + rowinfo_[row].offset_;
                        FontSetChanger dummy(pi.base, "mathrm");
-                       string const nl = nicelabel(row);
-                       docstring const dnl(nl.begin(), nl.end());
-                       pi.draw(xx, yy, dnl);
+                       docstring const nl = nicelabel(row);
+                       pi.draw(xx, yy, nl);
                }
        }
        setPosCache(pi, x, y);
@@ -361,7 +362,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
        if (display()) {
                InsetMathGrid::metricsT(mi, dim);
        } else {
-               ostringstream os;
+               odocstringstream os;
                WriteStream wi(os, false, true);
                write(wi);
                dim.wid = os.str().size();
@@ -376,7 +377,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
        if (display()) {
                InsetMathGrid::drawT(pain, x, y);
        } else {
-               ostringstream os;
+               odocstringstream os;
                WriteStream wi(os, false, true);
                write(wi);
                pain.draw(x, y, os.str().c_str());
@@ -386,9 +387,9 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
 
 namespace {
 
-string const latex_string(InsetMathHull const & inset)
+docstring const latex_string(InsetMathHull const & inset)
 {
-       ostringstream ls;
+       odocstringstream ls;
        WriteStream wi(ls, false, false);
        inset.write(wi);
        return ls.str();
@@ -400,7 +401,7 @@ string const latex_string(InsetMathHull const & inset)
 void InsetMathHull::addPreview(lyx::graphics::PreviewLoader & ploader) const
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               string const snippet = latex_string(*this);
+               docstring const snippet = latex_string(*this);
                preview_->addPreview(snippet, ploader);
        }
 }
@@ -410,7 +411,7 @@ bool InsetMathHull::notifyCursorLeaves(LCursor & cur)
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
                Buffer const & buffer = cur.buffer();
-               string const snippet = latex_string(*this);
+               docstring const snippet = latex_string(*this);
                preview_->addPreview(snippet, buffer);
                preview_->startLoading(buffer);
        }
@@ -463,11 +464,12 @@ bool InsetMathHull::display() const
 }
 
 
-void InsetMathHull::getLabelList(Buffer const &, vector<string> & labels) const
+void InsetMathHull::getLabelList(Buffer const &, vector<docstring> & labels) const
 {
        for (row_type row = 0; row < nrows(); ++row)
                if (!label_[row].empty() && nonum_[row] != 1)
-                       labels.push_back(label_[row]);
+                       // FIXME UNICODE
+                       labels.push_back(lyx::from_utf8(label_[row]));
 }
 
 
@@ -508,37 +510,46 @@ void InsetMathHull::header_write(WriteStream & os) const
 {
        bool n = numberedType();
 
-       if (type_ == hullNone)
-               ;
+       switch(type_) {
+       case hullNone:
+               break;
 
-       else if (type_ == hullSimple) {
+       case hullSimple:
                os << '$';
                if (cell(0).empty())
                        os << ' ';
-       }
+               break;
 
-       else if (type_ == hullEquation) {
+       case hullEquation:
                if (n)
                        os << "\\begin{equation" << star(n) << "}\n";
                else
                        os << "\\[\n";
-       }
+               break;
 
-       else if (type_ == hullEqnArray || type_ == hullAlign || type_ ==
-hullFlAlign
-                || type_ == hullGather || type_ == hullMultline)
-                       os << "\\begin{" << type_ << star(n) << "}\n";
+       case hullEqnArray:
+       case hullAlign:
+       case hullFlAlign:
+       case hullGather:
+       case hullMultline:
+               os << "\\begin{" << hullName(type_) << star(n) << "}\n";
+               break;
 
-       else if (type_ == hullAlignAt || type_ == hullXAlignAt)
-               os << "\\begin{" << type_ << star(n) << '}'
+       case hullAlignAt:
+       case hullXAlignAt:
+               os << "\\begin{" << hullName(type_) << star(n) << '}'
                  << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
+               break;
 
-       else if (type_ == hullXXAlignAt)
-               os << "\\begin{" << type_ << '}'
+       case hullXXAlignAt:
+               os << "\\begin{" << hullName(type_) << '}'
                  << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
+               break;
 
-       else
+       default:
                os << "\\begin{unknown" << star(n) << '}';
+               break;
+       }
 }
 
 
@@ -546,29 +557,40 @@ void InsetMathHull::footer_write(WriteStream & os) const
 {
        bool n = numberedType();
 
-       if (type_ == hullNone)
+       switch(type_) {
+       case hullNone:
                os << "\n";
+               break;
 
-       else if (type_ == hullSimple)
+       case hullSimple:
                os << '$';
+               break;
 
-       else if (type_ == hullEquation)
+       case hullEquation:
                if (n)
                        os << "\\end{equation" << star(n) << "}\n";
                else
                        os << "\\]\n";
+               break;
 
-       else if (type_ == hullEqnArray || type_ == hullAlign || type_ ==
-hullFlAlign
-                || type_ == hullAlignAt || type_ == hullXAlignAt
-                || type_ == hullGather || type_ == hullMultline)
-               os << "\\end{" << type_ << star(n) << "}\n";
+       case hullEqnArray:
+       case hullAlign:
+       case hullFlAlign:
+       case hullAlignAt:
+       case hullXAlignAt:
+       case hullGather:
+       case hullMultline:
+               os << "\\end{" << hullName(type_) << star(n) << "}\n";
+               break;
 
-       else if (type_ == hullXXAlignAt)
-               os << "\\end{" << type_ << "}\n";
+       case hullXXAlignAt:
+               os << "\\end{" << hullName(type_) << "}\n";
+               break;
 
-       else
+       default:
                os << "\\end{unknown" << star(n) << '}';
+               break;
+       }
 }
 
 
@@ -642,13 +664,14 @@ void InsetMathHull::delCol(col_type col)
 }
 
 
-string InsetMathHull::nicelabel(row_type row) const
+docstring InsetMathHull::nicelabel(row_type row) const
 {
        if (nonum_[row])
-               return string();
+               return docstring();
        if (label_[row].empty())
-               return string("(#)");
-       return '(' + label_[row] + ')';
+               return lyx::from_ascii("(#)");
+       // FIXME UNICODE
+       return lyx::from_utf8('(' + label_[row] + ')');
 }
 
 
@@ -873,8 +896,9 @@ void InsetMathHull::mutate(HullType newtype)
        }
 
        else {
-               lyxerr << "mutation from '" << type_
-                      << "' to '" << newtype << "' not implemented" << endl;
+               lyxerr << "mutation from '" << hullName(type_)
+                      << "' to '" << hullName(newtype)
+                      << "' not implemented" << endl;
        }
 }
 
@@ -902,7 +926,7 @@ void InsetMathHull::write(WriteStream & os) const
 
 void InsetMathHull::normalize(NormalStream & os) const
 {
-       os << "[formula " << type_ << ' ';
+       os << "[formula " << hullName(type_) << ' ';
        InsetMathGrid::normalize(os);
        os << "] ";
 }
@@ -916,7 +940,7 @@ void InsetMathHull::mathmlize(MathMLStream & os) const
 
 void InsetMathHull::infoize(ostream & os) const
 {
-       os << "Type: " << type_;
+       os << "Type: " << hullName(type_);
 }
 
 
@@ -929,12 +953,13 @@ void InsetMathHull::check() const
 
 void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
 {
-       string lang;
-       string extra;
-       istringstream iss(lyx::to_utf8(func.argument()));
-       iss >> lang >> extra;
+       docstring dlang;
+       docstring extra;
+       lyx::idocstringstream iss(func.argument());
+       iss >> dlang >> extra;
        if (extra.empty())
-               extra = "noextra";
+               extra = lyx::from_ascii("noextra");
+       string const lang = lyx::to_ascii(dlang);
 
 #ifdef WITH_WARNINGS
 #warning temporarily disabled
@@ -958,7 +983,8 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
                size_type pos = cur.cell().find_last(eq);
                MathArray ar;
                if (cur.inMathed() && cur.selection()) {
-                       asArray(grabAndEraseSelection(cur), ar);
+                       // FIXME UNICODE
+                       asArray(lyx::from_utf8(grabAndEraseSelection(cur)), ar);
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
@@ -1066,15 +1092,14 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_LABEL_INSERT: {
                recordUndoInset(cur);
                row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
-               string old_label = label(r);
-               string const default_label =
-                       (lyxrc.label_init_length >= 0) ? "eq:" : "";
+               docstring old_label = lyx::from_utf8(label(r));
+               docstring const default_label = lyx::from_ascii(
+                       (lyxrc.label_init_length >= 0) ? "eq:" : "");
                if (old_label.empty())
                        old_label = default_label;
-               string const contents = cmd.argument().empty() ?
-                       old_label : lyx::to_utf8(cmd.argument());
 
-               InsetCommandParams p("label", contents);
+               InsetCommandParams p("label");
+               p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
                string const data = InsetCommandMailer::params2string("label", p);
 
                if (cmd.argument().empty())
@@ -1090,7 +1115,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
                //lyxerr << "arg: " << lyx::to_utf8(cmd.argument()) << endl;
                string const name = cmd.getArg(0);
                if (name == "label") {
-                       InsetCommandParams p;
+                       InsetCommandParams p("label");
                        InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), p);
                        string str = p.getContents();
                        recordUndoInset(cur);
@@ -1100,18 +1125,14 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
                                numbered(r, true);
                        string old = label(r);
                        if (str != old) {
-                               cur.bv().buffer()->changeRefsIfUnique(old, str);
+                               cur.bv().buffer()->changeRefsIfUnique(old, str,
+                                                       InsetBase::REF_CODE);
                                label(r, str);
                        }
                        break;
                }
-               MathArray ar;
-               if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
-                       recordUndo(cur);
-                       cur.insert(ar);
-               } else
-                       cur.undispatched();
-               break;
+               InsetMathGrid::doDispatch(cur, cmd);
+               return;
        }
 
        case LFUN_MATH_EXTERN:
@@ -1173,15 +1194,12 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_LABEL_INSERT:
                status.enabled(type_ != hullSimple);
                return true;
-       case LFUN_INSET_INSERT: {
-               // Don't test createInsetMath_fromDialogStr(), since
-               // getStatus is not called with a valid reference and the
-               // dialog would not be applyable.
-               string const name = cmd.getArg(0);
-               status.enabled(name == "ref" ||
-                              (name == "label" && type_ != hullSimple));
-               break;
-       }
+       case LFUN_INSET_INSERT:
+               if (cmd.getArg(0) == "label") {
+                       status.enabled(type_ != hullSimple);
+                       return true;
+               }
+               return InsetMathGrid::getStatus(cur, cmd, status);
        case LFUN_TABULAR_FEATURE: {
                istringstream is(lyx::to_utf8(cmd.argument()));
                string s;
@@ -1261,7 +1279,7 @@ void InsetMathHull::mutateToText()
                view_->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
 
        // remove ourselves
-       //theApp->lyxFunc().dispatch(LFUN_ESCAPE);
+       //lyx::dispatch(LFUN_ESCAPE);
 #endif
 }
 
@@ -1397,9 +1415,11 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
 
 void InsetMathHull::write(Buffer const &, std::ostream & os) const
 {
-       WriteStream wi(os, false, false);
-       os << "Formula ";
+       odocstringstream oss;
+       WriteStream wi(oss, false, false);
+       oss << "Formula ";
        write(wi);
+       os << lyx::to_utf8(oss.str());
 }
 
 
@@ -1411,7 +1431,7 @@ void InsetMathHull::read(Buffer const &, LyXLex & lex)
 }
 
 
-int InsetMathHull::plaintext(Buffer const &, ostream & os,
+int InsetMathHull::plaintext(Buffer const &, odocstream & os,
                        OutputParams const &) const
 {
        if (0 && display()) {
@@ -1435,7 +1455,8 @@ int InsetMathHull::plaintext(Buffer const &, ostream & os,
 int InsetMathHull::docbook(Buffer const & buf, ostream & os,
                          OutputParams const & runparams) const
 {
-       MathMLStream ms(os);
+       odocstringstream oss;
+       MathMLStream ms(oss);
        int res = 0;
        string name;
        if (getType() == hullSimple)
@@ -1448,7 +1469,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os,
                bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\"";
        ms << MTag(bname.c_str());
 
-       ostringstream ls;
+       odocstringstream ls;
        if (runparams.flavor == OutputParams::XML) {
                ms << MTag("alt role=\"tex\" ");
                // Workaround for db2latex: db2latex always includes equations with
@@ -1456,7 +1477,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os,
                // so we strip LyX' math environment
                WriteStream wi(ls, false, false);
                InsetMathGrid::write(wi);
-               ms << subst(subst(ls.str(), "&", "&amp;"), "<", "&lt;");
+               ms << subst(subst(lyx::to_utf8(ls.str()), "&", "&amp;"), "<", "&lt;");
                ms << ETag("alt");
                ms << MTag("math");
                InsetMathGrid::mathmlize(ms);
@@ -1464,7 +1485,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os,
        } else {
                ms << MTag("alt role=\"tex\"");
                res = latex(buf, ls, runparams);
-               ms << subst(subst(ls.str(), "&", "&amp;"), "<", "&lt;");
+               ms << subst(subst(lyx::to_utf8(ls.str()), "&", "&amp;"), "<", "&lt;");
                ms << ETag("alt");
        }
 
@@ -1480,11 +1501,12 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os,
                ms << "\">";
 
        ms << ETag(name.c_str());
+       os << lyx::to_utf8(oss.str());
        return ms.line() + res;
 }
 
 
-int InsetMathHull::textString(Buffer const & buf, ostream & os,
+int InsetMathHull::textString(Buffer const & buf, odocstream & os,
                       OutputParams const & op) const
 {
        return plaintext(buf, os, op);