]> git.lyx.org Git - features.git/blobdiff - src/bufferparams.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / bufferparams.C
index 4ed8a2e915e19ad5f819c40359f97f0cc016a540..448edc75dc9ea4ae960fb3a706d767532134e414 100644 (file)
 #include "gettext.h"
 #include "language.h"
 #include "LaTeXFeatures.h"
-#include "latexrunparams.h"
+#include "LColor.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "lyxtextclasslist.h"
+#include "outputparams.h"
 #include "tex-strings.h"
 #include "Spacing.h"
 #include "texrow.h"
 
 #include "frontends/Alert.h"
 
-#include "support/LAssert.h"
 #include "support/lyxalgo.h" // for lyx::count
 
 #include <boost/array.hpp>
 
-#include "support/std_sstream.h"
+#include <sstream>
 
 namespace support = lyx::support;
-using namespace lyx::support;
+using lyx::support::bformat;
+using lyx::support::rtrim;
+using lyx::support::tokenPos;
 
 using std::endl;
-
+using std::string;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
 using std::pair;
 
+namespace biblio = lyx::biblio;
+
 
 struct BufferParams::Impl
 {
@@ -78,13 +82,26 @@ BufferParams::Impl::Impl()
 }
 
 
+BufferParams::Impl *
+BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
+{
+       return new BufferParams::Impl(*ptr);
+}
+
+
+void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
+{
+       delete ptr;
+}
+
+
 BufferParams::BufferParams()
-       : pimpl_(new Impl),
-         // Initialize textclass to point to article. if `first' is
+       : // Initialize textclass to point to article. if `first' is
          // true in the returned pair, then `second' is the textclass
          // number; if it is false, second is 0. In both cases, second
          // is what we want.
-         textclass(textclasslist.NumberOfClass("article").second)
+       textclass(textclasslist.NumberOfClass("article").second),
+       pimpl_(new Impl)
 {
        paragraph_separation = PARSEP_INDENT;
        quotes_language = InsetQuotes::EnglishQ;
@@ -98,8 +115,8 @@ BufferParams::BufferParams()
        orientation = ORIENTATION_PORTRAIT;
        use_geometry = false;
        use_amsmath = AMS_AUTO;
-       use_natbib = false;
-       use_numerical_citations = false;
+       cite_engine = biblio::ENGINE_BASIC;
+       use_bibtopic = false;
        tracking_changes = false;
        secnumdepth = 3;
        tocdepth = 3;
@@ -148,28 +165,28 @@ BranchList const & BufferParams::branchlist() const
 
 Bullet & BufferParams::temp_bullet(lyx::size_type index)
 {
-       support::Assert(index < 4);
+       BOOST_ASSERT(index < 4);
        return pimpl_->temp_bullets[index];
 }
 
 
 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
 {
-       support::Assert(index < 4);
+       BOOST_ASSERT(index < 4);
        return pimpl_->temp_bullets[index];
 }
 
 
 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
 {
-       support::Assert(index < 4);
+       BOOST_ASSERT(index < 4);
        return pimpl_->user_defined_bullets[index];
 }
 
 
 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
 {
-       support::Assert(index < 4);
+       BOOST_ASSERT(index < 4);
        return pimpl_->user_defined_bullets[index];
 }
 
@@ -300,12 +317,21 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                lex.nextToken();
                use_amsmath = static_cast<AMS>(
                        lex.getInteger());
-       } else if (token == "\\use_natbib") {
+       } else if (token == "\\cite_engine") {
                lex.nextToken();
-               use_natbib = lex.getInteger();
-       } else if (token == "\\use_numerical_citations") {
+               string const engine = lex.getString();
+
+               cite_engine = biblio::ENGINE_BASIC;
+               if (engine == "natbib_numerical")
+                       cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
+               else if (engine == "natbib_authoryear")
+                       cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
+               else if (engine == "jurabib")
+                       cite_engine = biblio::ENGINE_JURABIB;
+
+       } else if (token == "\\use_bibtopic") {
                lex.nextToken();
-               use_numerical_citations = lex.getInteger();
+               use_bibtopic = lex.getInteger();
        } else if (token == "\\tracking_changes") {
                lex.nextToken();
                tracking_changes = lex.getInteger();
@@ -318,25 +344,28 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                        string const tok = lex.getString();
                        if (tok == "\\end_branch")
                                break;
+                       Branch * branch_ptr = branchlist().find(branch);
                        if (tok == "\\selected") {
                                lex.nextToken();
-                               branchlist().setSelected(branch, lex.getInteger());
+                               if (branch_ptr)
+                                       branch_ptr->setSelected(lex.getInteger());
                        }
                        // not yet operational
                        if (tok == "\\color") {
                                lex.nextToken();
                                string color = lex.getString();
-                               branchlist().setColor(branch, color);
+                               if (branch_ptr)
+                                       branch_ptr->setColor(color);
                                // Update also the LColor table:
-                               if (color == "none") 
+                               if (color == "none")
                                        color = lcolor.getX11Name(LColor::background);
-                               lcolor.fill(static_cast<LColor::color>(lcolor.size()), 
-                                               branch, color);
+                               lcolor.setColor(branch, color);
+
                        }
                }
        } else if (token == "\\author") {
                lex.nextToken();
-               istringstream ss(STRCONV(lex.getString()));
+               istringstream ss(lex.getString());
                Author a;
                ss >> a;
                author_map.push_back(pimpl_->authorlist.record(a));
@@ -514,12 +543,27 @@ void BufferParams::writeFile(ostream & os) const
 
        spacing().writeFile(os);
 
+       string cite_engine_str = "basic";
+       switch (cite_engine) {
+       case biblio::ENGINE_BASIC:
+               break;
+       case biblio::ENGINE_NATBIB_NUMERICAL:
+               cite_engine_str = "natbib_numerical";
+               break;
+       case biblio::ENGINE_NATBIB_AUTHORYEAR:
+               cite_engine_str = "natbib_authoryear";
+               break;
+       case biblio::ENGINE_JURABIB:
+               cite_engine_str = "jurabib";
+               break;
+       }
+
        os << "\\papersize " << string_papersize[papersize2]
           << "\n\\paperpackage " << string_paperpackages[paperpackage]
           << "\n\\use_geometry " << use_geometry
           << "\n\\use_amsmath " << use_amsmath
-          << "\n\\use_natbib " << use_natbib
-          << "\n\\use_numerical_citations " << use_numerical_citations
+          << "\n\\cite_engine " << cite_engine_str
+          << "\n\\use_bibtopic " << use_bibtopic
           << "\n\\paperorientation " << string_orientation[orientation]
           << '\n';
 
@@ -527,9 +571,9 @@ void BufferParams::writeFile(ostream & os) const
        std::list<Branch>::const_iterator end = branchlist().end();
        for (; it != end; ++it) {
                os << "\\branch " << it->getBranch()
-                  << "\n\\selected " << it->getSelected()      
-                  << "\n\\color " << it->getColor()    
-                  << "\n\\end_branch" 
+                  << "\n\\selected " << it->getSelected()
+                  << "\n\\color " << it->getColor()
+                  << "\n\\end_branch"
                   << "\n";
        }
 
@@ -699,7 +743,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                clsoptions << options << ',';
        }
 
-       string strOptions(STRCONV(clsoptions.str()));
+       string strOptions(clsoptions.str());
        if (!strOptions.empty()) {
                strOptions = rtrim(strOptions, ",");
                os << '[' << strOptions << ']';
@@ -902,6 +946,14 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                texrow.newline();
        }
 
+       // If we use jurabib, we have to call babel here.
+       if (use_babel && features.isRequired("jurabib")) {
+               os << babelCall(language_options.str())
+                  << '\n'
+                  << features.getBabelOptions();
+               texrow.newline();
+       }
+
        // Now insert the LyX specific LaTeX commands...
 
        // The optional packages;
@@ -971,14 +1023,9 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
 
        // We try to load babel late, in case it interferes
        // with other packages.
-       if (use_babel) {
-               string tmp = lyxrc.language_package;
-               if (!lyxrc.language_global_options
-                   && tmp == "\\usepackage{babel}")
-                       tmp = string("\\usepackage[") +
-                               STRCONV(language_options.str()) +
-                               "]{babel}";
-               lyxpreamble += tmp + "\n";
+       // Jurabib has to be called after babel, though.
+       if (use_babel && !features.isRequired("jurabib")) {
+               lyxpreamble += babelCall(language_options.str()) + '\n';
                lyxpreamble += features.getBabelOptions();
        }
 
@@ -1170,3 +1217,12 @@ string const BufferParams::dvips_options() const
                result += ' ' + lyxrc.print_landscape_flag;
        return result;
 }
+
+
+string const BufferParams::babelCall(string const & lang_opts) const
+{
+       string tmp = lyxrc.language_package;
+       if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
+               tmp = string("\\usepackage[") + lang_opts + "]{babel}";
+       return tmp;
+}