]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
last commit was incomplete... not sure how I managed this..
[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 LYXTEXTCLASS_H
11 #define LYXTEXTCLASS_H
12
13 #include "Color.h"
14 #include "Font.h"
15 #include "LayoutEnums.h"
16 #include "lyxlayout_ptr_fwd.h"
17
18 #include <boost/shared_ptr.hpp>
19
20 #include <vector>
21 #include <set>
22 #include <map>
23
24 namespace lyx {
25
26 namespace support { class FileName; }
27
28 class Layout;
29 class Lexer;
30 class Counters;
31 class FloatList;
32
33
34 ///
35 class InsetLayout {
36 public:
37         std::string name;
38         std::string lyxtype;
39         docstring labelstring;
40         std::string decoration;
41         std::string latextype;
42         std::string latexname;
43         std::string latexparam;
44         Font font;
45         Font labelfont;
46         Color::color bgcolor;
47         std::string preamble;
48 };
49
50
51 /// List of inset layouts
52 typedef std::map<docstring, InsetLayout> InsetLayouts;
53
54 /// Stores the layout specification of a LyX document class.
55 class TextClass {
56 public:
57         /// The individual styles comprising the document class
58         typedef std::vector<LayoutPtr> LayoutList;
59         /// Enumerate the paragraph styles.
60         typedef LayoutList::const_iterator const_iterator;
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         /// paragraph styles begin iterator.
72         const_iterator begin() const { return layoutlist_.begin(); }
73         /// paragraph styles end iterator
74         const_iterator end() const { return layoutlist_.end(); }
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         bool read(support::FileName const & filename, ReadType rt = BASECLASS);
84         ///
85         void readOutputType(Lexer &);
86         ///
87         void readTitleType(Lexer &);
88         ///
89         void readMaxCounter(Lexer &);
90         ///
91         void readClassOptions(Lexer &);
92         ///
93         void readCharStyle(Lexer &, std::string const &);
94         ///
95         void readInsetLayout(Lexer &, docstring const &);
96         ///
97         void readFloat(Lexer &);
98         ///
99         void readCounter(Lexer &);
100         ///
101         bool hasLayout(docstring const & name) const;
102
103         ///
104         LayoutPtr const & operator[](docstring const & vname) const;
105
106         /// Sees to that the textclass structure has been loaded
107         bool load(std::string const & path = std::string()) const;
108         /// Has this layout file been loaded yet?
109         bool loaded() const { return loaded_; }
110
111         /// the list of floats defined in the document class
112         FloatList & floats();
113         /// the list of floats defined in the document class
114         FloatList const & floats() const;
115         /// The Counters present in this document class.
116         Counters & counters() const;
117         /// Inset layouts of this doc class
118         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
119         ///
120         InsetLayout const & insetlayout(docstring const & name) const;
121         ///
122         docstring const & defaultLayoutName() const;
123         ///
124         LayoutPtr const & defaultLayout() const;
125         ///
126         std::string const & name() const;
127         ///
128         docstring const & labelstring() const;
129         ///
130         std::string const & latexname() const;
131         ///
132         std::string const & description() const;
133         ///
134         bool isModular() const { return modular_; }
135         /// Sets the layout as a modular one. There is never any
136         /// need to reset this.
137         void markAsModular() { modular_ = true; }
138         ///
139         std::string const & opt_fontsize() const;
140         ///
141         std::string const & opt_pagestyle() const;
142         ///
143         std::string const & options() const;
144         ///
145         std::string const & class_header() const;
146         ///
147         std::string const & pagestyle() const;
148         ///
149         docstring const & preamble() const;
150
151         /// is this feature already provided by the class?
152         bool provides(std::string const & p) const;
153
154         ///
155         unsigned int columns() const;
156         ///
157         enum PageSides {
158                 ///
159                 OneSide,
160                 ///
161                 TwoSides
162         };
163         ///
164         PageSides sides() const;
165         ///
166         int secnumdepth() const;
167         ///
168         int tocdepth() const;
169
170         /// Can be LaTeX, DocBook, etc.
171         OutputType outputType() const;
172
173         ///
174         Font const & defaultfont() const;
175
176         /// Text that dictates how wide the left margin is on the screen
177         docstring const & leftmargin() const;
178
179         /// Text that dictates how wide the right margin is on the screen
180         docstring const & rightmargin() const;
181
182         /// The type of command used to produce a title
183         TitleLatexType titletype() const;
184         /// The name of the title command
185         std::string const & titlename() const;
186
187         ///
188         int size() const;
189         /// The minimal TocLevel of sectioning layouts
190         int min_toclevel() const;
191         /// The maximal TocLevel of sectioning layouts
192         int max_toclevel() const;
193         /// returns true if the class has a ToC structure
194         bool hasTocLevels() const;
195 private:
196         ///
197         bool delete_layout(docstring const &);
198         ///
199         bool do_readStyle(Lexer &, Layout &);
200         /// Layout file name
201         std::string name_;
202         /// document class name
203         std::string latexname_;
204         /// document class description
205         std::string description_;
206         /// whether this is a modular layout, i.e., whether it has been
207         /// modified by loading of layout modules.
208         bool modular_;
209         ///
210         std::string opt_fontsize_;
211         ///
212         std::string opt_pagestyle_;
213         /// Specific class options
214         std::string options_;
215         ///
216         std::string pagestyle_;
217         ///
218         std::string class_header_;
219         ///
220         docstring defaultlayout_;
221         /// preamble text to support layout styles
222         docstring preamble_;
223         /// latex packages loaded by document class.
224         std::set<std::string> provides_;
225         ///
226         unsigned int columns_;
227         ///
228         PageSides sides_;
229         /// header depth to have numbering
230         int secnumdepth_;
231         /// header depth to appear in table of contents
232         int tocdepth_;
233         /// Can be LaTeX, DocBook, etc.
234         OutputType outputType_;
235         /** Base font. The paragraph and layout fonts are resolved against
236             this font. This has to be fully instantiated. Attributes
237             Font::INHERIT, Font::IGNORE, and Font::TOGGLE are
238             extremely illegal.
239         */
240         Font defaultfont_;
241         /// Text that dictates how wide the left margin is on the screen
242         docstring leftmargin_;
243
244         /// Text that dictates how wide the right margin is on the screen
245         docstring rightmargin_;
246
247         /// The type of command used to produce a title
248         TitleLatexType titletype_;
249         /// The name of the title command
250         std::string titlename_;
251
252         /// Paragraph styles used in this layout
253         LayoutList layoutlist_;
254
255         /// Input layouts available to this layout
256         mutable InsetLayouts insetlayoutlist_;
257
258         /// available types of float, eg. figure, algorithm.
259         boost::shared_ptr<FloatList> floatlist_;
260
261         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
262         boost::shared_ptr<Counters> counters_;
263
264         /// Has this layout file been loaded yet?
265         mutable bool loaded_;
266
267         /// Is the TeX class available?
268         bool texClassAvail_;
269
270         /// The minimal TocLevel of sectioning layouts
271         int min_toclevel_;
272         /// The maximal TocLevel of sectioning layouts
273         int max_toclevel_;
274 };
275
276
277 /// convert page sides option to text 1 or 2
278 std::ostream & operator<<(std::ostream & os, TextClass::PageSides p);
279
280 /** Shared pointer for possibly modular layout. Needed so that paste,
281  *  for example, will still be able to retain the pointer, even when
282  *  the buffer itself is closed.
283  */
284 typedef boost::shared_ptr<TextClass> TextClassPtr;
285
286
287 } // namespace lyx
288
289 #endif