]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_hullinset.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / mathed / math_hullinset.C
index 87d2804dd05a15c99cb44196427009c0b94c78c8..b56dec9d2c70fb9b8414911e618de80382d843eb 100644 (file)
 #include "math_support.h"
 
 #include "BufferView.h"
+#include "CutAndPaste.h"
+#include "LColor.h"
+#include "LaTeXFeatures.h"
 #include "cursor.h"
-#include "dispatchresult.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "funcrequest.h"
 #include "gettext.h"
-#include "LaTeXFeatures.h"
-#include "LColor.h"
 #include "lyx_main.h"
 #include "lyxrc.h"
 #include "outputparams.h"
 
 #include "frontends/Alert.h"
 
+#include "graphics/PreviewImage.h"
 #include "graphics/PreviewLoader.h"
 
-#include "support/std_sstream.h"
-
 #include <boost/bind.hpp>
 
+#include <sstream>
+
+using lyx::cap::grabAndEraseSelection;
 
 using std::endl;
 using std::max;
@@ -226,9 +229,15 @@ char const * MathHullInset::standardFont() const
 
 void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       bool const use_preview = (!editing(mi.base.bv) &&
-                                 RenderPreview::activated() &&
-                                 preview_->previewReady());
+       BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
+
+       bool use_preview = false;
+       if (!editing(mi.base.bv) &&
+           RenderPreview::status() == LyXRC::PREVIEW_ON) {
+               lyx::graphics::PreviewImage const * pimage =
+                       preview_->getPreviewImage(*mi.base.bv->buffer());
+               use_preview = pimage && pimage->image();
+       }
 
        if (use_preview) {
                preview_->metrics(mi, dim);
@@ -274,10 +283,15 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void MathHullInset::draw(PainterInfo & pi, int x, int y) const
 {
-       // The previews are drawn only when we're not editing the inset.
-       bool const use_preview = (!editing(pi.base.bv) &&
-                                 RenderPreview::activated() &&
-                                 preview_->previewReady());
+       BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
+
+       bool use_preview = false;
+       if (!editing(pi.base.bv) &&
+           RenderPreview::status() == LyXRC::PREVIEW_ON) {
+               lyx::graphics::PreviewImage const * pimage =
+                       preview_->getPreviewImage(*pi.base.bv->buffer());
+               use_preview = pimage && pimage->image();
+       }
 
        if (use_preview) {
                // one pixel gap in front
@@ -345,14 +359,16 @@ string const latex_string(MathHullInset const & inset)
 
 void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
 {
-       string const snippet = latex_string(*this);
-       preview_->addPreview(snippet, ploader);
+       if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
+               string const snippet = latex_string(*this);
+               preview_->addPreview(snippet, ploader);
+       }
 }
 
 
 void MathHullInset::notifyCursorLeaves(LCursor & cur)
 {
-       if (!RenderPreview::activated())
+       if (RenderPreview::status() != LyXRC::PREVIEW_ON)
                return;
 
        Buffer const & buffer = cur.buffer();
@@ -822,7 +838,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
                size_type pos = cur.cell().find_last(eq);
                MathArray ar;
                if (cur.inMathed() && cur.selection()) {
-                       asArray(cur.grabAndEraseSelection(), ar);
+                       asArray(grabAndEraseSelection(cur), ar);
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
@@ -888,10 +904,10 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_BREAKLINE:
                if (type_ == "simple" || type_ == "equation") {
+                       recordUndoInset(cur);
                        mutate("eqnarray");
-                       cur.idx() = 1;
-                       cur.pos() = 0;
-                       //cur.dispatched(FINISHED);
+                       cur.idx() = 0;
+                       cur.pos() = cur.lastpos();
                        break;
                }
                MathGridInset::priv_dispatch(cur, cmd);
@@ -900,7 +916,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MATH_NUMBER:
                //lyxerr << "toggling all numbers" << endl;
                if (display()) {
-                       recordUndo(cur);
+                       recordUndoInset(cur);
                        bool old = numberedType();
                        if (type_ == "multline")
                                numbered(nrows() - 1, !old);
@@ -913,8 +929,8 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_MATH_NONUMBER:
                if (display()) {
+                       recordUndoInset(cur);
                        row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
-                       recordUndo(cur);
                        bool old = numbered(r);
                        cur.message(old ? _("No number") : _("Number"));
                        numbered(r, !old);
@@ -922,6 +938,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_INSERT_LABEL: {
+               recordUndoInset(cur);
                row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
                string old_label = label(r);
                string new_label = cmd.argument;
@@ -942,12 +959,12 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_MATH_EXTERN:
+               recordUndoInset(cur);
                doExtern(cur, cmd);
-               //cur.dispatched(FINISHED);
                break;
 
        case LFUN_MATH_MUTATE: {
-               lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
+               recordUndoInset(cur);
                row_type row = cur.row();
                col_type col = cur.col();
                mutate(cmd.argument);
@@ -963,6 +980,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_MATH_DISPLAY: {
+               recordUndoInset(cur);
                mutate(type_ == "simple" ? "equation" : "simple");
                cur.idx() = 0;
                cur.pos() = cur.lastpos();
@@ -1136,7 +1154,9 @@ InsetBase::Code MathHullInset::lyxCode() const
 bool MathHullInset::searchForward(BufferView * bv, string const & str,
                                     bool, bool)
 {
+#ifdef WITH_WARNINGS
 #warning completely broken
+#endif
        static MathHullInset * lastformula = 0;
        static CursorBase current = DocIterator(ibegin(nucleus()));
        static MathArray ar;
@@ -1221,7 +1241,9 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
                          OutputParams const & runparams) const
 {
        MathMLStream ms(os);
-       ms << MTag("equation");
+       string name="equation";
+       if (! label(0).empty()) name += " id=\"" + label(0)+ "\"";
+       ms << MTag(name.c_str());
        ms <<   MTag("alt");
        ms <<    "<[CDATA[";
        int res = plaintext(buf, ms.os(), runparams);