]> git.lyx.org Git - lyx.git/commitdiff
Revert 23154.
authorRichard Heck <rgheck@comcast.net>
Sun, 24 Feb 2008 14:59:23 +0000 (14:59 +0000)
committerRichard Heck <rgheck@comcast.net>
Sun, 24 Feb 2008 14:59:23 +0000 (14:59 +0000)
Sorry, Andre, but this broke not only the modules stuff but the general handling of TextClasses. I'm not opposed to doing this sort of thing, but it's going to be a little more complicated. I'll do it when I get a bit of time, or I can explain what the issue is here if you want to do it.

I'll separately re-commit some of the cleanup here.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23189 a592a061-630c-0410-9148-cb99ea01b6c8

56 files changed:
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/BufferView.cpp
src/CutAndPaste.cpp
src/CutAndPaste.h
src/LaTeXFeatures.cpp
src/LyXFunc.cpp
src/LyXFunc.h
src/MenuBackend.cpp
src/Paragraph.cpp
src/ParagraphMetrics.cpp
src/Text.cpp
src/Text2.cpp
src/Text3.cpp
src/TextClass.h
src/TextClassList.cpp
src/TextClassList.h
src/TextClassPtr.h [new file with mode: 0644]
src/TextMetrics.cpp
src/TocBackend.cpp
src/buffer_funcs.cpp
src/factory.cpp
src/frontends/qt4/Dialog.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiToc.cpp
src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiToolbars.cpp
src/frontends/qt4/GuiToolbars.h
src/insets/Inset.cpp
src/insets/InsetBibitem.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetBox.cpp
src/insets/InsetBranch.cpp
src/insets/InsetCaption.cpp
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetERT.cpp
src/insets/InsetEnvironment.cpp
src/insets/InsetFlex.cpp
src/insets/InsetFlex.h
src/insets/InsetFloat.cpp
src/insets/InsetFloatList.cpp
src/insets/InsetFoot.cpp
src/insets/InsetInclude.cpp
src/insets/InsetInfo.cpp
src/insets/InsetListings.cpp
src/insets/InsetNote.cpp
src/insets/InsetTabular.cpp
src/insets/InsetText.cpp
src/insets/InsetWrap.cpp
src/output_docbook.cpp
src/output_latex.cpp
src/paragraph_funcs.cpp
src/sgml.cpp
src/support/types.h

index 3a074cba943e6663a491b42c2dbff92c057c593c..e6f7cbb5c135cd66fda16b5dfaa9c582d8cdb3eb 100644 (file)
@@ -1187,19 +1187,19 @@ void Buffer::writeLaTeXSource(odocstream & os,
 
 bool Buffer::isLatex() const
 {
-       return params().textClass().outputType() == LATEX;
+       return params().getTextClass().outputType() == LATEX;
 }
 
 
 bool Buffer::isLiterate() const
 {
-       return params().textClass().outputType() == LITERATE;
+       return params().getTextClass().outputType() == LITERATE;
 }
 
 
 bool Buffer::isDocBook() const
 {
-       return params().textClass().outputType() == DOCBOOK;
+       return params().getTextClass().outputType() == DOCBOOK;
 }
 
 
@@ -1230,7 +1230,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
 
        d->texrow.reset();
 
-       TextClass const & tclass = params().textClass();
+       TextClass const & tclass = params().getTextClass();
        string const top_element = tclass.latexname();
 
        if (!only_body) {
@@ -1285,7 +1285,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
            << " file was created by LyX " << lyx_version
            << "\n  See http://www.lyx.org/ for more information -->\n";
 
-       params().textClass().counters().reset();
+       params().getTextClass().counters().reset();
 
        loadChildDocuments();
 
@@ -2536,7 +2536,7 @@ vector<Format const *> Buffer::exportableFormats(bool only_viewable) const
 vector<string> Buffer::backends() const
 {
        vector<string> v;
-       if (params().textClass().isTeXClassAvailable()) {
+       if (params().getTextClass().isTeXClassAvailable()) {
                v.push_back(bufferFormat());
                // FIXME: Don't hardcode format names here, but use a flag
                if (v.back() == "latex")
index 0ab1d830881a425cd7d71ede999f70a914d9b90a..d22d94fd5232ebb6f2e5d48ff8b8bde5898b235a 100644 (file)
@@ -283,16 +283,11 @@ public:
         */
        VSpace defskip;
        PDFOptions pdfoptions;
-
-       /// the base TextClass associated with the document
-       TextClassIndex baseClass_;
-       /// the possibly modular TextClass actually in use
-       TextClassIndex textClass_;
 };
 
 
 BufferParams::Impl::Impl()
-       : defskip(VSpace::MEDSKIP), baseClass_(0), textClass_(0)
+       : defskip(VSpace::MEDSKIP)
 {
        // set initial author
        // FIXME UNICODE
@@ -467,8 +462,8 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
                string const classname = lex.getString();
                // if there exists a local layout file, ignore the system one
                // NOTE: in this case, the textclass (.cls file) is assumed to be available.
-               pair<bool, TextClassIndex> pp =
-                       make_pair(false, TextClassIndex(0));
+               pair<bool, lyx::textclass_type> pp =
+                       make_pair(false, textclass_type(0));
                if (!filepath.empty())
                        pp = textclasslist.addTextClass(
                                classname, filepath.absFilename());
@@ -487,7 +482,7 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
                // FIXME: this warning will be given even if there exists a local .cls
                // file. Even worse, the .lyx file can not be compiled or exported
                // because the textclass is marked as unavilable.
-               if (!textClass().isTeXClassAvailable()) {
+               if (!getTextClass().isTeXClassAvailable()) {
                        docstring const msg =
                                bformat(_("The layout file requested by this document,\n"
                                                 "%1$s.layout,\n"
@@ -682,7 +677,7 @@ void BufferParams::writeFile(ostream & os) const
        // Prints out the buffer info into the .lyx file given by file
 
        // the textclass
-       os << "\\textclass " << textClass().name() << '\n';
+       os << "\\textclass " << textclasslist[baseClass_].name() << '\n';
 
        // then the preamble
        if (!preamble.empty()) {
@@ -824,7 +819,7 @@ void BufferParams::writeFile(ostream & os) const
 
 void BufferParams::validate(LaTeXFeatures & features) const
 {
-       features.require(textClass().requires());
+       features.require(getTextClass().requires());
 
        if (outputChanges) {
                bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
@@ -865,7 +860,8 @@ void BufferParams::validate(LaTeXFeatures & features) const
                features.require("float");
 
        // AMS Style is at document level
-       if (use_amsmath == package_on || textClass().provides("amsmath"))
+       if (use_amsmath == package_on
+           || getTextClass().provides("amsmath"))
                features.require("amsmath");
        if (use_esint == package_on)
                features.require("esint");
@@ -906,7 +902,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
 {
        os << "\\documentclass";
 
-       TextClass const & tclass = textClass(); 
+       TextClass const & tclass = getTextClass();
+
        ostringstream clsoptions; // the document class options.
 
        if (tokenPos(tclass.opt_fontsize(),
@@ -1246,7 +1243,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // hyperref, see
        // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
        if (language->lang() == "japanese-plain" &&
-               !textClass().provides("japanese")) {
+               !getTextClass().provides("japanese")) {
                //load babel in case it was not loaded due to an empty language list
                if (language_options.str().empty())
                        lyxpreamble += "\\usepackage{babel}\n";
@@ -1264,7 +1261,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // use hyperref explicitely when it is required
        if (features.isRequired("hyperref")) {
                odocstringstream oss;
-               pdfoptions().writeLaTeX(oss, textClass().provides("hyperref"));
+               pdfoptions().writeLaTeX(oss, getTextClass().provides("hyperref"));
                lyxpreamble += oss.str();
        }
 
@@ -1346,7 +1343,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
 
 void BufferParams::useClassDefaults()
 {
-       TextClass const & tclass = textclasslist[pimpl_->baseClass_];
+       TextClass const & tclass = textclasslist[baseClass_];
 
        sides = tclass.sides();
        columns = tclass.columns();
@@ -1362,39 +1359,37 @@ void BufferParams::useClassDefaults()
 
 bool BufferParams::hasClassDefaults() const
 {
-       TextClass const & tclass = textclasslist[pimpl_->baseClass_];
+       TextClass const & tclass = textclasslist[baseClass_];
 
-       return sides == tclass.sides()
+       return (sides == tclass.sides()
                && columns == tclass.columns()
                && pagestyle == tclass.pagestyle()
                && options == tclass.options()
                && secnumdepth == tclass.secnumdepth()
-               && tocdepth == tclass.tocdepth();
+               && tocdepth == tclass.tocdepth());
 }
 
 
-TextClass const & BufferParams::textClass() const
+TextClass const & BufferParams::getTextClass() const
 {
-       return textclasslist[pimpl_->textClass_];
+       return *textClass_;
 }
 
 
-TextClassIndex BufferParams::textClassIndex() const
-{
-       return pimpl_->textClass_;
+TextClassPtr BufferParams::getTextClassPtr() const {
+       return textClass_;
 }
 
 
-void BufferParams::setTextClass(TextClassIndex const & tc)
-{
-       pimpl_->textClass_ = tc;
+void BufferParams::setTextClass(TextClassPtr tc) {
+       textClass_ = tc;
 }
 
 
-bool BufferParams::setBaseClass(TextClassIndex const & tc)
+bool BufferParams::setBaseClass(textclass_type tc)
 {
        if (textclasslist[tc].load()) {
-               pimpl_->baseClass_ = tc;
+               baseClass_ = tc;
                return true;
        }
        
@@ -1406,15 +1401,15 @@ bool BufferParams::setBaseClass(TextClassIndex const & tc)
 }
 
 
-TextClassIndex BufferParams::baseClass() const
+textclass_type BufferParams::getBaseClass() const
 {
-       return pimpl_->baseClass_;
+       return baseClass_;
 }
 
 
 void BufferParams::makeTextClass()
 {
-       pimpl_->textClass_ = baseClass();
+       textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
        
        //FIXME It might be worth loading the children's modules here,
        //just as we load their bibliographies and such, instead of just 
@@ -1444,7 +1439,7 @@ void BufferParams::makeTextClass()
                        frontend::Alert::warning(_("Package not available"), msg);
                }
                FileName layout_file = libFileSearch("layouts", lm->getFilename());
-               if (!textclasslist.at(pimpl_->textClass_).read(layout_file, TextClass::MODULE)) {
+               if (!textClass_->read(layout_file, TextClass::MODULE)) {
                        docstring const msg =
                                bformat(_("Error reading module %1$s\n"), from_utf8(modName));
                        frontend::Alert::warning(_("Read Error"), msg);
@@ -1453,15 +1448,13 @@ void BufferParams::makeTextClass()
 }
 
 
-vector<string> const & BufferParams::getModules() const
-{
+vector<string> const & BufferParams::getModules() const {
        return layoutModules_;
 }
 
 
 
-bool BufferParams::addLayoutModule(string const & modName)
-{
+bool BufferParams::addLayoutModule(string const & modName) {
        LayoutModuleList::const_iterator it = layoutModules_.begin();
        LayoutModuleList::const_iterator end = layoutModules_.end();
        for (; it != end; it++) {
@@ -1475,15 +1468,14 @@ bool BufferParams::addLayoutModule(string const & modName)
 }
 
 
-void BufferParams::clearLayoutModules()
-{
+void BufferParams::clearLayoutModules() {
        layoutModules_.clear();
 }
 
 
 Font const BufferParams::getFont() const
 {
-       FontInfo f = textClass().defaultfont();
+       FontInfo f = getTextClass().defaultfont();
        if (fontsDefaultFamily == "rmdefault")
                f.setFamily(ROMAN_FAMILY);
        else if (fontsDefaultFamily == "sfdefault")
@@ -1524,8 +1516,7 @@ void BufferParams::readLanguage(Lexer & lex)
 
 void BufferParams::readGraphicsDriver(Lexer & lex)
 {
-       if (!lex.next())
-               return;
+       if (!lex.next()) return;
 
        string const tmptok = lex.getString();
        // check if tmptok is part of tex_graphics in tex_defs.h
@@ -1549,8 +1540,7 @@ void BufferParams::readGraphicsDriver(Lexer & lex)
 
 void BufferParams::readBullets(Lexer & lex)
 {
-       if (!lex.next())
-               return;
+       if (!lex.next()) return;
 
        int const index = lex.getInteger();
        lex.next();
@@ -1569,8 +1559,7 @@ void BufferParams::readBullets(Lexer & lex)
 void BufferParams::readBulletsLaTeX(Lexer & lex)
 {
        // The bullet class should be able to read this.
-       if (!lex.next())
-               return;
+       if (!lex.next()) return;
        int const index = lex.getInteger();
        lex.next(true);
        docstring const temp_str = lex.getDocString();
@@ -1933,7 +1922,7 @@ biblio::CiteEngine BufferParams::getEngine() const
 {
        // FIXME the class should provide the numerical/
        // authoryear choice
-       if (textClass().provides("natbib")
+       if (getTextClass().provides("natbib")
            && cite_engine_ != biblio::ENGINE_NATBIB_NUMERICAL)
                return biblio::ENGINE_NATBIB_AUTHORYEAR;
        return cite_engine_;
index a1d82104bf255c9065bdac3f04922640d6766aff..5fc57aecc81d290cf2e21ebb7cd288057429f5d7 100644 (file)
 #ifndef BUFFERPARAMS_H
 #define BUFFERPARAMS_H
 
-#include "BiblioInfo.h"
 #include "Font.h"
+#include "BiblioInfo.h"
 #include "paper.h"
+#include "TextClassPtr.h"
 
 #include "insets/InsetQuotes.h"
 
@@ -42,7 +43,6 @@ class LatexFeatures;
 class PDFOptions;
 class Spacing;
 class TextClass;
-class TextClassIndex;
 class TexRow;
 class VSpace;
 
@@ -106,25 +106,25 @@ public:
        InsetQuotes::quote_times quotes_times;
        ///
        std::string fontsize;
-       /// Get the LyX TextClass (that is, the layout file) this document is using.
-       TextClassIndex baseClass() const;
+       ///Get the LyX TextClass (that is, the layout file) this document is using.
+       textclass_type getBaseClass() const;
        /// Set the LyX TextClass (that is, the layout file) this document is using.
        /// NOTE: This does not call makeTextClass() to update the local TextClass.
        /// That needs to be done manually.
-       bool setBaseClass(TextClassIndex const & index);
+       bool setBaseClass(textclass_type);
        /// Adds the module information to the baseClass information to
        /// create our local TextClass.
        void makeTextClass();
        /// Returns the TextClass currently in use: the BaseClass as modified
        /// by modules.
-       TextClass const & textClass() const;
+       TextClass const & getTextClass() const;
        /// Returns a pointer to the TextClass currently in use: the BaseClass 
-       /// as modified by modules. (See \file TextClass.h for the definition.)
-       TextClassIndex textClassIndex() const;
+       /// as modified by modules. (See \file TextClassPtr.h for the typedef.)
+       TextClassPtr getTextClassPtr() const;
        /// This bypasses the baseClass and sets the textClass directly.
        /// Should be called with care and would be better not being here,
        /// but it seems to be needed by CutAndPaste::putClipboard().
-       void setTextClass(TextClassIndex const & index);
+       void setTextClass(TextClassPtr);
        /// List of modules in use
        std::vector<std::string> const & getModules() const;
        /// Add a module to the list of modules in use.
@@ -327,6 +327,10 @@ private:
 
        /// for use with natbib
        biblio::CiteEngine cite_engine_;
+       /// the base TextClass associated with the document
+       textclass_type baseClass_;
+       /// the possibly modular TextClass actually in use
+       TextClassPtr textClass_;
        ///
        typedef std::vector<std::string> LayoutModuleList;
        /// 
index 30b5fb6a94696da6f477a7fb179576cd59eb4063..dd0fe6f38559c20aa1b6523caf6895c4d3ab35ae 100644 (file)
@@ -1887,7 +1887,7 @@ void BufferView::insertLyXFile(FileName const & fname)
                el = buf.errorList("Parse");
                buffer_.undo().recordUndo(d->cursor_);
                cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
-                                            buf.params().textClassIndex(), el);
+                                            buf.params().getTextClassPtr(), el);
                res = _("Document %1$s inserted.");
        } else {
                res = _("Could not insert document %1$s");
index eed8123521bbd66d3a0e10b25c5d18cb64c3dfb8..fecfb6979b8b24d6f204619c61f05f2eb6f11f58 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/**
  * \file CutAndPaste.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
@@ -70,7 +70,7 @@ namespace {
 
 typedef pair<pit_type, int> PitPosPair;
 
-typedef limited_stack<pair<ParagraphList, TextClassIndex> > CutStack;
+typedef limited_stack<pair<ParagraphList, TextClassPtr> > CutStack;
 
 CutStack theCuts(10);
 // persistent selection, cleared until the next selection
@@ -106,7 +106,7 @@ bool checkPastePossible(int index)
 
 pair<PitPosPair, pit_type>
 pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
-                    TextClassIndex const & textclass, ErrorList & errorlist)
+                    TextClassPtr textclass, ErrorList & errorlist)
 {
        Buffer const & buffer = cur.buffer();
        pit_type pit = cur.pit();
@@ -120,7 +120,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
 
        // Make a copy of the CaP paragraphs.
        ParagraphList insertion = parlist;
-       TextClassIndex tcindex = buffer.params().textClassIndex();
+       TextClassPtr const tc = buffer.params().getTextClassPtr();
 
        // Now remove all out of the pars which is NOT allowed in the
        // new environment and set also another font if that is required.
@@ -148,7 +148,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        // supposed to be the default, not just if it is forced
        if (cur.inset().useEmptyLayout()) {
                LayoutPtr const layout =
-                       buffer.params().textClass().emptyLayout();
+                       buffer.params().getTextClass().emptyLayout();
                ParagraphList::iterator const end = insertion.end();
                for (ParagraphList::iterator par = insertion.begin();
                                par != end; ++par)
@@ -162,7 +162,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        // since we store pointers to insets at some places and we don't
        // want to invalidate them.
        insertion.swap(in.paragraphs());
-       cap::switchBetweenClasses(textclass, tcindex, in, errorlist);
+       cap::switchBetweenClasses(textclass, tc, in, errorlist);
        insertion.swap(in.paragraphs());
 
        ParagraphList::iterator tmpbuf = insertion.begin();
@@ -317,7 +317,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params,
 }
 
 
-void putClipboard(ParagraphList const & paragraphs, TextClassIndex textclass,
+void putClipboard(ParagraphList const & paragraphs, TextClassPtr textclass,
                  docstring const & plaintext)
 {
        // For some strange reason gcc 3.2 and 3.3 do not accept
@@ -336,7 +336,7 @@ void putClipboard(ParagraphList const & paragraphs, TextClassIndex textclass,
 
 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
        pit_type startpit, pit_type endpit,
-       int start, int end, TextClassIndex tc, CutStack & cutstack)
+       int start, int end, TextClassPtr tc, CutStack & cutstack)
 {
        BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
        BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
@@ -392,19 +392,20 @@ docstring grabAndEraseSelection(Cursor & cur)
 }
 
 
-void switchBetweenClasses(TextClassIndex const & oldtcindex,
-       TextClassIndex const & newtcindex, InsetText & in, ErrorList & errorlist)
+void switchBetweenClasses(TextClassPtr const & oldone, 
+       TextClassPtr const & newone, InsetText & in, ErrorList & errorlist)
 {
        errorlist.clear();
 
        BOOST_ASSERT(!in.paragraphs().empty());
-       if (oldtcindex == newtcindex)
+       if (oldone == newone)
                return;
        
+       TextClass const & oldtc = *oldone;
+       TextClass const & newtc = *newone;
+
        // layouts
        ParIterator end = par_iterator_end(in);
-       TextClass const & oldtc = textclasslist[oldtcindex];
-       TextClass const & newtc = textclasslist[newtcindex];
        for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
                docstring const name = it->layout()->name();
                bool hasLayout = newtc.hasLayout(name);
@@ -436,7 +437,7 @@ void switchBetweenClasses(TextClassIndex const & oldtcindex,
                if (inset->lyxCode() != FLEX_CODE)
                        // FIXME: Should we verify all InsetCollapsable?
                        continue;
-               inset->setLayout(newtcindex);
+               inset->setLayout(newone);
                if (!inset->undefined())
                        continue;
                // The flex inset is undefined in newtc
@@ -517,7 +518,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
                                text->paragraphs(),
                                begpit, endpit,
                                cur.selBegin().pos(), endpos,
-                               bp.textClassIndex(), theCuts);
+                               bp.getTextClassPtr(), theCuts);
                        // Stuff what we got on the clipboard.
                        // Even if there is no selection.
                        putClipboard(theCuts[0].first, theCuts[0].second,
@@ -601,7 +602,7 @@ void copySelectionToStack(Cursor & cur, CutStack & cutstack)
 
                copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
                        pos, cur.selEnd().pos(), 
-                       cur.buffer().params().textClassIndex(), cutstack);
+                       cur.buffer().params().getTextClassPtr(), cutstack);
                dirtyTabularStack(false);
        }
 
@@ -610,10 +611,10 @@ void copySelectionToStack(Cursor & cur, CutStack & cutstack)
                ParagraphList pars;
                Paragraph par;
                BufferParams const & bp = cur.buffer().params();
-               par.setLayout(bp.textClass().defaultLayout());
+               par.setLayout(bp.getTextClass().defaultLayout());
                par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
                pars.push_back(par);
-               cutstack.push(make_pair(pars, bp.textClassIndex()));
+               cutstack.push(make_pair(pars, bp.getTextClassPtr()));
        }
 }
 
@@ -637,10 +638,10 @@ void copySelection(Cursor & cur, docstring const & plaintext)
                ParagraphList pars;
                Paragraph par;
                BufferParams const & bp = cur.buffer().params();
-               par.setLayout(bp.textClass().defaultLayout());
+               par.setLayout(bp.getTextClass().defaultLayout());
                par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
                pars.push_back(par);
-               theCuts.push(make_pair(pars, bp.textClassIndex()));
+               theCuts.push(make_pair(pars, bp.getTextClassPtr()));
        } else {
                copySelectionToStack(cur, theCuts);
        }
@@ -691,7 +692,7 @@ docstring getSelection(Buffer const & buf, size_t sel_index)
 
 
 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
-                       TextClassIndex const & textclass, ErrorList & errorList)
+                       TextClassPtr textclass, ErrorList & errorList)
 {
        if (cur.inTexted()) {
                Text * text = cur.text();
@@ -701,7 +702,8 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
                PitPosPair ppp;
 
                boost::tie(ppp, endpit) =
-                       pasteSelectionHelper(cur, parlist, textclass, errorList);
+                       pasteSelectionHelper(cur, parlist,
+                                            textclass, errorList);
                updateLabels(cur.buffer());
                cur.clearSelection();
                text->setCursor(cur, ppp.first, ppp.second);
@@ -744,7 +746,7 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs)
                        if (buffer.readString(lyx)) {
                                cur.recordUndo();
                                pasteParagraphList(cur, buffer.paragraphs(),
-                                       buffer.params().textClassIndex(), errorList);
+                                       buffer.params().getTextClassPtr(), errorList);
                                cur.setSelection();
                                return;
                        }
@@ -763,7 +765,7 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs)
 }
 
 
-void pasteClipboardGraphics(Cursor & cur, ErrorList & /*errorList*/,
+void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
                            Clipboard::GraphicsType preferedType)
 {
        BOOST_ASSERT(theClipboard().hasGraphicsContents(preferedType));
index c4299654127c579fdfe7d0a6ec84facfffd15d6e..e3ba435b03416560aa8cffe6192800d3aaae8bbb 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef CUTANDPASTE_H
 #define CUTANDPASTE_H
 
+#include "TextClassPtr.h"
+
 #include "support/types.h"
 #include "support/docstring.h"
 
@@ -26,11 +28,10 @@ using lyx::frontend::Clipboard;
 namespace lyx {
 
 class Buffer;
-class Cursor;
 class ErrorList;
 class InsetText;
+class Cursor;
 class ParagraphList;
-class TextClassIndex;
 
 namespace cap {
 
@@ -101,15 +102,15 @@ void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
 /// Paste the paragraph list \p parlist at the position given by \p cur.
 /// Does not handle undo. Does only work in text, not mathed.
 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
-                       TextClassIndex const & textclass, ErrorList & errorList);
+                       TextClassPtr textclass, ErrorList & errorList);
 
 
 /** Needed to switch between different classes. This works
  *  for a list of paragraphs beginning with the specified par.
  *  It changes layouts and character styles.
  */
-void switchBetweenClasses(TextClassIndex const & c1, TextClassIndex const & c2,
-       InsetText & in, ErrorList &);
+void switchBetweenClasses(TextClassPtr const & c1, 
+       TextClassPtr const & c2, InsetText & in, ErrorList &);
 
 /// Get the current selection as a string. Does not change the selection.
 /// Does only work if the whole selection is in mathed.
@@ -139,7 +140,6 @@ void selClearOrDel(Cursor & cur);
 void dirtyTabularStack(bool b);
 /// is the tabular paste stack newer than the ordinary one?
 bool tabularStackDirty();
-
 } // namespace cap
 } // namespce lyx
 
index 903b87c72244b05d53dc48e2027af5489aa0de17..7df08f218730484409ce34f58171b530fe2a3fcd 100644 (file)
@@ -375,7 +375,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
                return;
        }
 
-       TextClass const & tclass = params_.textClass();
+       TextClass const & tclass = params_.getTextClass();
        if (tclass.hasLayout(layoutname)) {
                // Is this layout already in usedLayouts?
                if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname) 
@@ -409,7 +409,7 @@ bool LaTeXFeatures::isRequired(string const & name) const
 
 bool LaTeXFeatures::mustProvide(string const & name) const
 {
-       return isRequired(name) && !params_.textClass().provides(name);
+       return isRequired(name) && !params_.getTextClass().provides(name);
 }
 
 
@@ -439,7 +439,7 @@ void LaTeXFeatures::useFloat(string const & name)
        // We only need float.sty if we use non builtin floats, or if we
        // use the "H" modifier. This includes modified table and
        // figure floats. (Lgb)
-       Floating const & fl = params_.textClass().floats().getType(name);
+       Floating const & fl = params_.getTextClass().floats().getType(name);
        if (!fl.type().empty() && !fl.builtin()) {
                require("float");
        }
@@ -555,7 +555,7 @@ int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
 string const LaTeXFeatures::getPackages() const
 {
        ostringstream packages;
-       TextClass const & tclass = params_.textClass();
+       TextClass const & tclass = params_.getTextClass();
 
        // FIXME: currently, we can only load packages and macros known
        // to LyX.
@@ -828,7 +828,7 @@ string const LaTeXFeatures::getBabelOptions() const
 docstring const LaTeXFeatures::getTClassPreamble() const
 {
        // the text class specific preamble
-       TextClass const & tclass = params_.textClass();
+       TextClass const & tclass = params_.getTextClass();
        odocstringstream tcpreamble;
 
        tcpreamble << tclass.preamble();
@@ -903,7 +903,7 @@ BufferParams const & LaTeXFeatures::bufferParams() const
 
 void LaTeXFeatures::getFloatDefinitions(ostream & os) const
 {
-       FloatList const & floats = params_.textClass().floats();
+       FloatList const & floats = params_.getTextClass().floats();
 
        // Here we will output the code to create the needed float styles.
        // We will try to do this as minimal as possible.
index 45658cf68b4906769078daa83457e1e577f07dd5..95ff83dc53d5816c4c3fbddd831e15b7291e6ebb 100644 (file)
@@ -714,7 +714,7 @@ void showPrintError(string const & name)
 
 void loadTextClass(string const & name, string const & buf_path)
 {
-       pair<bool, TextClassIndex> const tc_pair =
+       pair<bool, textclass_type> const tc_pair =
                textclasslist.numberOfClass(name);
 
        if (!tc_pair.first) {
@@ -724,7 +724,7 @@ void loadTextClass(string const & name, string const & buf_path)
                return;
        }
 
-       TextClassIndex const tc = tc_pair.second;
+       textclass_type const tc = tc_pair.second;
 
        if (!textclasslist[tc].load(buf_path)) {
                docstring s = bformat(_("The document class %1$s."
@@ -1536,7 +1536,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        
                        Buffer * buffer = lyx_view_->buffer();
 
-                       TextClassIndex oldClass = buffer->params().textClassIndex();
+                       TextClassPtr oldClass = buffer->params().getTextClassPtr();
 
                        Cursor & cur = view()->cursor();
                        cur.recordUndoFullDocument();
@@ -1580,7 +1580,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_LAYOUT_MODULES_CLEAR: {
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
-                       TextClassIndex oldClass = buffer->params().textClassIndex();
+                       TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().clearLayoutModules();
                        buffer->params().makeTextClass();
@@ -1592,7 +1592,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_LAYOUT_MODULE_ADD: {
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
-                       TextClassIndex oldClass = buffer->params().textClassIndex();
+                       TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().addLayoutModule(argument);
                        buffer->params().makeTextClass();
@@ -1607,21 +1607,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        loadTextClass(argument, buffer->filePath());
 
-                       pair<bool, TextClassIndex> const tc_pair =
+                       pair<bool, textclass_type> const tc_pair =
                                textclasslist.numberOfClass(argument);
 
                        if (!tc_pair.first)
                                break;
 
-                       TextClassIndex const old_class = buffer->params().baseClass();
-                       TextClassIndex const new_class = tc_pair.second;
+                       textclass_type const old_class = buffer->params().getBaseClass();
+                       textclass_type const new_class = tc_pair.second;
 
                        if (old_class == new_class)
                                // nothing to do
                                break;
 
                        //Save the old, possibly modular, layout for use in conversion.
-                       TextClassIndex oldClass = buffer->params().textClassIndex();
+                       TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().setBaseClass(new_class);
                        buffer->params().makeTextClass();
@@ -1633,8 +1633,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_LAYOUT_RELOAD: {
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
-                       TextClassIndex oldClass = buffer->params().textClassIndex();
-                       TextClassIndex const tc = buffer->params().baseClass();
+                       TextClassPtr oldClass = buffer->params().getTextClassPtr();
+                       textclass_type const tc = buffer->params().getBaseClass();
                        textclasslist.reset(tc);
                        buffer->params().setBaseClass(tc);
                        buffer->params().makeTextClass();
@@ -1873,7 +1873,7 @@ bool LyXFunc::wasMetaKey() const
 }
 
 
-void LyXFunc::updateLayout(TextClassIndex const & oldlayout,
+void LyXFunc::updateLayout(TextClassPtr const & oldlayout,
                            Buffer * buffer)
 {
        lyx_view_->message(_("Converting document to new document class..."));
@@ -1881,7 +1881,7 @@ void LyXFunc::updateLayout(TextClassIndex const & oldlayout,
        StableDocIterator backcur(view()->cursor());
        ErrorList & el = buffer->errorList("Class Switch");
        cap::switchBetweenClasses(
-                       oldlayout, buffer->params().textClassIndex(),
+                       oldlayout, buffer->params().getTextClassPtr(),
                        static_cast<InsetText &>(buffer->inset()), el);
 
        view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
index 692fc732335ffd71eb2b8d02a509c7738c5adb85..ab8e9debf280836f79d4989e8dbe5b2b5f4cceae 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "KeySequence.h"
 #include "lfuns.h"
+#include "TextClassPtr.h"
 
 #include "support/docstring.h"
 
@@ -28,7 +29,6 @@ class FuncRequest;
 class FuncStatus;
 class KeySymbol;
 class Text;
-class TextClassIndex;
 
 namespace support {
 class FileName;
@@ -38,7 +38,6 @@ namespace frontend {
 class LyXView;
 }
 
-
 /** This class encapsulates all the LyX command operations.
     This is the class of the LyX's "high level event handler".
     Every user command is processed here, either invocated from
@@ -137,7 +136,7 @@ private:
        ///
        bool ensureBufferClean(BufferView * bv);
        ///
-       void updateLayout(TextClassIndex const & oldlayout, Buffer * buffer);
+       void updateLayout(TextClassPtr const & oldlayout, Buffer * buffer);
 };
 
 /// Implementation is in LyX.cpp
index fce89d6c25d5998d8b0230120869f4a74ae34ecf..e007ce60811fe5cdabf1bea710b113a3931cd717 100644 (file)
@@ -598,7 +598,8 @@ void expandFloatListInsert(Menu & tomenu, Buffer const * buf)
                return;
        }
 
-       FloatList const & floats = buf->params().textClass().floats();
+       FloatList const & floats =
+               buf->params().getTextClass().floats();
        FloatList::const_iterator cit = floats.begin();
        FloatList::const_iterator end = floats.end();
        for (; cit != end; ++cit) {
@@ -619,7 +620,8 @@ void expandFloatInsert(Menu & tomenu, Buffer const * buf)
                return;
        }
 
-       FloatList const & floats = buf->params().textClass().floats();
+       FloatList const & floats =
+               buf->params().getTextClass().floats();
        FloatList::const_iterator cit = floats.begin();
        FloatList::const_iterator end = floats.end();
        for (; cit != end; ++cit) {
@@ -641,7 +643,7 @@ void expandFlexInsert(Menu & tomenu, Buffer const * buf, string s)
                return;
        }
        InsetLayouts const & insetLayouts =
-               buf->params().textClass().insetLayouts();
+               buf->params().getTextClass().insetLayouts();
        InsetLayouts::const_iterator cit = insetLayouts.begin();
        InsetLayouts::const_iterator end = insetLayouts.end();
        for (; cit != end; ++cit) {
@@ -741,7 +743,7 @@ void expandToc(Menu & tomenu, Buffer const * buf)
                tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f));
        }
 
-       FloatList const & floatlist = buf->params().textClass().floats();
+       FloatList const & floatlist = buf->params().getTextClass().floats();
        TocList const & toc_list = buf->tocBackend().tocs();
        TocList::const_iterator cit = toc_list.begin();
        TocList::const_iterator end = toc_list.end();
index 293a62e8c8c6df76f7672a4af3e1b75695b98b9f..c34c8e8ac57cace3226abf58930d26bc7db8405b 100644 (file)
@@ -1512,7 +1512,7 @@ docstring const Paragraph::translateIfPossible(docstring const & s,
 docstring Paragraph::expandLabel(LayoutPtr const & layout,
                BufferParams const & bparams, bool process_appendix) const
 {
-       TextClass const & tclass = bparams.textClass();
+       TextClass const & tclass = bparams.getTextClass();
 
        docstring fmt;
        if (process_appendix && d->params_.appendix())
@@ -1817,10 +1817,11 @@ bool Paragraph::latex(Buffer const & buf,
        // to be valid!
        bool asdefault = forceEmptyLayout();
 
-       if (asdefault)
-               style = bparams.textClass().defaultLayout();
-       else
+       if (asdefault) {
+               style = bparams.getTextClass().defaultLayout();
+       } else {
                style = d->layout_;
+       }
 
        // Current base font for all inherited font changes, without any
        // change caused by an individual character, except for the language:
index fb6c77714d5998806e8ecd1e91085b38d7870655..09631228b919197dac0f8f5b66788cb08653dcc2 100644 (file)
@@ -62,9 +62,9 @@ using namespace lyx::support;
 namespace lyx {
 
 
-ParagraphMetrics::ParagraphMetrics(Paragraph const & par)
-       : position_(-1), par_(&par)
-{}
+ParagraphMetrics::ParagraphMetrics(Paragraph const & par): position_(-1), par_(&par)
+{
+}
 
 
 ParagraphMetrics & ParagraphMetrics::operator=(
@@ -198,7 +198,7 @@ void ParagraphMetrics::dump() const
 int ParagraphMetrics::rightMargin(BufferView const & bv) const
 {
        BufferParams const & params = bv.buffer().params();
-       TextClass const & tclass = params.textClass();
+       TextClass const & tclass = params.getTextClass();
        frontend::FontMetrics const & fm = theFontMetrics(params.getFont());
        int const r_margin =
                bv.rightMargin()
index 456584b8c75341811f06bd2d63dbcc167a7ebab1..c29876d9a1efe030cd6e0403c79387c6679887c6 100644 (file)
@@ -96,7 +96,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                font = Font(inherit_font, bp.language);
                change = Change(Change::UNCHANGED);
 
-               TextClass const & tclass = bp.textClass();
+               TextClass const & tclass = bp.getTextClass();
 
                if (layoutname.empty())
                        layoutname = tclass.defaultLayoutName();
@@ -125,12 +125,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                                        tclass.defaultLayoutName();
                }
 
-               par.setLayout(bp.textClass()[layoutname]);
+               par.setLayout(bp.getTextClass()[layoutname]);
 
                // Test whether the layout is obsolete.
                LayoutPtr const & layout = par.layout();
                if (!layout->obsoleted_by().empty())
-                       par.setLayout(bp.textClass()[layout->obsoleted_by()]);
+                       par.setLayout(bp.getTextClass()[layout->obsoleted_by()]);
 
                par.params().read(lex);
 
@@ -355,7 +355,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
        Paragraph & cpar = cur.paragraph();
        pit_type cpit = cur.pit();
 
-       TextClass const & tclass = cur.buffer().params().textClass();
+       TextClass const & tclass = cur.buffer().params().getTextClass();
        LayoutPtr const & layout = cpar.layout();
 
        // this is only allowed, if the current paragraph is not empty
@@ -928,9 +928,9 @@ bool Text::handleBibitems(Cursor & cur)
 
        // otherwise reset to default
        if (par.useEmptyLayout())
-               cur.paragraph().setLayout(bufparams.textClass().emptyLayout());
+               cur.paragraph().setLayout(bufparams.getTextClass().emptyLayout());
        else
-               cur.paragraph().setLayout(bufparams.textClass().defaultLayout());
+               cur.paragraph().setLayout(bufparams.getTextClass().defaultLayout());
        return true;
 }
 
@@ -991,7 +991,7 @@ bool Text::backspacePos0(Cursor & cur)
        bool needsUpdate = false;
 
        BufferParams const & bufparams = cur.buffer().params();
-       TextClass const & tclass = bufparams.textClass();
+       TextClass const & tclass = bufparams.getTextClass();
        ParagraphList & plist = cur.text()->paragraphs();
        Paragraph const & par = cur.paragraph();
        Cursor prevcur = cur;
@@ -1116,7 +1116,7 @@ bool Text::dissolveInset(Cursor & cur) {
                for (; it != it_end; it++)
                        it->changeLanguage(b.params(), latex_language, b.language());
 
-               pasteParagraphList(cur, plist, b.params().textClassIndex(),
+               pasteParagraphList(cur, plist, b.params().getTextClassPtr(),
                                   b.errorList("Paste"));
                // restore position
                cur.pit() = min(cur.lastpit(), spit);
index b7dc9a13d60373425bf835bd9eebf70d52594ef0..7ea03cd6bb064ed460b4ef1cd1633320b359b041 100644 (file)
@@ -199,7 +199,7 @@ void Text::setLayout(Buffer const & buffer, pit_type start, pit_type end,
        BOOST_ASSERT(start != end);
 
        BufferParams const & bufparams = buffer.params();
-       LayoutPtr const & lyxlayout = bufparams.textClass()[layout];
+       LayoutPtr const & lyxlayout = bufparams.getTextClass()[layout];
 
        for (pit_type pit = start; pit != end; ++pit) {
                Paragraph & par = pars_[pit];
@@ -218,7 +218,7 @@ void Text::setLayout(Cursor & cur, docstring const & layout)
        // special handling of new environment insets
        BufferView & bv = cur.bv();
        BufferParams const & params = bv.buffer().params();
-       LayoutPtr const & lyxlayout = params.textClass()[layout];
+       LayoutPtr const & lyxlayout = params.getTextClass()[layout];
        if (lyxlayout->is_environment) {
                // move everything in a new environment inset
                LYXERR(Debug::DEBUG, "setting layout " << to_utf8(layout));
index 4be361630a60dbdd76c6cc61483c13cc990fdbdb..5f2abc8847b562b08cf56af7319b30c2575ed222 100644 (file)
@@ -220,7 +220,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
        if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
                // reset first par to default
                cur.text()->paragraphs().begin()
-                       ->setEmptyOrDefaultLayout(bparams.textClass());
+                       ->setEmptyOrDefaultLayout(bparams.getTextClass());
                cur.pos() = 0;
                cur.pit() = 0;
                // Merge multiple paragraphs -- hack
@@ -229,8 +229,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
        } else {
                // reset surrounding par to default
                docstring const layoutname = insetText->useEmptyLayout()
-                       ? bparams.textClass().emptyLayoutName()
-                       : bparams.textClass().defaultLayoutName();
+                       ? bparams.getTextClass().emptyLayoutName()
+                       : bparams.getTextClass().defaultLayoutName();
                cur.leaveInset(*inset);
                text->setLayout(cur, layoutname);
        }
@@ -266,7 +266,7 @@ static void outline(OutlineOp mode, Cursor & cur)
        ParagraphList::iterator finish = start;
        ParagraphList::iterator end = pars.end();
 
-       TextClass const & tc = buf.params().textClass();
+       TextClass const & tc = buf.params().getTextClass();
 
        int const thistoclevel = start->layout()->toclevel;
        int toclevel;
@@ -1011,7 +1011,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                Paragraph const & para = cur.paragraph();
                docstring const old_layout = para.layout()->name();
-               TextClass const & tclass = bv->buffer().params().textClass();
+               TextClass const & tclass = bv->buffer().params().getTextClass();
 
                if (layout.empty())
                        layout = tclass.defaultLayoutName();
@@ -1384,7 +1384,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cur.posForward();
                ParagraphList & pars = cur.text()->paragraphs();
 
-               TextClass const & tclass = bv->buffer().params().textClass();
+               TextClass const & tclass = bv->buffer().params().getTextClass();
 
                // add a separate paragraph for the caption inset
                pars.push_back(Paragraph());
@@ -1675,7 +1675,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_FLOAT_LIST: {
-               TextClass const & tclass = bv->buffer().params().textClass();
+               TextClass const & tclass = bv->buffer().params().getTextClass();
                if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
                        cur.recordUndo();
                        if (cur.selection())
@@ -1946,7 +1946,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FLEX_INSERT: {
                code = FLEX_CODE;
                string s = cmd.getArg(0);
-               InsetLayout il =  cur.buffer().params().textClass().insetLayout(from_utf8(s));
+               InsetLayout il =  cur.buffer().params().getTextClass().insetLayout(from_utf8(s));
                if (il.lyxtype() != "charstyle" &&
                    il.lyxtype() != "custom" &&
                    il.lyxtype() != "element" &&
index b6030c4e85054e9fc0ab1f184dd014edb328859d..07b4f16893f49ce1c934c8d9953526f0bad8f080 100644 (file)
@@ -38,21 +38,6 @@ class FloatList;
 /// List of inset layouts
 typedef std::map<docstring, InsetLayout> InsetLayouts;
 
-/// Index in globel text class list. Basically a 'strong typedef'.
-class TextClassIndex
-{
-public:
-       ///
-       TextClassIndex(size_t t) : data_(t) {}
-       ///
-       operator size_t() const { return data_; }
-private:
-       ///
-       size_t data_;
-};
-
-
-
 /// Stores the layout specification of a LyX document class.
 class TextClass {
 public:
index 8a2f86923917a652dc0a9bf2e5f6c55ace7f2f4a..eb721bfc9c6c8b5470051da8a78f616fb1c59afd 100644 (file)
@@ -34,7 +34,7 @@ using boost::regex;
 using boost::smatch;
 
 // Gets textclass number from name
-pair<bool, TextClassIndex> const
+pair<bool, textclass_type> const
 TextClassList::numberOfClass(string const & textclass) const
 {
        ClassList::const_iterator cit =
@@ -44,24 +44,14 @@ TextClassList::numberOfClass(string const & textclass) const
                             textclass));
 
        return cit != classlist_.end() ?
-               make_pair(true, TextClassIndex(cit - classlist_.begin())) :
-               make_pair(false, TextClassIndex(0));
+               make_pair(true, textclass_type(cit - classlist_.begin())) :
+               make_pair(false, textclass_type(0));
 }
 
 
 // Gets a textclass structure from number
 TextClass const &
-TextClassList::operator[](TextClassIndex textclass) const
-{
-       if (textclass >= classlist_.size())
-               return classlist_[0];
-       
-       //FIXME I don't believe the following line is actually necessary (rgh)
-       classlist_[textclass].load();
-       return classlist_[textclass];
-}
-
-TextClass & TextClassList::at(TextClassIndex textclass)
+TextClassList::operator[](textclass_type textclass) const
 {
        if (textclass >= classlist_.size())
                return classlist_[0];
@@ -176,8 +166,7 @@ bool TextClassList::read()
 }
 
 
-void TextClassList::reset(TextClassIndex const & textclass)
-{
+void TextClassList::reset(textclass_type const textclass) {
        if (textclass >= classlist_.size())
                return;
        TextClass const & tc = classlist_[textclass];
@@ -187,7 +176,7 @@ void TextClassList::reset(TextClassIndex const & textclass)
 }
 
 
-pair<bool, TextClassIndex> const
+pair<bool, textclass_type> const
 TextClassList::addTextClass(string const & textclass, string const & path)
 {
        // only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS
@@ -217,7 +206,7 @@ TextClassList::addTextClass(string const & textclass, string const & path)
                                        tmpl.load(path);
                                // Do not add this local TextClass to classlist_ if it has
                                // already been loaded by, for example, a master buffer.
-                               pair<bool, lyx::TextClassIndex> pp =
+                               pair<bool, lyx::textclass_type> pp =
                                        textclasslist.numberOfClass(textclass);
                                // only layouts from the same directory are considered to be identical.
                                if (pp.first && classlist_[pp.second].description() == tmpl.description())
@@ -232,7 +221,7 @@ TextClassList::addTextClass(string const & textclass, string const & path)
                }
        }
        // If .layout is not in local directory, or an invalid layout is found, return false
-       return make_pair(false, TextClassIndex(0));
+       return make_pair(false, textclass_type(0));
 }
 
 
@@ -240,7 +229,7 @@ TextClassList::addTextClass(string const & textclass, string const & path)
 TextClassList textclasslist;
 
 
-TextClassIndex defaultTextclass()
+textclass_type defaultTextclass()
 {
        // We want to return the article class. if `first' is
        // true in the returned pair, then `second' is the textclass
index d05e6de73c7277b3a1f07b296dc828854e337849..8c1b3744d6e93c8500d78997818eaf9c668aecd6 100644 (file)
@@ -44,22 +44,21 @@ public:
        bool empty() const { return classlist_.empty(); }
 
        /// Gets textclass number from name, -1 if textclass name does not exist
-       std::pair<bool, TextClassIndex> const
-       numberOfClass(std::string const & textClassName) const;
+       std::pair<bool, textclass_type> const
+       numberOfClass(std::string const & textclass) const;
 
        ///
-       TextClass const & operator[](TextClassIndex index) const;
-       TextClass & at(TextClassIndex index);
+       TextClass const & operator[](textclass_type textclass) const;
 
        /// Read textclass list.  Returns false if this fails.
        bool read();
        
        /// Clears the textclass so as to force it to be reloaded
-       void reset(TextClassIndex const & index);
+       void reset(textclass_type const textclass);
 
        /// add a textclass from user local directory.
        /// Return ture/false, and textclass number
-       std::pair<bool, TextClassIndex> const
+       std::pair<bool, textclass_type> const
        addTextClass(std::string const & textclass, std::string const & path);
 
 private:
@@ -74,7 +73,7 @@ private:
 ///
 extern TextClassList textclasslist;
 ///
-TextClassIndex defaultTextclass();
+textclass_type defaultTextclass();
 
 
 } // namespace lyx
diff --git a/src/TextClassPtr.h b/src/TextClassPtr.h
new file mode 100644 (file)
index 0000000..cb610b1
--- /dev/null
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+/**
+ * \file TextClassPtr.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef TEXTCLASS_PTR_H
+#define TEXTCLASS_PTR_H
+
+#include <boost/shared_ptr.hpp>
+
+namespace lyx {
+
+class TextClass;
+
+/// Global typedef
+/** Shared pointer for possibly modular layout. Needed so that paste,
+ *  for example, will still be able to retain the pointer, even when
+ *  the buffer itself is closed.
+ */
+typedef boost::shared_ptr<TextClass> TextClassPtr;
+
+} // namespace lyx
+
+#endif
index 126e4a8422b28f901d016578cda23641dfa2fc36..a9ce0f04dc7321b9f232e0152e888f33f97b9eb9 100644 (file)
@@ -1764,7 +1764,7 @@ int TextMetrics::leftMargin(int max_width,
        BOOST_ASSERT(pos <= par.size());
        Buffer const & buffer = bv_->buffer();
        //lyxerr << "TextMetrics::leftMargin: pit: " << pit << " pos: " << pos << endl;
-       TextClass const & tclass = buffer.params().textClass();
+       TextClass const & tclass = buffer.params().getTextClass();
        LayoutPtr const & layout = par.layout();
 
        docstring parindent = layout->parindent;
index 00a55a987097d56475c809145c5bf1daa6e098a1..7c0084420e1fcf71e0a30d36254cd3778a6719f9 100644 (file)
@@ -108,7 +108,7 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
        }
 
        BufferParams const & bufparams = buffer_->params();
-       const int min_toclevel = bufparams.textClass().min_toclevel();
+       const int min_toclevel = bufparams.getTextClass().min_toclevel();
 
        TocIterator toc_item = item("tableofcontents", par_it);
 
@@ -133,8 +133,9 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
        }
 
        int const toclevel = toc_item->par_it_->layout()->toclevel;
-       if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel
-               && tocstring.empty()) 
+       if (toclevel != Layout::NOT_IN_TOC
+           && toclevel >= min_toclevel
+               && tocstring.empty())
                        tocstring = toc_item->par_it_->asString(*buffer_, true);
 
        const_cast<TocItem &>(*toc_item).str_ = tocstring;
@@ -146,7 +147,7 @@ void TocBackend::update()
        tocs_.clear();
 
        BufferParams const & bufparams = buffer_->params();
-       const int min_toclevel = bufparams.textClass().min_toclevel();
+       const int min_toclevel = bufparams.getTextClass().min_toclevel();
 
        Toc & toc = tocs_["tableofcontents"];
        ParConstIterator pit = buffer_->par_iterator_begin();
index 6e8e612f94480f6c191a88de63209102359fdab1..c07f136c0efbde341861b30ec771d56fb59ce383 100644 (file)
@@ -294,7 +294,7 @@ bool needEnumCounterReset(ParIterator const & it)
 // set the label of a paragraph. This includes the counters.
 void setLabel(Buffer const & buf, ParIterator & it)
 {
-       TextClass const & textclass = buf.params().textClass();
+       TextClass const & textclass = buf.params().getTextClass();
        Paragraph & par = it.paragraph();
        LayoutPtr const & layout = par.layout();
        Counters & counters = textclass.counters();
@@ -482,7 +482,7 @@ void updateLabels(Buffer const & buf, bool childonly)
 {
        Buffer const * const master = buf.masterBuffer();
        // Use the master text class also for child documents
-       TextClass const & textclass = master->params().textClass();
+       TextClass const & textclass = master->params().getTextClass();
 
        if (!childonly) {
                // If this is a child document start with the master
index 39a6b15c8fc284e37ffe387fc3c6d8564f329684..18bc3c18d89e5085e15d248f411e3d79e181e3be 100644 (file)
@@ -102,7 +102,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
 
                case LFUN_FLEX_INSERT: {
                        string s = cmd.getArg(0);
-                       return new InsetFlex(params, params.textClassIndex(), s);
+                       return new InsetFlex(params, params.getTextClassPtr(), s);
                }
 
                case LFUN_NOTE_INSERT: {
@@ -147,7 +147,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
                case LFUN_FLOAT_INSERT: {
                        // check if the float type exists
                        string const argument = to_utf8(cmd.argument());
-                       if (params.textClass().floats().typeExist(argument))
+                       if (params.getTextClass().floats().typeExist(argument))
                                return new InsetFloat(params, argument);
                        lyxerr << "Non-existent float type: " << argument << endl;
                }
@@ -155,7 +155,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
                case LFUN_FLOAT_WIDE_INSERT: {
                        // check if the float type exists
                        string const argument = to_utf8(cmd.argument());
-                       if (params.textClass().floats().typeExist(argument)) {
+                       if (params.getTextClass().floats().typeExist(argument)) {
                                auto_ptr<InsetFloat> p(new InsetFloat(params, argument));
                                p->wide(true, params);
                                return p.release();
@@ -484,7 +484,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        lex.next();
                        string s = lex.getString();
                        inset.reset(new InsetFlex(buf.params(), 
-                               buf.params().textClassIndex(), s));
+                               buf.params().getTextClassPtr(), s));
                } else if (tmptok == "Branch") {
                        inset.reset(new InsetBranch(buf.params(),
                                                    InsetBranchParams()));
index 2be31a4ffc4aff2343b140fab629afdfb53798f0..de358a63c0aece40b91637c0433e9310810c0201 100644 (file)
@@ -25,8 +25,6 @@
 #include <QSettings>
 #include <QString>
 
-#include <boost/assert.hpp>
-
 #include <string>
 
 using namespace std;
index 7ad3bd4f8332d585c9ec7f84a87ae9fdf5237f17..068636c2f1338d923aa30b60f0125fda5a6c269f 100644 (file)
@@ -1212,7 +1212,7 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel)
 
 void GuiDocument::classChanged()
 {
-       TextClassIndex const tc = latexModule->classCO->currentIndex();
+       textclass_type const tc = latexModule->classCO->currentIndex();
        bp_.setBaseClass(tc);
        if (lyxrc.auto_reset_options) {
                if (applyPB->isEnabled()) {
@@ -1230,8 +1230,8 @@ void GuiDocument::classChanged()
 
 
 namespace {
-       // This is an insanely complicated attempt to make this sort of thing
-       // work with RTL languages.
+       //This is an insanely complicated attempt to make this sort of thing
+       //work with RTL languages.
        docstring formatStrVec(vector<string> const & v, docstring const & s) 
        {
                //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
@@ -1354,7 +1354,7 @@ void GuiDocument::updateEmbeddedFileList()
 
 void GuiDocument::updateNumbering()
 {
-       TextClass const & tclass = bp_.textClass();
+       TextClass const & tclass = bp_.getTextClass();
 
        numberingModule->tocTW->setUpdatesEnabled(false);
        numberingModule->tocTW->clear();
@@ -1441,7 +1441,7 @@ void GuiDocument::apply(BufferParams & params)
        params.language = lyx::languages.getLanguage(lang_[pos]);
 
        // numbering
-       if (params.textClass().hasTocLevels()) {
+       if (params.getTextClass().hasTocLevels()) {
                params.tocdepth = numberingModule->tocSL->value();
                params.secnumdepth = numberingModule->depthSL->value();
        }
@@ -1793,7 +1793,7 @@ void GuiDocument::updateParams(BufferParams const & params)
        }
 
        // text layout
-       latexModule->classCO->setCurrentIndex(params.baseClass());
+       latexModule->classCO->setCurrentIndex(params.getBaseClass());
        
        updatePagestyle(textClass().opt_pagestyle(),
                                 params.pagestyle);
@@ -2113,7 +2113,7 @@ vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
 
 TextClass const & GuiDocument::textClass() const
 {
-       return textclasslist[bp_.baseClass()];
+       return textclasslist[bp_.getBaseClass()];
 }
 
 
index b10b864d1fb009c6f8838483d37757ee06925366..79c5f89f68cbd02fe204c0bfca764459876e80ba 100644 (file)
@@ -234,7 +234,7 @@ docstring GuiToc::guiName(string const & type) const
        if (type == "note")
                return _("List of Notes");
 
-       FloatList const & floats = buffer().params().textClass().floats();
+       FloatList const & floats = buffer().params().getTextClass().floats();
        if (floats.typeExist(type))
                return _(floats.getType(type).listName());
 
index ab61ce352a6b4681bdfbcd15b563b2727ac3bf94..a354021af5ffb51fc03af4bb7ade401f6e2593ef 100644 (file)
@@ -308,7 +308,7 @@ void GuiLayoutBox::updateContents(bool reset)
                return;
        }
 
-       TextClass const * text_class = &buffer->params().textClass();
+       TextClass const * text_class = &buffer->params().getTextClass();
        Inset const * inset = 
                owner_.view()->cursor().innerParagraph().inInset();
 
index 43b98086919fd45bff4d472359f8fd14a1ac7d25..dd89ae6943b09101f6be6759dd1549a7d22df320 100644 (file)
@@ -25,6 +25,7 @@
 #include "Layout.h"
 #include "LyX.h"
 #include "LyXFunc.h"
+#include "TextClass.h"
 #include "ToolbarBackend.h"
 
 #include "support/debug.h"
@@ -137,7 +138,7 @@ void GuiToolbars::init()
                LYXERR(Debug::INIT, "Adding " << tb->key << " at position "
                        << tb->info.posx << " " << tb->info.posy);
                // add toolbar break if posx or posy changes
-       bool newline = tb->info.location == last_loc && (
+               bool newline = tb->info.location == last_loc && (
                        // if two toolbars at the same location, assume uninitialized and add toolbar break
                        (tb->info.posx == last_posx && tb->info.posy == last_posy) ||
                        (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->info.posy != last_posy) ||
index b76339383c1812e76b29f2d6700cdabeda95be9d..d7015c8eb94f6244944c314d4f1db2b319948018 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef GUI_TOOLBARS_H
 #define GUI_TOOLBARS_H
 
+#include "TextClassPtr.h"
+
 #include "support/docstring.h"
 
 #include <map>
@@ -21,7 +23,6 @@
 namespace lyx {
 
 class ToolbarInfo;
-class TextClassIndex;
 
 namespace frontend {
 
@@ -83,10 +84,13 @@ private:
        /// Toolbar store providing access to individual toolbars by name.
        typedef std::map<std::string, GuiToolbar *> ToolbarsMap;
        ToolbarsMap toolbars_;
+
+       /// The last textclass layout list in the layout choice selector
+       TextClassPtr last_textclass_;
 };
 
 
 } // namespace frontend
 } // namespace lyx
 
-#endif // GUI_TOOLBARS_H
+#endif // NOT GUI_TOOLBARS_H
index ed94df8ae323079c475353dba28b72d470097f40..d77f4b10ec2a5a0fe5fefd4f26a17ab84091e245 100644 (file)
@@ -361,7 +361,7 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 
 InsetLayout const & Inset::getLayout(BufferParams const & bp) const
 {
-       return bp.textClass().insetLayout(name());  
+       return bp.getTextClass().insetLayout(name());  
 }
 
 
index 508b2f4d01833bc7b0f6bf85b4f2d52f61c805b3..1455e5ac8bfd191cf63b2cf677c6f2e8c473db51 100644 (file)
@@ -210,7 +210,7 @@ void InsetBibitem::fillWithBibKeys(Buffer const & buf,
 /// Update the counters of this inset and of its contents
 void InsetBibitem::updateLabels(Buffer const &buf, ParIterator const &) 
 {
-       Counters & counters = buf.params().textClass().counters();
+       Counters & counters = buf.params().getTextClass().counters();
        docstring const bibitem = from_ascii("bibitem");
        if (counters.hasCounter(bibitem) && getParam("label").empty()) {
                counters.step(bibitem);
index a23c8cac4055df9f3760fc53c6127716ac9de028..9a543716b49ddbeebbdb30c4f3921a27d866efe5 100644 (file)
@@ -313,7 +313,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
                // part of its name, because it's than book.
                // For the "official" lyx-layouts it's no problem to support
                // all well
-               if (!contains(buffer.params().textClass().name(),
+               if (!contains(buffer.params().getTextClass().name(),
                              "art")) {
                        if (buffer.params().sides == OneSide) {
                                // oneside
index 71620c32139d2ca7ce7b0119b49c8f8bcf3681ff..2400722fd33f829fcd17b33f75272824a8f5f6fe 100644 (file)
@@ -89,7 +89,7 @@ InsetBox::InsetBox(BufferParams const & bp, string const & label)
        : InsetCollapsable(bp), params_(label)
 {
        if (forceEmptyLayout())
-               paragraphs().back().setLayout(bp.textClass().emptyLayout());
+               paragraphs().back().setLayout(bp.getTextClass().emptyLayout());
 }
 
 
index cdd281ba8c25babe652058095d9cd7d3fb9f99d5..67b4adcd3934d682a894f0731bea510df63477e6 100644 (file)
@@ -225,7 +225,7 @@ void InsetBranch::updateLabels(Buffer const & buf, ParIterator const & it)
        if (isBranchSelected(buf))
                InsetCollapsable::updateLabels(buf, it);
        else {
-               TextClass const & tclass = buf.params().textClass();
+               TextClass const & tclass = buf.params().getTextClass();
                Counters savecnt = tclass.counters();
                InsetCollapsable::updateLabels(buf, it);
                tclass.counters() = savecnt;
index ae9e9eb5ecc09858ea15903fb81db80e066c376c..2a4f97b7a97f2e143d7da517fe1e598b775dda24 100644 (file)
@@ -57,14 +57,14 @@ InsetCaption::InsetCaption(InsetCaption const & ic)
 
 
 InsetCaption::InsetCaption(BufferParams const & bp)
-       : InsetText(bp), textclass_(bp.textClass())
+       : InsetText(bp), textclass_(bp.getTextClass())
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
        setFrameColor(Color_captionframe);
        //FIXME Do we need to set all paragraphs here? or will there
        //always only be one?
-       paragraphs().back().setLayout(bp.textClass().emptyLayout());
+       paragraphs().back().setLayout(bp.getTextClass().emptyLayout());
 }
 
 
@@ -278,7 +278,7 @@ int InsetCaption::getOptArg(Buffer const & buf, odocstream & os,
 
 void InsetCaption::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       TextClass const & tclass = buf.params().textClass();
+       TextClass const & tclass = buf.params().getTextClass();
        Counters & cnts = tclass.counters();
        string const & type = cnts.current_float();
        // Memorize type for addToToc().
index e35f18906bf3efb651a0fd6f1370511a2780f754..4dc2f96d14951b9bdbc32535d7f62d3fe9d262d5 100644 (file)
@@ -30,7 +30,6 @@
 #include "MetricsInfo.h"
 #include "ParagraphParameters.h"
 #include "TextClass.h"
-#include "TextClassList.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -79,15 +78,15 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const
 
 
 InsetCollapsable::InsetCollapsable(BufferParams const & bp,
-               CollapseStatus status, TextClassIndex tc)
-       : InsetText(bp), textClass_(tc), status_(status),
+               CollapseStatus status, TextClassPtr tc)
+       : InsetText(bp), status_(status),
          openinlined_(false), autoOpen_(false), mouse_hover_(false)
 {
        setLayout(tc);
        setAutoBreakRows(true);
        setDrawFrame(true);
        setFrameColor(Color_collapsableframe);
-       paragraphs().back().setLayout(bp.textClass().emptyLayout());
+       paragraphs().back().setLayout(bp.getTextClass().emptyLayout());
 }
 
 
@@ -111,7 +110,7 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
        Dimension dim = dimensionCollapsed();
        if (geometry() == NoButton)
                return layout_->labelstring();
-       if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des)
+       else if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des)
                return docstring();
 
        switch (status_) {
@@ -126,15 +125,15 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
 
 void InsetCollapsable::setLayout(BufferParams const & bp)
 {
-       setLayout(bp.textClassIndex());
+       setLayout(bp.getTextClassPtr());
 }
 
 
-void InsetCollapsable::setLayout(TextClassIndex tcindex)
+void InsetCollapsable::setLayout(TextClassPtr tc)
 {
-       textClass_ = tcindex;
-       if (tcindex != TextClassIndex(-1)) {
-               layout_ = &textclasslist[tcindex].insetLayout(name());
+       textClass_ = tc;
+       if ( tc.get() != 0 ) {
+               layout_ = &tc->insetLayout(name());
                labelstring_ = layout_->labelstring();
        } else {
                layout_ = &TextClass::emptyInsetLayout();
@@ -189,8 +188,7 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
                        lex.pushToken(token);
                }
        }
-
-       // this must be set before we enter InsetText::read()
+       //this must be set before we enter InsetText::read()
        setLayout(buf.params());
 
        InsetText::read(buf, lex);
@@ -256,7 +254,8 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        case LeftButton:
        case ButtonOnly:
                dim = dimensionCollapsed();
-               if (geometry() == TopButton || geometry() == LeftButton) {
+               if (geometry() == TopButton
+                || geometry() == LeftButton) {
                        Dimension textdim;
                        InsetText::metrics(mi, textdim);
                        openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
@@ -750,10 +749,10 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_TABULAR_INSERT:
        case LFUN_TOC_INSERT:
        case LFUN_WRAP_INSERT:
-               if (layout_->isPassThru()) {
-                       flag.enabled(false);
-                       return true;
-               }
+       if (layout_->isPassThru()) {
+               flag.enabled(false);
+               return true;
+       } else
                return InsetText::getStatus(cur, cmd, flag);
 
        case LFUN_INSET_TOGGLE:
@@ -797,7 +796,7 @@ void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
 docstring InsetCollapsable::floatName(
                string const & type, BufferParams const & bp) const
 {
-       FloatList const & floats = bp.textClass().floats();
+       FloatList const & floats = bp.getTextClass().floats();
        FloatList::const_iterator it = floats[type];
        // FIXME UNICODE
        return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
index bb1e53cdb53b6d35b2fc6de3cfb9dde87ebdb907..920a473917caecfab0c1d21085f397fd529c25c1 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "Box.h"
 #include "TextClass.h"
+#include "TextClassPtr.h"
 
 #include <string>
 
@@ -41,7 +42,7 @@ public:
        InsetCollapsable(
                BufferParams const &,
                CollapseStatus status = Inset::Open,
-               TextClassIndex tc = TextClassIndex(0)
+               TextClassPtr tc = TextClassPtr((TextClass *)0)
                );
        ///
        InsetCollapsable(InsetCollapsable const & rhs);
@@ -63,7 +64,7 @@ public:
        void setLayout(BufferParams const &);
        /// (Re-)set the character style parameters from \p tc according
        /// to name()
-       void setLayout(TextClassIndex tc);
+       void setLayout(TextClassPtr tc);
        ///
        virtual bool useEmptyLayout() { return true; }
        ///
@@ -177,7 +178,7 @@ protected:
 
 private:
        /// text class to keep the InsetLayout above in memory
-       TextClassIndex textClass_;
+       TextClassPtr textClass_;
        /// cache for the layout_. Make sure it is in sync with the text class!
        InsetLayout const * layout_;
        ///
index 90fc351f3ef57423e73c5884975fa99ba710a5f4..9d5c67dfb83196823785f711e49e9eaabaa59efd 100644 (file)
@@ -119,7 +119,7 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        BufferParams const & bp = cur.buffer().params();
        LayoutPtr const layout =
-                       bp.textClass().emptyLayout();
+                       bp.getTextClass().emptyLayout();
        //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
        switch (cmd.action) {
 
index 32d7850adee2493b7f65565ef2ca254c3dcbe2cd..73048ab52e87a8b9bb257c337e12733ed6b131c4 100644 (file)
@@ -27,7 +27,7 @@ namespace lyx {
 
 InsetEnvironment::InsetEnvironment
                (BufferParams const & bp, docstring const & name)
-       : InsetText(bp), layout_(bp.textClass()[name]), name_(name)
+       : InsetText(bp), layout_(bp.getTextClass()[name]), name_(name)
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
index 5ce4d0761953812b3b286e53a328e67c0e0e9b5d..279f9940542a2327f2fd1d300e5cf3b1bb4bf3b7 100644 (file)
@@ -40,7 +40,7 @@ namespace lyx {
 
 
 InsetFlex::InsetFlex(BufferParams const & bp,
-       TextClassIndex tc, string const & layoutName)
+       TextClassPtr tc, string const & layoutName)
        : InsetCollapsable(bp, Collapsed, tc),
        name_(layoutName)
 {
index 2f90ebf9e1d4cd0b2c7ed31d6d6f4cfdef0a0a4d..3bb10abe493a6b2918d784cb1296cc529e1fdd28 100644 (file)
@@ -27,7 +27,7 @@ class InsetFlex : public InsetCollapsable {
 public:
        ///
        InsetFlex(BufferParams const &,
-                 TextClassIndex tc, string const & layoutName);
+                 TextClassPtr tc, string const & layoutName);
        ///
        docstring name() const { return from_utf8(name_); }
 
index 07280d7ff70839f14ca571d2477f9ae63cb96f49..e966bb5d6c7b9a0c1f2720cc7e163a1d19e2cdda 100644 (file)
@@ -175,7 +175,7 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetFloat::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       Counters & cnts = buf.params().textClass().counters();
+       Counters & cnts = buf.params().getTextClass().counters();
        string const saveflt = cnts.current_float();
 
        // Tell to captions what the current float is
@@ -283,7 +283,7 @@ docstring const InsetFloat::editMessage() const
 int InsetFloat::latex(Buffer const & buf, odocstream & os,
                      OutputParams const & runparams) const
 {
-       FloatList const & floats = buf.params().textClass().floats();
+       FloatList const & floats = buf.params().getTextClass().floats();
        string tmptype = params_.type;
        if (params_.sideways)
                tmptype = "sideways" + params_.type;
index f3299d899f7892d7c7e1fa79c892818d0c8ad6b8..fd9a265cfa72ca8328d15c0cb735d1f57aeb0cb7 100644 (file)
@@ -68,7 +68,7 @@ bool InsetFloatList::isCompatibleCommand(string const & s)
 
 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
 {
-       FloatList const & floats = buf.params().textClass().floats();
+       FloatList const & floats = buf.params().getTextClass().floats();
        FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
        if (it != floats.end())
                return buf.B_(it->second.listName());
@@ -85,7 +85,7 @@ void InsetFloatList::write(Buffer const &, ostream & os) const
 
 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
 {
-       FloatList const & floats = buf.params().textClass().floats();
+       FloatList const & floats = buf.params().getTextClass().floats();
        string token;
 
        if (lex.eatLine()) {
@@ -114,7 +114,7 @@ void InsetFloatList::read(Buffer const & buf, Lexer & lex)
 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
                          OutputParams const &) const
 {
-       FloatList const & floats = buf.params().textClass().floats();
+       FloatList const & floats = buf.params().getTextClass().floats();
        FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
 
        if (cit != floats.end()) {
index 77733ef21cded28c82057708f8e66847857b6b9b..58acf7d562d312a4be4e8b2dde8656a59b8b60d0 100644 (file)
@@ -59,7 +59,7 @@ docstring const InsetFoot::editMessage() const
 
 void InsetFoot::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       TextClass const & tclass = buf.params().textClass();
+       TextClass const & tclass = buf.params().getTextClass();
        Counters & cnts = tclass.counters();
        docstring const foot = from_ascii("footnote");
        Paragraph const & outer =  it.paragraph();
index 686d445f5360d5c1f9ca79c184e534bf5b79ff27..ccff865b7a21520183a92eb66cf014a8f082c6f2 100644 (file)
@@ -441,14 +441,14 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
                Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
 
-               if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
+               if (tmp->params().getBaseClass() != masterBuffer->params().getBaseClass()) {
                        // FIXME UNICODE
                        docstring text = bformat(_("Included file `%1$s'\n"
                                                "has textclass `%2$s'\n"
                                                             "while parent file has textclass `%3$s'."),
                                              included_file.displayName(),
-                                             from_utf8(tmp->params().textClass().name()),
-                                             from_utf8(masterBuffer->params().textClass().name()));
+                                             from_utf8(tmp->params().getTextClass().name()),
+                                             from_utf8(masterBuffer->params().getTextClass().name()));
                        Alert::warning(_("Different textclasses"), text);
                        //return 0;
                }
@@ -902,7 +902,7 @@ void InsetInclude::updateLabels(Buffer const & buffer, ParIterator const &)
                listings_label_.clear();
                return;
        }
-       Counters & counters = buffer.params().textClass().counters();
+       Counters & counters = buffer.params().getTextClass().counters();
        docstring const cnt = from_ascii("listing");
        listings_label_ = buffer.B_("Program Listing");
        if (counters.hasCounter(cnt)) {
index ca68f32f0c9718c1ed1106d5c063d2073a29ec58..2218ef660d50bd5435d59f41adbe33ad4f0c5f9d 100644 (file)
@@ -73,10 +73,11 @@ void InsetInfo::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-static Translator<InsetInfo::info_type, string> initTranslator()
+namespace {
+
+Translator<InsetInfo::info_type, string> const initTranslator()
 {      
-       Translator<InsetInfo::info_type, string>
-               translator(InsetInfo::UNKNOWN_INFO, "unknown");
+       Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
 
        translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
        translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
@@ -88,12 +89,16 @@ static Translator<InsetInfo::info_type, string> initTranslator()
        return translator;
 }
 
+} // namespace anon
+
 Translator<InsetInfo::info_type, string> const & InsetInfo::nameTranslator() const
 {
-       static Translator<info_type, string> const translator = initTranslator();
+       static Translator<info_type, string> const translator =
+               initTranslator();
        return translator;
 }
 
+       
 
 void InsetInfo::read(Buffer const & buf, Lexer & lex)
 {
@@ -123,7 +128,8 @@ void InsetInfo::read(Buffer const & buf, Lexer & lex)
 
 void InsetInfo::write(Buffer const &, ostream & os) const
 {
-       os << "Info\ntype  \"" << nameTranslator().find(type_)
+       os << "Info\ntype  \""
+          << nameTranslator().find(type_)
           << "\"\narg   \"" << name_ << '\"';
 }
 
@@ -196,7 +202,8 @@ void InsetInfo::updateInfo(Buffer const & buf)
                break;
        case TEXTCLASS_INFO: {
                // name_ is the class name
-               pair<bool, TextClassIndex> pp = textclasslist.numberOfClass(name_);
+               pair<bool, lyx::textclass_type> pp =
+                       textclasslist.numberOfClass(name_);
                setText(pp.first ? _("yes") : _("no"),
                        bp.getFont(), false);
                break;
@@ -235,7 +242,7 @@ void InsetInfo::updateInfo(Buffer const & buf)
                else if (name_ == "path")
                        setText(from_utf8(buf.filePath()), bp.getFont(), false);
                else if (name_ == "class")
-                       setText(from_utf8(bp.textClass().name()), bp.getFont(), false);
+                       setText(from_utf8(bp.getTextClass().name()), bp.getFont(), false);
                else
                        setText(_("Unknown buffer info"), bp.getFont(), false);
                break;
index 48b51c1fcf82446d0fd6daf37a5326606cc834ee..21da448d7683a4df7686d4048d310b3563937017 100644 (file)
@@ -71,7 +71,7 @@ Inset::DisplayType InsetListings::display() const
 
 void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       Counters & cnts = buf.params().textClass().counters();
+       Counters & cnts = buf.params().getTextClass().counters();
        string const saveflt = cnts.current_float();
 
        // Tell to captions what the current float is
index 08189ca1297cd952e8dafe27ca208193305e611f..ab90288c6beb5530ad33f553567693c5c5bbf29d 100644 (file)
@@ -213,7 +213,7 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetNote::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       TextClass const & tclass = buf.params().textClass();
+       TextClass const & tclass = buf.params().getTextClass();
        Counters savecnt = tclass.counters();
        InsetCollapsable::updateLabels(buf, it);
        tclass.counters() = savecnt;
index 683dfc6cf0557c558469b72974eba2256889c504..e783fc842480b9262da92a91a8787e70a03171ec 100644 (file)
@@ -486,7 +486,7 @@ Tabular::cellstruct::cellstruct(BufferParams const & bp)
          rotate(false),
          inset(new InsetText(bp))
 {
-       inset->paragraphs().back().setLayout(bp.textClass().emptyLayout());
+       inset->paragraphs().back().setLayout(bp.getTextClass().emptyLayout());
 }
 
 
@@ -1093,7 +1093,7 @@ void toggleFixedWidth(Cursor & cur, InsetText * inset, bool fixedWidth)
        cur.push(*inset);
        // undo information has already been recorded
        inset->getText(0)->setLayout(cur.bv().buffer(), 0, cur.lastpit() + 1,
-                       bp.textClass().emptyLayoutName());
+                       bp.getTextClass().emptyLayoutName());
        cur.pop();
 }
 
@@ -3177,7 +3177,7 @@ void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
 void InsetTabular::updateLabels(Buffer const & buf, ParIterator const & it)
 {
        // In a longtable, tell captions what the current float is
-       Counters & cnts = buf.params().textClass().counters();
+       Counters & cnts = buf.params().getTextClass().counters();
        string const saveflt = cnts.current_float();
        if (tabular.isLongTabular())
                cnts.current_float("table");
index 4bb85a90642f818b874221d912f39c9870e5469e..bc473988fd729ba9b2445b8fad76e654330723ed 100644 (file)
@@ -100,7 +100,7 @@ InsetText::InsetText(BufferParams const & bp)
 {
        paragraphs().push_back(Paragraph());
        Paragraph & ourpar = paragraphs().back();
-       ourpar.setEmptyOrDefaultLayout(bp.textClass());
+       ourpar.setEmptyOrDefaultLayout(bp.getTextClass());
        ourpar.setInsetOwner(this);
 }
 
index 783668e35b00a4ce76ac2405c9f6565ab8f1b93b..fccc29695bf3b1fd98030873a3c7e73c676afc3b 100644 (file)
@@ -107,7 +107,7 @@ bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetWrap::updateLabels(Buffer const & buf, ParIterator const & it)
 {
-       Counters & cnts = buf.params().textClass().counters();
+       Counters & cnts = buf.params().getTextClass().counters();
        string const saveflt = cnts.current_float();
 
        // Tell to captions what the current float is
index b6c60ad655b3572b8b760955c59fcb0749b2af13..dda121059deab033add6b22885d1f94a3b5362c9 100644 (file)
@@ -102,7 +102,8 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf,
                                            ParagraphList::const_iterator const & pbegin,
                                            ParagraphList::const_iterator const & pend)
 {
-       LayoutPtr const & defaultstyle = buf.params().textClass().defaultLayout();
+       LayoutPtr const & defaultstyle =
+               buf.params().getTextClass().defaultLayout();
        for (ParagraphList::const_iterator par = pbegin; par != pend; ++par) {
                if (par != pbegin)
                        os << '\n';
@@ -126,7 +127,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
                                              ParagraphList::const_iterator const & pend) {
        ParagraphList::const_iterator par = pbegin;
 
-       LayoutPtr const & defaultstyle = buf.params().textClass().defaultLayout();
+       LayoutPtr const & defaultstyle = buf.params().getTextClass().defaultLayout();
        LayoutPtr const & bstyle = par->layout();
        string item_tag;
 
index cdf8a5bb21b21c21f59c0ed2a8a1141fa056132c..4865845b455ff465dc363271949719ad74d625c9 100644 (file)
@@ -109,7 +109,8 @@ TeXEnvironment(Buffer const & buf,
        BufferParams const & bparams = buf.params();
 
        LayoutPtr const & style = pit->forceEmptyLayout() ?
-                       bparams.textClass().emptyLayout() : pit->layout();
+                       bparams.getTextClass().emptyLayout() :
+                       pit->layout();
 
        ParagraphList const & paragraphs = text.paragraphs();
 
@@ -309,7 +310,8 @@ TeXOnePar(Buffer const & buf,
        // In an inset with unlimited length (all in one row),
        // force layout to default
        LayoutPtr const style = pit->forceEmptyLayout() ?
-               bparams.textClass().emptyLayout() : pit->layout();
+               bparams.getTextClass().emptyLayout() :
+               pit->layout();
 
        OutputParams runparams = runparams_in;
        runparams.moving_arg |= style->needprotect;
@@ -477,7 +479,7 @@ TeXOnePar(Buffer const & buf,
                }
        }
 
-       bool const useSetSpace = bparams.textClass().provides("SetSpace");
+       bool const useSetSpace = bparams.getTextClass().provides("SetSpace");
        if (pit->allowParagraphCustomization()) {
                if (pit->params().startOfAppendix()) {
                        os << "\\appendix\n";
@@ -743,7 +745,7 @@ void latexParagraphs(Buffer const & buf,
        bool was_title = false;
        bool already_title = false;
        BufferParams const & bparams = buf.params();
-       TextClass const & tclass = bparams.textClass();
+       TextClass const & tclass = bparams.getTextClass();
        ParagraphList const & paragraphs = text.paragraphs();
        ParagraphList::const_iterator par = paragraphs.begin();
        ParagraphList::const_iterator endpar = paragraphs.end();
index 2b2f5ab18314fcd6f62b35ae3bd8607e2dd56906..991341ab5f0a33ebd118aeadacecf5156291bd82 100644 (file)
@@ -77,9 +77,9 @@ void breakParagraph(BufferParams const & bparams,
        // without doing that we get a crash when typing <Return> at the
        // end of a paragraph
        if (par.useEmptyLayout())
-               tmp->setLayout(bparams.textClass().emptyLayout());
+               tmp->setLayout(bparams.getTextClass().emptyLayout());
        else
-               tmp->setLayout(bparams.textClass().defaultLayout());
+               tmp->setLayout(bparams.getTextClass().defaultLayout());
 
        // layout stays the same with latex-environments
        if (keep_layout) {
@@ -144,7 +144,7 @@ void breakParagraph(BufferParams const & bparams,
                par.params().clear();
                // do not lose start of appendix marker (bug 4212)
                par.params().startOfAppendix(soa);
-               par.setLayout(bparams.textClass().defaultLayout());
+               par.setLayout(bparams.getTextClass().defaultLayout());
        }
 
        // layout stays the same with latex-environments
index 2b0b02fd96154d84171204f6f0f0b56b8d219201..6ac6c8653b95af30c777cae4ed13e23c4bf6ac9d 100644 (file)
@@ -121,9 +121,9 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
        // and adds a number for uniqueness.
        // If you know what you are doing, you can set allowed==""
        // to disable this mangling.
-       TextClass const & tclass = buf.params().textClass();
+       TextClass const & tclass = buf.params().getTextClass();
        docstring const allowed = from_ascii(
-               runparams.flavor == OutputParams::XML? ".-_:" : tclass.options());
+               runparams.flavor == OutputParams::XML? ".-_:":tclass.options());
 
        if (allowed.empty())
                return orig;
@@ -139,7 +139,7 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
 
        MangledMap::const_iterator const known = mangledNames.find(orig);
        if (known != mangledNames.end())
-               return known->second;
+               return (*known).second;
 
        // make sure it starts with a letter
        if (!isAlphaASCII(*it) && allowed.find(*it) >= allowed.size())
@@ -204,7 +204,7 @@ void sgml::openTag(Buffer const & buf, odocstream & os,
        LayoutPtr const & style = par.layout();
        string const & name = style->latexname();
        string param = style->latexparam();
-       Counters & counters = buf.params().textClass().counters();
+       Counters & counters = buf.params().getTextClass().counters();
 
        string id = par.getID(buf, runparams);
 
index 94acd680ecfc3a626bbe8e2cf8bea8435695e385..206d2818b15672ca82067794227c4cf2fbde2ed4 100644 (file)
@@ -39,6 +39,9 @@ namespace lyx {
        /// a type for sizes
        typedef size_t     size_type;
 
+       /// a type used for numbering text classes
+       typedef size_t     textclass_type;
+
 #else
 
        // These structs wrap simple things to make them distinguishible
@@ -57,6 +60,19 @@ namespace lyx {
                base_type data_;
        };
 
+       struct textclass_type {
+               ///
+               typedef size_t   base_type;
+               ///
+               textclass_type(base_type t) { data_ = t; }
+               ///
+               operator base_type() const { return data_; }
+               ///
+               private:
+               base_type data_;
+       };
+
+
 #endif
 
        ///