]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formula.C
fix compilation error
[lyx.git] / src / mathed / formula.C
index 9dc7b582c3261e18616f8da691127642cdee2570..a6c0b602018d1942208792fcdc2a17c6e4868572 100644 (file)
@@ -44,7 +44,6 @@
 #include "math_support.h"
 #include "math_mathmlstream.h"
 #include "textpainter.h"
-#include "preview.h"
 
 #include <fstream>
 #include <boost/bind.hpp>
@@ -65,29 +64,24 @@ InsetFormula::InsetFormula()
 {}
 
 
-InsetFormula::InsetFormula(MathInsetTypes t)
-       : par_(MathAtom(new MathHullInset(t))), loader_(0)
-{}
-
-
-InsetFormula::InsetFormula(string const & s)
+InsetFormula::InsetFormula(BufferView * bv)
+       : par_(MathAtom(new MathHullInset)), loader_(0)
 {
-       if (s.size()) {
-               bool res = mathed_parse_normal(par_, s);
+       view_ = bv;
+}
 
-               if (!res)
-                       res = mathed_parse_normal(par_, "$" + s + "$");
 
-               if (!res) {
-                       lyxerr << "cannot interpret '" << s << "' as math\n";
-                       par_ = MathAtom(new MathHullInset(LM_OT_SIMPLE));
-               }
-       }
-       metrics();
-       updatePreview();
+InsetFormula::InsetFormula(string const & data)
+       : par_(MathAtom(new MathHullInset)), loader_(0)
+{
+       if (!data.size())
+               return;
+       if (!mathed_parse_normal(par_, data)) 
+               lyxerr << "cannot interpret '" << data << "' as math\n";
 }
 
 
+
 Inset * InsetFormula::clone(Buffer const &, bool) const
 {
        return new InsetFormula(*this);
@@ -110,6 +104,7 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
 }
 
 
+
 int InsetFormula::ascii(Buffer const *, ostream & os, int) const
 {
 #if 0
@@ -181,7 +176,8 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
        if (canPreview()) {
                pi.pain.image(x + 1, y - a + 1, w - 2, h - 2, *(loader_->image()));
        } else {
-               pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
+               //pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
+               pi.base.style = LM_ST_TEXT;
                pi.base.font  = font;
                pi.base.font.setColor(LColor::math);
                if (lcolor.getX11Name(LColor::mathbg)
@@ -299,7 +295,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        int x;
                        int y;
                        mathcursor->getPos(x, y);
-                       hull()->mutate(arg);
+                       mutate(arg);
                        mathcursor->setPos(x, y);
                        mathcursor->normalize();
                        updateLocal(bv, true);
@@ -322,10 +318,10 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        int x = 0;
                        int y = 0;
                        mathcursor->getPos(x, y);
-                       if (getType() == LM_OT_SIMPLE)
-                               hull()->mutate(LM_OT_EQUATION);
+                       if (hullType() == "simple")
+                               mutate("equation");
                        else
-                               hull()->mutate(LM_OT_SIMPLE);
+                               mutate("simple");
                        mathcursor->setPos(x, y);
                        mathcursor->normalize();
                        updateLocal(bv, true);
@@ -352,7 +348,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
 
 bool InsetFormula::display() const
 {
-       return getType() != LM_OT_SIMPLE;
+       return hullType() != "simple" && hullType() != "none";
 }
 
 
@@ -416,9 +412,16 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
 }
 
 
-MathInsetTypes InsetFormula::getType() const
+string InsetFormula::hullType() const
+{
+       return hull() ? hull()->getType() : "none";
+}
+
+
+void InsetFormula::mutate(string const & type )
 {
-       return hull()->getType();
+       if (hull())
+               hull()->mutate(type);
 }
 
 
@@ -468,7 +471,7 @@ void InsetFormula::updatePreview()
        // is this old data?
        if (it != theCache.end()) {
                // we have already a loader, connect to it anyway
-               lyxerr << "### updatePreview(), old loader: " << loader_ << "\n";
+               //lyxerr << "### updatePreview(), old loader: " << loader_ << "\n";
                loader_ = it->second.get();
                loader_->statusChanged.connect
                        (boost::bind(&InsetFormula::statusChanged, this));
@@ -482,7 +485,7 @@ void InsetFormula::updatePreview()
        string file = os.str();
 
        // the real work starts
-       lyxerr << "### updatePreview(), new file " << file << "\n";
+       //lyxerr << "### updatePreview(), new file " << file << "\n";
        std::ofstream of(file.c_str());
        of << "\\batchmode"
                 << "\\documentclass{article}"
@@ -496,8 +499,8 @@ void InsetFormula::updatePreview()
 
        // now we are done, start actual loading we will get called back via
        // InsetFormula::statusChanged() if this is finished
-       lyxerr << "### updatePreview(), new loader: " << loader_ << "\n";
        theCache[data].reset(new grfx::Loader(file));
+       //lyxerr << "### updatePreview(), new loader: " << loader_ << "\n";
        loader_ = theCache.find(data)->second.get();
        loader_->startLoading();
        loader_->statusChanged.connect(boost::bind(&InsetFormula::statusChanged, this));