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"
18 #include "insets/InsetLayout.h"
20 #include "support/docstring.h"
21 #include "support/types.h"
23 #include <boost/shared_ptr.hpp>
32 namespace support { class FileName; }
40 /// A TextClass represents a collection of layout information: At the
41 /// moment, this includes Layout's and InsetLayout's.
43 /// The main function of TextClass objecs is to provide layout information
44 /// to a Buffer, by being the TextClass associated with the BufferParams for
45 /// a given Buffer. This is the object returned by BufferParams::textClass().
46 /// These instances of TextClass do not necessarily correspond just to a
47 /// *.layout file---that is, to a LyX "document class" or *.layout file---
48 /// since a Buffer's TextClass, though always based upon a "document class"
49 /// may be modified by loading modules.
51 /// That said, some TextClass instances do correspond strictly to document
52 /// classes, that is, to *.layout files. These instances are known in the code
53 /// as "base classes". These are cached in BaseClassList.
55 /// Though it does not presently exist, one can imagine an extension of this
56 /// mechanism that would lead to caching of *.module or *.inc files. In that
57 /// case, some TextClass's would just correspond to *.module or *.inc files,
58 /// just as some now correspond to *.layout files.
61 /// The individual paragraph layouts comprising the document class
62 typedef std::vector<LayoutPtr> LayoutList;
63 /// The inset layouts available to this class
64 typedef std::map<docstring, InsetLayout> InsetLayouts;
65 /// Construct a layout with default values. Actual values loaded later.
66 explicit TextClass(std::string const & = std::string(),
67 std::string const & = std::string(),
68 std::string const & = std::string(),
69 bool texClassAvail = false);
71 /// check whether the TeX class is available
72 bool isTeXClassAvailable() const;
74 /// Enumerate the paragraph styles.
75 size_t layoutCount() const { return layoutlist_.size(); }
76 /// Access the paragraph styles.
77 LayoutPtr const & layout(size_t index) const { return layoutlist_[index]; }
79 /// Enum used with TextClass::read
81 BASECLASS, //>This is a base class, i.e., top-level layout file
82 MERGE, //>This is a file included in a layout file
83 MODULE //>This is a layout module
85 /// Performs the read of the layout file.
86 /// \return true on success.
87 bool read(support::FileName const & filename, ReadType rt = BASECLASS);
89 void readOutputType(Lexer &);
91 void readTitleType(Lexer &);
93 void readMaxCounter(Lexer &);
95 void readClassOptions(Lexer &);
97 void readCharStyle(Lexer &, std::string const &);
99 void readFloat(Lexer &);
101 void readCounter(Lexer &);
103 bool hasLayout(docstring const & name) const;
106 LayoutPtr const & operator[](docstring const & vname) const;
108 /// Sees to that the textclass structure has been loaded
109 bool load(std::string const & path = std::string()) const;
110 /// Has this layout file been loaded yet?
111 /// NOTE This only makes sense when used with "static" TextClass
112 /// objects, e.g., ones that represent files on disk, as opposed
113 /// to ones that can be modified by modules.
114 // FIXME Should we have a modular_ variable, set to true when
115 // we load a module, that would force false to be returned here?
116 bool loaded() const { return loaded_; }
118 /// the list of floats defined in the document class
119 FloatList & floats();
120 /// the list of floats defined in the document class
121 FloatList const & floats() const;
122 /// The Counters present in this document class.
123 Counters & counters() const;
124 /// Inset layouts of this doc class
125 InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
127 InsetLayout const & insetLayout(docstring const & name) const;
129 docstring const & defaultLayoutName() const;
131 LayoutPtr const & defaultLayout() const;
132 /// returns a special layout for use when we don't really want one,
133 /// e.g., in table cells
134 LayoutPtr const & emptyLayout() const
135 { return operator[](emptylayout_); };
137 docstring const & emptyLayoutName() const
138 { return emptylayout_; }
140 std::string const & name() const;
142 docstring const & labelstring() const;
144 std::string const & latexname() const;
146 std::string const & description() const;
148 bool isModular() const { return modular_; }
149 /// Sets the layout as a modular one. There is never any
150 /// need to reset this.
151 void markAsModular() { modular_ = true; }
153 std::string const & opt_fontsize() const;
155 std::string const & opt_pagestyle() const;
157 std::string const & options() const;
159 std::string const & class_header() const;
161 std::string const & pagestyle() const;
163 docstring const & preamble() const;
165 /// is this feature already provided by the class?
166 bool provides(std::string const & p) const;
167 /// features required by the class?
168 std::set<std::string> const & requires() const { return requires_; }
171 unsigned int columns() const;
173 PageSides sides() const;
175 int secnumdepth() const;
177 int tocdepth() const;
179 /// Can be LaTeX, DocBook, etc.
180 OutputType outputType() const;
183 FontInfo const & defaultfont() const;
185 /// Text that dictates how wide the left margin is on the screen
186 docstring const & leftmargin() const;
188 /// Text that dictates how wide the right margin is on the screen
189 docstring const & rightmargin() const;
191 /// The type of command used to produce a title
192 TitleLatexType titletype() const;
193 /// The name of the title command
194 std::string const & titlename() const;
198 /// The minimal TocLevel of sectioning layouts
199 int min_toclevel() const;
200 /// The maximal TocLevel of sectioning layouts
201 int max_toclevel() const;
202 /// returns true if the class has a ToC structure
203 bool hasTocLevels() const;
205 static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
208 bool deleteLayout(docstring const &);
209 /// \return true for success.
210 bool readStyle(Lexer &, Layout &);
213 /// document class name
214 std::string latexname_;
215 /// document class description
216 std::string description_;
217 /// whether this is a modular layout, i.e., whether it has been
218 /// modified by loading of layout modules.
221 std::string opt_fontsize_;
223 std::string opt_pagestyle_;
224 /// Specific class options
225 std::string options_;
227 std::string pagestyle_;
229 std::string class_header_;
231 docstring defaultlayout_;
232 /// name of empty layout
233 static const docstring emptylayout_;
234 /// preamble text to support layout styles
236 /// latex packages loaded by document class.
237 std::set<std::string> provides_;
238 /// latex packages requested by document class.
239 std::set<std::string> requires_;
241 unsigned int columns_;
244 /// header depth to have numbering
246 /// header depth to appear in table of contents
248 /// Can be LaTeX, DocBook, etc.
249 OutputType outputType_;
250 /** Base font. The paragraph and layout fonts are resolved against
251 this font. This has to be fully instantiated. Attributes
252 FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
255 FontInfo defaultfont_;
256 /// Text that dictates how wide the left margin is on the screen
257 docstring leftmargin_;
259 /// Text that dictates how wide the right margin is on the screen
260 docstring rightmargin_;
262 /// The type of command used to produce a title
263 TitleLatexType titletype_;
264 /// The name of the title command
265 std::string titlename_;
267 /// Paragraph styles used in this layout
268 LayoutList layoutlist_;
270 /// Input layouts available to this layout
271 mutable InsetLayouts insetlayoutlist_;
273 /// available types of float, eg. figure, algorithm.
274 boost::shared_ptr<FloatList> floatlist_;
276 /// Types of counters, eg. sections, eqns, figures, avail. in document class.
277 boost::shared_ptr<Counters> counters_;
279 /// Has this layout file been loaded yet?
280 mutable bool loaded_;
282 /// Is the TeX class available?
285 /// The minimal TocLevel of sectioning layouts
287 /// The maximal TocLevel of sectioning layouts
290 static InsetLayout empty_insetlayout_;
294 /// This class amounts to little more than a `strong typedef'.
295 /// Its purpose is to control the creation of TextClass objects
296 /// within the DocumentClassBundle.
297 /// These TextClasses represent the layout information that is
298 /// associated with a given buffer.
299 class DocumentClass : public TextClass {
301 /// Constructs a DocumentClass based upon a TextClass.
302 DocumentClass(TextClass const & tc);
303 /// The only class that can create a DocumentClass is
304 /// DocumentClassBundle, which calls the private constructor.
305 friend class DocumentClassBundle;
309 /// This is simply a container for the text classes generated when modules
310 /// are read, so that they stay in memory for use by Insets, CutAndPaste,
312 /// FIXME Some sort of garbage collection or reference counting wouldn't
313 /// be a bad idea here. It might be enough to check when a Buffer is closed
314 /// (or makeDocumentClass is called) whether the old DocumentClass is in use
317 /// This is a singleton class. Its sole instance is accessed via
318 /// DocumentClassBundle::get().
319 class DocumentClassBundle {
321 /// \return Pointer to a new class equal to baseClass
322 DocumentClass & newClass(TextClass const & baseClass);
323 /// \return The sole instance of this class.
324 static DocumentClassBundle & get();
326 /// control instantiation
327 DocumentClassBundle() {}
329 DocumentClassBundle(DocumentClassBundle const &);
331 std::list<DocumentClass> tc_list_;
335 /// convert page sides option to text 1 or 2
336 std::ostream & operator<<(std::ostream & os, PageSides p);