]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
644fb9c153cbed07a8de954cb5dded5f4d1eb1c1
[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 TEXTCLASS_H
11 #define TEXTCLASS_H
12
13 #include "ColorCode.h"
14 #include "FontInfo.h"
15 #include "LayoutEnums.h"
16 #include "LayoutPtr.h"
17
18 #include "insets/InsetLayout.h"
19
20 #include "support/docstring.h"
21 #include "support/types.h"
22
23 #include <boost/shared_ptr.hpp>
24
25 #include <vector>
26 #include <set>
27 #include <map>
28
29 namespace lyx {
30
31 namespace support { class FileName; }
32
33 class Layout;
34 class Lexer;
35 class Counters;
36 class FloatList;
37
38 /// List of inset layouts
39 typedef std::map<docstring, InsetLayout> InsetLayouts;
40
41 /// Stores the layout specification of a LyX document class.
42 class TextClass {
43 public:
44         /// The individual styles comprising the document class
45         typedef std::vector<LayoutPtr> LayoutList;
46         /// Enumerate the paragraph styles.
47         typedef LayoutList::const_iterator const_iterator;
48         /// Construct a layout with default values. Actual values loaded later.
49         explicit
50         TextClass(std::string const & = std::string(),
51                      std::string const & = std::string(),
52                      std::string const & = std::string(),
53                      bool texClassAvail = false);
54         
55         /// check whether the TeX class is available
56         bool isTeXClassAvailable() const;
57
58         /// paragraph styles begin iterator.
59         const_iterator begin() const { return layoutlist_.begin(); }
60         /// paragraph styles end iterator
61         const_iterator end() const { return layoutlist_.end(); }
62
63         ///Enum used with TextClass::read
64         enum ReadType { 
65                 BASECLASS, //>This is a base class, i.e., top-level layout file
66                 MERGE, //>This is a file included in a layout file
67                 MODULE //>This is a layout module
68         };
69         /// Performs the read of the layout file.
70         bool read(support::FileName const & filename, ReadType rt = BASECLASS);
71         ///
72         void readOutputType(Lexer &);
73         ///
74         void readTitleType(Lexer &);
75         ///
76         void readMaxCounter(Lexer &);
77         ///
78         void readClassOptions(Lexer &);
79         ///
80         void readCharStyle(Lexer &, std::string const &);
81         ///
82         void readInsetLayout(Lexer &, docstring const &);
83         ///
84         void readFloat(Lexer &);
85         ///
86         void readCounter(Lexer &);
87         ///
88         bool hasLayout(docstring const & name) const;
89
90         ///
91         LayoutPtr const & operator[](docstring const & vname) const;
92
93         /// Sees to that the textclass structure has been loaded
94         bool load(std::string const & path = std::string()) const;
95         /// Has this layout file been loaded yet?
96         bool loaded() const { return loaded_; }
97
98         /// the list of floats defined in the document class
99         FloatList & floats();
100         /// the list of floats defined in the document class
101         FloatList const & floats() const;
102         /// The Counters present in this document class.
103         Counters & counters() const;
104         /// Inset layouts of this doc class
105         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
106         ///
107         InsetLayout const & insetlayout(docstring const & name) const;
108         ///
109         docstring const & defaultLayoutName() const;
110         ///
111         LayoutPtr const & defaultLayout() const;
112         /// returns a special layout for use when we don't really want one,
113         /// e.g., in table cells
114         LayoutPtr const & emptyLayout() const 
115                         { return operator[](emptylayout_); };
116         ///
117         docstring const & emptyLayoutName() const 
118                         { return emptylayout_; }
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         bool isModular() const { return modular_; }
129         /// Sets the layout as a modular one. There is never any
130         /// need to reset this.
131         void markAsModular() { modular_ = true; }
132         ///
133         std::string const & opt_fontsize() const;
134         ///
135         std::string const & opt_pagestyle() const;
136         ///
137         std::string const & options() const;
138         ///
139         std::string const & class_header() const;
140         ///
141         std::string const & pagestyle() const;
142         ///
143         docstring const & preamble() const;
144
145         /// is this feature already provided by the class?
146         bool provides(std::string const & p) const;
147         /// features required by the class?
148         std::set<std::string> const & requires() const { return requires_; }
149
150         ///
151         unsigned int columns() const;
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         FontInfo 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         TitleLatexType 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 deleteLayout(docstring const &);
187         /// \return true for success.
188         bool 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         /// whether this is a modular layout, i.e., whether it has been
196         /// modified by loading of layout modules.
197         bool modular_;
198         ///
199         std::string opt_fontsize_;
200         ///
201         std::string opt_pagestyle_;
202         /// Specific class options
203         std::string options_;
204         ///
205         std::string pagestyle_;
206         ///
207         std::string class_header_;
208         ///
209         docstring defaultlayout_;
210         /// name of empty layout
211         static const docstring emptylayout_;
212         /// preamble text to support layout styles
213         docstring preamble_;
214         /// latex packages loaded by document class.
215         std::set<std::string> provides_;
216         /// latex packages requested by document class.
217         std::set<std::string> requires_;
218         ///
219         unsigned int columns_;
220         ///
221         PageSides sides_;
222         /// header depth to have numbering
223         int secnumdepth_;
224         /// header depth to appear in table of contents
225         int tocdepth_;
226         /// Can be LaTeX, DocBook, etc.
227         OutputType outputType_;
228         /** Base font. The paragraph and layout fonts are resolved against
229             this font. This has to be fully instantiated. Attributes
230             FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
231             extremely illegal.
232         */
233         FontInfo defaultfont_;
234         /// Text that dictates how wide the left margin is on the screen
235         docstring leftmargin_;
236
237         /// Text that dictates how wide the right margin is on the screen
238         docstring rightmargin_;
239
240         /// The type of command used to produce a title
241         TitleLatexType titletype_;
242         /// The name of the title command
243         std::string titlename_;
244
245         /// Paragraph styles used in this layout
246         LayoutList layoutlist_;
247
248         /// Input layouts available to this layout
249         mutable InsetLayouts insetlayoutlist_;
250
251         /// available types of float, eg. figure, algorithm.
252         boost::shared_ptr<FloatList> floatlist_;
253
254         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
255         boost::shared_ptr<Counters> counters_;
256
257         /// Has this layout file been loaded yet?
258         mutable bool loaded_;
259
260         /// Is the TeX class available?
261         bool texClassAvail_;
262
263         /// The minimal TocLevel of sectioning layouts
264         int min_toclevel_;
265         /// The maximal TocLevel of sectioning layouts
266         int max_toclevel_;
267 };
268
269
270 /// convert page sides option to text 1 or 2
271 std::ostream & operator<<(std::ostream & os, PageSides p);
272
273 } // namespace lyx
274
275 #endif