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