From 2e7d1199dfa7ec7b7d963c374a014f2a2227ae7c Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sun, 24 Feb 2008 14:59:23 +0000 Subject: [PATCH] Revert 23154. 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 --- src/Buffer.cpp | 12 ++--- src/BufferParams.cpp | 83 ++++++++++++++----------------- src/BufferParams.h | 22 ++++---- src/BufferView.cpp | 2 +- src/CutAndPaste.cpp | 50 ++++++++++--------- src/CutAndPaste.h | 12 ++--- src/LaTeXFeatures.cpp | 12 ++--- src/LyXFunc.cpp | 26 +++++----- src/LyXFunc.h | 5 +- src/MenuBackend.cpp | 10 ++-- src/Paragraph.cpp | 9 ++-- src/ParagraphMetrics.cpp | 8 +-- src/Text.cpp | 16 +++--- src/Text2.cpp | 4 +- src/Text3.cpp | 16 +++--- src/TextClass.h | 15 ------ src/TextClassList.cpp | 29 ++++------- src/TextClassList.h | 13 +++-- src/TextClassPtr.h | 28 +++++++++++ src/TextMetrics.cpp | 2 +- src/TocBackend.cpp | 9 ++-- src/buffer_funcs.cpp | 4 +- src/factory.cpp | 8 +-- src/frontends/qt4/Dialog.cpp | 2 - src/frontends/qt4/GuiDocument.cpp | 14 +++--- src/frontends/qt4/GuiToc.cpp | 2 +- src/frontends/qt4/GuiToolbar.cpp | 2 +- src/frontends/qt4/GuiToolbars.cpp | 3 +- src/frontends/qt4/GuiToolbars.h | 8 ++- src/insets/Inset.cpp | 2 +- src/insets/InsetBibitem.cpp | 2 +- src/insets/InsetBibtex.cpp | 2 +- src/insets/InsetBox.cpp | 2 +- src/insets/InsetBranch.cpp | 2 +- src/insets/InsetCaption.cpp | 6 +-- src/insets/InsetCollapsable.cpp | 35 +++++++------ src/insets/InsetCollapsable.h | 7 +-- src/insets/InsetERT.cpp | 2 +- src/insets/InsetEnvironment.cpp | 2 +- src/insets/InsetFlex.cpp | 2 +- src/insets/InsetFlex.h | 2 +- src/insets/InsetFloat.cpp | 4 +- src/insets/InsetFloatList.cpp | 6 +-- src/insets/InsetFoot.cpp | 2 +- src/insets/InsetInclude.cpp | 8 +-- src/insets/InsetInfo.cpp | 21 +++++--- src/insets/InsetListings.cpp | 2 +- src/insets/InsetNote.cpp | 2 +- src/insets/InsetTabular.cpp | 6 +-- src/insets/InsetText.cpp | 2 +- src/insets/InsetWrap.cpp | 2 +- src/output_docbook.cpp | 5 +- src/output_latex.cpp | 10 ++-- src/paragraph_funcs.cpp | 6 +-- src/sgml.cpp | 8 +-- src/support/types.h | 16 ++++++ 56 files changed, 310 insertions(+), 282 deletions(-) create mode 100644 src/TextClassPtr.h diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3a074cba94..e6f7cbb5c1 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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 Buffer::exportableFormats(bool only_viewable) const vector Buffer::backends() const { vector 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") diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 0ab1d83088..d22d94fd52 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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 pp = - make_pair(false, TextClassIndex(0)); + pair 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 const & BufferParams::getModules() const -{ +vector 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_; diff --git a/src/BufferParams.h b/src/BufferParams.h index a1d82104bf..5fc57aecc8 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -15,9 +15,10 @@ #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 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 LayoutModuleList; /// diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 30b5fb6a94..dd0fe6f385 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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"); diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index eed8123521..fecfb6979b 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -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 PitPosPair; -typedef limited_stack > CutStack; +typedef limited_stack > CutStack; CutStack theCuts(10); // persistent selection, cleared until the next selection @@ -106,7 +106,7 @@ bool checkPastePossible(int index) pair 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)); diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index c429965412..e3ba435b03 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -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 diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 903b87c722..7df08f2187 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -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. diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 45658cf68b..95ff83dc53 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -714,7 +714,7 @@ void showPrintError(string const & name) void loadTextClass(string const & name, string const & buf_path) { - pair const tc_pair = + pair 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 const tc_pair = + pair 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(buffer->inset()), el); view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); diff --git a/src/LyXFunc.h b/src/LyXFunc.h index 692fc73233..ab8e9debf2 100644 --- a/src/LyXFunc.h +++ b/src/LyXFunc.h @@ -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 diff --git a/src/MenuBackend.cpp b/src/MenuBackend.cpp index fce89d6c25..e007ce6081 100644 --- a/src/MenuBackend.cpp +++ b/src/MenuBackend.cpp @@ -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(); diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 293a62e8c8..c34c8e8ac5 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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: diff --git a/src/ParagraphMetrics.cpp b/src/ParagraphMetrics.cpp index fb6c77714d..09631228b9 100644 --- a/src/ParagraphMetrics.cpp +++ b/src/ParagraphMetrics.cpp @@ -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() diff --git a/src/Text.cpp b/src/Text.cpp index 456584b8c7..c29876d9a1 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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); diff --git a/src/Text2.cpp b/src/Text2.cpp index b7dc9a13d6..7ea03cd6bb 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -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)); diff --git a/src/Text3.cpp b/src/Text3.cpp index 4be361630a..5f2abc8847 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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" && diff --git a/src/TextClass.h b/src/TextClass.h index b6030c4e85..07b4f16893 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -38,21 +38,6 @@ class FloatList; /// List of inset layouts typedef std::map 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: diff --git a/src/TextClassList.cpp b/src/TextClassList.cpp index 8a2f869239..eb721bfc9c 100644 --- a/src/TextClassList.cpp +++ b/src/TextClassList.cpp @@ -34,7 +34,7 @@ using boost::regex; using boost::smatch; // Gets textclass number from name -pair const +pair 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 const +pair 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 pp = + pair 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 diff --git a/src/TextClassList.h b/src/TextClassList.h index d05e6de73c..8c1b3744d6 100644 --- a/src/TextClassList.h +++ b/src/TextClassList.h @@ -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 const - numberOfClass(std::string const & textClassName) const; + std::pair 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 const + std::pair 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 index 0000000000..cb610b1bb0 --- /dev/null +++ b/src/TextClassPtr.h @@ -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 + +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 TextClassPtr; + +} // namespace lyx + +#endif diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 126e4a8422..a9ce0f04dc 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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; diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 00a55a9870..7c0084420e 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -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(*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(); diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 6e8e612f94..c07f136c0e 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -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 diff --git a/src/factory.cpp b/src/factory.cpp index 39a6b15c8f..18bc3c18d8 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -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 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())); diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 2be31a4ffc..de358a63c0 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include using namespace std; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 7ad3bd4f83..068636c2f1 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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 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 const GuiDocument::getSelectedModules() TextClass const & GuiDocument::textClass() const { - return textclasslist[bp_.baseClass()]; + return textclasslist[bp_.getBaseClass()]; } diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index b10b864d1f..79c5f89f68 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -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()); diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index ab61ce352a..a354021af5 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -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(); diff --git a/src/frontends/qt4/GuiToolbars.cpp b/src/frontends/qt4/GuiToolbars.cpp index 43b9808691..dd89ae6943 100644 --- a/src/frontends/qt4/GuiToolbars.cpp +++ b/src/frontends/qt4/GuiToolbars.cpp @@ -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) || diff --git a/src/frontends/qt4/GuiToolbars.h b/src/frontends/qt4/GuiToolbars.h index b76339383c..d7015c8eb9 100644 --- a/src/frontends/qt4/GuiToolbars.h +++ b/src/frontends/qt4/GuiToolbars.h @@ -14,6 +14,8 @@ #ifndef GUI_TOOLBARS_H #define GUI_TOOLBARS_H +#include "TextClassPtr.h" + #include "support/docstring.h" #include @@ -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 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 diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index ed94df8ae3..d77f4b10ec 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -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()); } diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index 508b2f4d01..1455e5ac8b 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -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); diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index a23c8cac40..9a543716b4 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -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 diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 71620c3213..2400722fd3 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -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()); } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index cdd281ba8c..67b4adcd39 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -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; diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index ae9e9eb5ec..2a4f97b7a9 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -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(). diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index e35f18906b..4dc2f96d14 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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()); diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index bb1e53cdb5..920a473917 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -19,6 +19,7 @@ #include "Box.h" #include "TextClass.h" +#include "TextClassPtr.h" #include @@ -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_; /// diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index 90fc351f3e..9d5c67dfb8 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -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) { diff --git a/src/insets/InsetEnvironment.cpp b/src/insets/InsetEnvironment.cpp index 32d7850ade..73048ab52e 100644 --- a/src/insets/InsetEnvironment.cpp +++ b/src/insets/InsetEnvironment.cpp @@ -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); diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 5ce4d07619..279f994054 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -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) { diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index 2f90ebf9e1..3bb10abe49 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -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_); } diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 07280d7ff7..e966bb5d6c 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -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; diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp index f3299d899f..fd9a265cfa 100644 --- a/src/insets/InsetFloatList.cpp +++ b/src/insets/InsetFloatList.cpp @@ -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()) { diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index 77733ef21c..58acf7d562 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -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(); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 686d445f53..ccff865b7a 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -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)) { diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index ca68f32f0c..2218ef660d 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -73,10 +73,11 @@ void InsetInfo::draw(PainterInfo & pi, int x, int y) const } -static Translator initTranslator() +namespace { + +Translator const initTranslator() { - Translator - translator(InsetInfo::UNKNOWN_INFO, "unknown"); + Translator translator(InsetInfo::UNKNOWN_INFO, "unknown"); translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut"); translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc"); @@ -88,12 +89,16 @@ static Translator initTranslator() return translator; } +} // namespace anon + Translator const & InsetInfo::nameTranslator() const { - static Translator const translator = initTranslator(); + static Translator 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 pp = textclasslist.numberOfClass(name_); + pair 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; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 48b51c1fcf..21da448d76 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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 diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 08189ca129..ab90288c6b 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -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; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 683dfc6cf0..e783fc8424 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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"); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 4bb85a9064..bc473988fd 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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); } diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 783668e35b..fccc29695b 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -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 diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index b6c60ad655..dda121059d 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -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; diff --git a/src/output_latex.cpp b/src/output_latex.cpp index cdf8a5bb21..4865845b45 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -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(); diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index 2b2f5ab183..991341ab5f 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -77,9 +77,9 @@ void breakParagraph(BufferParams const & bparams, // without doing that we get a crash when typing 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 diff --git a/src/sgml.cpp b/src/sgml.cpp index 2b0b02fd96..6ac6c8653b 100644 --- a/src/sgml.cpp +++ b/src/sgml.cpp @@ -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); diff --git a/src/support/types.h b/src/support/types.h index 94acd680ec..206d2818b1 100644 --- a/src/support/types.h +++ b/src/support/types.h @@ -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 ///