mbox needs access to a buffer pretty much the same way as LyXText does.
So do some preparation.

The patch itself does not change anything yet as (a) the 'wrong case'
buf==0 is explicitly checked for in math_mboxinset.C and (b) currently
no mboxes are produced anyway (factory code is dead...)

The rest is spelling/whitespace.

Would be nice if someone could apply this on, say, Monday (unless
complaints show up) as I can't use CVS right now.

Andre'

--- ./src/cursor.C      2005-01-29 08:21:43.000000000 +0100
+++ ../lyx-devel/./src/cursor.C 2005-02-05 09:20:50.000000000 +0100
@@ -870,7 +870,7 @@
                lyxerr << "this should not really happen - 2: "
                        << pos() << ' ' << lastpos() <<  " in idx: " << idx()
                       << " in atom: '";
-               WriteStream wi(lyxerr, false, true);
+               WriteStream wi(lyxerr, bv().buffer(), false, true);
                inset().asMathInset()->write(wi);
                lyxerr << endl;
        }
@@ -1132,7 +1132,7 @@
                bv().buffer()->params(),
                sl.pos(),
                outerFont(sl.pit(), text.paragraphs()));
-       for (; s < size(); ++s)
+       for (; s < int(size()); ++s)
                ;
        return font;
 }
--- ./src/mathed/command_inset.C        2004-11-29 08:20:55.000000000 +0100
+++ ../lyx-devel/./src/mathed/command_inset.C   2005-02-05 09:18:46.000000000 
+0100
@@ -73,7 +73,7 @@
 {
        ostringstream os;
        os << name << " LatexCommand ";
-       WriteStream ws(os);
+       WriteStream ws(os, 0);
        write(ws);
        ws << "\n\\end_inset\n\n";
        return os.str();
--- ./src/mathed/math_mathmlstream.C    2004-08-19 19:18:14.000000000 +0200
+++ ../lyx-devel/./src/mathed/math_mathmlstream.C       2005-02-05 
08:44:06.000000000 +0100
@@ -31,15 +31,16 @@
 }
 
 
-WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
+WriteStream::WriteStream(ostream & os, Buffer const * buf,
+               bool fragile, bool latex)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
-         pendingspace_(false), line_(0)
+         pendingspace_(false), line_(0), buf_(buf)
 {}
 
 
-WriteStream::WriteStream(ostream & os)
+WriteStream::WriteStream(ostream & os, Buffer const * buf)
        : os_(os), fragile_(false), firstitem_(false), latex_(false),
-         pendingspace_(false), line_(0)
+         pendingspace_(false), line_(0), buf_(buf)
 {}
 
 
--- ./src/mathed/math_mathmlstream.h    2005-01-29 08:22:38.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_mathmlstream.h       2005-02-05 
08:44:48.000000000 +0100
@@ -24,6 +24,7 @@
 class MathArray;
 class MathInset;
 class MathAtom;
+class Buffer;
 
 //
 // LaTeX/LyX
@@ -32,9 +33,9 @@
 class WriteStream {
 public:
        ///
-       WriteStream(std::ostream & os, bool fragile, bool latex);
+       WriteStream(std::ostream & os, Buffer const * buf, bool fragile, bool 
latex);
        ///
-       explicit WriteStream(std::ostream & os);
+       explicit WriteStream(std::ostream & os, Buffer const * buf);
        ///
        ~WriteStream();
        ///
@@ -53,6 +54,8 @@
        void pendingSpace(bool how);
        /// writes space if next thing is isalpha()
        bool pendingSpace() const { return pendingspace_; }
+       ///
+       Buffer const * buffer() const { return buf_; }
 private:
        ///
        std::ostream & os_;
@@ -66,6 +69,8 @@
        bool pendingspace_;
        ///
        int line_;
+       ///
+       Buffer const * buf_;
 };
 
 ///
--- ./src/mathed/math_macrotemplate.C   2004-11-29 08:20:59.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_macrotemplate.C      2005-02-05 
08:52:28.000000000 +0100
@@ -169,9 +169,9 @@
 }
 
 
-void MathMacroTemplate::write(Buffer const &, std::ostream & os) const
+void MathMacroTemplate::write(Buffer const & buf, std::ostream & os) const
 {
-       WriteStream wi(os, false, false);
+       WriteStream wi(os, &buf, false, false);
        os << "FormulaMacro\n";
        write(wi);
 }
--- ./src/mathed/math_nestinset.C       2005-01-29 08:22:39.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_nestinset.C  2005-02-05 08:53:34.000000000 
+0100
@@ -205,7 +205,8 @@
 
 void MathNestInset::dump() const
 {
-       WriteStream os(lyxerr);
+       // FIXME: buf should not be 0
+       WriteStream os(lyxerr, 0);
        os << "---------------------------------------------\n";
        write(os);
        os << "\n";
@@ -340,10 +341,10 @@
 }
 
 
-int MathNestInset::latex(Buffer const &, std::ostream & os,
+int MathNestInset::latex(Buffer const & buf, std::ostream & os,
                        OutputParams const & runparams) const
 {
-       WriteStream wi(os, runparams.moving_arg, true);
+       WriteStream wi(os, &buf, runparams.moving_arg, true);
        write(wi);
        return wi.line();
 }
--- ./src/mathed/math_colorinset.C      2005-01-29 08:22:35.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_colorinset.C 2005-02-05 09:13:43.000000000 
+0100
@@ -28,7 +28,7 @@
 // color "none" (reset to default) needs special treatment
 bool normalcolor(MathArray const & ar)
 {
-       return (asString(ar) == "none");
+       return asString(ar) == "none";
 }
 
 } // namespace anon
--- ./src/mathed/math_autocorrect.C     2004-08-19 19:18:13.000000000 +0200
+++ ../lyx-devel/./src/mathed/math_autocorrect.C        2005-02-05 
09:22:08.000000000 +0100
@@ -87,6 +87,7 @@
        //      << "trying to correct ar: " << at << " from: '" << from1_ << 
'\'' << endl;
        if (from2_ != c)
                return false;
+       // FIXME: buf wrong
        if (asString(at) != asString(from1_))
                return false;
        lyxerr[Debug::MATHED]
--- ./src/mathed/math_mboxinset.C       2004-12-11 13:03:22.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_mboxinset.C  2005-02-05 09:26:12.000000000 
+0100
@@ -65,15 +65,18 @@
 {
        if (ws.latex()) {
                ws << "\\mbox{\n";
-               TexRow texrow;
-               OutputParams runparams;
-               latexParagraphs(*bv_->buffer(), text_.paragraphs(),
-                       ws.os(), texrow, runparams);
-               ws.addlines(texrow.rows());
+               if (ws.buffer()) {
+                       TexRow texrow;
+                       OutputParams runparams;
+                       latexParagraphs(*ws.buffer(), text_.paragraphs(),
+                               ws.os(), texrow, runparams);
+                       ws.addlines(texrow.rows());
+               }
                ws << "}";
        } else {
                ws << "\\mbox{\n";
-               text_.write(*bv_->buffer(), ws.os());
+               if (ws.buffer())
+                       text_.write(*ws.buffer(), ws.os());
                ws << "}";
        }
 }
--- ./src/mathed/math_support.C 2005-01-29 08:22:40.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_support.C    2005-02-05 09:24:38.000000000 
+0100
@@ -698,7 +698,8 @@
 string asString(MathArray const & ar)
 {
        std::ostringstream os;
-       WriteStream ws(os);
+       // FIXME: buf should not be 0!
+       WriteStream ws(os, 0);
        ws << ar;
        return os.str();
 }
@@ -713,7 +714,8 @@
 string asString(MathInset const & inset)
 {
        std::ostringstream os;
-       WriteStream ws(os);
+       // FIXME: buf should not be 0!
+       WriteStream ws(os, 0);
        inset.write(ws);
        return os.str();
 }
@@ -722,7 +724,8 @@
 string asString(MathAtom const & at)
 {
        std::ostringstream os;
-       WriteStream ws(os);
+       // FIXME: buf should not be 0!
+       WriteStream ws(os, 0);
        at->write(ws);
        return os.str();
 }
--- ./src/mathed/math_support.h 2004-08-19 19:18:14.000000000 +0200
+++ ../lyx-devel/./src/mathed/math_support.h    2005-02-05 09:21:32.000000000 
+0100
@@ -15,9 +15,10 @@
 
 #include <string>
 
-class PainterInfo;
-class LyXFont;
+class Buffer;
 class Dimension;
+class LyXFont;
+class PainterInfo;
 class MathArray;
 class MathAtom;
 class MathInset;
--- ./src/mathed/math_hullinset.C       2004-11-29 08:20:58.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_hullinset.C  2005-02-05 08:50:01.000000000 
+0100
@@ -330,7 +330,8 @@
                MathGridInset::metricsT(mi, dim);
        } else {
                ostringstream os;
-               WriteStream wi(os, false, true);
+               // FIXME buf should be given
+               WriteStream wi(os, 0, false, true);
                write(wi);
                dim.wid = os.str().size();
                dim.asc = 1;
@@ -345,7 +346,8 @@
                MathGridInset::drawT(pain, x, y);
        } else {
                ostringstream os;
-               WriteStream wi(os, false, true);
+               // FIXME buf should be given
+               WriteStream wi(os, 0, false, true);
                write(wi);
                pain.draw(x, y, os.str().c_str());
        }
@@ -354,10 +356,10 @@
 
 namespace {
 
-string const latex_string(MathHullInset const & inset)
+string const latexString(MathHullInset const & inset, Buffer const * buf)
 {
        ostringstream ls;
-       WriteStream wi(ls, false, false);
+       WriteStream wi(ls, buf, false, false);
        inset.write(wi);
        return ls.str();
 }
@@ -368,7 +370,8 @@
 void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               string const snippet = latex_string(*this);
+               // FIXME: buffer should not be 0!
+               string const snippet = latexString(*this, 0);
                preview_->addPreview(snippet, ploader);
        }
 }
@@ -378,7 +381,7 @@
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
                Buffer const & buffer = cur.buffer();
-               string const snippet = latex_string(*this);
+               string const snippet = latexString(*this, &buffer);
                preview_->addPreview(snippet, buffer);
                preview_->startLoading(buffer);
        }
@@ -1319,9 +1322,9 @@
 #endif
 
 
-void MathHullInset::write(Buffer const &, std::ostream & os) const
+void MathHullInset::write(Buffer const & buf, std::ostream & os) const
 {
-       WriteStream wi(os, false, false);
+       WriteStream wi(os, false, false, &buf);
        os << "Formula ";
        write(wi);
 }
@@ -1335,7 +1338,7 @@
 }
 
 
-int MathHullInset::plaintext(Buffer const &, ostream & os,
+int MathHullInset::plaintext(Buffer const & buf, ostream & os,
                        OutputParams const &) const
 {
        if (0 && display()) {
@@ -1349,7 +1352,7 @@
                //metrics();
                return tpain.textheight();
        } else {
-               WriteStream wi(os, false, true);
+               WriteStream wi(os, &buf, false, true);
                wi << cell(0);
                return wi.line();
        }
@@ -1385,7 +1388,7 @@
                // Workaround for db2latex: db2latex always includes equations 
with
                // \ensuremath{} or \begin{display}\end{display}
                // so we strip LyX' math environment
-               WriteStream wi(ls, false, false);
+               WriteStream wi(ls, &buf, false, false);
                MathGridInset::write(wi);
                ms << subst(subst(ls.str(), "&", "&amp;"), "<", "&lt;");
                ms << ETag("alt");
--- ./src/mathed/math_gridinset.C       2004-11-29 08:20:58.000000000 +0100
+++ ../lyx-devel/./src/mathed/math_gridinset.C  2005-02-05 08:42:22.000000000 
+0100
@@ -53,12 +53,12 @@
                return theName;
        }
        ///
-       virtual string const inset2string(Buffer const &) const
+       virtual string const inset2string(Buffer const & buf) const
        {
                ostringstream data;
                //data << name() << " active_cell " << inset.getActCell() << 
'\n';
                data << name() << " active_cell " << 0 << '\n';
-               WriteStream ws(data);
+               WriteStream ws(data, &buf);
                inset_.write(ws);
                return data.str();
        }
--- ./src/mathed/math_inset.C   2004-08-19 19:18:13.000000000 +0200
+++ ../lyx-devel/./src/mathed/math_inset.C      2005-02-05 08:51:47.000000000 
+0100
@@ -40,7 +40,8 @@
 void MathInset::dump() const
 {
        lyxerr << "---------------------------------------------" << endl;
-       WriteStream wi(lyxerr, false, true);
+       // FIXME: buf shouild not be 0
+       WriteStream wi(lyxerr, 0, false, true);
        write(wi);
        lyxerr << "\n---------------------------------------------" << endl;
 }
@@ -126,7 +127,8 @@
 
 ostream & operator<<(ostream & os, MathAtom const & at)
 {
-       WriteStream wi(os, false, false);
+       // FIXME: buf shouild not be 0
+       WriteStream wi(os, 0, false, false);
        at->write(wi);
        return os;
 }
--- ./src/text.C        2005-01-29 08:22:01.000000000 +0100
+++ ../lyx-devel/./src/text.C   2005-02-05 17:51:04.000000000 +0100
@@ -476,8 +476,8 @@
        l_margin += font_metrics::signedWidth(tclass.leftmargin(), 
tclass.defaultfont());
 
        if (par.getDepth() != 0) {
-       // find the next level paragraph
-       pit_type newpar = outerHook(pit, pars_);
+               // find the next level paragraph
+               pit_type newpar = outerHook(pit, pars_);
                if (newpar != pit_type(pars_.size())) {
                        if (pars_[newpar].layout()->isEnvironment()) {
                                l_margin = leftMargin(newpar);
@@ -613,7 +613,7 @@
 int LyXText::rightMargin(Paragraph const & par) const
 {
        // We do not want rightmargins on inner texts.
-       if (bv()->text() != this)
+       if (!isMainText())
                return 0;
 
        LyXTextClass const & tclass = 
bv()->buffer()->params().getLyXTextClass();
@@ -1001,7 +1001,7 @@
        maxdesc += int(layoutdesc * 2 / (2 + pars_[pit].getDepth()));
 
        // Top and bottom margin of the document (only at top-level)
-       if (bv_owner->text() == this) {
+       if (isMainText()) {
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
                if (pit == pars_.size() - 1 && row.endpos() == par.size())
@@ -1013,10 +1013,6 @@
 }
 
 
-namespace {
-
-}
-
 void LyXText::breakParagraph(LCursor & cur, char keep_layout)
 {
        BOOST_ASSERT(this == cur.text());
--- ./src/bufferparams.h        2005-01-29 08:21:41.000000000 +0100
+++ ../lyx-devel/./src/bufferparams.h   2005-02-05 17:59:39.000000000 +0100
@@ -51,7 +51,7 @@
        CiteEngine val_;
 public:
        CiteEngine_enum(CiteEngine val) : val_(val) {}
-       operator CiteEngine() const{ return val_; }
+       operator CiteEngine() const { return val_; }
 };
 
 } // namespace biblio
@@ -74,6 +74,7 @@
        };
        ///
        BufferParams();
+       ///
        ~BufferParams();
 
        /// read a header token, if unrecognised, return it or an unknown class 
name
@@ -90,20 +91,16 @@
 
        ///
        void setPaperStuff();
-
        ///
        void useClassDefaults();
-
        ///
        bool hasClassDefaults() const;
-
        ///
        VSpace const & getDefSkip() const;
-
        ///
        void setDefSkip(VSpace const & vs);
 
-       /** Wether paragraphs are separated by using a indent like in
+       /** Whether paragraphs are separated by using a indent like in
         *  articles or by using a little skip like in letters.
         */
        PARSEP paragraph_separation;
@@ -118,10 +115,10 @@
        ///
        LyXTextClass const & getLyXTextClass() const;
 
-       /* this are for the PaperLayout */
+       /* these are for the PaperLayout */
        /// the general papersize (papersize2 or paperpackage
        PAPER_SIZE papersize;
-       ///  the selected Geometry papersize
+       ///  the selected geometry papersize
        VMARGIN_PAPER_TYPE papersize2;
        /// a special paperpackage .sty-file
        PAPER_PACKAGES paperpackage;

Reply via email to