X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathHull.C;h=8ee9abe9aebc371be7c449ac3cae093edfa2d101;hb=2db7521b7080d63acbcd3bd5bfe892f5a414b2b0;hp=4a640da966943ebef6204bfaaef9a912401e2b90;hpb=b02242bfaf88de225615770ec907e25a443a15cd;p=features.git diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index 4a640da966..8ee9abe9ae 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -18,7 +18,7 @@ #include "MathExtern.h" #include "MathFactory.h" #include "InsetMathHull.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "InsetMathSpace.h" #include "MathStream.h" @@ -60,18 +60,18 @@ #include -using lyx::docstring; -using lyx::cap::grabAndEraseSelection; -using lyx::support::bformat; -using lyx::support::subst; + +namespace lyx { + +using cap::grabAndEraseSelection; +using support::bformat; +using support::subst; using std::endl; using std::max; -using std::string; using std::ostream; using std::auto_ptr; using std::istringstream; -using std::ostream; using std::ostringstream; using std::pair; using std::swap; @@ -117,7 +117,7 @@ namespace { } // end anon namespace -HullType hullType(std::string const & s) +HullType hullType(docstring const & s) { if (s == "none") return hullNone; if (s == "simple") return hullSimple; @@ -130,28 +130,28 @@ HullType hullType(std::string const & s) if (s == "multline") return hullMultline; if (s == "gather") return hullGather; if (s == "flalign") return hullFlAlign; - lyxerr << "unknown hull type '" << s << "'" << endl; + lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl; return HullType(-1); } -std::string hullName(HullType type) +docstring hullName(HullType type) { switch (type) { - case hullNone: return "none"; - case hullSimple: return "simple"; - case hullEquation: return "equation"; - case hullEqnArray: return "eqnarray"; - case hullAlign: return "align"; - case hullAlignAt: return "alignat"; - case hullXAlignAt: return "xalignat"; - case hullXXAlignAt: return "xxalignat"; - case hullMultline: return "multline"; - case hullGather: return "gather"; - case hullFlAlign: return "flalign"; + case hullNone: return from_ascii("none"); + case hullSimple: return from_ascii("simple"); + case hullEquation: return from_ascii("equation"); + case hullEqnArray: return from_ascii("eqnarray"); + case hullAlign: return from_ascii("align"); + case hullAlignAt: return from_ascii("alignat"); + case hullXAlignAt: return from_ascii("xalignat"); + case hullXXAlignAt: return from_ascii("xxalignat"); + case hullMultline: return from_ascii("multline"); + case hullGather: return from_ascii("gather"); + case hullFlAlign: return from_ascii("flalign"); default: lyxerr << "unknown hull type '" << type << "'" << endl; - return "none"; + return from_ascii("none"); } } @@ -266,16 +266,16 @@ int InsetMathHull::defaultColSpace(col_type col) } -char const * InsetMathHull::standardFont() const +docstring InsetMathHull::standardFont() const { - return type_ == hullNone ? "lyxnochange" : "mathnormal"; + return from_ascii(type_ == hullNone ? "lyxnochange" : "mathnormal"); } bool InsetMathHull::previewState(BufferView * bv) const { if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) { - lyx::graphics::PreviewImage const * pimage = + graphics::PreviewImage const * pimage = preview_->getPreviewImage(*bv->buffer()); return pimage && pimage->image(); } @@ -307,7 +307,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const } if (numberedType()) { - FontSetChanger dummy(mi.base, "mathbf"); + FontSetChanger dummy(mi.base, from_ascii("mathbf")); int l = 0; for (row_type row = 0; row < nrows(); ++row) l = max(l, mathed_string_width(mi.base.font, nicelabel(row))); @@ -346,7 +346,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const 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, "mathrm"); + FontSetChanger dummy(pi.base, from_ascii("mathrm")); docstring const nl = nicelabel(row); pi.draw(xx, yy, nl); } @@ -360,7 +360,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(); @@ -375,7 +375,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()); @@ -385,9 +385,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(); @@ -396,10 +396,10 @@ string const latex_string(InsetMathHull const & inset) } // namespace anon -void InsetMathHull::addPreview(lyx::graphics::PreviewLoader & ploader) const +void InsetMathHull::addPreview(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); } } @@ -409,7 +409,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); } @@ -417,14 +417,14 @@ bool InsetMathHull::notifyCursorLeaves(LCursor & cur) } -string InsetMathHull::label(row_type row) const +docstring InsetMathHull::label(row_type row) const { BOOST_ASSERT(row < nrows()); return label_[row]; } -void InsetMathHull::label(row_type row, string const & label) +void InsetMathHull::label(row_type row, docstring const & label) { //lyxerr << "setting label '" << label << "' for row " << row << endl; label_[row] = label; @@ -466,8 +466,7 @@ void InsetMathHull::getLabelList(Buffer const &, vector & labels) con { for (row_type row = 0; row < nrows(); ++row) if (!label_[row].empty() && nonum_[row] != 1) - // FIXME UNICODE - labels.push_back(lyx::from_utf8(label_[row])); + labels.push_back(label_[row]); } @@ -615,7 +614,7 @@ void InsetMathHull::addRow(row_type row) if (!rowChangeOK()) return; nonum_.insert(nonum_.begin() + row + 1, !numberedType()); - label_.insert(label_.begin() + row + 1, string()); + label_.insert(label_.begin() + row + 1, docstring()); InsetMathGrid::addRow(row); } @@ -667,9 +666,9 @@ docstring InsetMathHull::nicelabel(row_type row) const if (nonum_[row]) return docstring(); if (label_[row].empty()) - return lyx::from_ascii("(#)"); + return from_ascii("(#)"); // FIXME UNICODE - return lyx::from_utf8('(' + label_[row] + ')'); + return '(' + label_[row] + ')'; } @@ -822,7 +821,7 @@ void InsetMathHull::mutate(HullType newtype) allnonum = false; // set first non-empty label - string label; + docstring label; for (row_type row = 0; row < nrows(); ++row) { if (!label_[row].empty()) { label = label_[row]; @@ -894,16 +893,16 @@ void InsetMathHull::mutate(HullType newtype) } else { - lyxerr << "mutation from '" << hullName(type_) - << "' to '" << hullName(newtype) + lyxerr << "mutation from '" << to_utf8(hullName(type_)) + << "' to '" << to_utf8(hullName(newtype)) << "' not implemented" << endl; } } -string InsetMathHull::eolString(row_type row, bool emptyline, bool fragile) const +docstring InsetMathHull::eolString(row_type row, bool emptyline, bool fragile) const { - string res; + docstring res; if (numberedType()) { if (!label_[row].empty() && !nonum_[row]) res += "\\label{" + label_[row] + '}'; @@ -930,13 +929,13 @@ void InsetMathHull::normalize(NormalStream & os) const } -void InsetMathHull::mathmlize(MathMLStream & os) const +void InsetMathHull::mathmlize(MathStream & os) const { InsetMathGrid::mathmlize(os); } -void InsetMathHull::infoize(ostream & os) const +void InsetMathHull::infoize(odocstream & os) const { os << "Type: " << hullName(type_); } @@ -951,12 +950,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; + idocstringstream iss(func.argument()); + iss >> dlang >> extra; if (extra.empty()) - extra = "noextra"; + extra = from_ascii("noextra"); + std::string const lang = to_ascii(dlang); #ifdef WITH_WARNINGS #warning temporarily disabled @@ -981,7 +981,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) MathArray ar; if (cur.inMathed() && cur.selection()) { // FIXME UNICODE - asArray(lyx::from_utf8(grabAndEraseSelection(cur)), ar); + asArray(grabAndEraseSelection(cur), ar); } else if (pos == cur.cell().size()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; @@ -1053,7 +1053,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) if (type_ == hullSimple || type_ == hullEquation) { recordUndoInset(cur); bool const align = - cur.bv().buffer()->params().use_amsmath == BufferParams::AMS_ON; + cur.bv().buffer()->params().use_amsmath == BufferParams::package_on; mutate(align ? hullAlign : hullEqnArray); cur.idx() = 0; cur.pos() = cur.lastpos(); @@ -1089,15 +1089,15 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_LABEL_INSERT: { recordUndoInset(cur); row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row(); - docstring old_label = lyx::from_utf8(label(r)); - docstring const default_label = lyx::from_ascii( + docstring old_label = label(r); + docstring const default_label = from_ascii( (lyxrc.label_init_length >= 0) ? "eq:" : ""); if (old_label.empty()) old_label = default_label; InsetCommandParams p("label"); p["name"] = cmd.argument().empty() ? old_label : cmd.argument(); - string const data = InsetCommandMailer::params2string("label", p); + std::string const data = InsetCommandMailer::params2string("label", p); if (cmd.argument().empty()) cur.bv().showInsetDialog("label", data, 0); @@ -1109,18 +1109,18 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_INSET_INSERT: { - //lyxerr << "arg: " << lyx::to_utf8(cmd.argument()) << endl; - string const name = cmd.getArg(0); + //lyxerr << "arg: " << to_utf8(cmd.argument()) << endl; + std::string const name = cmd.getArg(0); if (name == "label") { InsetCommandParams p("label"); - InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), p); - string str = p.getContents(); + InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), p); + docstring str = p["name"]; recordUndoInset(cur); row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row(); - str = lyx::support::trim(str); + str = support::trim(str); if (!str.empty()) numbered(r, true); - string old = label(r); + docstring old = label(r); if (str != old) { cur.bv().buffer()->changeRefsIfUnique(old, str, InsetBase::REF_CODE); @@ -1141,7 +1141,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) recordUndoInset(cur); row_type row = cur.row(); col_type col = cur.col(); - mutate(hullType(lyx::to_utf8(cmd.argument()))); + mutate(hullType(cmd.argument())); cur.idx() = row * ncols() + col; if (cur.idx() > cur.lastidx()) { cur.idx() = cur.lastidx(); @@ -1198,16 +1198,16 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, } return InsetMathGrid::getStatus(cur, cmd, status); case LFUN_TABULAR_FEATURE: { - istringstream is(lyx::to_utf8(cmd.argument())); - string s; + istringstream is(to_utf8(cmd.argument())); + std::string s; is >> s; if (!rowChangeOK() && (s == "append-row" || s == "delete-row" || s == "copy-row")) { status.message(bformat( - lyx::from_utf8(N_("Can't change number of rows in '%1$s'")), - lyx::from_utf8(hullName(type_)))); + from_utf8(N_("Can't change number of rows in '%1$s'")), + hullName(type_))); status.enabled(false); return true; } @@ -1216,8 +1216,8 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, || s == "delete-column" || s == "copy-column")) { status.message(bformat( - lyx::from_utf8(N_("Can't change number of columns in '%1$s'")), - lyx::from_utf8(hullName(type_)))); + from_utf8(N_("Can't change number of columns in '%1$s'")), + hullName(type_))); status.enabled(false); return true; } @@ -1226,15 +1226,15 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, || type_ == hullNone) && (s == "add-hline-above" || s == "add-hline-below")) { status.message(bformat( - lyx::from_utf8(N_("Can't add horizontal grid lines in '%1$s'")), - lyx::from_utf8(hullName(type_)))); + from_utf8(N_("Can't add horizontal grid lines in '%1$s'")), + hullName(type_))); status.enabled(false); return true; } if (s == "add-vline-left" || s == "add-vline-right") { status.message(bformat( - lyx::from_utf8(N_("Can't add vertical grid lines in '%1$s'")), - lyx::from_utf8(hullName(type_)))); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), + hullName(type_))); status.enabled(false); return true; } @@ -1276,19 +1276,19 @@ void InsetMathHull::mutateToText() view_->getIntl()->getTransManager().TranslateAndInsert(*cit, lt); // remove ourselves - //lyx::dispatch(LFUN_ESCAPE); + //dispatch(LFUN_ESCAPE); #endif } -void InsetMathHull::handleFont(LCursor & cur, string const & arg, - string const & font) +void InsetMathHull::handleFont(LCursor & cur, docstring const & arg, + docstring const & font) { // this whole function is a hack and won't work for incremental font // changes... recordUndo(cur); if (cur.inset().asInsetMath()->name() == font) - cur.handleFont(font); + cur.handleFont(to_utf8(font)); else { cur.handleNest(createInsetMath(font)); cur.insert(arg); @@ -1296,12 +1296,12 @@ void InsetMathHull::handleFont(LCursor & cur, string const & arg, } -void InsetMathHull::handleFont2(LCursor & cur, string const & arg) +void InsetMathHull::handleFont2(LCursor & cur, docstring const & arg) { recordUndo(cur); LyXFont font; bool b; - bv_funcs::string2font(arg, font, b); + bv_funcs::string2font(to_utf8(arg), font, b); if (font.color() != LColor::inherit) { MathAtom at = MathAtom(new InsetMathColor(true, font.color())); cur.handleNest(at, 0); @@ -1326,9 +1326,9 @@ void InsetMathHull::revealCodes(LCursor & cur) const { if (!cur.inMathed()) return; - ostringstream os; + odocstringstream os; cur.info(os); - cur.message(lyx::from_utf8(os.str())); + cur.message(os.str()); /* // write something to the minibuffer // translate to latex @@ -1412,9 +1412,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 << to_utf8(oss.str()); } @@ -1426,7 +1428,7 @@ void InsetMathHull::read(Buffer const &, LyXLex & lex) } -int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, +int InsetMathHull::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { if (0 && display()) { @@ -1440,70 +1442,72 @@ int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, //metrics(); return tpain.textheight(); } else { - std::ostringstream oss; - WriteStream wi(oss, false, true); + WriteStream wi(os, false, true); wi << cell(0); - // FIXME UNICODE - os << lyx::from_utf8(oss.str()); return wi.line(); } } -int InsetMathHull::docbook(Buffer const & buf, ostream & os, +int InsetMathHull::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - MathMLStream ms(os); + MathStream ms(os); int res = 0; - string name; + docstring name; if (getType() == hullSimple) - name = "inlineequation"; + name = from_ascii("inlineequation"); else - name = "informalequation"; + name = from_ascii("informalequation"); - string bname = name; + docstring bname = name; if (!label(0).empty()) - bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\""; - ms << MTag(bname.c_str()); + bname += " id='" + sgml::cleanID(buf, runparams, label(0)) + "'"; + ms << MTag(bname); - ostringstream ls; + odocstringstream ls; if (runparams.flavor == OutputParams::XML) { - ms << MTag("alt role=\"tex\" "); + ms << MTag(from_ascii("alt role='tex' ")); // Workaround for db2latex: db2latex always includes equations with // \ensuremath{} or \begin{display}\end{display} // so we strip LyX' math environment WriteStream wi(ls, false, false); InsetMathGrid::write(wi); - ms << subst(subst(ls.str(), "&", "&"), "<", "<"); - ms << ETag("alt"); - ms << MTag("math"); + ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<")); + ms << ETag(from_ascii("alt")); + ms << MTag(from_ascii("math")); + ms << ETag(from_ascii("alt")); + ms << MTag(from_ascii("math")); InsetMathGrid::mathmlize(ms); - ms << ETag("math"); + ms << ETag(from_ascii("math")); } else { - ms << MTag("alt role=\"tex\""); + ms << MTag(from_ascii("alt role='tex'")); res = latex(buf, ls, runparams); - ms << subst(subst(ls.str(), "&", "&"), "<", "<"); - ms << ETag("alt"); + ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<")); + ms << ETag(from_ascii("alt")); } - ms << ""; + ms << from_ascii("\"/>"); else - ms << "\">"; + ms << from_ascii("\">"); - ms << ETag(name.c_str()); + ms << ETag(name); return ms.line() + res; } -int InsetMathHull::textString(Buffer const & buf, lyx::odocstream & os, +int InsetMathHull::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); } + + +} // namespace lyx