]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formula.C
further code uglification to make Jean-Marc's compiler happy
[lyx.git] / src / mathed / formula.C
index 88dacdbed85c116473fd9143eb4e823102e85845..b99d255eb971d075756d03cf9a910ba41929f9c7 100644 (file)
@@ -46,9 +46,6 @@ using std::pair;
 using std::endl;
 using std::vector;
 
-extern char const * latex_mathenv[];
-extern MathCursor * mathcursor;
-
 
 InsetFormula::InsetFormula()
        : par_(new MathMatrixInset)
@@ -68,6 +65,13 @@ InsetFormula::InsetFormula(MathInsetTypes t)
 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();
 }
 
@@ -84,40 +88,40 @@ Inset * InsetFormula::clone(Buffer const &, bool) const
 }
 
 
-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);
        return 1;
 }
 
 
-int InsetFormula::ascii(ostream & os, int) const
+int InsetFormula::ascii(Buffer const *, ostream & os, int) const
 {
        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_normal(lex));
        metrics();
@@ -156,6 +160,7 @@ void InsetFormula::metrics() const
        par_->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
 }
 
+
 vector<string> const InsetFormula::getLabelList() const
 {
        return par_->getLabelList();
@@ -172,9 +177,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
 
                case LFUN_BREAKLINE: 
                        bv->lockedInsetStoreUndo(Undo::INSERT);
-                       int x;
-                       int y;
-                       mathcursor->getPos(x, y);
                        mathcursor->breakLine();
                        mathcursor->normalize();
                        updateLocal(bv, true);
@@ -186,7 +188,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        if (display()) {
                                bv->lockedInsetStoreUndo(Undo::INSERT);
                                bool old = par_->numberedType();
-                               for (int row = 0; row < par_->nrows(); ++row)
+                               for (unsigned int row = 0; row < par_->nrows(); ++row)
                                        par_->numbered(row, !old);
                                bv->owner()->message(old ? _("No number") : _("Number"));
                                updateLocal(bv, true);
@@ -288,6 +290,15 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        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);
        }
@@ -342,9 +353,10 @@ void InsetFormula::validate(LaTeXFeatures & features) const
        par_->validate(features);
 }
 
+
 bool InsetFormula::insetAllowed(Inset::Code code) const
 {
-       return code == Inset::LABEL_CODE; 
+       return code == Inset::LABEL_CODE && display()
 }
 
 
@@ -369,5 +381,5 @@ int InsetFormula::width(BufferView *, LyXFont const &) const
 
 MathInsetTypes InsetFormula::getType() const
 {
-       return par_->getType();;
+       return par_->getType();
 }