]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Andre's s/getTextClass/textClass/ cleanup.
[lyx.git] / src / Layout.cpp
index 4d0a468d2b8b1980f1e0baa76c25e7951faf5598..7fedb3209c11fc16da9b7edc43a6c3d4626958e2 100644 (file)
 #include "Layout.h"
 #include "TextClass.h"
 #include "Lexer.h"
-#include "debug.h"
+#include "Font.h"
 
+#include "support/debug.h"
 #include "support/lstrings.h"
 
+#include <ostream>
 
-namespace lyx {
-
-using support::subst;
-using support::trim;
+using namespace std;
+using namespace lyx::support;
 
-using std::endl;
-using std::string;
+namespace lyx {
 
 /// Special value of toclevel for layouts that to not belong in a TOC
 const int Layout::NOT_IN_TOC = -1000;
@@ -82,6 +81,7 @@ enum LayoutTags {
        LT_PARSKIP,
        //LT_PLAIN,
        LT_PREAMBLE,
+       LT_REQUIRES,
        LT_RIGHTMARGIN,
        LT_SPACING,
        LT_TOPSEP,
@@ -94,8 +94,7 @@ enum LayoutTags {
 
 /////////////////////
 
-// Constructor for layout
-Layout::Layout ()
+Layout::Layout()
 {
        margintype = MARGIN_STATIC;
        latextype = LATEX_PARAGRAPH;
@@ -103,10 +102,10 @@ Layout::Layout ()
        optionalargs = 0;
        needprotect = false;
        keepempty = false;
-       font = Font(Font::ALL_INHERIT);
-       labelfont = Font(Font::ALL_INHERIT);
-       resfont = Font(Font::ALL_SANE);
-       reslabelfont = Font(Font::ALL_SANE);
+       font = inherit_font;
+       labelfont = inherit_font;
+       resfont = sane_font;
+       reslabelfont = sane_font;
        nextnoindent = false;
        parskip = 0.0;
        itemsep = 0;
@@ -131,7 +130,6 @@ Layout::Layout ()
 }
 
 
-// Reads a layout definition from file
 bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 {
        // This table is sorted alphabetically [asierra 30March96]
@@ -181,6 +179,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 },
@@ -224,14 +223,9 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                                               << 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())
+                                       for (size_t i = 0; i != tclass.layoutCount(); ++i)
+                                               lyxerr << to_utf8(tclass.layout(i)->name())
                                                       << endl;
-                                       }
 
                                        //lexrc.printError("Cannot copy known "
                                        //               "style `$$Token'");
@@ -312,16 +306,16 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
                        break;
 
                case LT_FONT:
-                       font.lyxRead(lexrc);
-                       labelfont= font;
+                       font = lyxRead(lexrc, font);
+                       labelfont = font;
                        break;
 
                case LT_TEXTFONT:
-                       font.lyxRead(lexrc);
+                       font = lyxRead(lexrc, font);
                        break;
 
                case LT_LABELFONT:
-                       labelfont.lyxRead(lexrc);
+                       labelfont = lyxRead(lexrc, labelfont);
                        break;
 
                case LT_NEXTNOINDENT:   // Indent next paragraph?
@@ -375,22 +369,22 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 
                case LT_LEFTMARGIN:     // left margin type
                        if (lexrc.next())
-                               leftmargin = lexrc.getString();
+                               leftmargin = lexrc.getDocString();
                        break;
 
                case LT_RIGHTMARGIN:    // right margin type
                        if (lexrc.next())
-                               rightmargin = lexrc.getString();
+                               rightmargin = lexrc.getDocString();
                        break;
 
                case LT_LABELINDENT:    // label indenting flag
                        if (lexrc.next())
-                               labelindent = lexrc.getString();
+                               labelindent = lexrc.getDocString();
                        break;
 
                case LT_PARINDENT:      // paragraph indent. flag
                        if (lexrc.next())
-                               parindent = lexrc.getString();
+                               parindent = lexrc.getDocString();
                        break;
 
                case LT_PARSKIP:        // paragraph skip size
@@ -420,7 +414,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
 
                case LT_LABELSEP:       // label separator
                        if (lexrc.next()) {
-                               labelsep = subst(lexrc.getString(), 'x', ' ');
+                               labelsep = from_utf8(subst(lexrc.getString(), 'x', ' '));
                        }
                        break;
 
@@ -486,11 +480,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;
 }
 
 
@@ -656,17 +658,14 @@ void Layout::readLabelType(Lexer & lexrc)
 }
 
 
-namespace {
-
-keyword_item endlabelTypeTags[] = {
+static keyword_item endlabelTypeTags[] =
+{
        { "box",        END_LABEL_BOX },
        { "filled_box", END_LABEL_FILLED_BOX },
        { "no_label",   END_LABEL_NO_LABEL },
        { "static",     END_LABEL_STATIC }
 };
 
-} // namespace anon
-
 
 void Layout::readEndLabelType(Lexer & lexrc)
 {
@@ -681,7 +680,7 @@ void Layout::readEndLabelType(Lexer & lexrc)
        case END_LABEL_BOX:
        case END_LABEL_FILLED_BOX:
        case END_LABEL_NO_LABEL:
-               endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
+               endlabeltype = static_cast<EndLabelType>(le);
                break;
        default:
                lyxerr << "Unhandled value " << le
@@ -713,7 +712,7 @@ void Layout::readMargin(Lexer & lexrc)
        case MARGIN_DYNAMIC:
        case MARGIN_FIRST_DYNAMIC:
        case MARGIN_RIGHT_ADDRESS_BOX:
-               margintype = static_cast<LYX_MARGIN_TYPE>(le);
+               margintype = static_cast<MarginType>(le);
                break;
        default:
                lyxerr << "Unhandled value " << le
@@ -746,7 +745,7 @@ void Layout::readLatexType(Lexer & lexrc)
        case LATEX_ITEM_ENVIRONMENT:
        case LATEX_BIB_ENVIRONMENT:
        case LATEX_LIST_ENVIRONMENT:
-               latextype = static_cast<LYX_LATEX_TYPES>(le);
+               latextype = static_cast<LatexType>(le);
                break;
        default:
                lyxerr << "Unhandled value " << le
@@ -805,9 +804,9 @@ docstring const & Layout::name() const
 }
 
 
-void Layout::setName(docstring const & n)
+void Layout::setName(docstring const & name)
 {
-       name_ = n;
+       name_ = name;
 }
 
 
@@ -833,6 +832,4 @@ Layout * Layout::forCaption()
        return lay;
 }
 
-
-
 } // namespace lyx