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