]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
* src/insets/InsetNote.h:
[lyx.git] / src / Layout.cpp
index 1374fbefd7d738fb9af23446bed37efe1a8c6dc6..e368f23bbda0e821d3928b0f58538e5290a9e577 100644 (file)
 #include "TextClass.h"
 #include "Lexer.h"
 #include "Font.h"
-#include "support/debug.h"
-
 
+#include "support/debug.h"
 #include "support/lstrings.h"
 
 #include <ostream>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::subst;
-using support::trim;
-
-
 /// Special value of toclevel for layouts that to not belong in a TOC
 const int Layout::NOT_IN_TOC = -1000;
 
@@ -41,6 +37,7 @@ enum LayoutTags {
        LT_ALIGNPOSSIBLE,
        LT_MARGIN,
        LT_BOTTOMSEP,
+       LT_CATEGORY,
        LT_COMMANDDEPTH,
        LT_COPYSTYLE,
        LT_DEPENDSON,
@@ -85,6 +82,7 @@ enum LayoutTags {
        LT_PARSKIP,
        //LT_PLAIN,
        LT_PREAMBLE,
+       LT_REQUIRES,
        LT_RIGHTMARGIN,
        LT_SPACING,
        LT_TOPSEP,
@@ -140,6 +138,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
                { "bottomsep",      LT_BOTTOMSEP },
+               { "category",       LT_CATEGORY },
                { "commanddepth",   LT_COMMANDDEPTH },
                { "copystyle",      LT_COPYSTYLE },
                { "dependson",      LT_DEPENDSON },
@@ -182,6 +181,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                { "parskip",        LT_PARSKIP },
                { "passthru",       LT_PASS_THRU },
                { "preamble",       LT_PREAMBLE },
+               { "requires",       LT_REQUIRES },
                { "rightmargin",    LT_RIGHTMARGIN },
                { "spacing",        LT_SPACING },
                { "textfont",       LT_TEXTFONT },
@@ -211,6 +211,11 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                        finished = true;
                        break;
 
+               case LT_CATEGORY:
+                       if (lexrc.next())
+                               category_ = lexrc.getDocString();
+                       break;
+
                case LT_COPYSTYLE:     // initialize with a known style
                        if (lexrc.next()) {
                                docstring const style = subst(lexrc.getDocString(),
@@ -218,21 +223,17 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 
                                if (tclass.hasLayout(style)) {
                                        docstring const tmpname = name_;
-                                       this->operator=(*tclass[style]);
+                                       this->operator=(tclass[style]);
                                        name_ = tmpname;
                                } else {
                                        lyxerr << "Cannot copy unknown style `"
                                               << to_utf8(style) << "'\n"
                                               << "All layouts so far:"
                                               << endl;
-                                       TextClass::const_iterator it =
-                                               tclass.begin();
-                                       TextClass::const_iterator end =
-                                               tclass.end();
-                                       for (; it != end; ++it) {
-                                               lyxerr << to_utf8((*it)->name())
-                                                      << endl;
-                                       }
+                                       DocumentClass::const_iterator lit = tclass.begin();
+                                       DocumentClass::const_iterator len = tclass.end();
+                                       for (; lit != len; ++lit)
+                                               lyxerr << to_utf8(lit->name()) << endl;
 
                                        //lexrc.printError("Cannot copy known "
                                        //               "style `$$Token'");
@@ -247,7 +248,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 
                                if (tclass.hasLayout(style)) {
                                        docstring const tmpname = name_;
-                                       this->operator=(*tclass[style]);
+                                       this->operator=(tclass[style]);
                                        name_ = tmpname;
                                        if (obsoleted_by().empty())
                                                obsoleted_by_ = style;
@@ -487,11 +488,19 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                case LT_SPACING: // setspace.sty
                        readSpacing(lexrc);
                        break;
+
+               case LT_REQUIRES:
+                       lexrc.eatLine();
+                       vector<string> const req = 
+                               getVectorFromString(lexrc.getString());
+                       requires_.insert(req.begin(), req.end());
+                       break;
+
                }
        }
        lexrc.popTable();
 
-       return error;
+       return !error;
 }
 
 
@@ -821,6 +830,16 @@ docstring const & Layout::depends_on() const
 }
 
 
+bool Layout::operator==(Layout const & rhs) const
+{
+       // This is enough for the applications we actually make,
+       // at least at the moment. But we could check more.
+       return name() == rhs.name()
+               && latexname() == rhs.latexname()
+               && latextype == rhs.latextype;
+}
+
+
 Layout * Layout::forCaption()
 {
        Layout * lay = new Layout();