]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
ad2d28f7ac5c3dc8263d6e9509ba6dd4d3a57a38
[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 InsetLayout {
33 public:
34         std::string name;
35         std::string lyxtype;
36         docstring labelstring;
37         std::string decoration;
38         std::string latextype;
39         std::string latexname;
40         std::string latexparam;
41         Font font;
42         Font labelfont;
43         std::string preamble;
44 };
45
46
47 /// List of semantically defined character style insets
48 typedef std::vector<InsetLayout> CharStyles;
49
50 /// List of inset layouts
51 typedef std::map<docstring, InsetLayout> InsetLayouts;
52
53 /// Stores the layout specification of a LyX document class.
54 class TextClass {
55 public:
56         /// The individual styles comprising the document class
57         typedef std::vector<LayoutPtr> LayoutList;
58         /// Enumerate the paragraph styles.
59         typedef LayoutList::const_iterator const_iterator;
60         /// Construct a layout with default values. Actual values loaded later.
61         explicit
62         TextClass(std::string const & = std::string(),
63                      std::string const & = std::string(),
64                      std::string const & = std::string(),
65                      bool = false);
66
67         /// check whether the TeX class is available
68         bool isTeXClassAvailable() const;
69
70         /// paragraph styles begin iterator.
71         const_iterator begin() const { return layoutlist_.begin(); }
72         /// paragraph styles end iterator
73         const_iterator end() const { return layoutlist_.end(); }
74
75         /// Performs the read of the layout file.
76         bool read(support::FileName const & filename, bool merge = false);
77         ///
78         void readOutputType(Lexer &);
79         ///
80         void readTitleType(Lexer &);
81         ///
82         void readMaxCounter(Lexer &);
83         ///
84         void readClassOptions(Lexer &);
85         ///
86         void readCharStyle(Lexer &, std::string const &);
87         ///
88         void readInsetLayout(Lexer &, docstring const &);
89         ///
90         void readFloat(Lexer &);
91         ///
92         void readCounter(Lexer &);
93         ///
94         bool hasLayout(docstring const & name) const;
95
96         ///
97         LayoutPtr const & operator[](docstring const & vname) const;
98
99         /// Sees to that the textclass structure has been loaded
100         bool load(std::string const & path = std::string()) const;
101         /// Has this layout file been loaded yet?
102         bool loaded() const { return loaded_; }
103
104         /// the list of floats defined in the document class
105         FloatList & floats();
106         /// the list of floats defined in the document class
107         FloatList const & floats() const;
108         /// The Counters present in this document class.
109         Counters & counters() const;
110         /// CharStyles of this doc class
111         CharStyles & charstyles() const { return charstylelist_; };
112         /// Inset layouts of this doc class
113         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
114         ///
115         InsetLayout const & insetlayout(docstring const & name) const;
116         /// Retrieve element of name s:
117         CharStyles::iterator charstyle(std::string const & s) 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