]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / mathed / InsetMathHull.cpp
index 0142885559e6307eb89d0916af5e3a033ebe7fdb..57137db2f2d1ea286e6cc2cbd5a498640e36b906 100644 (file)
@@ -28,6 +28,8 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
+#include "MacroTable.h"
+#include "output_xhtml.h"
 #include "sgml.h"
 #include "TextPainter.h"
 #include "TocBackend.h"
@@ -37,6 +39,7 @@
 #include "insets/RenderPreview.h"
 
 #include "graphics/PreviewImage.h"
+#include "graphics/PreviewLoader.h"
 
 #include "frontends/Painter.h"
 
@@ -210,7 +213,7 @@ void InsetMathHull::setBuffer(Buffer & buffer)
 }
 
 
-void InsetMathHull::updateLabels(ParIterator const & it)
+void InsetMathHull::updateLabels(ParIterator const & it, bool out)
 {
        if (!buffer_) {
                //FIXME: buffer_ should be set at creation for this inset! Problem is
@@ -220,7 +223,7 @@ void InsetMathHull::updateLabels(ParIterator const & it)
        }
        for (size_t i = 0; i != label_.size(); ++i) {
                if (label_[i])
-                       label_[i]->updateLabels(it);
+                       label_[i]->updateLabels(it, out);
        }
 }
 
@@ -368,6 +371,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);
@@ -456,22 +467,50 @@ void InsetMathHull::initUnicodeMath() const
 }
 
 
-void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const
+void InsetMathHull::addPreview(DocIterator const & inset_pos,
+       graphics::PreviewLoader & /*ploader*/) const
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               docstring const snippet = latexString(*this);
-               preview_->addPreview(snippet, ploader);
+               preparePreview(inset_pos);
        }
 }
 
 
-bool InsetMathHull::notifyCursorLeaves(Cursor const & /*old*/, Cursor & cur)
+void InsetMathHull::preparePreview(DocIterator const & pos) const  
+{
+       Buffer const * buffer = pos.buffer();  
+
+       // collect macros at this position  
+       MacroNameSet macros;  
+       buffer->listMacroNames(macros);  
+       MacroNameSet::iterator it = macros.begin();  
+       MacroNameSet::iterator end = macros.end();  
+       odocstringstream macro_preamble;  
+       for (; it != end; ++it) {  
+               MacroData const * data = buffer->getMacro(*it, pos, true);  
+               if (data) {  
+                       data->write(macro_preamble, true);  
+                       macro_preamble << endl;  
+               }
+       }  
+
+       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) {
-               Buffer const * buffer = cur.buffer();
-               docstring const snippet = latexString(*this);
-               preview_->addPreview(snippet, *buffer);
-               preview_->startLoading(*buffer);
+               reloadPreview(old);
                cur.updateFlags(Update::Force);
        }
        return false;
@@ -1735,15 +1774,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 << 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 << StartTag("math", 
+                       "display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
+       MathStream ms(xs.os());
        InsetMathGrid::mathmlize(ms);
-       os << "</math>";
+       xs << EndTag("math");
        return docstring();
 }