]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
Transfer the setting of the current LyXView from workArea::focusInEvent() to GuiView...
[lyx.git] / src / TextClass.cpp
index 54f5ef36ac0f8abcd7373feb495e0b0b3d2d5739..83a7bf9e3332d844e7f8552d008ca6752ee73213 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "TextClass.h"
 #include "debug.h"
+#include "Layout.h"
 #include "Lexer.h"
 #include "Counters.h"
 #include "gettext.h"
 #include "support/os.h"
 
 #include <boost/filesystem/operations.hpp>
-namespace fs = boost::filesystem;
 
 #include <sstream>
 
+namespace fs = boost::filesystem;
 
 namespace lyx {
 
@@ -107,6 +108,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 +175,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 +210,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 +273,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 +450,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 +493,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;
 }
@@ -501,7 +515,7 @@ void TextClass::readTitleType(Lexer & lexrc)
                return;
        case TITLE_COMMAND_AFTER:
        case TITLE_ENVIRONMENT:
-               titletype_ = static_cast<LYX_TITLE_LATEX_TYPES>(le);
+               titletype_ = static_cast<TitleLatexType>(le);
                break;
        default:
                lyxerr << "Unhandled value " << le
@@ -598,6 +612,7 @@ void TextClass::readClassOptions(Lexer & lexrc)
 
 enum InsetLayoutTags {
        IL_FONT = 1,
+       IL_BGCOLOR,
        IL_DECORATION,
        IL_LABELFONT,
        IL_LABELSTRING,
@@ -613,6 +628,7 @@ 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 },
@@ -635,6 +651,7 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
        string latexparam;
        Font font(Font::ALL_INHERIT);
        Font labelfont(Font::ALL_INHERIT);
+       Color::color bgcolor(Color::background);
        string preamble;
 
        bool getout = false;
@@ -678,8 +695,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;
@@ -702,6 +726,7 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                il.latexparam = latexparam;
                il.font = font;
                il.labelfont = labelfont;
+               il.bgcolor = bgcolor;           
                il.preamble = preamble;
                insetlayoutlist_[name] = il;
        }
@@ -1035,6 +1060,7 @@ InsetLayout const & TextClass::insetlayout(docstring const & name) const
        }
        static InsetLayout empty;
        empty.labelstring = from_utf8("UNDEFINED");
+       empty.bgcolor = Color::error;
        return empty;
 }
 
@@ -1143,7 +1169,7 @@ unsigned int TextClass::columns() const
 }
 
 
-LYX_TITLE_LATEX_TYPES TextClass::titletype() const
+TitleLatexType TextClass::titletype() const
 {
        return titletype_;
 }