]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtextclass.C
float2string #4 (Spacing)
[lyx.git] / src / lyxtextclass.C
index 058db9e89305b043741ce91d942c4c11f3581e24..168520301dfa345535120f4a6dec85d789450db4 100644 (file)
@@ -36,30 +36,29 @@ using std::string;
 using std::ostream;
 
 
-namespace { // anon
+namespace {
 
-struct compare_name {
-
-       compare_name(string const & name)
+class LayoutNamesEqual : public std::unary_function<LyXLayout_ptr, bool> {
+public:
+       LayoutNamesEqual(string const & name)
                : name_(name)
        {}
-
-       bool operator()(boost::shared_ptr<LyXLayout> const & c)
+       bool operator()(LyXLayout_ptr const & c) const
        {
                return c->name() == name_;
        }
-
+private:
        string name_;
-
 };
 
-} // anon
+} // namespace anon
 
 
 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
                           string const & desc, bool texClassAvail )
        : name_(fn), latexname_(cln), description_(desc),
-         floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
+         floatlist_(new FloatList), ctrs_(new Counters),
+         texClassAvail_(texClassAvail)
 {
        outputType_ = LATEX;
        columns_ = 1;
@@ -73,7 +72,7 @@ LyXTextClass::LyXTextClass(string const & fn, string const & cln,
        provides_ = nothing;
        titletype_ = TITLE_COMMAND_AFTER;
        titlename_ = "maketitle";
-       loaded = false;
+       loaded_ = false;
 }
 
 
@@ -470,6 +469,7 @@ enum ClassOptionsTags {
        CO_FONTSIZE = 1,
        CO_PAGESTYLE,
        CO_OTHER,
+       CO_HEADER,
        CO_END
 };
 
@@ -479,6 +479,7 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc)
        keyword_item classOptionsTags[] = {
                {"end", CO_END },
                {"fontsize", CO_FONTSIZE },
+               {"header", CO_HEADER },
                {"other", CO_OTHER },
                {"pagestyle", CO_PAGESTYLE }
        };
@@ -506,6 +507,10 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc)
                        lexrc.next();
                        options_ = lexrc.getString();
                        break;
+               case CO_HEADER:
+                       lexrc.next();
+                       class_header_ = subst(lexrc.getString(), "&quot;", "\"");
+                       break;
                case CO_END:
                        getout = true;
                        break;
@@ -519,6 +524,7 @@ enum CharStyleTags {
        CS_LABELFONT,
        CS_LATEXTYPE,
        CS_LATEXNAME,
+       CS_LATEXPARAM,
        CS_PREAMBLE,
        CS_END
 };
@@ -531,6 +537,7 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
                { "font", CS_FONT },
                { "labelfont", CS_LABELFONT },
                { "latexname", CS_LATEXNAME },
+               { "latexparam", CS_LATEXPARAM },
                { "latextype", CS_LATEXTYPE },
                { "preamble", CS_PREAMBLE}
        };
@@ -539,10 +546,11 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
 
        string latextype;
        string latexname;
+       string latexparam;
        LyXFont font(LyXFont::ALL_INHERIT);
        LyXFont labelfont(LyXFont::ALL_INHERIT);
        string preamble;
-       
+
        bool getout = false;
        while (!getout && lexrc.isOK()) {
                int le = lexrc.lex();
@@ -561,6 +569,10 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
                        lexrc.next();
                        latexname = lexrc.getString();
                        break;
+               case CS_LATEXPARAM:
+                       lexrc.next();
+                       latexparam = subst(lexrc.getString(), "&quot;", "\"");
+                       break;
                case CS_LABELFONT:
                        labelfont.lyxRead(lexrc);
                        break;
@@ -584,6 +596,7 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
                cs.name = name;
                cs.latextype = latextype;
                cs.latexname = latexname;
+               cs.latexparam = latexparam;
                cs.font = font;
                cs.labelfont = labelfont;
                cs.preamble = preamble;
@@ -776,7 +789,7 @@ bool LyXTextClass::hasLayout(string const & n) const
        string const name = (n.empty() ? defaultLayoutName() : n);
 
        return find_if(layoutlist_.begin(), layoutlist_.end(),
-                      compare_name(name))
+                      LayoutNamesEqual(name))
                != layoutlist_.end();
 }
 
@@ -789,7 +802,7 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const
        LayoutList::const_iterator cit =
                find_if(layoutlist_.begin(),
                        layoutlist_.end(),
-                       compare_name(name));
+                       LayoutNamesEqual(name));
 
        if (cit == layoutlist_.end()) {
                lyxerr << "We failed to find the layout '" << name
@@ -815,7 +828,7 @@ bool LyXTextClass::delete_layout(string const & name)
 
        LayoutList::iterator it =
                remove_if(layoutlist_.begin(), layoutlist_.end(),
-                         compare_name(name));
+                         LayoutNamesEqual(name));
 
        LayoutList::iterator end = layoutlist_.end();
        bool const ret = (it != end);
@@ -827,22 +840,22 @@ bool LyXTextClass::delete_layout(string const & name)
 // Load textclass info if not loaded yet
 bool LyXTextClass::load() const
 {
-       if (loaded)
+       if (loaded_)
                return true;
 
        // Read style-file
        string const real_file = LibFileSearch("layouts", name_, "layout");
+       loaded_ = const_cast<LyXTextClass*>(this)->Read(real_file) == 0;
 
-       if (const_cast<LyXTextClass*>(this)->Read(real_file)) {
+       if (!loaded_) {
                lyxerr << "Error reading `"
                       << MakeDisplayPath(real_file)
                       << "'\n(Check `" << name_
                       << "')\nCheck your installation and "
                        "try Options/Reconfigure..." << endl;
-               loaded = false;
        }
-       loaded = true;
-       return loaded;
+
+       return loaded_;
 }
 
 
@@ -926,6 +939,12 @@ string const & LyXTextClass::options() const
 }
 
 
+string const & LyXTextClass::class_header() const
+{
+       return class_header_;
+}
+
+
 string const & LyXTextClass::pagestyle() const
 {
        return pagestyle_;