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