]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / TextClass.cpp
index 2ea70537312090a7499cda7200602f4e1d5e88ce..cb8b8c43b2aad52600192e65a7e32494ef095280 100644 (file)
@@ -61,7 +61,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 56; //spitz: New Float tags AllowedPlacement
+int const LAYOUT_FORMAT = 60; //lasgouttes LongTableNoNumber => Unnumbered
 
 namespace {
 
@@ -129,9 +129,6 @@ string translateReadType(TextClass::ReadType rt)
 docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout"));
 
 
-InsetLayout DocumentClass::plain_insetlayout_;
-
-
 /////////////////////////////////////////////////////////////////////////
 //
 // TextClass
@@ -139,22 +136,16 @@ InsetLayout DocumentClass::plain_insetlayout_;
 /////////////////////////////////////////////////////////////////////////
 
 TextClass::TextClass()
+       : loaded_(false), tex_class_avail_(false),
+         opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"),
+         opt_pagestyle_("empty|plain|headings|fancy"), pagestyle_("default"),
+         columns_(1), sides_(OneSide), secnumdepth_(3), tocdepth_(3),
+         outputType_(LATEX), outputFormat_("latex"),
+         defaultfont_(sane_font),
+         titletype_(TITLE_COMMAND_AFTER), titlename_("maketitle"),
+         min_toclevel_(0), max_toclevel_(0),
+         cite_full_author_list_(true)
 {
-       outputType_ = LATEX;
-       outputFormat_ = "latex";
-       columns_ = 1;
-       sides_ = OneSide;
-       secnumdepth_ = 3;
-       tocdepth_ = 3;
-       pagestyle_ = "default";
-       defaultfont_ = sane_font;
-       opt_enginetype_ = "authoryear|numerical";
-       opt_fontsize_ = "10|11|12";
-       opt_pagestyle_ = "empty|plain|headings|fancy";
-       cite_full_author_list_ = true;
-       titletype_ = TITLE_COMMAND_AFTER;
-       titlename_ = "maketitle";
-       loaded_ = false;
 }
 
 
@@ -179,7 +170,8 @@ enum TextClassTags {
        TC_OUTPUTFORMAT,
        TC_INPUT,
        TC_STYLE,
-       TC_IFSTYLE,
+       TC_MODIFYSTYLE,
+       TC_PROVIDESTYLE,
        TC_DEFAULTSTYLE,
        TC_INSETLAYOUT,
        TC_NOINSETLAYOUT,
@@ -218,7 +210,8 @@ enum TextClassTags {
        TC_CITEENGINETYPE,
        TC_CITEFORMAT,
        TC_DEFAULTBIBLIO,
-       TC_FULLAUTHORLIST
+       TC_FULLAUTHORLIST,
+       TC_OUTLINERNAME
 };
 
 
@@ -246,14 +239,15 @@ LexerKeyword textClassTags[] = {
        { "htmlstyles",        TC_HTMLSTYLES },
        { "htmltocsection",    TC_HTMLTOCSECTION },
        { "ifcounter",         TC_IFCOUNTER },
-       { "ifstyle",           TC_IFSTYLE },
        { "input",             TC_INPUT },
        { "insetlayout",       TC_INSETLAYOUT },
        { "leftmargin",        TC_LEFTMARGIN },
+       { "modifystyle",       TC_MODIFYSTYLE },
        { "nocounter",         TC_NOCOUNTER },
        { "nofloat",           TC_NOFLOAT },
        { "noinsetlayout",     TC_NOINSETLAYOUT },
        { "nostyle",           TC_NOSTYLE },
+       { "outlinername",      TC_OUTLINERNAME },
        { "outputformat",      TC_OUTPUTFORMAT },
        { "outputtype",        TC_OUTPUTTYPE },
        { "packageoptions",    TC_PKGOPTS },
@@ -261,6 +255,7 @@ LexerKeyword textClassTags[] = {
        { "preamble",          TC_PREAMBLE },
        { "provides",          TC_PROVIDES },
        { "providesmodule",    TC_PROVIDESMODULE },
+       { "providestyle",      TC_PROVIDESTYLE },
        { "requires",          TC_REQUIRES },
        { "rightmargin",       TC_RIGHTMARGIN },
        { "secnumdepth",       TC_SECNUMDEPTH },
@@ -419,8 +414,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                }
 
                // used below to track whether we are in an IfStyle or IfCounter tag.
-               bool ifstyle    = false;
-               bool ifcounter  = false;
+               bool modifystyle  = false;
+               bool providestyle = false;
+               bool ifcounter    = false;
 
                switch (static_cast<TextClassTags>(le)) {
 
@@ -451,8 +447,13 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
 
                case TC_INPUT: // Include file
                        if (lexrc.next()) {
+                               FileName tmp;
                                string const inc = lexrc.getString();
-                               FileName tmp = libFileSearch("layouts", inc,
+                               if (!path().empty() && (prefixIs(inc, "./") ||
+                                                       prefixIs(inc, "../")))
+                                       tmp = fileSearch(path(), inc, "layout");
+                               else
+                                       tmp = libFileSearch("layouts", inc,
                                                            "layout");
 
                                if (tmp.empty()) {
@@ -473,9 +474,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        }
                        break;
 
-               case TC_IFSTYLE:
-                       ifstyle = true;
-                       // fall through
+               case TC_MODIFYSTYLE:
+                       modifystyle = true;
+               // fall through
+               case TC_PROVIDESTYLE:
+                       // if modifystyle is true, then we got here by falling through
+                       // so we are not in an ProvideStyle block
+                       if (!modifystyle)
+                               providestyle = true;
+               // fall through
                case TC_STYLE: {
                        if (!lexrc.next()) {
                                lexrc.printError("No name given for style: `$$Token'.");
@@ -492,10 +499,21 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                // Since we couldn't read the name, we just scan the rest
                                // of the style and discard it.
                                error = !readStyle(lexrc, lay);
-                       } else if (hasLayout(name)) {
+                               break;
+                       }
+                       
+                       bool const have_layout = hasLayout(name);
+                       
+                       // If the layout already exists, then we want to add it to
+                       // the existing layout, as long as we are not in an ProvideStyle
+                       // block.
+                       if (have_layout && !providestyle) {
                                Layout & lay = operator[](name);
                                error = !readStyle(lexrc, lay);
-                       } else if (!ifstyle) {
+                       }
+                       // If the layout does not exist, then we want to create a new
+                       // one, but not if we are in a ModifyStyle block.
+                       else if (!have_layout && !modifystyle) {
                                Layout layout;
                                layout.setName(name);
                                error = !readStyle(lexrc, layout);
@@ -508,15 +526,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                        defaultlayout_ = name;
                                }
                        }
+                       // There are two ways to get here:
+                       //  (i)  The layout exists but we are in an ProvideStyle block
+                       //  (ii) The layout doesn't exist, but we are in an ModifyStyle
+                       //       block.
+                       // Either way, we just scan the rest and discard it
                        else {
-                               // this was an ifstyle where we didn't have the style
-                               // scan the rest and discard it
                                Layout lay;
                                readStyle(lexrc, lay);
                        }
-
-                       // reset flag
-                       ifstyle = false;
                        break;
                }
 
@@ -751,6 +769,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
 
                case TC_IFCOUNTER:
                        ifcounter = true;
+                       // fall through
                case TC_COUNTER:
                        if (lexrc.next()) {
                                docstring const name = lexrc.getDocString();
@@ -769,8 +788,6 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                lexrc.printError("No name given for style: `$$Token'.");
                                error = true;
                        }
-                       // reset flag
-                       ifcounter = false;
                        break;
 
                case TC_TITLELATEXTYPE:
@@ -788,6 +805,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                floatlist_.erase(nofloat);
                        }
                        break;
+
+               case TC_OUTLINERNAME:
+                       error = !readOutlinerName(lexrc);
+                       break;
                } // end of switch
 
                // Note that this is triggered the first time through the loop unless
@@ -802,7 +823,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                return ERROR;
 
        if (rt != BASECLASS)
-               return (error ? ERROR : OK);
+               return OK;
 
        if (defaultlayout_.empty()) {
                LYXERR0("Error: Textclass '" << name_
@@ -1098,11 +1119,15 @@ bool TextClass::readFloat(Lexer & lexrc)
                FT_LISTCOMMAND,
                FT_REFPREFIX,
                FT_ALLOWED_PLACEMENT,
+               FT_ALLOWS_SIDEWAYS,
+               FT_ALLOWS_WIDE,
                FT_END
        };
 
        LexerKeyword floatTags[] = {
                { "allowedplacement", FT_ALLOWED_PLACEMENT },
+               { "allowssideways", FT_ALLOWS_SIDEWAYS },
+               { "allowswide", FT_ALLOWS_WIDE },
                { "end", FT_END },
                { "extension", FT_EXT },
                { "guiname", FT_NAME },
@@ -1137,6 +1162,8 @@ bool TextClass::readFloat(Lexer & lexrc)
        string within;
        bool usesfloat = true;
        bool ispredefined = false;
+       bool allowswide = true;
+       bool allowssideways = true;
 
        bool getout = false;
        while (!getout && lexrc.isOK()) {
@@ -1212,6 +1239,14 @@ bool TextClass::readFloat(Lexer & lexrc)
                        lexrc.next();
                        ispredefined = lexrc.getBool();
                        break;
+               case FT_ALLOWS_SIDEWAYS:
+                       lexrc.next();
+                       allowssideways = lexrc.getBool();
+                       break;
+               case FT_ALLOWS_WIDE:
+                       lexrc.next();
+                       allowswide = lexrc.getBool();
+                       break;
                case FT_HTMLATTR:
                        lexrc.next();
                        htmlattr = lexrc.getString();
@@ -1252,8 +1287,9 @@ bool TextClass::readFloat(Lexer & lexrc)
                                  "not be able to produce a float list.");
                }
                Floating fl(type, placement, ext, within, style, name,
-                               listname, listcommand, refprefix, allowed_placement,
-                               htmltag, htmlattr, htmlstyle, usesfloat, ispredefined);
+                           listname, listcommand, refprefix, allowed_placement,
+                           htmltag, htmlattr, htmlstyle, usesfloat, ispredefined,
+                           allowswide, allowssideways);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
@@ -1267,6 +1303,39 @@ bool TextClass::readFloat(Lexer & lexrc)
 }
 
 
+bool TextClass::readOutlinerName(Lexer & lexrc)
+{
+       std::string type;
+       docstring name;
+       if (lexrc.next())
+               type = lexrc.getString();
+       else {
+               lexrc.printError("No type given for OutlinerName: `$$Token'.");
+               return false;
+       }
+       if (lexrc.next())
+               name = lexrc.getDocString();
+       else {
+               lexrc.printError("No name given for OutlinerName: `$$Token'.");
+               return false;
+       }
+       outliner_names_[type] = name;
+    return true;
+}
+
+
+docstring TextClass::outlinerName(std::string const & type) const
+{
+       std::map<std::string,docstring>::const_iterator const it
+               = outliner_names_.find(type);
+       if (it == outliner_names_.end()) {
+               LYXERR0("Missing OutlinerName for " << type << "!");
+               return from_utf8(type);
+       } else
+               return it->second;
+}
+
+
 string const & TextClass::prerequisites(string const & sep) const
 {
        if (contains(prerequisites_, ',')) {
@@ -1442,6 +1511,12 @@ InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
                n = n.substr(0, i);
        }
        // Layout "name" not found.
+       return plainInsetLayout();
+}
+
+
+InsetLayout const & DocumentClass::plainInsetLayout() {
+       static const InsetLayout plain_insetlayout_;
        return plain_insetlayout_;
 }