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