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