]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
Replace the text class shared ptr by good old index-into-global-list.
[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 /// Index in globel text class list. Basically a 'strong typedef'/
42 class TextClassIndex
43 {
44 public:
45         ///
46         TextClassIndex(size_t t) : data_(t) {}
47         ///
48         operator size_t() const { return data_; }
49 private:
50         ///
51         size_t data_;
52 };
53
54
55
56 /// Stores the layout specification of a LyX document class.
57 class TextClass {
58 public:
59         /// The individual styles comprising the document class
60         typedef std::vector<LayoutPtr> LayoutList;
61         /// Enumerate the paragraph styles.
62         typedef LayoutList::const_iterator const_iterator;
63         /// Construct a layout with default values. Actual values loaded later.
64         explicit
65         TextClass(std::string const & = std::string(),
66                      std::string const & = std::string(),
67                      std::string const & = std::string(),
68                      bool texClassAvail = false);
69         
70         /// check whether the TeX class is available
71         bool isTeXClassAvailable() const;
72
73         /// paragraph styles begin iterator.
74         const_iterator begin() const { return layoutlist_.begin(); }
75         /// paragraph styles end iterator
76         const_iterator end() const { return layoutlist_.end(); }
77
78         ///Enum used with TextClass::read
79         enum ReadType { 
80                 BASECLASS, //>This is a base class, i.e., top-level layout file
81                 MERGE, //>This is a file included in a layout file
82                 MODULE //>This is a layout module
83         };
84         /// Performs the read of the layout file.
85         /// \return true on success.
86         bool read(support::FileName const & filename, ReadType rt = BASECLASS);
87         ///
88         void readOutputType(Lexer &);
89         ///
90         void readTitleType(Lexer &);
91         ///
92         void readMaxCounter(Lexer &);
93         ///
94         void readClassOptions(Lexer &);
95         ///
96         void readCharStyle(Lexer &, std::string 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         /// Inset layouts of this doc class
119         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
120         ///
121         InsetLayout const & insetlayout(docstring const & name) const;
122         ///
123         docstring const & defaultLayoutName() const;
124         ///
125         LayoutPtr const & defaultLayout() const;
126         /// returns a special layout for use when we don't really want one,
127         /// e.g., in table cells
128         LayoutPtr const & emptyLayout() const 
129                         { return operator[](emptylayout_); };
130         ///
131         docstring const & emptyLayoutName() const 
132                         { return emptylayout_; }
133         ///
134         std::string const & name() const;
135         ///
136         docstring const & labelstring() const;
137         ///
138         std::string const & latexname() const;
139         ///
140         std::string const & description() const;
141         ///
142         bool isModular() const { return modular_; }
143         /// Sets the layout as a modular one. There is never any
144         /// need to reset this.
145         void markAsModular() { modular_ = true; }
146         ///
147         std::string const & opt_fontsize() const;
148         ///
149         std::string const & opt_pagestyle() const;
150         ///
151         std::string const & options() const;
152         ///
153         std::string const & class_header() const;
154         ///
155         std::string const & pagestyle() const;
156         ///
157         docstring const & preamble() const;
158
159         /// is this feature already provided by the class?
160         bool provides(std::string const & p) const;
161         /// features required by the class?
162         std::set<std::string> const & requires() const { return requires_; }
163
164         ///
165         unsigned int columns() const;
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         FontInfo 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         TitleLatexType 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         ///
199         static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
200 private:
201         ///
202         bool deleteLayout(docstring const &);
203         /// \return true for success.
204         bool readStyle(Lexer &, Layout &);
205         /// Layout file name
206         std::string name_;
207         /// document class name
208         std::string latexname_;
209         /// document class description
210         std::string description_;
211         /// whether this is a modular layout, i.e., whether it has been
212         /// modified by loading of layout modules.
213         bool modular_;
214         ///
215         std::string opt_fontsize_;
216         ///
217         std::string opt_pagestyle_;
218         /// Specific class options
219         std::string options_;
220         ///
221         std::string pagestyle_;
222         ///
223         std::string class_header_;
224         ///
225         docstring defaultlayout_;
226         /// name of empty layout
227         static const docstring emptylayout_;
228         /// preamble text to support layout styles
229         docstring preamble_;
230         /// latex packages loaded by document class.
231         std::set<std::string> provides_;
232         /// latex packages requested by document class.
233         std::set<std::string> requires_;
234         ///
235         unsigned int columns_;
236         ///
237         PageSides sides_;
238         /// header depth to have numbering
239         int secnumdepth_;
240         /// header depth to appear in table of contents
241         int tocdepth_;
242         /// Can be LaTeX, DocBook, etc.
243         OutputType outputType_;
244         /** Base font. The paragraph and layout fonts are resolved against
245             this font. This has to be fully instantiated. Attributes
246             FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
247             extremely illegal.
248         */
249         FontInfo defaultfont_;
250         /// Text that dictates how wide the left margin is on the screen
251         docstring leftmargin_;
252
253         /// Text that dictates how wide the right margin is on the screen
254         docstring rightmargin_;
255
256         /// The type of command used to produce a title
257         TitleLatexType titletype_;
258         /// The name of the title command
259         std::string titlename_;
260
261         /// Paragraph styles used in this layout
262         LayoutList layoutlist_;
263
264         /// Input layouts available to this layout
265         mutable InsetLayouts insetlayoutlist_;
266
267         /// available types of float, eg. figure, algorithm.
268         boost::shared_ptr<FloatList> floatlist_;
269
270         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
271         boost::shared_ptr<Counters> counters_;
272
273         /// Has this layout file been loaded yet?
274         mutable bool loaded_;
275
276         /// Is the TeX class available?
277         bool texClassAvail_;
278
279         /// The minimal TocLevel of sectioning layouts
280         int min_toclevel_;
281         /// The maximal TocLevel of sectioning layouts
282         int max_toclevel_;
283         ///
284         static InsetLayout empty_insetlayout_;
285 };
286
287
288 /// convert page sides option to text 1 or 2
289 std::ostream & operator<<(std::ostream & os, PageSides p);
290
291 } // namespace lyx
292
293 #endif