#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::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");
- string const nl = nicelabel(row);
- docstring const dnl(nl.begin(), nl.end());
- pi.draw(xx, yy, dnl);
+ FontSetChanger dummy(pi.base, from_ascii("mathrm"));
+ docstring const nl = nicelabel(row);
+ pi.draw(xx, yy, nl);
}
}
setPosCache(pi, x, y);
if (display()) {
InsetMathGrid::metricsT(mi, dim);
} else {
- ostringstream os;
+ odocstringstream os;
WriteStream wi(os, false, true);
write(wi);
dim.wid = os.str().size();
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());
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();
} // 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);
}
}
{
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);
}
}
-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;
}
-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)
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);
}
}
-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 from_ascii("(#)");
+ // FIXME UNICODE
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_);
}
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
size_type pos = cur.cell().find_last(eq);
MathArray ar;
if (cur.inMathed() && cur.selection()) {
+ // FIXME UNICODE
asArray(grabAndEraseSelection(cur), ar);
} else if (pos == cur.cell().size()) {
ar = cur.cell();
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 = label(r);
+ docstring const default_label = 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);
- string const data = InsetCommandMailer::params2string("label", p);
+ InsetCommandParams p("label");
+ p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
+ 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;
- InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), p);
- string str = p.getContents();
+ InsetCommandParams p("label");
+ 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);
+ cur.bv().buffer()->changeRefsIfUnique(old, str,
+ InsetBase::REF_CODE);
label(r, str);
}
break;
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
- //theApp->lyxFunc().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
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());
}
}
-int InsetMathHull::plaintext(Buffer const &, ostream & os,
+int InsetMathHull::plaintext(Buffer const &, odocstream & os,
OutputParams const &) const
{
if (0 && display()) {
}
-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 << "<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;
}
-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);
}
+
+
+} // namespace lyx