4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * Full author contact details are available in file CREDITS.
13 #include "ColorCode.h"
15 #include "LayoutEnums.h"
16 #include "LayoutPtr.h"
17 #include "TextClassPtr.h"
19 #include "insets/InsetLayout.h"
21 #include "support/docstring.h"
22 #include "support/types.h"
24 #include <boost/shared_ptr.hpp>
33 namespace support { class FileName; }
41 /// A TextClass represents a collection of layout information: At the
42 /// moment, this includes Layout's and InsetLayout's.
44 /// The main function of TextClass objecs is to provide layout information
45 /// to a Buffer, by being the TextClass associated with the BufferParams for
46 /// a given Buffer. This is the object returned by BufferParams::textClass().
47 /// These instances of TextClass do not necessarily correspond just to a
48 /// *.layout file---that is, to a LyX "document class" or *.layout file---
49 /// since a Buffer's TextClass, though always based upon a "document class"
50 /// may be modified by loading modules.
52 /// That said, some TextClass instances do correspond strictly to document
53 /// classes, that is, to *.layout files. These instances are known in the code
54 /// as "base classes". These are cached in BaseClassList.
56 /// Though it does not presently exist, one can imagine an extension of this
57 /// mechanism that would lead to caching of *.module or *.inc files. In that
58 /// case, some TextClass's would just correspond to *.module or *.inc files,
59 /// just as some now correspond to *.layout files.
62 /// The individual paragraph layouts comprising the document class
63 typedef std::vector<LayoutPtr> LayoutList;
64 /// The inset layouts available to this class
65 typedef std::map<docstring, InsetLayout> InsetLayouts;
66 /// Construct a layout with default values. Actual values loaded later.
67 explicit TextClass(std::string const & = std::string(),
68 std::string const & = std::string(),
69 std::string const & = std::string(),
70 bool texClassAvail = false);
72 /// check whether the TeX class is available
73 bool isTeXClassAvailable() const;
75 /// Enumerate the paragraph styles.
76 size_t layoutCount() const { return layoutlist_.size(); }
77 /// Access the paragraph styles.
78 LayoutPtr const & layout(size_t index) const { return layoutlist_[index]; }
80 /// Enum used with TextClass::read
82 BASECLASS, //>This is a base class, i.e., top-level layout file
83 MERGE, //>This is a file included in a layout file
84 MODULE //>This is a layout module
86 /// Performs the read of the layout file.
87 /// \return true on success.
88 bool read(support::FileName const & filename, ReadType rt = BASECLASS);
90 void readOutputType(Lexer &);
92 void readTitleType(Lexer &);
94 void readMaxCounter(Lexer &);
96 void readClassOptions(Lexer &);
98 void readCharStyle(Lexer &, std::string const &);
100 void readFloat(Lexer &);
102 void readCounter(Lexer &);
104 bool hasLayout(docstring const & name) const;
107 LayoutPtr const & operator[](docstring const & vname) const;
109 /// Sees to that the textclass structure has been loaded
110 bool load(std::string const & path = std::string()) const;
111 /// Has this layout file been loaded yet?
112 /// NOTE This only makes sense when used with "static" TextClass
113 /// objects, e.g., ones that represent files on disk, as opposed
114 /// to ones that can be modified by modules.
115 // FIXME Should we have a modular_ variable, set to true when
116 // we load a module, that would force false to be returned here?
117 bool loaded() const { return loaded_; }
119 /// the list of floats defined in the document class
120 FloatList & floats();
121 /// the list of floats defined in the document class
122 FloatList const & floats() const;
123 /// The Counters present in this document class.
124 Counters & counters() const;
125 /// Inset layouts of this doc class
126 InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
128 InsetLayout const & insetLayout(docstring const & name) const;
130 docstring const & defaultLayoutName() const;
132 LayoutPtr const & defaultLayout() const;
133 /// returns a special layout for use when we don't really want one,
134 /// e.g., in table cells
135 LayoutPtr const & emptyLayout() const
136 { return operator[](emptylayout_); };
138 docstring const & emptyLayoutName() const
139 { return emptylayout_; }
141 std::string const & name() const;
143 docstring const & labelstring() const;
145 std::string const & latexname() const;
147 std::string const & description() const;
149 bool isModular() const { return modular_; }
150 /// Sets the layout as a modular one. There is never any
151 /// need to reset this.
152 void markAsModular() { modular_ = true; }
154 std::string const & opt_fontsize() const;
156 std::string const & opt_pagestyle() const;
158 std::string const & options() const;
160 std::string const & class_header() const;
162 std::string const & pagestyle() const;
164 docstring const & preamble() const;
166 /// is this feature already provided by the class?
167 bool provides(std::string const & p) const;
168 /// features required by the class?
169 std::set<std::string> const & requires() const { return requires_; }
172 unsigned int columns() const;
174 PageSides sides() const;
176 int secnumdepth() const;
178 int tocdepth() const;
180 /// Can be LaTeX, DocBook, etc.
181 OutputType outputType() const;
184 FontInfo const & defaultfont() const;
186 /// Text that dictates how wide the left margin is on the screen
187 docstring const & leftmargin() const;
189 /// Text that dictates how wide the right margin is on the screen
190 docstring const & rightmargin() const;
192 /// The type of command used to produce a title
193 TitleLatexType titletype() const;
194 /// The name of the title command
195 std::string const & titlename() const;
199 /// The minimal TocLevel of sectioning layouts
200 int min_toclevel() const;
201 /// The maximal TocLevel of sectioning layouts
202 int max_toclevel() const;
203 /// returns true if the class has a ToC structure
204 bool hasTocLevels() const;
206 static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
209 bool deleteLayout(docstring const &);
210 /// \return true for success.
211 bool readStyle(Lexer &, Layout &);
214 /// document class name
215 std::string latexname_;
216 /// document class description
217 std::string description_;
218 /// whether this is a modular layout, i.e., whether it has been
219 /// modified by loading of layout modules.
222 std::string opt_fontsize_;
224 std::string opt_pagestyle_;
225 /// Specific class options
226 std::string options_;
228 std::string pagestyle_;
230 std::string class_header_;
232 docstring defaultlayout_;
233 /// name of empty layout
234 static const docstring emptylayout_;
235 /// preamble text to support layout styles
237 /// latex packages loaded by document class.
238 std::set<std::string> provides_;
239 /// latex packages requested by document class.
240 std::set<std::string> requires_;
242 unsigned int columns_;
245 /// header depth to have numbering
247 /// header depth to appear in table of contents
249 /// Can be LaTeX, DocBook, etc.
250 OutputType outputType_;
251 /** Base font. The paragraph and layout fonts are resolved against
252 this font. This has to be fully instantiated. Attributes
253 FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
256 FontInfo defaultfont_;
257 /// Text that dictates how wide the left margin is on the screen
258 docstring leftmargin_;
260 /// Text that dictates how wide the right margin is on the screen
261 docstring rightmargin_;
263 /// The type of command used to produce a title
264 TitleLatexType titletype_;
265 /// The name of the title command
266 std::string titlename_;
268 /// Paragraph styles used in this layout
269 LayoutList layoutlist_;
271 /// Input layouts available to this layout
272 mutable InsetLayouts insetlayoutlist_;
274 /// available types of float, eg. figure, algorithm.
275 boost::shared_ptr<FloatList> floatlist_;
277 /// Types of counters, eg. sections, eqns, figures, avail. in document class.
278 boost::shared_ptr<Counters> counters_;
280 /// Has this layout file been loaded yet?
281 mutable bool loaded_;
283 /// Is the TeX class available?
286 /// The minimal TocLevel of sectioning layouts
288 /// The maximal TocLevel of sectioning layouts
291 static InsetLayout empty_insetlayout_;
295 /// This is simply a container for the text classes generated when modules
296 /// are read, so that they stay in memory for use by Insets, CutAndPaste,
297 /// and the like. Since they're constructed via new, they wouldn't actually
298 /// disappear without this class---but this class holds the pointers to them
299 /// so that they don't leak.
300 /// FIXME Some sort of garbage collection or reference counting wouldn't
301 /// be a bad idea here. It might be enough to check when a Buffer is closed
302 /// (or makeTextClass is called) whether the old TextClass is in use anywhere.
304 /// This is a singleton class. Its sole instance is accessed via
305 /// TextClassBundle::get().
307 /// See \file TextClassPtr.h for the definition of TextClassPtr.
308 class TextClassBundle {
310 /// \return Pointer to a new class equal to baseClass
311 TextClassPtr newClass(TextClass const & baseClass);
312 /// \return The sole instance of this class.
313 static TextClassBundle & get();
317 /// control instantiation
318 TextClassBundle() {};
320 TextClassBundle(TextClassBundle const &);
322 std::list<TextClassPtr> tc_list_;
326 /// convert page sides option to text 1 or 2
327 std::ostream & operator<<(std::ostream & os, PageSides p);