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>
31 namespace support { class FileName; }
38 /// List of inset layouts
39 typedef std::map<docstring, InsetLayout> InsetLayouts;
41 /// Index in globel text class list. Basically a 'strong typedef'/
46 TextClassIndex(size_t t) : data_(t) {}
48 operator size_t() const { return data_; }
56 /// Stores the layout specification of a LyX document class.
59 /// The individual styles comprising the document class
60 typedef std::vector<LayoutPtr> LayoutList;
61 /// Construct a layout with default values. Actual values loaded later.
63 TextClass(std::string const & = std::string(),
64 std::string const & = std::string(),
65 std::string const & = std::string(),
66 bool texClassAvail = false);
68 /// check whether the TeX class is available
69 bool isTeXClassAvailable() const;
71 /// Enumerate the paragraph styles.
72 size_t layoutCount() const { return layoutlist_.size(); }
73 /// Access the paragraph styles.
74 LayoutPtr const & layout(size_t index) const { return layoutlist_[index]; }
76 /// Enum used with TextClass::read
78 BASECLASS, //>This is a base class, i.e., top-level layout file
79 MERGE, //>This is a file included in a layout file
80 MODULE //>This is a layout module
82 /// Performs the read of the layout file.
83 /// \return true on success.
84 bool read(support::FileName const & filename, ReadType rt = BASECLASS);
86 void readOutputType(Lexer &);
88 void readTitleType(Lexer &);
90 void readMaxCounter(Lexer &);
92 void readClassOptions(Lexer &);
94 void readCharStyle(Lexer &, std::string const &);
96 void readFloat(Lexer &);
98 void readCounter(Lexer &);
100 bool hasLayout(docstring const & name) const;
103 LayoutPtr const & operator[](docstring const & vname) const;
105 /// Sees to that the textclass structure has been loaded
106 bool load(std::string const & path = std::string()) const;
107 /// Has this layout file been loaded yet?
108 bool loaded() const { return loaded_; }
110 /// the list of floats defined in the document class
111 FloatList & floats();
112 /// the list of floats defined in the document class
113 FloatList const & floats() const;
114 /// The Counters present in this document class.
115 Counters & counters() const;
116 /// Inset layouts of this doc class
117 InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
119 InsetLayout const & insetLayout(docstring const & name) const;
121 docstring const & defaultLayoutName() const;
123 LayoutPtr const & defaultLayout() const;
124 /// returns a special layout for use when we don't really want one,
125 /// e.g., in table cells
126 LayoutPtr const & emptyLayout() const
127 { return operator[](emptylayout_); };
129 docstring const & emptyLayoutName() const
130 { return emptylayout_; }
132 std::string const & name() const;
134 docstring const & labelstring() const;
136 std::string const & latexname() const;
138 std::string const & description() const;
140 bool isModular() const { return modular_; }
141 /// Sets the layout as a modular one. There is never any
142 /// need to reset this.
143 void markAsModular() { modular_ = true; }
145 std::string const & opt_fontsize() const;
147 std::string const & opt_pagestyle() const;
149 std::string const & options() const;
151 std::string const & class_header() const;
153 std::string const & pagestyle() const;
155 docstring const & preamble() const;
157 /// is this feature already provided by the class?
158 bool provides(std::string const & p) const;
159 /// features required by the class?
160 std::set<std::string> const & requires() const { return requires_; }
163 unsigned int columns() const;
165 PageSides sides() const;
167 int secnumdepth() const;
169 int tocdepth() const;
171 /// Can be LaTeX, DocBook, etc.
172 OutputType outputType() const;
175 FontInfo const & defaultfont() const;
177 /// Text that dictates how wide the left margin is on the screen
178 docstring const & leftmargin() const;
180 /// Text that dictates how wide the right margin is on the screen
181 docstring const & rightmargin() const;
183 /// The type of command used to produce a title
184 TitleLatexType titletype() const;
185 /// The name of the title command
186 std::string const & titlename() const;
190 /// The minimal TocLevel of sectioning layouts
191 int min_toclevel() const;
192 /// The maximal TocLevel of sectioning layouts
193 int max_toclevel() const;
194 /// returns true if the class has a ToC structure
195 bool hasTocLevels() const;
197 static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
200 bool deleteLayout(docstring const &);
201 /// \return true for success.
202 bool readStyle(Lexer &, Layout &);
205 /// document class name
206 std::string latexname_;
207 /// document class description
208 std::string description_;
209 /// whether this is a modular layout, i.e., whether it has been
210 /// modified by loading of layout modules.
213 std::string opt_fontsize_;
215 std::string opt_pagestyle_;
216 /// Specific class options
217 std::string options_;
219 std::string pagestyle_;
221 std::string class_header_;
223 docstring defaultlayout_;
224 /// name of empty layout
225 static const docstring emptylayout_;
226 /// preamble text to support layout styles
228 /// latex packages loaded by document class.
229 std::set<std::string> provides_;
230 /// latex packages requested by document class.
231 std::set<std::string> requires_;
233 unsigned int columns_;
236 /// header depth to have numbering
238 /// header depth to appear in table of contents
240 /// Can be LaTeX, DocBook, etc.
241 OutputType outputType_;
242 /** Base font. The paragraph and layout fonts are resolved against
243 this font. This has to be fully instantiated. Attributes
244 FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
247 FontInfo defaultfont_;
248 /// Text that dictates how wide the left margin is on the screen
249 docstring leftmargin_;
251 /// Text that dictates how wide the right margin is on the screen
252 docstring rightmargin_;
254 /// The type of command used to produce a title
255 TitleLatexType titletype_;
256 /// The name of the title command
257 std::string titlename_;
259 /// Paragraph styles used in this layout
260 LayoutList layoutlist_;
262 /// Input layouts available to this layout
263 mutable InsetLayouts insetlayoutlist_;
265 /// available types of float, eg. figure, algorithm.
266 boost::shared_ptr<FloatList> floatlist_;
268 /// Types of counters, eg. sections, eqns, figures, avail. in document class.
269 boost::shared_ptr<Counters> counters_;
271 /// Has this layout file been loaded yet?
272 mutable bool loaded_;
274 /// Is the TeX class available?
277 /// The minimal TocLevel of sectioning layouts
279 /// The maximal TocLevel of sectioning layouts
282 static InsetLayout empty_insetlayout_;
286 /// convert page sides option to text 1 or 2
287 std::ostream & operator<<(std::ostream & os, PageSides p);