]> git.lyx.org Git - features.git/commitdiff
This is the second commit in the process of making InsetLayout a real class.
authorRichard Heck <rgheck@comcast.net>
Fri, 22 Feb 2008 03:27:42 +0000 (03:27 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 22 Feb 2008 03:27:42 +0000 (03:27 +0000)
Here, we move TextClass::readInsetLayout() to InsetLayout::read().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23117 a592a061-630c-0410-9148-cb99ea01b6c8

src/TextClass.cpp
src/TextClass.h
src/insets/InsetCollapsable.cpp
src/insets/InsetLayout.cpp [new file with mode: 0644]
src/insets/InsetLayout.h

index 2dbd10b6f364d82d679f1fbb29f47afc33c5241a..c5dcd2ec13e971e9503ab54b8d9b121777087ef7 100644 (file)
@@ -450,8 +450,11 @@ bool TextClass::read(FileName const & filename, ReadType rt)
 
                case TC_INSETLAYOUT:
                        if (lexrc.next()) {
-                               docstring const name = subst(lexrc.getDocString(), '_', ' ');
-                               readInsetLayout(lexrc, name);
+                               InsetLayout il;
+                               if (il.read(lexrc)) {
+                                       insetlayoutlist_[il.name()] = il;
+                               }
+                               // else there was an error, so forget it
                        }
                        break;
 
@@ -668,191 +671,6 @@ void TextClass::readClassOptions(Lexer & lexrc)
 }
 
 
-enum InsetLayoutTags {
-       IL_FONT = 1,
-       IL_BGCOLOR,
-       IL_DECORATION,
-       IL_FREESPACING,
-       IL_FORCELTR,
-       IL_LABELFONT,
-       IL_LABELSTRING,
-       IL_LATEXNAME,
-       IL_LATEXPARAM,
-       IL_LATEXTYPE,
-       IL_LYXTYPE,
-       IL_KEEPEMPTY,
-       IL_MULTIPAR,
-       IL_NEEDPROTECT,
-       IL_PASSTHRU,
-       IL_PREAMBLE,
-       IL_REQUIRES,
-       IL_END
-};
-
-
-void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
-{
-       keyword_item elementTags[] = {
-               { "bgcolor", IL_BGCOLOR },
-               { "decoration", IL_DECORATION },
-               { "end", IL_END },
-               { "font", IL_FONT },
-               { "forceltr", IL_FORCELTR },
-               { "freespacing", IL_FREESPACING },
-               { "keepempty", IL_KEEPEMPTY },
-               { "labelfont", IL_LABELFONT },
-               { "labelstring", IL_LABELSTRING },
-               { "latexname", IL_LATEXNAME },
-               { "latexparam", IL_LATEXPARAM },
-               { "latextype", IL_LATEXTYPE },
-               { "lyxtype", IL_LYXTYPE },
-               { "multipar", IL_MULTIPAR },
-               { "needprotect", IL_NEEDPROTECT },
-               { "passthru", IL_PASSTHRU },
-               { "preamble", IL_PREAMBLE },
-               { "requires", IL_REQUIRES }
-       };
-
-       lexrc.pushTable(elementTags, IL_END);
-
-       string lyxtype;
-       docstring labelstring;
-       string latextype;
-       string decoration;
-       string latexname;
-       string latexparam;
-       FontInfo font = inherit_font;
-       FontInfo labelfont = inherit_font;
-       ColorCode bgcolor(Color_background);
-       string preamble;
-       set<string> requires;
-       bool multipar = false;
-       bool passthru = false;
-       bool needprotect = false;
-       bool keepempty = false;
-       bool freespacing = false;
-       bool forceltr = false;
-
-       bool getout = false;
-       while (!getout && lexrc.isOK()) {
-               int le = lexrc.lex();
-               switch (le) {
-               case Lexer::LEX_UNDEF:
-                       lexrc.printError("Unknown InsetLayout tag `$$Token'");
-                       continue;
-               default: break;
-               }
-               switch (static_cast<InsetLayoutTags>(le)) {
-               case IL_LYXTYPE:
-                       lexrc.next();
-                       lyxtype = lexrc.getString();
-                       break;
-               case IL_LATEXTYPE:
-                       lexrc.next();
-                       latextype = lexrc.getString();
-                       break;
-               case IL_LABELSTRING:
-                       lexrc.next();
-                       labelstring = lexrc.getDocString();
-                       break;
-               case IL_DECORATION:
-                       lexrc.next();
-                       decoration = lexrc.getString();
-                       break;
-               case IL_LATEXNAME:
-                       lexrc.next();
-                       latexname = lexrc.getString();
-                       break;
-               case IL_LATEXPARAM:
-                       lexrc.next();
-                       latexparam = subst(lexrc.getString(), "&quot;", "\"");
-                       break;
-               case IL_LABELFONT:
-                       labelfont = lyxRead(lexrc, inherit_font);
-                       break;
-               case IL_FORCELTR:
-                       lexrc.next();
-                       forceltr = lexrc.getBool();
-                       break;
-               case IL_MULTIPAR:
-                       lexrc.next();
-                       multipar = lexrc.getBool();
-                       break;
-               case IL_PASSTHRU:
-                       lexrc.next();
-                       passthru = lexrc.getBool();
-                       break;
-               case IL_KEEPEMPTY:
-                       lexrc.next();
-                       keepempty = lexrc.getBool();
-                       break;
-               case IL_FREESPACING:
-                       lexrc.next();
-                       freespacing = lexrc.getBool();
-                       break;
-               case IL_NEEDPROTECT:
-                       lexrc.next();
-                       needprotect = lexrc.getBool();
-                       break;
-               case IL_FONT:
-                       font = lyxRead(lexrc, inherit_font);
-                       // So: define font before labelfont
-                       labelfont = font;
-                       break;
-               case IL_BGCOLOR: {
-                       lexrc.next();
-                       string const token = lexrc.getString();
-                       bgcolor = lcolor.getFromLyXName(token);
-                       break;
-               }
-               case IL_PREAMBLE:
-                       preamble = lexrc.getLongString("EndPreamble");
-                       break;
-               case IL_REQUIRES: {
-                       lexrc.eatLine();
-                       vector<string> const req 
-                               = getVectorFromString(lexrc.getString());
-                       requires.insert(req.begin(), req.end());
-                       break;
-               }
-               case IL_END:
-                       getout = true;
-                       break;
-               }
-       }
-
-       // Here add element to list if getout == true
-       if (getout) {
-               InsetLayout il;
-               il.name_ = to_ascii(name);
-               il.lyxtype_ = lyxtype;
-               il.labelstring_ = labelstring;
-               il.decoration_ = decoration;
-               il.latextype_ = latextype;
-               il.latexname_ = latexname;
-               il.latexparam_ = latexparam;
-               il.multipar_ = multipar;
-               il.passthru_ = passthru;
-               il.needprotect_ = needprotect;
-               il.freespacing_ = freespacing;
-               il.forceltr_ = forceltr;
-               il.keepempty_ = keepempty;
-               il.font_ = font;
-               // The label font is generally used as-is without
-               // any realization against a given context.
-               labelfont.realize(sane_font);
-               il.labelfont_ = labelfont;
-               il.bgcolor_ = bgcolor;
-               il.preamble_ = preamble;
-               il.requires_ = requires;
-               insetlayoutlist_[name] = il;
-       }
-
-       lexrc.popTable();
-}
-
-
-
 enum FloatTags {
        FT_TYPE = 1,
        FT_NAME,
index 818ce6a56dfb4ec69c40058f6b99980e32fadeb3..88b693b41d352fa103cd1a57a0a9194ea9510e9b 100644 (file)
@@ -80,8 +80,6 @@ public:
        ///
        void readCharStyle(Lexer &, std::string const &);
        ///
-       void readInsetLayout(Lexer &, docstring const &);
-       ///
        void readFloat(Lexer &);
        ///
        void readCounter(Lexer &);
index 97783d564321769782a461632d091ea17ea33118..46aff94a0d395cf82ecccf5b1abfebefd6f7fc33 100644 (file)
@@ -880,14 +880,14 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
                return;
 
        // Force inclusion of preamble snippet in layout file
-       features.require(layout_->name());
+       features.require(to_utf8(layout_->name()));
        InsetText::validate(features);
 }
 
 
 bool InsetCollapsable::undefined() const
 {
-       std::string const & n = getLayout().name();
+       docstring const & n = getLayout().name();
        return n.empty() || n == TextClass::emptyInsetLayout().name();
 }
 
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
new file mode 100644 (file)
index 0000000..e921974
--- /dev/null
@@ -0,0 +1,193 @@
+// -*- C++ -*-
+/**
+ * \file InsetLayout.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Martin Vermeer
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetLayout.h"
+
+#include "Color.h"
+#include "Font.h"
+#include "support/lstrings.h"
+
+#include <vector>
+
+using std::string;
+using std::set;
+using std::vector;
+
+namespace lyx {
+
+InsetLayout::InsetLayout() :
+       name_(from_ascii("undefined")), labelstring_(from_ascii("UNDEFINED")),
+       font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error), 
+       multipar_(false), passthru_(false), needprotect_(false),
+       freespacing_(false), keepempty_(false), forceltr_(false)
+{ 
+       labelfont_.setColor(Color_error); 
+}
+
+
+enum InsetLayoutTags {
+       IL_FONT = 1,
+       IL_BGCOLOR,
+       IL_DECORATION,
+       IL_FREESPACING,
+       IL_FORCELTR,
+       IL_LABELFONT,
+       IL_LABELSTRING,
+       IL_LATEXNAME,
+       IL_LATEXPARAM,
+       IL_LATEXTYPE,
+       IL_LYXTYPE,
+       IL_KEEPEMPTY,
+       IL_MULTIPAR,
+       IL_NEEDPROTECT,
+       IL_PASSTHRU,
+       IL_PREAMBLE,
+       IL_REQUIRES,
+       IL_END
+};
+
+
+bool InsetLayout::read(Lexer & lexrc)
+{
+       name_ = support::subst(lexrc.getDocString(), '_', ' ');
+
+       keyword_item elementTags[] = {
+               { "bgcolor", IL_BGCOLOR },
+               { "decoration", IL_DECORATION },
+               { "end", IL_END },
+               { "font", IL_FONT },
+               { "forceltr", IL_FORCELTR },
+               { "freespacing", IL_FREESPACING },
+               { "keepempty", IL_KEEPEMPTY },
+               { "labelfont", IL_LABELFONT },
+               { "labelstring", IL_LABELSTRING },
+               { "latexname", IL_LATEXNAME },
+               { "latexparam", IL_LATEXPARAM },
+               { "latextype", IL_LATEXTYPE },
+               { "lyxtype", IL_LYXTYPE },
+               { "multipar", IL_MULTIPAR },
+               { "needprotect", IL_NEEDPROTECT },
+               { "passthru", IL_PASSTHRU },
+               { "preamble", IL_PREAMBLE },
+               { "requires", IL_REQUIRES }
+       };
+
+       lexrc.pushTable(elementTags, IL_END);
+
+       FontInfo font = inherit_font;
+       labelfont_ = inherit_font;
+       bgcolor_ = Color_background;
+       bool getout = false;
+       
+       while (!getout && lexrc.isOK()) {
+               int le = lexrc.lex();
+               switch (le) {
+               case Lexer::LEX_UNDEF:
+                       lexrc.printError("Unknown InsetLayout tag `$$Token'");
+                       continue;
+               default: break;
+               }
+               switch (static_cast<InsetLayoutTags>(le)) {
+               case IL_LYXTYPE:
+                       lexrc.next();
+                       lyxtype_ = lexrc.getString();
+                       break;
+               case IL_LATEXTYPE:
+                       lexrc.next();
+                       latextype_ = lexrc.getString();
+                       break;
+               case IL_LABELSTRING:
+                       lexrc.next();
+                       labelstring_ = lexrc.getDocString();
+                       break;
+               case IL_DECORATION:
+                       lexrc.next();
+                       decoration_ = lexrc.getString();
+                       break;
+               case IL_LATEXNAME:
+                       lexrc.next();
+                       latexname_ = lexrc.getString();
+                       break;
+               case IL_LATEXPARAM:
+                       lexrc.next();
+                       latexparam_ = support::subst(lexrc.getString(), "&quot;", "\"");
+                       break;
+               case IL_LABELFONT:
+                       labelfont_ = lyxRead(lexrc, inherit_font);
+                       break;
+               case IL_FORCELTR:
+                       lexrc.next();
+                       forceltr_ = lexrc.getBool();
+                       break;
+               case IL_MULTIPAR:
+                       lexrc.next();
+                       multipar_ = lexrc.getBool();
+                       break;
+               case IL_PASSTHRU:
+                       lexrc.next();
+                       passthru_ = lexrc.getBool();
+                       break;
+               case IL_KEEPEMPTY:
+                       lexrc.next();
+                       keepempty_ = lexrc.getBool();
+                       break;
+               case IL_FREESPACING:
+                       lexrc.next();
+                       freespacing_ = lexrc.getBool();
+                       break;
+               case IL_NEEDPROTECT:
+                       lexrc.next();
+                       needprotect_ = lexrc.getBool();
+                       break;
+               case IL_FONT: {
+                       font = lyxRead(lexrc, inherit_font);
+                       // So: define font before labelfont
+                       labelfont_ = font;
+                       break;
+               }
+               case IL_BGCOLOR: {
+                       lexrc.next();
+                       string const token = lexrc.getString();
+                       bgcolor_ = lcolor.getFromLyXName(token);
+                       break;
+               }
+               case IL_PREAMBLE:
+                       preamble_ = lexrc.getLongString("EndPreamble");
+                       break;
+               case IL_REQUIRES: {
+                       lexrc.eatLine();
+                       vector<string> const req 
+                               = support::getVectorFromString(lexrc.getString());
+                       requires_.insert(req.begin(), req.end());
+                       break;
+               }
+               case IL_END:
+                       getout = true;
+                       break;
+               }
+       }
+
+       // Here add element to list if getout == true
+       if (!getout)
+               return false;
+       
+       // The label font is generally used as-is without
+       // any realization against a given context.
+       labelfont_.realize(sane_font);
+
+       lexrc.popTable();
+       return true;
+}
+
+} //namespace lyx
index 08cab983d405366a584cae9e78b5850f2192ef9e..477b0c2609eb4a4e11e4fb58acaa07d762aabcf5 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "ColorCode.h"
 #include "FontInfo.h"
+#include "Lexer.h"
 
 #include "support/docstring.h"
 
@@ -29,7 +30,9 @@ public:
        ///
        InsetLayout();
        ///
-       std::string name() const { return name_; };
+       bool read(Lexer & lexrc);
+       ///
+       docstring name() const { return name_; };
        ///
        std::string lyxtype() const { return lyxtype_; };
        ///
@@ -67,7 +70,7 @@ public:
        bool isForceLtr() const { return forceltr_; };
 private:
        ///
-       std::string name_;
+       docstring name_;
        ///
        std::string lyxtype_;
        ///
@@ -102,9 +105,6 @@ private:
        bool keepempty_;
        ///
        bool forceltr_;
-       
-       //FIXME This will be removed.
-       friend class TextClass;
 };
 
 } // namespace lyx