]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtextclass.C
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[lyx.git] / src / lyxtextclass.C
index 9418b24464e77029deaab2cd3e95a66a486e04fa..63c6f92bb8c290e9ce28c91f6535c83ecda300d7 100644 (file)
@@ -31,8 +31,20 @@ using std::find_if;
 using std::remove_if;
 using std::ostream;
 
+namespace { // anon
+
+struct compare_name {
+       compare_name(string const & name)
+               : name_(name) {}
+       template <class C>
+       bool operator()(C & c) {
+               return c->name() == name_;
+       }
+       string name_;
+};
+
+} // anon
 
-/* ******************************************************************* */
 
 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
                           string const & desc)
@@ -91,6 +103,7 @@ enum TextClassTags {
        TC_CLASSOPTIONS,
        TC_PREAMBLE,
        TC_PROVIDESAMSMATH,
+       TC_PROVIDESNATBIB,
        TC_PROVIDESMAKEIDX,
        TC_PROVIDESURL,
        TC_LEFTMARGIN,
@@ -115,6 +128,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                { "preamble",        TC_PREAMBLE },
                { "providesamsmath", TC_PROVIDESAMSMATH },
                { "providesmakeidx", TC_PROVIDESMAKEIDX },
+               { "providesnatbib",  TC_PROVIDESNATBIB },
                { "providesurl",     TC_PROVIDESURL },
                { "rightmargin",     TC_RIGHTMARGIN },
                { "secnumdepth",     TC_SECNUMDEPTH },
@@ -183,14 +197,14 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                                string const name = subst(lexrc.getString(),
                                                    '_', ' ');
                                if (hasLayout(name)) {
-                                       LyXLayout & lay =
-                                               const_cast<LyXLayout &>(operator[](name));
-                                       error = do_readStyle(lexrc, lay);
+                                       LyXLayout * lay =
+                                               operator[](name).get();
+                                       error = do_readStyle(lexrc, *lay);
                                } else {
                                        LyXLayout lay;
                                        lay.setName(name);
                                        if (!(error = do_readStyle(lexrc, lay)))
-                                               layoutlist.push_back(lay);
+                                               layoutlist_.push_back(boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
                                        if (defaultlayout_.empty()) {
                                                // We do not have a default
                                                // layout yet, so we choose
@@ -239,7 +253,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 
                case TC_PAGESTYLE:
                        lexrc.next();
-                       pagestyle_ = strip(lexrc.getString());
+                       pagestyle_ = rtrim(lexrc.getString());
                        break;
 
                case TC_DEFAULTFONT:
@@ -284,6 +298,11 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                                provides_ |= amsmath;
                        break;
 
+               case TC_PROVIDESNATBIB:
+                       if (lexrc.next() && lexrc.getInteger())
+                               provides_ |= natbib;
+                       break;
+
                case TC_PROVIDESMAKEIDX:
                        if (lexrc.next() && lexrc.getInteger())
                                provides_ |= makeidx;
@@ -291,7 +310,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 
                case TC_PROVIDESURL:
                        if (lexrc.next() && lexrc.getInteger())
-                               provides_ = url;
+                               provides_ |= url;
                        break;
 
                case TC_LEFTMARGIN:     // left margin type
@@ -457,11 +476,11 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc)
                switch (static_cast<ClassOptionsTags>(le)) {
                case CO_FONTSIZE:
                        lexrc.next();
-                       opt_fontsize_ = strip(lexrc.getString());
+                       opt_fontsize_ = rtrim(lexrc.getString());
                        break;
                case CO_PAGESTYLE:
                        lexrc.next();
-                       opt_pagestyle_ = strip(lexrc.getString());
+                       opt_pagestyle_ = rtrim(lexrc.getString());
                        break;
                case CO_OTHER:
                        lexrc.next();
@@ -498,13 +517,13 @@ bool LyXTextClass::hasLayout(string const & n) const
 {
        string const name = (n.empty() ? defaultLayoutName() : n);
 
-       return find_if(layoutlist.begin(), layoutlist.end(),
-                      lyx::compare_memfun(&LyXLayout::name, name))
-               != layoutlist.end();
+       return find_if(layoutlist_.begin(), layoutlist_.end(),
+                      compare_name(name))
+               != layoutlist_.end();
 }
 
 
-LyXLayout const & LyXTextClass::operator[](string const & n) const
+LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
 {
        lyx::Assert(!n.empty());
 
@@ -517,15 +536,14 @@ LyXLayout const & LyXTextClass::operator[](string const & n) const
        static LayoutList::difference_type lastLayoutIndex;
 
        if (name == lastLayoutName)
-               return layoutlist[lastLayoutIndex];
-
+               return layoutlist_[lastLayoutIndex];
 
        LayoutList::const_iterator cit =
-               find_if(layoutlist.begin(),
-                       layoutlist.end(),
-                       lyx::compare_memfun(&LyXLayout::name, name));
+               find_if(layoutlist_.begin(),
+                       layoutlist_.end(),
+                       compare_name(name));
 
-       if (cit == layoutlist.end()) {
+       if (cit == layoutlist_.end()) {
                lyxerr << "We failed to find the layout '" << name
                       << "' in the layout list. You MUST investigate!"
                       << endl;
@@ -535,9 +553,9 @@ LyXLayout const & LyXTextClass::operator[](string const & n) const
        }
 
        lastLayoutName = name;
-       lastLayoutIndex = std::distance(layoutlist.begin(), cit);
+       lastLayoutIndex = std::distance(layoutlist_.begin(), cit);
 
-       return *cit;
+       return (*cit);
 }
 
 
@@ -547,11 +565,12 @@ bool LyXTextClass::delete_layout(string const & name)
                return false;
 
        LayoutList::iterator it =
-               remove_if(layoutlist.begin(), layoutlist.end(),
-                         lyx::compare_memfun(&LyXLayout::name, name));
-       LayoutList::iterator end = layoutlist.end();
+               remove_if(layoutlist_.begin(), layoutlist_.end(),
+                         compare_name(name));
+
+       LayoutList::iterator end = layoutlist_.end();
        bool const ret = (it != end);
-       layoutlist.erase(it, end);
+       layoutlist_.erase(it, end);
        return ret;
 }
 
@@ -575,7 +594,18 @@ bool LyXTextClass::load() const
        }
        loaded = true;
        return loaded;
+}
+
 
+FloatList & LyXTextClass::floats()
+{
+       return floatlist_;
+}
+
+
+FloatList const & LyXTextClass::floats() const
+{
+       return floatlist_;
 }
 
 
@@ -586,7 +616,7 @@ string const LyXTextClass::defaultLayoutName() const
 }
 
 
-LyXLayout const & LyXTextClass::defaultLayout() const
+LyXLayout_ptr const & LyXTextClass::defaultLayout() const
 {
        return operator[](defaultLayoutName());
 }
@@ -685,7 +715,7 @@ int LyXTextClass::maxcounter() const
 
 int LyXTextClass::size() const
 {
-       return layoutlist.size();
+       return layoutlist_.size();
 }