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