#include <config.h>
#include "BaseClassList.h"
-#include "TextClass.h"
+#include "Counters.h"
+#include "Floating.h"
+#include "FloatList.h"
#include "Lexer.h"
+#include "TextClass.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/gettext.h"
#include <boost/bind.hpp>
#include <boost/regex.hpp>
using boost::regex;
using boost::smatch;
+LayoutFile::LayoutFile(string const & fn, string const & cln,
+ string const & desc, bool texClassAvail )
+{
+ name_ = fn;
+ latexname_ = cln;
+ description_ = desc;
+ texClassAvail_ = texClassAvail;
+}
+
+
BaseClassList & BaseClassList::get()
{
static BaseClassList baseclasslist;
}
+LayoutFile const & BaseClassList::operator[](string const & classname) const
+{
+ BOOST_ASSERT(haveClass(classname));
+ return classmap_[classname];
+}
+
+
// Gets a textclass structure from string
-TextClass const &
- BaseClassList::operator[](string const & classname) const
+LayoutFile &
+ BaseClassList::operator[](string const & classname)
{
BOOST_ASSERT(haveClass(classname));
return classmap_[classname];
LYXERR(Debug::TCLASS, "Avail: " << avail);
// This code is run when we have
// fname, clname, desc, and avail
- TextClass tmpl(fname, clname, desc, avail);
+ LayoutFile tmpl(fname, clname, desc, avail);
if (lyxerr.debugging(Debug::TCLASS)) {
// only system layout files are loaded here so no
// buffer path is needed.
}
-std::vector<BaseClassIndex> BaseClassList::classList() const
+std::vector<LayoutFileIndex> BaseClassList::classList() const
{
- std::vector<BaseClassIndex> cl;
+ std::vector<LayoutFileIndex> cl;
ClassMap::const_iterator it = classmap_.begin();
ClassMap::const_iterator en = classmap_.end();
for (; it != en; ++it)
}
-void BaseClassList::reset(BaseClassIndex const & classname) {
+void BaseClassList::reset(LayoutFileIndex const & classname) {
BOOST_ASSERT(haveClass(classname));
- TextClass const & tc = classmap_[classname];
- TextClass tmpl(tc.name(), tc.latexname(), tc.description(),
+ LayoutFile const & tc = classmap_[classname];
+ LayoutFile tmpl(tc.name(), tc.latexname(), tc.description(),
tc.isTeXClassAvailable());
classmap_[classname] = tmpl;
}
string const BaseClassList::localPrefix = "LOCAL:";
-BaseClassIndex
- BaseClassList::addTextClass(string const & textclass, string const & path)
+LayoutFileIndex
+ BaseClassList::addLayoutFile(string const & textclass, string const & path)
{
// FIXME BUGS
// There be bugs here. The way this presently works, the local class gets
// returns: whole string, classtype (not used here), class name, description
BOOST_ASSERT(sub.size() == 4);
// now, create a TextClass with description containing path information
- TextClass tmpl(textclass, sub.str(2) == "" ? textclass : sub.str(2),
+ LayoutFile tmpl(textclass, sub.str(2) == "" ? textclass : sub.str(2),
sub.str(3) + " <" + path + ">", true);
// Do not add this local TextClass to classmap_ if it has
// already been loaded by, for example, a master buffer.
}
-BaseClassIndex defaultBaseclass()
+LayoutFileIndex defaultBaseclass()
{
if (BaseClassList::get().haveClass("article"))
return string("article");
/// Index into BaseClassList. Basically a 'strong typedef'.
-class BaseClassIndex {
+class LayoutFileIndex {
public:
///
typedef std::string base_type;
///
- BaseClassIndex(base_type t) { data_ = t; }
+ LayoutFileIndex(base_type t) { data_ = t; }
///
operator base_type() const { return data_; }
///
base_type data_;
};
+/// This class amounts to little more than a `strong typedef'.
+/// A LayoutFile represents the layout information that is
+/// contained in a *.layout file.
+class LayoutFile : public TextClass {
+public:
+ /// This should never be used, but it has to be provided for
+ /// std::map operator[] to work. Something like:
+ /// mapthingy[stuff] = otherthing
+ /// creates an empty object before doing the assignment.
+ LayoutFile() {}
+ /// check whether the TeX class is available
+ bool isTeXClassAvailable() const { return texClassAvail_; }
+private:
+ /// Construct a layout with default values. Actual values loaded later.
+ explicit LayoutFile(std::string const &,
+ std::string const & = std::string(),
+ std::string const & = std::string(),
+ bool texClassAvail = false);
+ /// The only class that should create a LayoutFile is
+ /// BaseClassList, which calls the private constructor.
+ friend class BaseClassList;
+};
+
/// A list of base document classes (*.layout files).
/// This is a singleton class. The sole instance is accessed
///
bool haveClass(std::string const & classname) const;
///
- TextClass const & operator[](std::string const & classname) const;
+ LayoutFile const & operator[](std::string const & classname) const;
+ ///
+ LayoutFile & operator[](std::string const & classname);
/// Read textclass list. Returns false if this fails.
bool read();
/// Clears the textclass so as to force it to be reloaded
- void reset(BaseClassIndex const & tc);
+ void reset(LayoutFileIndex const & tc);
/// add a textclass from user local directory.
/// \return the identifier for the loaded file, or else an
/// empty string if no file was loaded.
- BaseClassIndex
- addTextClass(std::string const & textclass, std::string const & path);
+ LayoutFileIndex
+ addLayoutFile(std::string const & textclass, std::string const & path);
/// a list of the available classes
- std::vector<BaseClassIndex> classList() const;
+ std::vector<LayoutFileIndex> classList() const;
///
static std::string const localPrefix;
private:
///
- typedef std::map<std::string, TextClass> ClassMap;
+ typedef std::map<std::string, LayoutFile> ClassMap;
/// noncopyable
BaseClassList(BaseClassList const &);
/// nonassignable
};
///
-BaseClassIndex defaultBaseclass();
+LayoutFileIndex defaultBaseclass();
} // namespace lyx
#include "Buffer.h"
#include "Author.h"
+#include "BaseClassList.h"
#include "BiblioInfo.h"
#include "BranchList.h"
#include "buffer_funcs.h"
vector<string> Buffer::backends() const
{
vector<string> v;
- if (params().documentClass().isTeXClassAvailable()) {
+ if (params().baseClass()->isTeXClassAvailable()) {
v.push_back(bufferFormat());
// FIXME: Don't hardcode format names here, but use a flag
if (v.back() == "latex")
*/
VSpace defskip;
PDFOptions pdfoptions;
- BaseClassIndex baseClass_;
+ LayoutFileIndex baseClass_;
};
string tcp;
BaseClassList & bcl = BaseClassList::get();
if (!filepath.empty())
- tcp = bcl.addTextClass(classname, filepath.absFilename());
+ tcp = bcl.addLayoutFile(classname, filepath.absFilename());
if (!tcp.empty())
setBaseClass(tcp);
else if (bcl.haveClass(classname)) {
// 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 (!documentClass().isTeXClassAvailable()) {
+ if (!baseClass()->isTeXClassAvailable()) {
docstring const msg =
bformat(_("The layout file requested by this document,\n"
"%1$s.layout,\n"
}
-TextClass const * BufferParams::baseClass() const
+LayoutFile const * BufferParams::baseClass() const
{
if (BaseClassList::get().haveClass(pimpl_->baseClass_))
return &(BaseClassList::get()[pimpl_->baseClass_]);
}
-BaseClassIndex const & BufferParams::baseClassID() const
+LayoutFileIndex const & BufferParams::baseClassID() const
{
return pimpl_->baseClass_;
}
}
class AuthorList;
-class BaseClassIndex;
+class LayoutFileIndex;
class BranchList;
class Bullet;
class DocumentClass;
class Language;
class Lexer;
class LatexFeatures;
+class LayoutFile;
class PDFOptions;
class Spacing;
-class TextClass;
class TexRow;
class VSpace;
InsetQuotes::quote_times quotes_times;
///
std::string fontsize;
- ///Get the LyX TextClass (that is, the layout file) this document is using.
- TextClass const * baseClass() const;
+ ///Get the LayoutFile this document is using.
+ LayoutFile const * baseClass() const;
///
- BaseClassIndex const & baseClassID() const;
- /// Set the LyX TextClass (that is, the layout file) this document is using.
+ LayoutFileIndex const & baseClassID() const;
+ /// Set the LyX layout file this document is using.
/// NOTE: This does not call makeDocumentClass() to update the local
/// DocumentClass. That needs to be done manually.
/// \param filename the name of the layout file
}
-bool loadTextClass(string const & name, string const & buf_path)
+bool loadLayoutFile(string const & name, string const & buf_path)
{
if (!BaseClassList::get().haveClass(name)) {
lyxerr << "Document class \"" << name
return false;
}
- TextClass const & tc = BaseClassList::get()[name];
+ LayoutFile & tc = BaseClassList::get()[name];
if (!tc.load(buf_path)) {
docstring s = bformat(_("The document class %1$s."
"could not be loaded."), from_utf8(name));
BOOST_ASSERT(lyx_view_);
Buffer * buffer = lyx_view_->buffer();
- if (!loadTextClass(argument, buffer->filePath()))
+ if (!loadLayoutFile(argument, buffer->filePath()))
break;
- TextClass const * old_class = buffer->params().baseClass();
- TextClass const * new_class = &(BaseClassList::get()[argument]);
+ LayoutFile const * old_layout = buffer->params().baseClass();
+ LayoutFile const * new_layout = &(BaseClassList::get()[argument]);
- if (old_class == new_class)
+ if (old_layout == new_layout)
// nothing to do
break;
BOOST_ASSERT(lyx_view_);
Buffer * buffer = lyx_view_->buffer();
DocumentClass * oldClass = buffer->params().documentClassPtr();
- BaseClassIndex bc = buffer->params().baseClassID();
+ LayoutFileIndex bc = buffer->params().baseClassID();
BaseClassList::get().reset(bc);
buffer->params().makeDocumentClass();
updateLayout(oldClass, buffer);
}
case LFUN_TEXTCLASS_LOAD:
- loadTextClass(argument, lyx_view_->buffer()->filePath());
+ loadLayoutFile(argument, lyx_view_->buffer()->filePath());
break;
case LFUN_LYXRC_APPLY: {
#include "TextClass.h"
+#include "BaseClassList.h"
#include "Color.h"
#include "Counters.h"
#include "Floating.h"
} // namespace anon
-TextClass::TextClass(string const & fn, string const & cln,
- string const & desc, bool texClassAvail )
- : name_(fn), latexname_(cln), description_(desc),
- floatlist_(new FloatList), counters_(new Counters),
- texClassAvail_(texClassAvail)
+docstring const TextClass::emptylayout_ = from_ascii("PlainLayout");
+
+
+InsetLayout DocumentClass::empty_insetlayout_;
+
+
+TextClass::TextClass()
{
- modular_ = false;
+ floatlist_ = boost::shared_ptr<FloatList>(new FloatList);
+ counters_ = boost::shared_ptr<Counters>(new Counters);
outputType_ = LATEX;
columns_ = 1;
sides_ = OneSide;
}
-docstring const TextClass::emptylayout_ = from_ascii("PlainLayout");
-
-
-InsetLayout TextClass::empty_insetlayout_;
-
-
-bool TextClass::isTeXClassAvailable() const
-{
- return texClassAvail_;
-}
-
-
bool TextClass::readStyle(Lexer & lexrc, Layout & lay)
{
LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
}
// Resolve fonts
lay.resfont = lay.font;
- lay.resfont.realize(defaultfont());
+ lay.resfont.realize(defaultfont_);
lay.reslabelfont = lay.labelfont;
- lay.reslabelfont.realize(defaultfont());
+ lay.reslabelfont.realize(defaultfont_);
return true; // no errors
}
}
-FontInfo const & TextClass::defaultfont() const
-{
- return defaultfont_;
-}
-
-
-docstring const & TextClass::leftmargin() const
-{
- return leftmargin_;
-}
-
-
-docstring const & TextClass::rightmargin() const
-{
- return rightmargin_;
-}
-
-
bool TextClass::hasLayout(docstring const & n) const
{
docstring const name = n.empty() ? defaultLayoutName() : n;
}
-FloatList & TextClass::floats()
-{
- return *floatlist_.get();
-}
-
-
-FloatList const & TextClass::floats() const
-{
- return *floatlist_.get();
-}
-
-
-Counters & TextClass::counters() const
-{
- return *counters_.get();
-}
-
-
-// Return the layout object of an inset given by name. If the name
-// is not found as such, the part after the ':' is stripped off, and
-// searched again. In this way, an error fallback can be provided:
-// An erroneous 'CharStyle:badname' (e.g., after a documentclass switch)
-// will invoke the layout object defined by name = 'CharStyle'.
-// If that doesn't work either, an empty object returns (shouldn't
-// happen). -- Idea JMarc, comment MV
-InsetLayout const & TextClass::insetLayout(docstring const & name) const
+InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
{
docstring n = name;
while (!n.empty()) {
}
-string const & TextClass::name() const
-{
- return name_;
-}
-
-
-string const & TextClass::latexname() const
-{
- // No buffer path information is needed here because on-demand layout files
- // have already been loaded, and no path is needed for system layouts.
- const_cast<TextClass*>(this)->load();
- return latexname_;
-}
-
-
-string const & TextClass::description() const
-{
- return description_;
-}
-
-
-string const & TextClass::opt_fontsize() const
-{
- return opt_fontsize_;
-}
-
-
-string const & TextClass::opt_pagestyle() const
-{
- return opt_pagestyle_;
-}
-
-
-string const & TextClass::options() const
-{
- return options_;
-}
-
-
-string const & TextClass::class_header() const
-{
- return class_header_;
-}
-
-
-string const & TextClass::pagestyle() const
-{
- return pagestyle_;
-}
-
-
-docstring const & TextClass::preamble() const
-{
- return preamble_;
-}
-
-
-PageSides TextClass::sides() const
-{
- return sides_;
-}
-
-
-int TextClass::secnumdepth() const
-{
- return secnumdepth_;
-}
-
-
-int TextClass::tocdepth() const
-{
- return tocdepth_;
-}
-
-
-OutputType TextClass::outputType() const
-{
- return outputType_;
-}
-
-
-bool TextClass::provides(string const & p) const
-{
- return provides_.find(p) != provides_.end();
-}
-
-
-unsigned int TextClass::columns() const
-{
- return columns_;
-}
-
-
-TitleLatexType TextClass::titletype() const
-{
- return titletype_;
-}
-
-
-string const & TextClass::titlename() const
-{
- return titlename_;
-}
-
-
-int TextClass::size() const
-{
- return layoutlist_.size();
-}
-
-
-int TextClass::min_toclevel() const
-{
- return min_toclevel_;
-}
-
-
-int TextClass::max_toclevel() const
-{
- return max_toclevel_;
-}
-
-
-bool TextClass::hasTocLevels() const
-{
- return min_toclevel_ != Layout::NOT_IN_TOC;
-}
-
-
-DocumentClass & DocumentClassBundle::newClass(TextClass const & baseClass)
+DocumentClass & DocumentClassBundle::newClass(LayoutFile const & baseClass)
{
DocumentClass dc(baseClass);
tc_list_.push_back(dc);
}
-DocumentClass::DocumentClass(TextClass const & tc)
+DocumentClass::DocumentClass(LayoutFile const & tc)
: TextClass(tc)
{}
}
+bool DocumentClass::provides(string const & p) const
+{
+ return provides_.find(p) != provides_.end();
+}
+
+
+bool DocumentClass::hasTocLevels() const
+{
+ return min_toclevel_ != Layout::NOT_IN_TOC;
+}
+
+
ostream & operator<<(ostream & os, PageSides p)
{
switch (p) {
class Counters;
class FloatList;
class Layout;
+class LayoutFile;
class Lexer;
/// A TextClass represents a collection of layout information: At the
/// moment, this includes Layout's and InsetLayout's.
///
-/// The main function of TextClass objecs is to provide layout information
-/// to a Buffer, by being the TextClass associated with the BufferParams for
-/// a given Buffer. This is the object returned by BufferParams::textClass().
-/// These instances of TextClass do not necessarily correspond just to a
-/// *.layout file---that is, to a LyX "document class" or *.layout file---
-/// since a Buffer's TextClass, though always based upon a "document class"
-/// may be modified by loading modules.
-
-/// That said, some TextClass instances do correspond strictly to document
-/// classes, that is, to *.layout files. These instances are known in the code
-/// as "base classes". These are cached in BaseClassList.
-///
-/// Though it does not presently exist, one can imagine an extension of this
-/// mechanism that would lead to caching of *.module or *.inc files. In that
-/// case, some TextClass's would just correspond to *.module or *.inc files,
-/// just as some now correspond to *.layout files.
+/// There are two major subclasses of TextClass: LayoutFile and
+/// DocumentClass. These subclasses are what are actually used in LyX.
+/// Simple TextClass objects are not directly constructed in the main
+/// LyX code---the constructor is protected. (That said, in tex2lyx
+/// there are what amount to simple TextClass objects.)
class TextClass {
public:
+ ///
+ virtual ~TextClass() {};
+ ///////////////////////////////////////////////////////////////////
+ // typedefs
+ ///////////////////////////////////////////////////////////////////
/// The individual paragraph layouts comprising the document class
typedef std::vector<LayoutPtr> LayoutList;
/// The inset layouts available to this class
typedef std::map<docstring, InsetLayout> InsetLayouts;
- /// Construct a layout with default values. Actual values loaded later.
- explicit TextClass(std::string const & = std::string(),
- std::string const & = std::string(),
- std::string const & = std::string(),
- bool texClassAvail = false);
-
- /// check whether the TeX class is available
- bool isTeXClassAvailable() const;
+ ///////////////////////////////////////////////////////////////////
+ // Layout Info
+ ///////////////////////////////////////////////////////////////////
+ ///
+ LayoutPtr const & defaultLayout() const;
+ ///
+ docstring const & defaultLayoutName() const;
+ /// returns a special layout for use when we don't really want one,
+ /// e.g., in table cells
+ LayoutPtr const & emptyLayout() const
+ { return operator[](emptylayout_); };
+ /// the name of the empty layout
+ docstring const & emptyLayoutName() const
+ { return emptylayout_; }
/// Enumerate the paragraph styles.
size_t layoutCount() const { return layoutlist_.size(); }
/// Access the paragraph styles.
LayoutPtr const & layout(size_t index) const { return layoutlist_[index]; }
+ ///
+ bool hasLayout(docstring const & name) const;
+ ///
+ LayoutPtr const & operator[](docstring const & vname) const;
+ ///////////////////////////////////////////////////////////////////
+ // reading routines
+ ///////////////////////////////////////////////////////////////////
/// Enum used with TextClass::read
enum ReadType {
BASECLASS, //>This is a base class, i.e., top-level layout file
/// Performs the read of the layout file.
/// \return true on success.
bool read(support::FileName const & filename, ReadType rt = BASECLASS);
- ///
- void readOutputType(Lexer &);
- ///
- void readTitleType(Lexer &);
- ///
- void readMaxCounter(Lexer &);
- ///
- void readClassOptions(Lexer &);
- ///
- void readCharStyle(Lexer &, std::string const &);
- ///
- void readFloat(Lexer &);
- ///
- void readCounter(Lexer &);
- ///
- bool hasLayout(docstring const & name) const;
-
- ///
- LayoutPtr const & operator[](docstring const & vname) const;
- /// Sees to that the textclass structure has been loaded
+ ///////////////////////////////////////////////////////////////////
+ // loading
+ ///////////////////////////////////////////////////////////////////
+ /// Sees to it the textclass structure has been loaded
bool load(std::string const & path = std::string()) const;
/// Has this layout file been loaded yet?
- /// NOTE This only makes sense when used with "static" TextClass
- /// objects, e.g., ones that represent files on disk, as opposed
- /// to ones that can be modified by modules.
- // FIXME Therefore it should return true only for BaseClass objects,
- // and false for DocumentClass objects.
- // Indeed, quite generally, those two sorts of objects should now be
- // disentangled a bit.
- bool loaded() const { return loaded_; }
+ /// Overridden by DocumentClass
+ virtual bool loaded() const { return loaded_; }
- /// the list of floats defined in the document class
- FloatList & floats();
- /// the list of floats defined in the document class
- FloatList const & floats() const;
- /// The Counters present in this document class.
- Counters & counters() const;
- /// Inset layouts of this doc class
- InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
+ ///////////////////////////////////////////////////////////////////
+ // accessors
+ ///////////////////////////////////////////////////////////////////
///
- InsetLayout const & insetLayout(docstring const & name) const;
+ std::string const & name() const { return name_; };
///
- docstring const & defaultLayoutName() const;
- ///
- LayoutPtr const & defaultLayout() const;
- /// returns a special layout for use when we don't really want one,
- /// e.g., in table cells
- LayoutPtr const & emptyLayout() const
- { return operator[](emptylayout_); };
- ///
- docstring const & emptyLayoutName() const
- { return emptylayout_; }
- ///
- std::string const & name() const;
- ///
- docstring const & labelstring() const;
- ///
- std::string const & latexname() const;
- ///
- std::string const & description() const;
- ///
- bool isModular() const { return modular_; }
- /// Sets the layout as a modular one. There is never any
- /// need to reset this.
- void markAsModular() { modular_ = true; }
- ///
- std::string const & opt_fontsize() const;
- ///
- std::string const & opt_pagestyle() const;
- ///
- std::string const & options() const;
- ///
- std::string const & class_header() const;
- ///
- std::string const & pagestyle() const;
- ///
- docstring const & preamble() const;
-
- /// is this feature already provided by the class?
- bool provides(std::string const & p) const;
- /// features required by the class?
- std::set<std::string> const & requires() const { return requires_; }
-
- ///
- unsigned int columns() const;
- ///
- PageSides sides() const;
- ///
- int secnumdepth() const;
- ///
- int tocdepth() const;
-
- /// Can be LaTeX, DocBook, etc.
- OutputType outputType() const;
-
- ///
- FontInfo const & defaultfont() const;
-
- /// Text that dictates how wide the left margin is on the screen
- docstring const & leftmargin() const;
-
- /// Text that dictates how wide the right margin is on the screen
- docstring const & rightmargin() const;
-
- /// The type of command used to produce a title
- TitleLatexType titletype() const;
- /// The name of the title command
- std::string const & titlename() const;
-
- ///
- int size() const;
- /// The minimal TocLevel of sectioning layouts
- int min_toclevel() const;
- /// The maximal TocLevel of sectioning layouts
- int max_toclevel() const;
- /// returns true if the class has a ToC structure
- bool hasTocLevels() const;
+ std::string const & description() const { return description_; };
///
- static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
+ std::string const & latexname() const { return latexname_; }
protected:
+ /// Protect construction
+ TextClass();
+ ///////////////////////////////////////////////////////////////////
+ // members
+ ///////////////////////////////////////////////////////////////////
/// Paragraph styles used in this layout
LayoutList layoutlist_;
-private:
- ///
- bool deleteLayout(docstring const &);
- /// \return true for success.
- bool readStyle(Lexer &, Layout &);
/// Layout file name
std::string name_;
/// document class name
std::string latexname_;
/// document class description
std::string description_;
- /// whether this is a modular layout, i.e., whether it has been
- /// modified by loading of layout modules.
- bool modular_;
+ /// available types of float, eg. figure, algorithm.
+ boost::shared_ptr<FloatList> floatlist_;
+ /// Types of counters, eg. sections, eqns, figures, avail. in document class.
+ boost::shared_ptr<Counters> counters_;
+ /// Has this layout file been loaded yet?
+ mutable bool loaded_;
+ /// Is the TeX class available?
+ bool texClassAvail_;
///
std::string opt_fontsize_;
///
FontInfo defaultfont_;
/// Text that dictates how wide the left margin is on the screen
docstring leftmargin_;
-
/// Text that dictates how wide the right margin is on the screen
docstring rightmargin_;
-
/// The type of command used to produce a title
TitleLatexType titletype_;
/// The name of the title command
std::string titlename_;
/// Input layouts available to this layout
mutable InsetLayouts insetlayoutlist_;
-
- /// available types of float, eg. figure, algorithm.
- boost::shared_ptr<FloatList> floatlist_;
-
- /// Types of counters, eg. sections, eqns, figures, avail. in document class.
- boost::shared_ptr<Counters> counters_;
-
- /// Has this layout file been loaded yet?
- mutable bool loaded_;
-
- /// Is the TeX class available?
- bool texClassAvail_;
-
/// The minimal TocLevel of sectioning layouts
int min_toclevel_;
/// The maximal TocLevel of sectioning layouts
int max_toclevel_;
+private:
+ ///////////////////////////////////////////////////////////////////
+ // helper routines for reading layout files
+ ///////////////////////////////////////////////////////////////////
///
- static InsetLayout empty_insetlayout_;
+ bool deleteLayout(docstring const &);
+ /// \return true for success.
+ bool readStyle(Lexer &, Layout &);
+ ///
+ void readOutputType(Lexer &);
+ ///
+ void readTitleType(Lexer &);
+ ///
+ void readMaxCounter(Lexer &);
+ ///
+ void readClassOptions(Lexer &);
+ ///
+ void readCharStyle(Lexer &, std::string const &);
+ ///
+ void readFloat(Lexer &);
+ ///
+ void readCounter(Lexer &);
};
-/// This class amounts to little more than a `strong typedef'.
-/// Its purpose is to control the creation of TextClass objects
-/// within the DocumentClassBundle.
-/// These TextClasses represent the layout information that is
-/// associated with a given buffer.
+/// A DocumentClass represents the layout information associated with a
+/// Buffer. It is based upon a LayoutFile, but may be modified by loading
+/// various Modules. It is thus a dynamic object, as opposed to LayoutFile's
+/// which are pretty much static.
+///
+/// In the main LyX code, DocumentClass objects are created only by
+/// DocumentClassBundle, for which see below.
class DocumentClass : public TextClass {
public:
+ ///
+ virtual ~DocumentClass() {}
+
+ ///////////////////////////////////////////////////////////////////
+ // Layout Info
+ ///////////////////////////////////////////////////////////////////
+ /// \return true if there is a Layout with latexname lay
bool hasLaTeXLayout(std::string const & lay) const;
+ /// A DocumentClass nevers count as loaded, since it is dynamic
+ virtual bool loaded() { return false; }
+ /// Inset layouts of this doc class
+ InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
+ /// \return the layout object of an inset given by name. If the name
+ /// is not found as such, the part after the ':' is stripped off, and
+ /// searched again. In this way, an error fallback can be provided:
+ /// An erroneous 'CharStyle:badname' (e.g., after a documentclass switch)
+ /// will invoke the layout object defined by name = 'CharStyle'.
+ /// If that doesn't work either, an empty object returns (shouldn't
+ /// happen). -- Idea JMarc, comment MV
+ ///
+ InsetLayout const & insetLayout(docstring const & name) const;
+ /// an empty inset layout for use as a default
+ static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
+
+ ///////////////////////////////////////////////////////////////////
+ // accessors
+ ///////////////////////////////////////////////////////////////////
+ /// the list of floats defined in the document class
+ FloatList & floats() { return *floatlist_.get(); }
+ /// the list of floats defined in the document class
+ FloatList const & floats() const { return *floatlist_.get(); }
+ /// The Counters present in this document class.
+ Counters & counters() const { return *counters_.get(); }
+ ///
+ std::string const & opt_fontsize() const { return opt_fontsize_; }
+ ///
+ std::string const & opt_pagestyle() const { return opt_pagestyle_; }
+ ///
+ std::string const & options() const { return options_; }
+ ///
+ std::string const & class_header() const { return class_header_; }
+ ///
+ std::string const & pagestyle() const { return pagestyle_; }
+ ///
+ docstring const & preamble() const { return preamble_; }
+ /// is this feature already provided by the class?
+ bool provides(std::string const & p) const;
+ /// features required by the class?
+ std::set<std::string> const & requires() const { return requires_; }
+ ///
+ unsigned int columns() const { return columns_; }
+ ///
+ PageSides sides() const { return sides_; }
+ ///
+ int secnumdepth() const { return secnumdepth_; }
+ ///
+ int tocdepth() const { return tocdepth_; }
+ ///
+ FontInfo const & defaultfont() const { return defaultfont_; }
+ /// Text that dictates how wide the left margin is on the screen
+ docstring const & leftmargin() const { return leftmargin_; }
+ /// Text that dictates how wide the right margin is on the screen
+ docstring const & rightmargin() const { return rightmargin_; }
+ /// The type of command used to produce a title
+ TitleLatexType titletype() const { return titletype_; };
+ /// The name of the title command
+ std::string const & titlename() const { return titlename_; };
+ ///
+ int size() const { return layoutlist_.size(); }
+ /// The minimal TocLevel of sectioning layouts
+ int min_toclevel() const { return min_toclevel_; }
+ /// The maximal TocLevel of sectioning layouts
+ int max_toclevel() const { return max_toclevel_; }
+ /// returns true if the class has a ToC structure
+ bool hasTocLevels() const;
+ /// Can be LaTeX, DocBook, etc.
+ OutputType outputType() const { return outputType_; }
+protected:
+ /// Constructs a DocumentClass based upon a LayoutFile.
+ DocumentClass(LayoutFile const & tc);
+ /// Needed in tex2lyx
+ DocumentClass() {};
private:
- /// Constructs a DocumentClass based upon a TextClass.
- DocumentClass(TextClass const & tc);
/// The only class that can create a DocumentClass is
/// DocumentClassBundle, which calls the private constructor.
friend class DocumentClassBundle;
+ ///
+ static InsetLayout empty_insetlayout_;
};
-/// This is simply a container for the text classes generated when modules
-/// are read, so that they stay in memory for use by Insets, CutAndPaste,
-/// and the like.
+/// DocumentClassBundle is a container for DocumentClass objects, so that
+/// they stay in memory for use by Insets, CutAndPaste, and the like, even
+/// when their associated Buffers are destroyed.
/// FIXME Some sort of garbage collection or reference counting wouldn't
/// be a bad idea here. It might be enough to check when a Buffer is closed
/// (or makeDocumentClass is called) whether the old DocumentClass is in use
class DocumentClassBundle {
public:
/// \return Pointer to a new class equal to baseClass
- DocumentClass & newClass(TextClass const & baseClass);
+ DocumentClass & newClass(LayoutFile const & baseClass);
/// \return The sole instance of this class.
static DocumentClassBundle & get();
private:
// Ordering criteria:
// 1. Availability of text class
// 2. Description (lexicographic)
- TextClass const & tc1 = BaseClassList::get()[lhs];
- TextClass const & tc2 = BaseClassList::get()[rhs];
+ LayoutFile const & tc1 = BaseClassList::get()[lhs];
+ LayoutFile const & tc2 = BaseClassList::get()[rhs];
return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
(tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
_(tc1.description()) < _(tc2.description()));
//give us a list of entries or something of the sort.
latexModule->classCO->setModel(&classes_model_);
BaseClassList const & bcl = BaseClassList::get();
- vector<BaseClassIndex> classList = bcl.classList();
+ vector<LayoutFileIndex> classList = bcl.classList();
sort(classList.begin(), classList.end(), less_textclass_avail_desc());
- vector<BaseClassIndex>::const_iterator cit = classList.begin();
- vector<BaseClassIndex>::const_iterator cen = classList.end();
+ vector<LayoutFileIndex>::const_iterator cit = classList.begin();
+ vector<LayoutFileIndex>::const_iterator cen = classList.end();
for (int i = 0; cit != cen; ++cit, ++i) {
- TextClass const & tc = bcl[*cit];
+ LayoutFile const & tc = bcl[*cit];
docstring item = (tc.isTeXClassAvailable()) ?
from_utf8(tc.description()) :
bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
namespace lyx {
class Inset;
-class TextClass;
+class DocumentClass;
class ToolbarItem;
namespace frontend {
private:
GuiView & owner_;
- TextClass const * text_class_;
+ DocumentClass const * text_class_;
Inset const * inset_;
};
InsetCaption::InsetCaption(InsetCaption const & ic)
- : InsetText(ic), textclass_(ic.textclass_)
+ : InsetText(ic)
{
setAutoBreakRows(true);
setDrawFrame(true);
InsetCaption::InsetCaption(BufferParams const & bp)
- : InsetText(bp), textclass_(bp.documentClass())
+ : InsetText(bp)
{
setAutoBreakRows(true);
setDrawFrame(true);
namespace lyx {
-class TextClass;
-
/** A caption inset
*/
class InsetCaption : public InsetText {
std::string type_;
///
docstring custom_label_;
- ///
- TextClass const & textclass_;
};
layout_ = &(dc->insetLayout(name()));
labelstring_ = layout_->labelstring();
} else {
- layout_ = &TextClass::emptyInsetLayout();
+ layout_ = &DocumentClass::emptyInsetLayout();
labelstring_ = _("UNDEFINED");
}
bool InsetCollapsable::undefined() const
{
docstring const & n = getLayout().name();
- return n.empty() || n == TextClass::emptyInsetLayout().name();
+ return n.empty() || n == DocumentClass::emptyInsetLayout().name();
}
Context::Context(bool need_layout_,
- TextClass const & textclass_,
+ TeX2LyXDocClass const & textclass_,
LayoutPtr layout_, LayoutPtr parent_layout_,
TeXFont font_)
: need_layout(need_layout_),
#ifndef CONTEXT_H
#define CONTEXT_H
-#include "TextClass.h"
+#include "tex2lyx.h"
#include <iosfwd>
class Context {
public:
Context(bool need_layout_,
- TextClass const & textclass_,
+ TeX2LyXDocClass const & textclass_,
LayoutPtr layout_ = LayoutPtr(),
LayoutPtr parent_layout_= LayoutPtr(),
TeXFont font_ = TeXFont());
static bool empty;
/// The textclass of the document. Could actually be a global variable
- TextClass const & textclass;
+ TeX2LyXDocClass const & textclass;
/// The layout of the current paragraph
LayoutPtr layout;
/// The layout of the outer paragraph (for environment layouts)
../Floating.cpp \
../Counters.cpp \
../insets/InsetLayout.cpp \
+ ../BaseClassList.h \
../Layout.h \
../Layout.cpp \
../TextClass.cpp \
#include "tex2lyx.h"
+#include "BaseClassList.h"
#include "Layout.h"
#include "Lexer.h"
#include "TextClass.h"
} // anonymous namespace
-TextClass const parse_preamble(Parser & p, ostream & os, string const & forceclass)
+TeX2LyXDocClass const parse_preamble(Parser & p, ostream & os, string const & forceclass)
{
// initialize fixed types
special_columns['D'] = 3;
cerr << "Error: Could not find layout file for textclass \"" << h_textclass << "\"." << endl;
exit(1);
}
- TextClass textclass;
+ TeX2LyXDocClass textclass;
textclass.read(layoutfilename);
if (h_papersides.empty()) {
ostringstream ss;
//p.dump();
stringstream ss;
- TextClass textclass = parse_preamble(p, ss, documentclass);
+ TeX2LyXDocClass textclass = parse_preamble(p, ss, documentclass);
captionlayout = LayoutPtr(Layout::forCaption());
active_environments.push_back("document");
class Context;
+/// A trivial subclass, just to give us a public default constructor
+class TeX2LyXDocClass : public DocumentClass
+{};
+
/// in preamble.cpp
-TextClass const parse_preamble(Parser & p, std::ostream & os, std::string const & forceclass);
+TeX2LyXDocClass const parse_preamble(Parser & p, std::ostream & os, std::string const & forceclass);
/// used packages with options
extern std::map<std::string, std::vector<std::string> > used_packages;