]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_funcs.C
zlib stuff
[lyx.git] / src / paragraph_funcs.C
index 0842302dbb236d9a94a56b6c9bdf66f4982a69b8..b10f4e31d4e5afcc9793c2928d676607bbad0509 100644 (file)
@@ -23,7 +23,9 @@
 #include "lyxlex.h"
 #include "factory.h"
 #include "Lsstream.h"
+
 #include "support/lstrings.h"
+
 #include "insets/insetoptarg.h"
 #include "insets/insetcommandparams.h"
 #include "insets/insetbibitem.h"
 #include "insets/insetlatexaccent.h"
 #include "insets/insettabular.h"
 #include "insets/insethfill.h"
-#include "insets/inseterror.h"
 #include "insets/insetnewline.h"
 
 extern string bibitemWidest(Buffer const *);
 
+using namespace lyx::support;
+
 using lyx::pos_type;
 //using lyx::layout_type;
 using std::endl;
@@ -71,7 +74,7 @@ void breakParagraph(BufferParams const & bparams,
                tmp->setLabelWidthString(par->params().labelWidthString());
        }
 
-       bool const isempty = (par->layout()->keepempty && par->empty());
+       bool const isempty = (par->allowEmpty() && par->empty());
 
        if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
                tmp->layout(par->layout());
@@ -428,8 +431,8 @@ InsetOptArg * optArgInset(Paragraph const & par)
        InsetList::const_iterator it = par.insetlist.begin();
        InsetList::const_iterator end = par.insetlist.end();
        for (; it != end; ++it) {
-               Inset * ins = it->inset;
-               if (ins->lyxCode() == Inset::OPTARG_CODE) {
+               InsetOld * ins = it->inset;
+               if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
                        return static_cast<InsetOptArg *>(ins);
                }
        }
@@ -449,7 +452,7 @@ TeXOnePar(Buffer const * buf,
 << "'" << endl;
        BufferParams const & bparams = buf->params;
 
-       Inset const * in = pit->inInset();
+       InsetOld const * in = pit->inInset();
        bool further_blank_line = false;
        LyXLayout_ptr style;
 
@@ -708,7 +711,7 @@ void latexParagraphs(Buffer const * buf,
 
        // if only_body
        while (par != endpar) {
-               Inset * in = par->inInset();
+               InsetOld * in = par->inInset();
                // well we have to check if we are in an inset with unlimited
                // length (all in one row) if that is true then we don't allow
                // any special options in the paragraph and also we don't allow
@@ -814,81 +817,24 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
                        layoutname = tclass.defaultLayoutName();
                }
 
-#ifdef USE_CAPTION
-               // The is the compability reading of layout caption.
-               if (compare_ascii_no_case(layoutname, "caption") == 0) {
-                       // We expect that the par we are now working on is
-                       // really inside a InsetText inside a InsetFloat.
-                       // We also know that captions can only be
-                       // one paragraph. (Lgb)
-
-                       // We should now read until the next "\layout"
-                       // is reached.
-                       // This is probably not good enough, what if the
-                       // caption is the last par in the document (Lgb)
-                       istream & ist = lex.getStream();
-                       stringstream ss;
-                       string line;
-                       int begin = 0;
-                       while (true) {
-                               getline(ist, line);
-                               if (prefixIs(line, "\\layout")) {
-                                       lex.pushToken(line);
-                                       break;
-                               }
-                               if (prefixIs(line, "\\begin_inset"))
-                                       ++begin;
-                               if (prefixIs(line, "\\end_inset")) {
-                                       if (begin)
-                                               --begin;
-                                       else {
-                                               lex.pushToken(line);
-                                               break;
-                                       }
-                               }
+               par.layout(bp.getLyXTextClass()[layoutname]);
 
-                               ss << line << '\n';
-                       }
-
-                       // Now we should have the whole layout in ss
-                       // we should now be able to give this to the
-                       // caption inset.
-                       ss << "\\end_inset\n";
-
-                       // This seems like a bug in stringstream.
-                       // We really should be able to use ss
-                       // directly. (Lgb)
-                       istringstream is(ss.str());
-                       LyXLex tmplex(0, 0);
-                       tmplex.setStream(is);
-                       Inset * inset = new InsetCaption;
-                       inset->Read(this, tmplex);
-                       par.insertInset(pos, inset, font);
-                       ++pos;
-               } else {
-#endif
-                       par.layout(bp.getLyXTextClass()[layoutname]);
-
-                       // Test whether the layout is obsolete.
-                       LyXLayout_ptr const & layout = par.layout();
-                       if (!layout->obsoleted_by().empty())
-                               par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
+               // Test whether the layout is obsolete.
+               LyXLayout_ptr const & layout = par.layout();
+               if (!layout->obsoleted_by().empty())
+                       par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
 
-                       par.params().read(lex);
-#if USE_CAPTION
-               }
-#endif
+               par.params().read(lex);
 
+       } else if (token == "\\end_layout") {
+               lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
+                      << "Missing \\layout?.\n";
        } else if (token == "\\end_inset") {
                lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
                       << "Missing \\begin_inset?.\n";
-               // Simply ignore this. The insets do not have
-               // to read this.
-               // But insets should read it, it is a part of
-               // the inset isn't it? Lgb.
        } else if (token == "\\begin_inset") {
-               Inset * i = readInset(lex, buf);
-               par.insertInset(par.size(), i, font, change);
+               InsetOld * inset = readInset(lex, buf);
+               par.insertInset(par.size(), inset, font, change);
        } else if (token == "\\family") {
                lex.next();
                font.setLyXFamily(lex.getString());
@@ -937,10 +883,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
                lex.next();
                font.setLyXColor(lex.getString());
        } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
-               LyXLayout_ptr const & layout = par.layout();
 
                // Insets don't make sense in a free-spacing context! ---Kayvan
-               if (layout->free_spacing || par.isFreeSpacing()) {
+               if (par.isFreeSpacing()) {
                        if (token == "\\InsetSpace")
                                par.insertChar(par.size(), ' ', font, change);
                        else if (lex.isOK()) {
@@ -955,7 +900,7 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
                                }
                        }
                } else {
-                       Inset * inset = 0;
+                       InsetOld * inset = 0;
                        if (token == "\\SpecialChar" )
                                inset = new InsetSpecialChar;
                        else
@@ -964,17 +909,17 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
                        par.insertInset(par.size(), inset, font, change);
                }
        } else if (token == "\\i") {
-               Inset * inset = new InsetLatexAccent;
+               InsetOld * inset = new InsetLatexAccent;
                inset->read(&buf, lex);
                par.insertInset(par.size(), inset, font, change);
        } else if (token == "\\backslash") {
                par.insertChar(par.size(), '\\', font, change);
        } else if (token == "\\newline") {
-               Inset * inset = new InsetNewline;
+               InsetOld * inset = new InsetNewline;
                inset->read(&buf, lex);
                par.insertInset(par.size(), inset, font, change);
        } else if (token == "\\LyXTable") {
-               Inset * inset = new InsetTabular(buf);
+               InsetOld * inset = new InsetTabular(buf);
                inset->read(&buf, lex);
                par.insertInset(par.size(), inset, font, change);
        } else if (token == "\\bibitem") {
@@ -1008,9 +953,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
                lex.eatLine();
                string const s = bformat(_("Unknown token: %1$s %2$s\n"),
                        token, lex.getString());
-               // we can do this here this way because we're actually reading
-               // the buffer and don't care about LyXText right now.
-               par.insertInset(par.size(), new InsetError(s), font);
+
+               buf.error(ErrorItem(_("Unknown token"), s,
+                                   par.id(), 0, par.size()));
                return 1;
        }
        return 0;
@@ -1036,16 +981,20 @@ int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
                if (token.empty())
                        continue;
 
+               if (token == "\\end_layout") {
+                       //Ok, paragraph finished
+                       break;
+               }
+
                lyxerr[Debug::PARSER] << "Handling paragraph token: `"
                                      << token << '\'' << endl;
-
-               // reached the next paragraph. FIXME: really we should
-               // change the file format to indicate the end of a par
-               // clearly, but for now, this hack will do
                if (token == "\\layout" || token == "\\the_end"
                    || token == "\\end_inset" || token == "\\begin_deeper"
                    || token == "\\end_deeper") {
                        lex.pushToken(token);
+                       lyxerr << "Paragraph ended in line "
+                              << lex.getLineNo() << "\n"
+                              << "Missing \\end_layout.\n";
                        break;
                }
        }
@@ -1072,13 +1021,3 @@ LyXFont const outerFont(ParagraphList::iterator pit,
 
        return tmpfont;
 }
-
-
-LyXFont const realizeFont(LyXFont const & font,
-                         BufferParams const & params)
-{
-       LyXTextClass const & tclass = params.getLyXTextClass();
-       LyXFont tmpfont(font);
-       tmpfont.realize(tclass.defaultfont());
-       return tmpfont;
-}