]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
e3a4a66fb37d57400a68b4f997e5ee0e16d91279
[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 "Font.h"
15 #include "LayoutEnums.h"
16 #include "LayoutPtr.h"
17
18 #include <boost/shared_ptr.hpp>
19
20 #include <vector>
21 #include <set>
22 #include <map>
23
24 namespace lyx {
25
26 namespace support { class FileName; }
27
28 class Layout;
29 class Lexer;
30 class Counters;
31 class FloatList;
32
33
34 ///
35 class InsetLayout {
36 public:
37         std::string name;
38         std::string lyxtype;
39         docstring labelstring;
40         std::string decoration;
41         std::string latextype;
42         std::string latexname;
43         std::string latexparam;
44         Font font;
45         Font labelfont;
46         Color::color bgcolor;
47         std::string preamble;
48         bool multipar;
49         bool verbatim;
50 };
51
52
53 /// List of inset layouts
54 typedef std::map<docstring, InsetLayout> InsetLayouts;
55
56 /// Stores the layout specification of a LyX document class.
57 class TextClass {
58 public:
59         /// The individual styles comprising the document class
60         typedef std::vector<LayoutPtr> LayoutList;
61         /// Enumerate the paragraph styles.
62         typedef LayoutList::const_iterator const_iterator;
63         /// Construct a layout with default values. Actual values loaded later.
64         explicit
65         TextClass(std::string const & = std::string(),
66                      std::string const & = std::string(),
67                      std::string const & = std::string(),
68                      bool texClassAvail = false);
69         
70         /// check whether the TeX class is available
71         bool isTeXClassAvailable() const;
72
73         /// paragraph styles begin iterator.
74         const_iterator begin() const { return layoutlist_.begin(); }
75         /// paragraph styles end iterator
76         const_iterator end() const { return layoutlist_.end(); }
77
78         ///Enum used with TextClass::read
79         enum ReadType { 
80                 BASECLASS, //>This is a base class, i.e., top-level layout file
81                 MERGE, //>This is a file included in a layout file
82                 MODULE //>This is a layout module
83         };
84         /// Performs the read of the layout file.
85         bool read(support::FileName const & filename, ReadType rt = BASECLASS);
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         LayoutPtr 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         /// Inset layouts of this doc class
120         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
121         ///
122         InsetLayout const & insetlayout(docstring const & name) const;
123         ///
124         docstring const & defaultLayoutName() const;
125         ///
126         LayoutPtr const & defaultLayout() const;
127         ///
128         std::string const & name() const;
129         ///
130         docstring const & labelstring() const;
131         ///
132         std::string const & latexname() const;
133         ///
134         std::string const & description() const;
135         ///
136         bool isModular() const { return modular_; }
137         /// Sets the layout as a modular one. There is never any
138         /// need to reset this.
139         void markAsModular() { modular_ = true; }
140         ///
141         std::string const & opt_fontsize() const;
142         ///
143         std::string const & opt_pagestyle() const;
144         ///
145         std::string const & options() const;
146         ///
147         std::string const & class_header() const;
148         ///
149         std::string const & pagestyle() const;
150         ///
151         docstring const & preamble() const;
152
153         /// is this feature already provided by the class?
154         bool provides(std::string const & p) const;
155
156         ///
157         unsigned int columns() const;
158         ///
159         enum PageSides {
160                 ///
161                 OneSide,
162                 ///
163                 TwoSides
164         };
165         ///
166         PageSides sides() const;
167         ///
168         int secnumdepth() const;
169         ///
170         int tocdepth() const;
171
172         /// Can be LaTeX, DocBook, etc.
173         OutputType outputType() const;
174
175         ///
176         Font const & defaultfont() const;
177
178         /// Text that dictates how wide the left margin is on the screen
179         docstring const & leftmargin() const;
180
181         /// Text that dictates how wide the right margin is on the screen
182         docstring const & rightmargin() const;
183
184         /// The type of command used to produce a title
185         TitleLatexType titletype() const;
186         /// The name of the title command
187         std::string const & titlename() const;
188
189         ///
190         int size() const;
191         /// The minimal TocLevel of sectioning layouts
192         int min_toclevel() const;
193         /// The maximal TocLevel of sectioning layouts
194         int max_toclevel() const;
195         /// returns true if the class has a ToC structure
196         bool hasTocLevels() const;
197 private:
198         ///
199         bool delete_layout(docstring const &);
200         ///
201         bool do_readStyle(Lexer &, Layout &);
202         /// Layout file name
203         std::string name_;
204         /// document class name
205         std::string latexname_;
206         /// document class description
207         std::string description_;
208         /// whether this is a modular layout, i.e., whether it has been
209         /// modified by loading of layout modules.
210         bool modular_;
211         ///
212         std::string opt_fontsize_;
213         ///
214         std::string opt_pagestyle_;
215         /// Specific class options
216         std::string options_;
217         ///
218         std::string pagestyle_;
219         ///
220         std::string class_header_;
221         ///
222         docstring defaultlayout_;
223         /// preamble text to support layout styles
224         docstring preamble_;
225         /// latex packages loaded by document class.
226         std::set<std::string> provides_;
227         ///
228         unsigned int columns_;
229         ///
230         PageSides sides_;
231         /// header depth to have numbering
232         int secnumdepth_;
233         /// header depth to appear in table of contents
234         int tocdepth_;
235         /// Can be LaTeX, DocBook, etc.
236         OutputType outputType_;
237         /** Base font. The paragraph and layout fonts are resolved against
238             this font. This has to be fully instantiated. Attributes
239             Font::INHERIT, Font::IGNORE, and Font::TOGGLE are
240             extremely illegal.
241         */
242         Font defaultfont_;
243         /// Text that dictates how wide the left margin is on the screen
244         docstring leftmargin_;
245
246         /// Text that dictates how wide the right margin is on the screen
247         docstring rightmargin_;
248
249         /// The type of command used to produce a title
250         TitleLatexType titletype_;
251         /// The name of the title command
252         std::string titlename_;
253
254         /// Paragraph styles used in this layout
255         LayoutList layoutlist_;
256
257         /// Input layouts available to this layout
258         mutable InsetLayouts insetlayoutlist_;
259
260         /// available types of float, eg. figure, algorithm.
261         boost::shared_ptr<FloatList> floatlist_;
262
263         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
264         boost::shared_ptr<Counters> counters_;
265
266         /// Has this layout file been loaded yet?
267         mutable bool loaded_;
268
269         /// Is the TeX class available?
270         bool texClassAvail_;
271
272         /// The minimal TocLevel of sectioning layouts
273         int min_toclevel_;
274         /// The maximal TocLevel of sectioning layouts
275         int max_toclevel_;
276 };
277
278
279 /// convert page sides option to text 1 or 2
280 std::ostream & operator<<(std::ostream & os, TextClass::PageSides p);
281
282 /** Shared pointer for possibly modular layout. Needed so that paste,
283  *  for example, will still be able to retain the pointer, even when
284  *  the buffer itself is closed.
285  */
286 typedef boost::shared_ptr<TextClass> TextClassPtr;
287
288
289 } // namespace lyx
290
291 #endif