This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.

Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.

This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.

The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory.

The action is in BufferParams.{h,cpp}. Everything else is pretty much adapting to the new interface.

Comments welcome, as well as comment on whether it is OK to commit to trunk.

Richard

--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: src/buffer_funcs.h
===================================================================
--- src/buffer_funcs.h	(revision 19737)
+++ src/buffer_funcs.h	(working copy)
@@ -72,6 +72,9 @@
 void checkBufferStructure(Buffer &, ParIterator const &);
 
 ///
+textclass_type defaultTextclass();
+
+///
 void loadChildDocuments(Buffer const & buffer);
 
 } // namespace lyx
Index: src/buffer_funcs.cpp
===================================================================
--- src/buffer_funcs.cpp	(revision 19737)
+++ src/buffer_funcs.cpp	(working copy)
@@ -28,6 +28,7 @@
 #include "LaTeX.h"
 #include "LyX.h"
 #include "TextClass.h"
+#include "TextClassList.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphList.h"
@@ -632,7 +633,16 @@
 	}
 }
 
+textclass_type defaultTextclass()
+{
+	// Initialize textclass to point to article. if `first' is
+	// true in the returned pair, then `second' is the textclass
+	// number; if it is false, second is 0. In both cases, second
+	// is what we want.
+	return textclasslist.numberOfClass("article").second;
+}
 
+
 void loadChildDocuments(Buffer const & buf)
 {
 	bool parse_error = false;
@@ -652,5 +662,4 @@
 	if (use_gui && buf.getMasterBuffer() == &buf)
 		updateLabels(buf);
 }
-
 } // namespace lyx
Index: src/BufferParams.h
===================================================================
--- src/BufferParams.h	(revision 19737)
+++ src/BufferParams.h	(working copy)
@@ -17,18 +17,19 @@
 
 #include "BiblioInfo.h"
 #include "TextClass.h"
+#include "TextClass_sptr.h"
 #include "paper.h"
 
 #include "insets/InsetQuotes.h"
 
 #include "support/copied_ptr.h"
+#include "support/FileName.h"
 #include "support/types.h"
 
 #include "frontends/controllers/frontend_helpers.h"
 
 #include <vector>
 
-
 namespace lyx {
 
 class AuthorList;
@@ -42,9 +43,8 @@
 class VSpace;
 class Language;
 
-
 /** Buffer parameters.
- *  This class contains all the parameters for this a buffer uses. Some
+ *  This class contains all the parameters for this buffer's use. Some
  *  work needs to be done on this class to make it nice. Now everything
  *  is in public.
  */
@@ -88,7 +88,7 @@
 	///
 	void setDefSkip(VSpace const & vs);
 
-	/** Wether paragraphs are separated by using a indent like in
+	/** Whether paragraphs are separated by using a indent like in
 	 *  articles or by using a little skip like in letters.
 	 */
 	PARSEP paragraph_separation;
@@ -98,10 +98,30 @@
 	InsetQuotes::quote_times quotes_times;
 	///
 	std::string fontsize;
-	///
-	textclass_type textclass;
-	///
+	///Get the LyX TextClass---layout file---this document is using.
+	textclass_type getBaseClass() const;
+	///Set the LyX TextClass---layout file---this document is using.
+	///NOTE This also calls makeTextClass(), to update the local
+	///TextClass.
+	void setBaseClass(textclass_type);
+	///Returns the TextClass currently in use: the BaseClass as modified
+	///by modules.
 	TextClass const & getTextClass() const;
+	///Returns a pointer to the TextClass currently in use: the BaseClass 
+	///as modified by modules. (See \file TextClass_sptr.h for the typedef.)
+	TextClass_sptr getTextClass_sptr() const;
+	///Set the LyX TextClass---layout file---this document is using.
+	///This does NOT call makeTextClass() and so should be used with
+	///care. This is most likely not what you want if you are operating on 
+	///BufferParams that are actually associatd with a Buffer. If, on the
+	///other hand, you are using a temporary set of BufferParams---say, in
+	///a controller, it may well be, since in that case the local TextClass
+	///has nothing to do.
+	void setJustBaseClass(textclass_type);
+	/// 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(TextClass_sptr);
 
 	/// returns the main font for the buffer (document)
 	Font const getFont() const;
@@ -202,16 +222,6 @@
 	/// \param index should lie in the range 0 <= \c index <= 3.
 	Bullet & user_defined_bullet(size_type index);
 	Bullet const & user_defined_bullet(size_type index) const;
-	///
-	void readPreamble(Lexer &);
-	///
-	void readLanguage(Lexer &);
-	///
-	void readGraphicsDriver(Lexer &);
-	///
-	void readBullets(Lexer &);
-	///
-	void readBulletsLaTeX(Lexer &);
 
 	/// Whether to load a package such as amsmath or esint.
 	/// The enum values must not be changed (file format!)
@@ -271,6 +281,27 @@
 	void setCiteEngine(biblio::CiteEngine const);
 
 private:
+	///
+	void readPreamble(Lexer &);
+	///
+	void readLanguage(Lexer &);
+	///
+	void readGraphicsDriver(Lexer &);
+	///
+	void readBullets(Lexer &);
+	///
+	void readBulletsLaTeX(Lexer &);
+	/// create our local TextClass.
+	void makeTextClass();
+
+	
+	/// 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
+	TextClass_sptr textClass;
+
 	/** Use the Pimpl idiom to hide those member variables that would otherwise
 	 *  drag in other header files.
 	 */
@@ -282,8 +313,6 @@
 	};
 	support::copied_ptr<Impl, MemoryTraits> pimpl_;
 
-	///
-	biblio::CiteEngine cite_engine_;
 };
 
 } // namespace lyx
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(revision 19737)
+++ src/BufferParams.cpp	(working copy)
@@ -19,6 +19,7 @@
 
 #include "Author.h"
 #include "BranchList.h"
+#include "buffer_funcs.h"
 #include "Bullet.h"
 #include "debug.h"
 #include "Encoding.h"
@@ -268,15 +269,6 @@
 }
 
 
-textclass_type defaultTextclass()
-{
-	// Initialize textclass to point to article. if `first' is
-	// true in the returned pair, then `second' is the textclass
-	// number; if it is false, second is 0. In both cases, second
-	// is what we want.
-	return textclasslist.numberOfClass("article").second;
-}
-
 } // anon namespace
 
 
@@ -322,8 +314,9 @@
 
 
 BufferParams::BufferParams()
-	: textclass(defaultTextclass()), pimpl_(new Impl)
+	: pimpl_(new Impl)
 {
+	setBaseClass(defaultTextclass());
 	paragraph_separation = PARSEP_INDENT;
 	quotes_language = InsetQuotes::EnglishQ;
 	fontsize = "default";
@@ -458,20 +451,17 @@
 		pair<bool, lyx::textclass_type> pp =
 			textclasslist.numberOfClass(classname);
 		if (pp.first) {
-			textclass = pp.second;
+			setBaseClass(pp.second);
 		} else {
 			// if text class does not exist, try to load it from filepath
 			pp = textclasslist.addTextClass(classname, filepath);
 			if (pp.first) {
-				textclass = pp.second;
+				setBaseClass(pp.second);
 			} else {
-				textclass = defaultTextclass();
+				setBaseClass(defaultTextclass());
 				return classname;
 			}
 		}
-		// FIXME: isTeXClassAvailable will try to load the layout file, but will
-		// fail because of the lack of path info. Warnings will be given although
-		// the layout file will be correctly loaded later.
 		if (!getTextClass().isTeXClassAvailable()) {
 			docstring const msg =
 				bformat(_("The layout file requested by this document,\n"
@@ -648,7 +638,7 @@
 	// Prints out the buffer info into the .lyx file given by file
 
 	// the textclass
-	os << "\\textclass " << textclasslist[textclass].name() << '\n';
+	os << "\\textclass " << textclasslist[baseClass].name() << '\n';
 
 	// then the preamble
 	if (!preamble.empty()) {
@@ -1172,7 +1162,7 @@
 
 void BufferParams::useClassDefaults()
 {
-	TextClass const & tclass = textclasslist[textclass];
+	TextClass const & tclass = textclasslist[baseClass];
 
 	sides = tclass.sides();
 	columns = tclass.columns();
@@ -1188,7 +1178,7 @@
 
 bool BufferParams::hasClassDefaults() const
 {
-	TextClass const & tclass = textclasslist[textclass];
+	TextClass const & tclass = textclasslist[baseClass];
 
 	return (sides == tclass.sides()
 		&& columns == tclass.columns()
@@ -1201,10 +1191,45 @@
 
 TextClass const & BufferParams::getTextClass() const
 {
-	return textclasslist[textclass];
+	return *textClass;
 }
 
 
+TextClass_sptr BufferParams::getTextClass_sptr() const {
+	return textClass;
+}
+
+
+void BufferParams::setTextClass(TextClass_sptr tc) {
+	textClass = tc;
+}
+
+
+void BufferParams::setBaseClass(textclass_type tc)
+{
+	baseClass = tc;
+	makeTextClass();
+}
+
+
+void BufferParams::setJustBaseClass(textclass_type tc)
+{ 
+	baseClass = tc; 
+}
+
+
+textclass_type BufferParams::getBaseClass() const
+{
+	return baseClass;
+}
+
+
+void BufferParams::makeTextClass()
+{
+	textClass.reset(new TextClass(textclasslist[getBaseClass()]));
+}
+
+
 Font const BufferParams::getFont() const
 {
 	Font f = getTextClass().defaultfont();
Index: src/Text.cpp
===================================================================
--- src/Text.cpp	(revision 19737)
+++ src/Text.cpp	(working copy)
@@ -1342,7 +1342,7 @@
 					b.getLanguage());
 		}
 
-		pasteParagraphList(cur, plist, b.params().textclass,
+		pasteParagraphList(cur, plist, b.params().getTextClass_sptr(),
 				   b.errorList("Paste"));
 		// restore position
 		cur.pit() = std::min(cur.lastpit(), spit);
Index: src/CutAndPaste.h
===================================================================
--- src/CutAndPaste.h	(revision 19737)
+++ src/CutAndPaste.h	(working copy)
@@ -15,6 +15,7 @@
 #define CUTANDPASTE_H
 
 #include "support/docstring.h"
+#include "TextClass_sptr.h"
 
 #include <vector>
 
@@ -89,14 +90,14 @@
 /// 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,
-			textclass_type textclass, ErrorList & errorList);
+			TextClass_sptr 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(textclass_type c1, textclass_type c2,
+void switchBetweenClasses(TextClass_sptr c1, TextClass_sptr c2,
 			  InsetText & in, ErrorList &);
 
 /// Get the current selection as a string. Does not change the selection.
Index: src/frontends/Toolbars.h
===================================================================
--- src/frontends/Toolbars.h	(revision 19737)
+++ src/frontends/Toolbars.h	(working copy)
@@ -23,6 +23,7 @@
 #ifndef TOOLBARS_H
 #define TOOLBARS_H
 
+#include "TextClass_sptr.h"
 #include "ToolbarBackend.h"
 #include "Session.h"
 
@@ -115,7 +116,7 @@
 	/** Populate the layout combox - returns whether we did a full
 	 *  update or not
 	 */
-	bool updateLayoutList(int textclass);
+	bool updateLayoutList(TextClass_sptr textclass);
 
 	/// Drop down the layout list.
 	void openLayoutList();
@@ -150,7 +151,7 @@
 	ToolbarsMap toolbars_;
 
 	/// The last textclass layout list in the layout choice selector
-	int last_textclass_;
+	TextClass_sptr last_textclass_;
 
 	// load flags with saved values
 	void initFlags(ToolbarInfo & tbinfo);
Index: src/frontends/Toolbars.cpp
===================================================================
--- src/frontends/Toolbars.cpp	(revision 19737)
+++ src/frontends/Toolbars.cpp	(working copy)
@@ -35,7 +35,7 @@
 Toolbars::Toolbars(LyXView & owner)
 	: owner_(owner),
 	  layout_(0),
-	  last_textclass_(-1)
+	  last_textclass_(TextClass_sptr())
 {}
 
 #define TurnOnFlag(x)   flags |= ToolbarInfo::x
@@ -286,7 +286,7 @@
 }
 
 
-bool Toolbars::updateLayoutList(int textclass)
+bool Toolbars::updateLayoutList(TextClass_sptr textclass)
 {
 	// update the layout display
 	if (last_textclass_ != textclass) {
@@ -308,7 +308,7 @@
 
 void Toolbars::clearLayoutList()
 {
-	last_textclass_ = -1;
+	last_textclass_ = TextClass_sptr();
 	if (layout_)
 		layout_->clear();
 }
Index: src/frontends/qt4/QDocument.cpp
===================================================================
--- src/frontends/qt4/QDocument.cpp	(revision 19737)
+++ src/frontends/qt4/QDocument.cpp	(working copy)
@@ -834,12 +834,12 @@
 	textclass_type const tc = latexModule->classCO->currentIndex();
 
 	if (form_->controller().loadTextclass(tc)) {
-		params.textclass = tc;
+		params.setJustBaseClass(tc);
 		if (lyxrc.auto_reset_options)
 			params.useClassDefaults();
 		form_->update_contents();
 	} else {
-		latexModule->classCO->setCurrentIndex(params.textclass);
+		latexModule->classCO->setCurrentIndex(params.getBaseClass());
 	}
 }
 
@@ -969,8 +969,7 @@
 	}
 
 	// text layout
-	params.textclass =
-		latexModule->classCO->currentIndex();
+	params.setJustBaseClass(latexModule->classCO->currentIndex());
 
 	if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
 		params.pagestyle = "default";
@@ -1255,7 +1254,7 @@
 	}
 
 	// text layout
-	latexModule->classCO->setCurrentIndex(params.textclass);
+	latexModule->classCO->setCurrentIndex(params.getBaseClass());
 
 	updatePagestyle(form_->controller().textClass().opt_pagestyle(),
 				 params.pagestyle);
@@ -1454,8 +1453,7 @@
 {
 	BufferParams & params = controller().params();
 
-	///\todo verify the use of below with lyx-devel:
-	params.textclass = dialog_->latexModule->classCO->currentIndex();
+	params.setJustBaseClass(dialog_->latexModule->classCO->currentIndex());
 
 	params.useClassDefaults();
 	update_contents();
Index: src/frontends/LyXView.cpp
===================================================================
--- src/frontends/LyXView.cpp	(revision 19737)
+++ src/frontends/LyXView.cpp	(working copy)
@@ -366,7 +366,7 @@
 	}
 
 	// Update the layout display
-	if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
+	if (toolbars_->updateLayoutList(buffer()->params().getTextClass_sptr())) {
 		current_layout = buffer()->params().getTextClass().defaultLayoutName();
 	}
 
Index: src/frontends/controllers/ControlDocument.cpp
===================================================================
--- src/frontends/controllers/ControlDocument.cpp	(revision 19737)
+++ src/frontends/controllers/ControlDocument.cpp	(working copy)
@@ -87,7 +87,7 @@
 
 TextClass const & ControlDocument::textClass() const
 {
-	return textclasslist[bp_->textclass];
+	return textclasslist[bp_->getBaseClass()];
 }
 
 
@@ -113,8 +113,8 @@
 
 	// Set the document class.
 	textclass_type const old_class =
-		kernel().buffer().params().textclass;
-	textclass_type const new_class = bp_->textclass;
+		kernel().buffer().params().getBaseClass();
+	textclass_type const new_class = bp_->getBaseClass();
 	if (new_class != old_class) {
 		string const name = textclasslist[new_class].name();
 		kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 19737)
+++ src/Makefile.am	(working copy)
@@ -250,6 +250,7 @@
 	Text3.cpp \
 	TextClass.cpp \
 	TextClass.h \
+	TextClass_sptr.h \
 	TextClassList.cpp \
 	TextClassList.h \
 	TextMetrics.cpp \
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp	(revision 19737)
+++ src/LyXFunc.cpp	(working copy)
@@ -818,10 +818,10 @@
 	textclass_type const tc = tc_pair.second;
 
 	if (!textclasslist[tc].load()) {
-		docstring s = bformat(_("The document could not be converted\n"
-						  "into the document class %1$s."),
+		docstring s = bformat(_("The document class %1$s."
+				   "could not be loaded."),
 				   from_utf8(textclasslist[tc].name()));
-		Alert::error(_("Could not change class"), s);
+		Alert::error(_("Could not load class"), s);
 	}
 }
 
@@ -1780,9 +1780,6 @@
 			BOOST_ASSERT(lyx_view_);
 			Buffer * buffer = lyx_view_->buffer();
 
-			textclass_type const old_class =
-				buffer->params().textclass;
-
 			loadTextclass(argument);
 
 			std::pair<bool, textclass_type> const tc_pair =
@@ -1791,18 +1788,23 @@
 			if (!tc_pair.first)
 				break;
 
+			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;
 
 			lyx_view_->message(_("Converting document to new document class..."));
 			recordUndoFullDocument(view());
-			buffer->params().textclass = new_class;
+			//Save the old, possibly modular, layout for use in conversion.
+			TextClass_sptr oldClass = buffer->params().getTextClass_sptr();
+			buffer->params().setBaseClass(new_class);
+			
 			StableDocIterator backcur(view()->cursor());
 			ErrorList & el = buffer->errorList("Class Switch");
 			cap::switchBetweenClasses(
-				old_class, new_class,
+				oldClass, buffer->params().getTextClass_sptr(),
 				static_cast<InsetText &>(buffer->inset()), el);
 
 			view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(revision 19737)
+++ src/CutAndPaste.cpp	(working copy)
@@ -30,6 +30,7 @@
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Text.h"
+#include "TextClass_sptr.h"
 #include "TextClassList.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
@@ -71,7 +72,7 @@
 
 typedef std::pair<pit_type, int> PitPosPair;
 
-typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
+typedef limited_stack<pair<ParagraphList, TextClass_sptr> > CutStack;
 
 CutStack theCuts(10);
 // persistent selection, cleared until the next selection
@@ -107,7 +108,7 @@
 
 pair<PitPosPair, pit_type>
 pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
-		     textclass_type textclass, ErrorList & errorlist)
+		     TextClass_sptr textclass, ErrorList & errorlist)
 {
 	Buffer const & buffer = cur.buffer();
 	pit_type pit = cur.pit();
@@ -121,7 +122,7 @@
 
 	// Make a copy of the CaP paragraphs.
 	ParagraphList insertion = parlist;
-	textclass_type const tc = buffer.params().textclass;
+	TextClass_sptr const tc = buffer.params().getTextClass_sptr();
 
 	// Now remove all out of the pars which is NOT allowed in the
 	// new environment and set also another font if that is required.
@@ -335,7 +336,7 @@
 }
 
 
-void putClipboard(ParagraphList const & paragraphs, textclass_type textclass,
+void putClipboard(ParagraphList const & paragraphs, TextClass_sptr textclass,
 		  docstring const & plaintext)
 {
 	// For some strange reason gcc 3.2 and 3.3 do not accept
@@ -343,7 +344,7 @@
 	Buffer buffer("", false);
 	buffer.setUnnamed(true);
 	buffer.paragraphs() = paragraphs;
-	buffer.params().textclass = textclass;
+	buffer.params().setTextClass(textclass);
 	std::ostringstream lyx;
 	if (buffer.write(lyx))
 		theClipboard().put(lyx.str(), plaintext);
@@ -354,7 +355,7 @@
 
 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
 	pit_type startpit, pit_type endpit,
-	int start, int end, textclass_type tc, CutStack & cutstack)
+	int start, int end, TextClass_sptr tc, CutStack & cutstack)
 {
 	BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
 	BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
@@ -411,7 +412,7 @@
 }
 
 
-void switchBetweenClasses(textclass_type c1, textclass_type c2,
+void switchBetweenClasses(TextClass_sptr c1, TextClass_sptr c2,
 	InsetText & in, ErrorList & errorlist)
 {
 	errorlist.clear();
@@ -419,10 +420,10 @@
 	BOOST_ASSERT(!in.paragraphs().empty());
 	if (c1 == c2)
 		return;
+	
+	TextClass const & tclass1 = *c1;
+	TextClass const & tclass2 = *c2;
 
-	TextClass const & tclass1 = textclasslist[c1];
-	TextClass const & tclass2 = textclasslist[c2];
-
 	// layouts
 	ParIterator end = par_iterator_end(in);
 	for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
@@ -542,7 +543,7 @@
 				text->paragraphs(),
 				begpit, endpit,
 				cur.selBegin().pos(), endpos,
-				bp.textclass, theCuts);
+				bp.getTextClass_sptr(), theCuts);
 			// Stuff what we got on the clipboard.
 			// Even if there is no selection.
 			putClipboard(theCuts[0].first, theCuts[0].second,
@@ -626,7 +627,8 @@
 			++pos;
 
 		copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
-			pos, cur.selEnd().pos(), cur.buffer().params().textclass, cutstack);
+			pos, cur.selEnd().pos(), 
+			cur.buffer().params().getTextClass_sptr(), cutstack);
 		dirtyTabularStack(false);
 	}
 
@@ -638,7 +640,7 @@
 		par.layout(bp.getTextClass().defaultLayout());
 		par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
 		pars.push_back(par);
-		cutstack.push(make_pair(pars, bp.textclass));
+		cutstack.push(make_pair(pars, bp.getTextClass_sptr()));
 	}
 }
 
@@ -665,7 +667,7 @@
 		par.layout(bp.getTextClass().defaultLayout());
 		par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
 		pars.push_back(par);
-		theCuts.push(make_pair(pars, bp.textclass));
+		theCuts.push(make_pair(pars, bp.getTextClass_sptr()));
 	} else
 		copySelectionToStack(cur, theCuts);
 
@@ -711,7 +713,7 @@
 
 
 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
-			textclass_type textclass, ErrorList & errorList)
+			TextClass_sptr textclass, ErrorList & errorList)
 {
 	if (cur.inTexted()) {
 		Text * text = cur.text();
@@ -765,7 +767,7 @@
 			if (buffer.readString(lyx)) {
 				recordUndo(cur);
 				pasteParagraphList(cur, buffer.paragraphs(),
-					buffer.params().textclass, errorList);
+					buffer.params().getTextClass_sptr(), errorList);
 				cur.setSelection();
 				return;
 			}
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 19737)
+++ src/Buffer.cpp	(working copy)
@@ -49,6 +49,7 @@
 #include "ParIterator.h"
 #include "sgml.h"
 #include "TexRow.h"
+#include "TextClassList.h"
 #include "TexStream.h"
 #include "TocBackend.h"
 #include "Undo.h"
@@ -439,6 +440,7 @@
 	params().headsep.erase();
 	params().footskip.erase();
 	params().listings_params.clear();
+	
 	for (int i = 0; i < 4; ++i) {
 		params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
 		params().temp_bullet(i) = ITEMIZE_DEFAULTS[i];
@@ -515,7 +517,7 @@
 		Alert::error(_("Can't load document class"), bformat(
 			_("Using the default document class, because the "
 				     "class %1$s could not be loaded."), from_utf8(theclass)));
-		params().textclass = 0;
+		params().setBaseClass(defaultTextclass());
 	}
 
 	if (params().outputChanges) {
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(revision 19737)
+++ src/insets/InsetInclude.cpp	(working copy)
@@ -482,7 +482,7 @@
 
 		Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
 
-		if (tmp->params().textclass != m_buffer->params().textclass) {
+		if (tmp->params().getBaseClass() != m_buffer->params().getBaseClass()) {
 			// FIXME UNICODE
 			docstring text = bformat(_("Included file `%1$s'\n"
 						"has textclass `%2$s'\n"
Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp	(revision 19737)
+++ src/BufferView.cpp	(working copy)
@@ -1516,7 +1516,7 @@
 		el = buf.errorList("Parse");
 		recordUndo(cursor_);
 		cap::pasteParagraphList(cursor_, buf.paragraphs(),
-					     buf.params().textclass, el);
+					     buf.params().getTextClass_sptr(), el);
 		res = _("Document %1$s inserted.");
 	} else
 		res = _("Could not insert document %1$s");

Reply via email to