]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
rename TextClass::ctrs_ to counters_
[lyx.git] / src / TextClass.h
1 // -*- C++ -*-
2 /**
3  * \file TextClass.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * Full author contact details are available in file CREDITS.
8  */
9
10 #ifndef LYXTEXTCLASS_H
11 #define LYXTEXTCLASS_H
12
13 #include "Layout.h"
14 #include "lyxlayout_ptr_fwd.h"
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <vector>
19 #include <set>
20 #include <map>
21
22 namespace lyx {
23
24 namespace support { class FileName; }
25
26 class Lexer;
27 class Counters;
28 class FloatList;
29
30
31 ///
32 class CharStyle {
33 public:
34         std::string name;
35         std::string latextype;
36         std::string latexname;
37         std::string latexparam;
38         Font font;
39         Font labelfont;
40         docstring preamble;
41 };
42
43
44 class InsetLayout {
45 public:
46         docstring labelstring;
47         std::string latextype;
48         std::string latexname;
49         std::string latexparam;
50         Font font;
51         Font labelfont;
52         docstring preamble;
53 };
54
55
56 /// List of semantically defined character style insets
57 typedef std::vector<CharStyle> CharStyles;
58
59 /// List of inset layouts
60 typedef std::map<docstring, InsetLayout> InsetLayouts;
61
62 /// Stores the layout specification of a LyX document class.
63 class TextClass {
64 public:
65         /// The individual styles comprising the document class
66         typedef std::vector<Layout_ptr> LayoutList;
67         /// Enumerate the paragraph styles.
68         typedef LayoutList::const_iterator const_iterator;
69         /// Construct a layout with default values. Actual values loaded later.
70         explicit
71         TextClass(std::string const & = std::string(),
72                      std::string const & = std::string(),
73                      std::string const & = std::string(),
74                      bool = false);
75
76         /// check whether the TeX class is available
77         bool isTeXClassAvailable() const;
78
79         /// paragraph styles begin iterator.
80         const_iterator begin() const { return layoutlist_.begin(); }
81         /// paragraph styles end iterator
82         const_iterator end() const { return layoutlist_.end(); }
83
84         /// Performs the read of the layout file.
85         bool read(support::FileName const & filename, bool merge = false);
86         ///
87         void readOutputType(Lexer &);
88         ///
89         void readTitleType(Lexer &);
90         ///
91         void readMaxCounter(Lexer &);
92         ///
93         void readClassOptions(Lexer &);
94         ///
95         void readCharStyle(Lexer &, std::string const &);
96         ///
97         void readInsetLayout(Lexer &, docstring const &);
98         ///
99         void readFloat(Lexer &);
100         ///
101         void readCounter(Lexer &);
102         ///
103         bool hasLayout(docstring const & name) const;
104
105         ///
106         Layout_ptr const & operator[](docstring const & vname) const;
107
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         bool loaded() const { return loaded_; }
112
113         /// the list of floats defined in the document class
114         FloatList & floats();
115         /// the list of floats defined in the document class
116         FloatList const & floats() const;
117         /// The Counters present in this document class.
118         Counters & counters() const;
119         /// CharStyles of this doc class
120         CharStyles & charstyles() const { return charstylelist_; };
121         ///  Inset layouts of this doc class
122         InsetLayout const & insetlayout(docstring const & name) const;
123         /// Retrieve element of name s:
124         CharStyles::iterator charstyle(std::string const & s) const;
125         ///
126         docstring const & defaultLayoutName() const;
127         ///
128         Layout_ptr const & defaultLayout() const;
129         ///
130         std::string const & name() const;
131         ///
132         docstring const & labelstring() const;
133         ///
134         std::string const & latexname() const;
135         ///
136         std::string const & description() const;
137         ///
138         std::string const & opt_fontsize() const;
139         ///
140         std::string const & opt_pagestyle() const;
141         ///
142         std::string const & options() const;
143         ///
144         std::string const & class_header() const;
145         ///
146         std::string const & pagestyle() const;
147         ///
148         docstring const & preamble() const;
149
150         /// is this feature already provided by the class?
151         bool provides(std::string const & p) const;
152
153         ///
154         unsigned int columns() const;
155         ///
156         enum PageSides {
157                 ///
158                 OneSide,
159                 ///
160                 TwoSides
161         };
162         ///
163         PageSides sides() const;
164         ///
165         int secnumdepth() const;
166         ///
167         int tocdepth() const;
168
169         /// Can be LaTeX, DocBook, etc.
170         OutputType outputType() const;
171
172         ///
173         Font const & defaultfont() const;
174
175         /// Text that dictates how wide the left margin is on the screen
176         std::string const & leftmargin() const;
177
178         /// Text that dictates how wide the right margin is on the screen
179         std::string const & rightmargin() const;
180
181         /// The type of command used to produce a title
182         LYX_TITLE_LATEX_TYPES titletype() const;
183         /// The name of the title command
184         std::string const & titlename() const;
185
186         ///
187         int size() const;
188         /// The minimal TocLevel of sectioning layouts
189         int min_toclevel() const;
190         /// The maximal TocLevel of sectioning layouts
191         int max_toclevel() const;
192         /// returns true if the class has a ToC structure
193         bool hasTocLevels() const;
194 private:
195         ///
196         bool delete_layout(docstring const &);
197         ///
198         bool do_readStyle(Lexer &, Layout &);
199         /// Layout file name
200         std::string name_;
201         /// document class name
202         std::string latexname_;
203         /// document class description
204         std::string description_;
205         /// Specific class options
206         std::string opt_fontsize_;
207         ///
208         std::string opt_pagestyle_;
209         ///
210         std::string options_;
211         ///
212         std::string pagestyle_;
213         ///
214         std::string class_header_;
215         ///
216         docstring defaultlayout_;
217         /// preamble text to support layout styles
218         docstring preamble_;
219         /// latex packages loaded by document class.
220         std::set<std::string> provides_;
221         ///
222         unsigned int columns_;
223         ///
224         PageSides sides_;
225         /// header depth to have numbering
226         int secnumdepth_;
227         /// header depth to appear in table of contents
228         int tocdepth_;
229         /// Can be LaTeX, DocBook, etc.
230         OutputType outputType_;
231         /** Base font. The paragraph and layout fonts are resolved against
232             this font. This has to be fully instantiated. Attributes
233             Font::INHERIT, Font::IGNORE, and Font::TOGGLE are
234             extremely illegal.
235         */
236         Font defaultfont_;
237         /// Text that dictates how wide the left margin is on the screen
238         std::string leftmargin_;
239
240         /// Text that dictates how wide the right margin is on the screen
241         std::string rightmargin_;
242
243         /// The type of command used to produce a title
244         LYX_TITLE_LATEX_TYPES titletype_;
245         /// The name of the title command
246         std::string titlename_;
247
248         /// Paragraph styles used in this layout
249         LayoutList layoutlist_;
250         /// CharStyles available to this layout
251         mutable CharStyles charstylelist_;
252
253         /// Input layouts available to this layout
254         mutable InsetLayouts insetlayoutlist_;
255
256         /// available types of float, eg. figure, algorithm.
257         boost::shared_ptr<FloatList> floatlist_;
258
259         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
260         boost::shared_ptr<Counters> counters_;
261
262         /// Has this layout file been loaded yet?
263         mutable bool loaded_;
264
265         /// Is the TeX class available?
266         bool texClassAvail_;
267
268         /// The minimal TocLevel of sectioning layouts
269         int min_toclevel_;
270         /// The maximal TocLevel of sectioning layouts
271         int max_toclevel_;
272 };
273
274
275 /// convert page sides option to text 1 or 2
276 std::ostream & operator<<(std::ostream & os, TextClass::PageSides p);
277
278
279 } // namespace lyx
280
281 #endif