]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.git] / src / TextClass.cpp
index 4cd7599116e0fed62fb23f703a3e460fc8a06a8d..8aae1abe87667f081ba339f8327cb8a461266ccc 100644 (file)
@@ -107,6 +107,7 @@ TextClass::TextClass(string const & fn, string const & cln,
          floatlist_(new FloatList), counters_(new Counters),
          texClassAvail_(texClassAvail)
 {
+       modular_ = false;
        outputType_ = LATEX;
        columns_ = 1;
        sides_ = OneSide;
@@ -173,7 +174,7 @@ enum TextClassTags {
 
 
 // Reads a textclass structure from file.
-bool TextClass::read(FileName const & filename, bool merge)
+bool TextClass::read(FileName const & filename, ReadType rt)
 {
        if (!support::isFileReadable(filename)) {
                lyxerr << "Cannot read layout file `" << filename << "'."
@@ -208,14 +209,21 @@ bool TextClass::read(FileName const & filename, bool merge)
                { "tocdepth",        TC_TOCDEPTH }
        };
 
-       if (!merge)
-               LYXERR(Debug::TCLASS) << "Reading textclass "
-                                     << to_utf8(makeDisplayPath(filename.absFilename()))
-                                     << endl;
-       else
-               LYXERR(Debug::TCLASS) << "Reading input file "
-                                     << to_utf8(makeDisplayPath(filename.absFilename()))
-                                     << endl;
+       switch (rt) {
+       case BASECLASS:
+               LYXERR(Debug::TCLASS) << "Reading textclass ";
+               break;
+       case MERGE:
+               LYXERR(Debug::TCLASS) << "Reading input file ";
+         break;
+       case MODULE:
+               LYXERR(Debug::TCLASS) << "Reading module file ";
+               break;
+       default:
+               BOOST_ASSERT(false);
+       }
+       LYXERR(Debug::TCLASS) << to_utf8(makeDisplayPath(filename.absFilename()))
+               << endl;
 
        Lexer lexrc(textClassTags,
                sizeof(textClassTags) / sizeof(textClassTags[0]));
@@ -264,7 +272,7 @@ bool TextClass::read(FileName const & filename, bool merge)
                                        lexrc.printError("Could not find input"
                                                         "file: " + inc);
                                        error = true;
-                               } else if (read(tmp, true)) {
+                               } else if (read(tmp, MERGE)) {
                                        lexrc.printError("Error reading input"
                                                         "file: " + tmp.absFilename());
                                        error = true;
@@ -441,12 +449,20 @@ bool TextClass::read(FileName const & filename, bool merge)
                FileName const tempfile(support::tempName());
                error = !layout2layout(filename, tempfile);
                if (!error)
-                       error = read(tempfile, merge);
+                       error = read(tempfile, rt);
                support::unlink(tempfile);
                return error;
        }
 
-       if (!merge) { // we are at top level here.
+       if (rt == MODULE) 
+               LYXERR(Debug::TCLASS) << "Finished reading module file "
+                               << to_utf8(makeDisplayPath(filename.absFilename()))
+                               << endl;
+       else if (rt == MERGE)
+               LYXERR(Debug::TCLASS) << "Finished reading input file "
+                               << to_utf8(makeDisplayPath(filename.absFilename()))
+                               << endl;
+       else { // we are at top level here.
                LYXERR(Debug::TCLASS) << "Finished reading textclass "
                                      << to_utf8(makeDisplayPath(filename.absFilename()))
                                      << endl;
@@ -476,10 +492,7 @@ bool TextClass::read(FileName const & filename, bool merge)
                        << "Minimum TocLevel is " << min_toclevel_
                        << ", maximum is " << max_toclevel_ <<endl;
 
-       } else
-               LYXERR(Debug::TCLASS) << "Finished reading input file "
-                                     << to_utf8(makeDisplayPath(filename.absFilename()))
-                                     << endl;
+       }
 
        return error;
 }
@@ -598,6 +611,8 @@ void TextClass::readClassOptions(Lexer & lexrc)
 
 enum InsetLayoutTags {
        IL_FONT = 1,
+       IL_BGCOLOR,
+       IL_DECORATION,
        IL_LABELFONT,
        IL_LABELSTRING,
        IL_LATEXNAME,
@@ -612,6 +627,8 @@ enum InsetLayoutTags {
 void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
 {
        keyword_item elementTags[] = {
+               { "bgcolor", IL_BGCOLOR },
+               { "decoration", IL_DECORATION },
                { "end", IL_END },
                { "font", IL_FONT },
                { "labelfont", IL_LABELFONT },
@@ -628,10 +645,12 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
        string lyxtype;
        docstring labelstring;
        string latextype;
+       string decoration;
        string latexname;
        string latexparam;
        Font font(Font::ALL_INHERIT);
        Font labelfont(Font::ALL_INHERIT);
+       Color::color bgcolor(Color::background);
        string preamble;
 
        bool getout = false;
@@ -656,6 +675,10 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                        lexrc.next();
                        labelstring = lexrc.getDocString();
                        break;
+               case IL_DECORATION:
+                       lexrc.next();
+                       decoration = lexrc.getString();
+                       break;
                case IL_LATEXNAME:
                        lexrc.next();
                        latexname = lexrc.getString();
@@ -671,8 +694,15 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                case IL_FONT:
                        font.lyxRead(lexrc);
                        font.realize(defaultfont());
+                       // 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;
@@ -689,18 +719,15 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                il.name = to_ascii(name);
                il.lyxtype = lyxtype;
                il.labelstring = labelstring;
+               il.decoration = decoration;
                il.latextype = latextype;
                il.latexname = latexname;
                il.latexparam = latexparam;
                il.font = font;
                il.labelfont = labelfont;
+               il.bgcolor = bgcolor;           
                il.preamble = preamble;
                insetlayoutlist_[name] = il;
-
-               // test name for CS:
-               if (il.lyxtype == "charstyle" || il.lyxtype == "custom") {
-                       charstyles().push_back(il);
-               }
        }
 
        lexrc.popTable();
@@ -1011,6 +1038,14 @@ Counters & TextClass::counters() const
        return *counters_.get();
 }
 
+
+// Return the layout object of an inset given by name. If the name
+// is not found as such, the part after the ':' is stripped off, and
+// searched again. In this way, an error fallback can be provided:
+// An erroneous 'CharStyle:badname' (e.g., after a documentclass switch)
+// will invoke the layout object defined by name = 'CharStyle'.
+// If that doesn't work either, an empty object returns (shouldn't
+// happen).  -- Idea JMarc, comment MV
 InsetLayout const & TextClass::insetlayout(docstring const & name) const 
 {
        docstring n = name;
@@ -1022,23 +1057,13 @@ InsetLayout const & TextClass::insetlayout(docstring const & name) const
                        break;
                n = n.substr(0,i);
        }
-       static const InsetLayout empty;
+       static InsetLayout empty;
+       empty.labelstring = from_utf8("UNDEFINED");
+       empty.bgcolor = Color::error;
        return empty;
 }
 
 
-CharStyles::iterator TextClass::charstyle(string const & s) const
-{
-       CharStyles::iterator cs = charstyles().begin();
-       CharStyles::iterator csend = charstyles().end();
-       for (; cs != csend; ++cs) {
-               if (cs->name == s)
-                       return cs;
-       }
-       return csend;
-}
-
-
 docstring const & TextClass::defaultLayoutName() const
 {
        // This really should come from the actual layout... (Lgb)