]> git.lyx.org Git - features.git/blobdiff - src/Layout.cpp
next try...
[features.git] / src / Layout.cpp
index 7fedb3209c11fc16da9b7edc43a6c3d4626958e2..05efa9c38713959f12013061090443b696edaeb3 100644 (file)
@@ -37,6 +37,7 @@ enum LayoutTags {
        LT_ALIGNPOSSIBLE,
        LT_MARGIN,
        LT_BOTTOMSEP,
+       LT_CATEGORY,
        LT_COMMANDDEPTH,
        LT_COPYSTYLE,
        LT_DEPENDSON,
@@ -133,10 +134,11 @@ Layout::Layout()
 bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 {
        // This table is sorted alphabetically [asierra 30March96]
-       keyword_item layoutTags[] = {
+       LexerKeyword layoutTags[] = {
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
                { "bottomsep",      LT_BOTTOMSEP },
+               { "category",       LT_CATEGORY },
                { "commanddepth",   LT_COMMANDDEPTH },
                { "copystyle",      LT_COPYSTYLE },
                { "dependson",      LT_DEPENDSON },
@@ -189,7 +191,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 
        bool error = false;
        bool finished = false;
-       lexrc.pushTable(layoutTags, LT_INTITLE);
+       lexrc.pushTable(layoutTags);
        // parse style section
        while (!finished && lexrc.isOK() && !error) {
                int le = lexrc.lex();
@@ -209,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(),
@@ -216,16 +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;
-                                       for (size_t i = 0; i != tclass.layoutCount(); ++i)
-                                               lyxerr << to_utf8(tclass.layout(i)->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'");
@@ -240,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;
@@ -507,7 +515,7 @@ enum AlignTags {
 
 void Layout::readAlign(Lexer & lexrc)
 {
-       keyword_item alignTags[] = {
+       LexerKeyword alignTags[] = {
                { "block",  AT_BLOCK },
                { "center", AT_CENTER },
                { "layout", AT_LAYOUT },
@@ -545,7 +553,7 @@ void Layout::readAlign(Lexer & lexrc)
 
 void Layout::readAlignPossible(Lexer & lexrc)
 {
-       keyword_item alignTags[] = {
+       LexerKeyword alignTags[] = {
                { "block",  AT_BLOCK },
                { "center", AT_CENTER },
                { "layout", AT_LAYOUT },
@@ -553,9 +561,9 @@ void Layout::readAlignPossible(Lexer & lexrc)
                { "right",  AT_RIGHT }
        };
 
-       lexrc.pushTable(alignTags, AT_LAYOUT);
+       lexrc.pushTable(alignTags);
        alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
-       int lineno = lexrc.getLineNo();
+       int lineno = lexrc.lineNumber();
        do {
                int le = lexrc.lex();
                switch (le) {
@@ -581,7 +589,7 @@ void Layout::readAlignPossible(Lexer & lexrc)
                        alignpossible |= LYX_ALIGN_LAYOUT;
                        break;
                }
-       } while (lineno == lexrc.getLineNo());
+       } while (lineno == lexrc.lineNumber());
        lexrc.popTable();
 }
 
@@ -602,7 +610,7 @@ enum LabelTypeTags {
 
 void Layout::readLabelType(Lexer & lexrc)
 {
-       keyword_item labelTypeTags[] = {
+       LexerKeyword labelTypeTags[] = {
        { "bibliography",             LA_BIBLIO },
        { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
        { "counter",                  LA_COUNTER },
@@ -658,7 +666,7 @@ void Layout::readLabelType(Lexer & lexrc)
 }
 
 
-static keyword_item endlabelTypeTags[] =
+static LexerKeyword endlabelTypeTags[] =
 {
        { "box",        END_LABEL_BOX },
        { "filled_box", END_LABEL_FILLED_BOX },
@@ -692,7 +700,7 @@ void Layout::readEndLabelType(Lexer & lexrc)
 
 void Layout::readMargin(Lexer & lexrc)
 {
-       keyword_item marginTags[] = {
+       LexerKeyword marginTags[] = {
                { "dynamic",           MARGIN_DYNAMIC },
                { "first_dynamic",     MARGIN_FIRST_DYNAMIC },
                { "manual",            MARGIN_MANUAL },
@@ -724,7 +732,7 @@ void Layout::readMargin(Lexer & lexrc)
 
 void Layout::readLatexType(Lexer & lexrc)
 {
-       keyword_item latexTypeTags[] = {
+       LexerKeyword latexTypeTags[] = {
                { "bib_environment",  LATEX_BIB_ENVIRONMENT },
                { "command",          LATEX_COMMAND },
                { "environment",      LATEX_ENVIRONMENT },
@@ -765,7 +773,7 @@ enum SpacingTags {
 
 void Layout::readSpacing(Lexer & lexrc)
 {
-       keyword_item spacingTags[] = {
+       LexerKeyword spacingTags[] = {
                {"double",  ST_SPACING_DOUBLE },
                {"onehalf", ST_SPACING_ONEHALF },
                {"other",   ST_OTHER },
@@ -822,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();