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