]> git.lyx.org Git - features.git/blobdiff - src/mathed/InsetMathHull.cpp
s/updateLabels/updateBuffer/g, per a suggestion of Abdel's.
[features.git] / src / mathed / InsetMathHull.cpp
index 657c593094219c71814e9131b4079deefd18c164..62a28ec4c99005711f938a808d22c37a6517018d 100644 (file)
@@ -22,6 +22,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "ColorSet.h"
 #include "CutAndPaste.h"
 #include "Encoding.h"
 #include "FuncRequest.h"
@@ -29,6 +30,7 @@
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
 #include "MacroTable.h"
+#include "output_xhtml.h"
 #include "sgml.h"
 #include "TextPainter.h"
 #include "TocBackend.h"
@@ -38,6 +40,7 @@
 #include "insets/RenderPreview.h"
 
 #include "graphics/PreviewImage.h"
+#include "graphics/PreviewLoader.h"
 
 #include "frontends/Painter.h"
 
@@ -211,7 +214,7 @@ void InsetMathHull::setBuffer(Buffer & buffer)
 }
 
 
-void InsetMathHull::updateLabels(ParIterator const & it, bool out)
+void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype)
 {
        if (!buffer_) {
                //FIXME: buffer_ should be set at creation for this inset! Problem is
@@ -221,8 +224,10 @@ void InsetMathHull::updateLabels(ParIterator const & it, bool out)
        }
        for (size_t i = 0; i != label_.size(); ++i) {
                if (label_[i])
-                       label_[i]->updateLabels(it, out);
+                       label_[i]->updateBuffer(it, utype);
        }
+       // pass down
+       InsetMathGrid::updateBuffer(it, utype);
 }
 
 
@@ -308,7 +313,18 @@ int InsetMathHull::defaultColSpace(col_type col)
 
 docstring InsetMathHull::standardFont() const
 {
-       return from_ascii(type_ == hullNone ? "lyxnochange" : "mathnormal");
+       const char *font_name;
+       switch (type_) {
+       case hullRegexp:
+               font_name = "texttt";
+               break;
+       case hullNone:
+               font_name = "lyxnochange";
+               break;
+       default:
+               font_name = "mathnormal";
+       }
+       return from_ascii(font_name);
 }
 
 
@@ -369,6 +385,14 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
+ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
+{
+       if (previewState(pi.base.bv))
+               return graphics::PreviewLoader::backgroundColor();
+       return Color_mathbg;
+}
+
+
 void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
 {
        Dimension const dim = dimension(*pi.base.bv);
@@ -381,6 +405,11 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 {
        use_preview_ = previewState(pi.base.bv);
 
+       if (type_ == hullRegexp) {
+               Dimension const dim = dimension(*pi.base.bv);
+               pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
+                       dim.width() - 2, dim.height() - 2, Color_regexpframe);
+       }
        if (use_preview_) {
                // one pixel gap in front
                preview_->draw(pi, x + 1, y);
@@ -487,13 +516,20 @@ void InsetMathHull::preparePreview(DocIterator const & pos) const
        docstring const snippet = macro_preamble.str() + latexString(*this);  
        LYXERR(Debug::MACROS, "Preview snippet: " << snippet);  
        preview_->addPreview(snippet, *buffer);  
-}  
+}
+
+
+void InsetMathHull::reloadPreview(DocIterator const & pos) const
+{
+       preparePreview(pos);
+       preview_->startLoading(*pos.buffer());
+}
+
 
 bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               preparePreview(old);
-               preview_->startLoading(buffer());
+               reloadPreview(old);
                cur.updateFlags(Update::Force);
        }
        return false;
@@ -517,9 +553,9 @@ void InsetMathHull::label(row_type row, docstring const & label)
                        delete label_[row];
                        label_[row] = dummy_pointer;
                        // We need an update of the Buffer reference cache.
-                       // This is achieved by updateLabels().
+                       // This is achieved by updateBuffer().
                        if (buffer_)
-                               buffer().updateLabels();
+                               buffer().updateBuffer();
                } else {
                        if (buffer_)
                                label_[row]->updateCommand(label);
@@ -548,8 +584,8 @@ void InsetMathHull::numbered(row_type row, bool num)
                        return;
                }
                // We need an update of the Buffer reference cache.
-               // This is achieved by updateLabels().
-               buffer().updateLabels();
+               // This is achieved by updateBuffer().
+               buffer().updateBuffer();
        }
 }
 
@@ -601,6 +637,16 @@ void InsetMathHull::validate(LaTeXFeatures & features) const
        if (ams())
                features.require("amsmath");
 
+       if (type_ == hullRegexp) {
+               features.require("color");
+               string frcol = lcolor.getLaTeXName(Color_regexpframe);
+               string bgcol = "white";
+               features.addPreambleSnippet(
+                       string("\\newcommand{\\regexp}[1]{\\fcolorbox{")
+                       + frcol + string("}{")
+                       + bgcol + string("}{\\texttt{#1}}}"));
+       }
+
        // Validation is necessary only if not using AMS math.
        // To be safe, we will always run mathedvalidate.
        //if (features.amsstyle)
@@ -653,7 +699,7 @@ void InsetMathHull::header_write(WriteStream & os) const
                break;
 
        case hullRegexp:
-               os << "\\regexp{";
+               os << "\\regexp{{{";
                break;
 
        default:
@@ -698,7 +744,7 @@ void InsetMathHull::footer_write(WriteStream & os) const
                break;
 
        case hullRegexp:
-               os << "}";
+               os << "}}}";
                break;
 
        default:
@@ -1050,7 +1096,8 @@ docstring InsetMathHull::eolString(row_type row, bool fragile) const
        docstring res;
        if (numberedType()) {
                if (label_[row] && !nonum_[row])
-                       res += "\\label{" + label_[row]->getParam("name") + '}';
+                       res += "\\label{" +
+                           escape(label_[row]->getParam("name")) + '}';
                if (nonum_[row] && (type_ != hullMultline))
                        res += "\\nonumber ";
        }
@@ -1440,10 +1487,13 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                }
                return InsetMathGrid::getStatus(cur, cmd, status);
 
-       case LFUN_TABULAR_FEATURE: {
+       case LFUN_INSET_MODIFY: {
                istringstream is(to_utf8(cmd.argument()));
                string s;
                is >> s;
+               if (s != "tabular")
+                       return InsetMathGrid::getStatus(cur, cmd, status);
+               is >> s;
                if (!rowChangeOK()
                    && (s == "append-row"
                        || s == "delete-row"
@@ -1757,15 +1807,16 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
 }
 
 
-docstring InsetMathHull::xhtml(odocstream & os, OutputParams const &) const
+docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const &) const
 {
        if (getType() == hullSimple)
-               os << "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">";
+               xs << html::StartTag("math", "xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
        else 
-               os << "<math display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\">";
-       MathStream ms(os);
+               xs << html::StartTag("math", 
+                       "display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
+       MathStream ms(xs.os());
        InsetMathGrid::mathmlize(ms);
-       os << "</math>";
+       xs << html::EndTag("math");
        return docstring();
 }