#include "support/LOstream.h"
#include "support/lyxlib.h"
#include "support/syscall.h"
+#include "support/lstrings.h"
#include "LyXView.h"
#include "Painter.h"
#include "lyxrc.h"
using std::endl;
using std::vector;
-extern char const * latex_mathenv[];
-extern MathCursor * mathcursor;
-
-// quite a hack i know. Should be done with return values...
-int number_of_newlines = 0;
+InsetFormula::InsetFormula()
+ : par_(new MathMatrixInset)
+{}
-InsetFormula::InsetFormula()
- : InsetFormulaBase(new MathMatrixInset)
+InsetFormula::InsetFormula(const InsetFormula & f)
+ : InsetFormulaBase(f), par_(static_cast<MathMatrixInset *>(f.par_->clone()))
{}
InsetFormula::InsetFormula(MathInsetTypes t)
- : InsetFormulaBase(new MathMatrixInset(t))
+ : par_(new MathMatrixInset(t))
{}
-InsetFormula::InsetFormula(string const & s)
- : InsetFormulaBase(mathed_parse(s))
+InsetFormula::InsetFormula(string const & s)
+ : par_(mathed_parse_normal(s))
{
+ if (!par_)
+ par_ = mathed_parse_normal("$" + s + "$");
+
+ if (!par_) {
+ lyxerr << "cannot interpret '" << s << "' as math\n";
+ par_ = new MathMatrixInset(LM_OT_SIMPLE);
+ }
metrics();
}
+InsetFormula::~InsetFormula()
+{
+ delete par_;
+}
+
+
Inset * InsetFormula::clone(Buffer const &, bool) const
{
return new InsetFormula(*this);
}
-void InsetFormula::write(ostream & os) const
+void InsetFormula::write(Buffer const * buf, ostream & os) const
{
os << "Formula ";
- latex(os, false, false);
+ latex(buf, os, false, false);
}
-int InsetFormula::latex(ostream & os, bool fragile, bool) const
+int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
{
- par()->write(os, fragile);
+ par_->write(os, fragile);
return 1;
}
-int InsetFormula::ascii(ostream & os, int) const
+int InsetFormula::ascii(Buffer const *, ostream & os, int) const
{
- par()->write(os, false);
+ par_->write(os, false);
return 1;
}
-int InsetFormula::linuxdoc(ostream & os) const
+int InsetFormula::linuxdoc(Buffer const * buf, ostream & os) const
{
- return ascii(os, 0);
+ return ascii(buf, os, 0);
}
-int InsetFormula::docBook(ostream & os) const
+int InsetFormula::docbook(Buffer const * buf, ostream & os) const
{
- return ascii(os, 0);
+ return ascii(buf, os, 0);
}
-void InsetFormula::read(LyXLex & lex)
+void InsetFormula::read(Buffer const *, LyXLex & lex)
{
- par(mathed_parse(lex));
+ par(mathed_parse_normal(lex));
metrics();
}
Painter & pain = bv->painter();
metrics();
- int w = par()->width();
- int h = par()->height();
- int a = par()->ascent();
+ int w = par_->width();
+ int h = par_->height();
+ int a = par_->ascent();
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
if (mathcursor && mathcursor->formula() == this) {
pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
- par()->draw(pain, x, y);
- xx += par()->width();
+ par_->draw(pain, x, y);
+ xx += par_->width();
setCursorVisible(false);
}
void InsetFormula::metrics() const
{
- const_cast<MathInset *>(par_)->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ par_->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
}
+
vector<string> const InsetFormula::getLabelList() const
{
- return par()->getLabelList();
+ return par_->getLabelList();
}
case LFUN_BREAKLINE:
bv->lockedInsetStoreUndo(Undo::INSERT);
- int x;
- int y;
- mathcursor->getPos(x, y);
mathcursor->breakLine();
mathcursor->normalize();
updateLocal(bv, true);
//lyxerr << "toggling all numbers\n";
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
- bool old = par()->numberedType();
- for (int row = 0; row < par()->nrows(); ++row)
- par()->numbered(row, !old);
+ bool old = par_->numberedType();
+ for (unsigned int row = 0; row < par_->nrows(); ++row)
+ par_->numbered(row, !old);
bv->owner()->message(old ? _("No number") : _("Number"));
updateLocal(bv, true);
}
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
int row = mathcursor->row();
- bool old = par()->numbered(row);
+ bool old = par_->numbered(row);
bv->owner()->message(old ? _("No number") : _("Number"));
- par()->numbered(row, !old);
+ par_->numbered(row, !old);
updateLocal(bv, true);
}
break;
bv->lockedInsetStoreUndo(Undo::INSERT);
int row = mathcursor->row();
- string old_label = par()->label(row);
+ string old_label = par_->label(row);
string new_label = arg;
if (new_label.empty()) {
if (!new_label.empty()) {
lyxerr << "setting label to '" << new_label << "'\n";
- par()->numbered(row, true);
+ par_->numbered(row, true);
}
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw();
- par()->label(row, new_label);
+ par_->label(row, new_label);
updateLocal(bv, true);
break;
int x;
int y;
mathcursor->getPos(x, y);
- par()->mutate(arg);
+ par_->mutate(arg);
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
int x;
int y;
mathcursor->getPos(x, y);
- if (par()->getType() == LM_OT_SIMPLE)
- par()->mutate(LM_OT_EQUATION);
+ if (par_->getType() == LM_OT_SIMPLE)
+ par_->mutate(LM_OT_EQUATION);
else
- par()->mutate(LM_OT_SIMPLE);
+ par_->mutate(LM_OT_SIMPLE);
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
{
string const clip = bv->getClipboard();
if (!clip.empty())
- par(mathed_parse(clip));
+ par(mathed_parse_normal(clip));
break;
}
+ case LFUN_MATH_COLUMN_INSERT:
+ {
+ if (par_->getType() == LM_OT_ALIGN)
+ par_->mutate(LM_OT_ALIGNAT);
+ par_->addCol(par_->ncols());
+ mathcursor->normalize();
+ updateLocal(bv, true);
+ }
+
default:
result = InsetFormulaBase::localDispatch(bv, action, arg);
}
//string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + arg + ".out";
ostringstream os;
- par()->writeNormal(os);
+ par_->writeNormal(os);
string code = os.str().c_str();
string script = "lyx2" + arg + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
ifstream is(outfile.c_str());
- par(mathed_parse(is));
+ par(mathed_parse_normal(is));
metrics();
}
}
-MathMatrixInset * InsetFormula::par() const
+MathInset const * InsetFormula::par() const
{
- return static_cast<MathMatrixInset *>(par_);
+ return par_;
}
-void InsetFormula::par(MathInset * p)
+
+void InsetFormula::par(MathMatrixInset * p)
{
delete par_;
- par_ = p ? p : new MathMatrixInset;
+ par_ = p ? static_cast<MathMatrixInset *>(p) : new MathMatrixInset;
}
void InsetFormula::validate(LaTeXFeatures & features) const
{
- par()->validate(features);
+ par_->validate(features);
}
+
bool InsetFormula::insetAllowed(Inset::Code code) const
{
- return code == Inset::LABEL_CODE;
+ return code == Inset::LABEL_CODE && display();
}
int InsetFormula::ascent(BufferView *, LyXFont const &) const
{
- return par()->ascent() + 1;
+ return par_->ascent() + 1;
}
int InsetFormula::descent(BufferView *, LyXFont const &) const
{
- return par()->descent() + 1;
+ return par_->descent() + 1;
}
int InsetFormula::width(BufferView *, LyXFont const &) const
{
metrics();
- return par()->width();
+ return par_->width();
+}
+
+
+MathInsetTypes InsetFormula::getType() const
+{
+ return par_->getType();
}