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