#include <config.h>
#include "MathMacroTemplate.h"
-#include "MathMLStream.h"
+#include "MathStream.h"
#include "MathParser.h"
#include "MathSupport.h"
#include "lyxlex.h"
#include "LColor.h"
-#include "frontends/Application.h"
-#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/lstrings.h"
-using lyx::docstring;
-using lyx::support::bformat;
-using std::string;
+namespace lyx {
+
+using support::bformat;
+
using std::auto_ptr;
using std::ostream;
using std::endl;
MathMacroTemplate::MathMacroTemplate()
- : InsetMathNest(2), numargs_(0), name_(), type_("newcommand")
+ : InsetMathNest(2), numargs_(0), name_(), type_(from_ascii("newcommand"))
{
initMath();
}
-MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
- string const & type, MathArray const & ar1, MathArray const & ar2)
- : InsetMathNest(2), numargs_(numargs), name_(nm), type_(type)
+MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs,
+ docstring const & type, MathArray const & ar1, MathArray const & ar2)
+ : InsetMathNest(2), numargs_(numargs), name_(name), type_(type)
{
initMath();
}
-MathMacroTemplate::MathMacroTemplate(std::istream & is)
+MathMacroTemplate::MathMacroTemplate(docstring const & str)
: InsetMathNest(2), numargs_(0), name_()
{
initMath();
MathArray ar;
- mathed_parse_cell(ar, is);
+ mathed_parse_cell(ar, str);
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
- lyxerr << "cannot read macro from '" << ar << "'" << endl;
+ lyxerr << "Cannot read macro from '" << ar << "'" << endl;
return;
}
operator=( *(ar[0]->asMacroTemplate()) );
void MathMacroTemplate::edit(LCursor & cur, bool)
{
- lyxerr << "MathMacroTemplate: edit left/right" << endl;
+ //lyxerr << "MathMacroTemplate: edit left/right" << endl;
cur.push(*this);
}
}
-string MathMacroTemplate::name() const
+docstring MathMacroTemplate::name() const
{
return name_;
}
// FIXME UNICODE
// delete the conversion when bformat() will return a docstring.
// delete the conversion when bformat() takes a docstring arg.
- return bformat(_(" Macro: %1$s: "), lyx::from_utf8(name_));
+ return bformat(_(" Macro: %1$s: "), name_);
}
cell(1).metrics(mi);
docstring dp = prefix();
dim.wid = cell(0).width() + cell(1).width() + 20
- + theApp->fontLoader().metrics(mi.base.font).width(dp);
+ + theFontMetrics(mi.base.font).width(dp);
dim.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 7;
dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7;
dim_ = dim;
docstring dp = prefix();
pi.pain.text(x + 2, y, dp, font);
// FIXME: Painter text should retain the drawn text width
- x += theApp->fontLoader().metrics(font).width(dp) + 6;
+ x += theFontMetrics(font).width(dp) + 6;
int const w0 = cell(0).width();
int const w1 = cell(1).width();
void MathMacroTemplate::read(Buffer const &, LyXLex & lex)
{
MathArray ar;
- mathed_parse_cell(ar, lex.getStream());
+ lex.next(); // eat \begin_inset FormulaMacro line
+ docstring const str = lex.getDocString();
+ lex.next(); // eat that macro definition
+ lex.next(); // eat the \\end_insrt line
+ //lyxerr << "Got to read from: " << to_utf8(str) << endl;
+ mathed_parse_cell(ar, str);
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
- lyxerr << "cannot read macro from '" << ar << "'" << endl;
+ lyxerr << "Cannot read macro from '" << ar << "'" << endl;
+ lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
return;
}
operator=( *(ar[0]->asMacroTemplate()) );
void MathMacroTemplate::write(Buffer const &, std::ostream & os) const
{
- WriteStream wi(os, false, false);
- os << "FormulaMacro\n";
+ odocstringstream oss;
+ WriteStream wi(oss, false, false);
+ oss << "FormulaMacro\n";
write(wi);
+ os << to_utf8(oss.str());
}
{
return MacroData(asString(cell(0)), numargs(), asString(cell(1)));
}
+
+
+} // namespace lyx