#include "MathExtern.h"
#include "MathFactory.h"
#include "InsetMathHull.h"
-#include "MathMLStream.h"
+#include "MathStream.h"
#include "MathParser.h"
#include "InsetMathSpace.h"
#include "MathStream.h"
#include <sstream>
-using lyx::docstring;
-using lyx::odocstream;
-using lyx::odocstringstream;
-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;
} // end anon namespace
-HullType hullType(std::string const & s)
+HullType hullType(docstring const & s)
{
if (s == "none") return hullNone;
if (s == "simple") return hullSimple;
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");
}
}
}
-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();
}
}
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)));
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);
}
} // namespace anon
-void InsetMathHull::addPreview(lyx::graphics::PreviewLoader & ploader) const
+void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const
{
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
docstring const snippet = latex_string(*this);
}
-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;
{
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]);
}
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);
}
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] + ')';
}
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];
}
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] + '}';
}
-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_);
}
{
docstring dlang;
docstring extra;
- lyx::idocstringstream iss(func.argument());
+ idocstringstream iss(func.argument());
iss >> dlang >> extra;
if (extra.empty())
- extra = lyx::from_ascii("noextra");
- string const lang = lyx::to_ascii(dlang);
+ extra = from_ascii("noextra");
+ std::string const lang = to_ascii(dlang);
#ifdef WITH_WARNINGS
#warning temporarily disabled
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;
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);
}
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 = lyx::to_utf8(p["name"]);
+ 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);
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();
}
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;
}
|| 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;
}
|| 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;
}
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);
}
-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);
{
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
WriteStream wi(oss, false, false);
oss << "Formula ";
write(wi);
- os << lyx::to_utf8(oss.str());
+ os << to_utf8(oss.str());
}
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);
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(lyx::to_utf8(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(lyx::to_utf8(ls.str()), "&", "&"), "<", "<");
- ms << ETag("alt");
+ ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
+ ms << ETag(from_ascii("alt"));
}
- ms << "<graphic fileref=\"eqn/";
- if ( !label(0).empty())
+ ms << from_ascii("<graphic fileref=\"eqn/");
+ if (!label(0).empty())
ms << sgml::cleanID(buf, runparams, label(0));
else
- ms << sgml::uniqueID("anon");
+ ms << sgml::uniqueID(from_ascii("anon"));
if (runparams.flavor == OutputParams::XML)
- ms << "\"/>";
+ ms << from_ascii("\"/>");
else
- ms << "\">";
+ ms << from_ascii("\">");
- ms << ETag(name.c_str());
+ ms << ETag(name);
return ms.line() + res;
}
{
return plaintext(buf, os, op);
}
+
+
+} // namespace lyx