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