]> git.lyx.org Git - lyx.git/blob - src/TextClass.h
adjust
[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         bool multipar;
49 };
50
51
52 /// List of inset layouts
53 typedef std::map<docstring, InsetLayout> InsetLayouts;
54
55 /// Stores the layout specification of a LyX document class.
56 class TextClass {
57 public:
58         /// The individual styles comprising the document class
59         typedef std::vector<LayoutPtr> LayoutList;
60         /// Enumerate the paragraph styles.
61         typedef LayoutList::const_iterator const_iterator;
62         /// Construct a layout with default values. Actual values loaded later.
63         explicit
64         TextClass(std::string const & = std::string(),
65                      std::string const & = std::string(),
66                      std::string const & = std::string(),
67                      bool texClassAvail = false);
68         
69         /// check whether the TeX class is available
70         bool isTeXClassAvailable() const;
71
72         /// paragraph styles begin iterator.
73         const_iterator begin() const { return layoutlist_.begin(); }
74         /// paragraph styles end iterator
75         const_iterator end() const { return layoutlist_.end(); }
76
77         ///Enum used with TextClass::read
78         enum ReadType { 
79                 BASECLASS, //>This is a base class, i.e., top-level layout file
80                 MERGE, //>This is a file included in a layout file
81                 MODULE //>This is a layout module
82         };
83         /// Performs the read of the layout file.
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 readInsetLayout(Lexer &, docstring 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         ///
127         std::string const & name() const;
128         ///
129         docstring const & labelstring() const;
130         ///
131         std::string const & latexname() const;
132         ///
133         std::string const & description() const;
134         ///
135         bool isModular() const { return modular_; }
136         /// Sets the layout as a modular one. There is never any
137         /// need to reset this.
138         void markAsModular() { modular_ = true; }
139         ///
140         std::string const & opt_fontsize() const;
141         ///
142         std::string const & opt_pagestyle() const;
143         ///
144         std::string const & options() const;
145         ///
146         std::string const & class_header() const;
147         ///
148         std::string const & pagestyle() const;
149         ///
150         docstring const & preamble() const;
151
152         /// is this feature already provided by the class?
153         bool provides(std::string const & p) const;
154
155         ///
156         unsigned int columns() const;
157         ///
158         enum PageSides {
159                 ///
160                 OneSide,
161                 ///
162                 TwoSides
163         };
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         Font 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 private:
197         ///
198         bool delete_layout(docstring const &);
199         ///
200         bool do_readStyle(Lexer &, Layout &);
201         /// Layout file name
202         std::string name_;
203         /// document class name
204         std::string latexname_;
205         /// document class description
206         std::string description_;
207         /// whether this is a modular layout, i.e., whether it has been
208         /// modified by loading of layout modules.
209         bool modular_;
210         ///
211         std::string opt_fontsize_;
212         ///
213         std::string opt_pagestyle_;
214         /// Specific class options
215         std::string options_;
216         ///
217         std::string pagestyle_;
218         ///
219         std::string class_header_;
220         ///
221         docstring defaultlayout_;
222         /// preamble text to support layout styles
223         docstring preamble_;
224         /// latex packages loaded by document class.
225         std::set<std::string> provides_;
226         ///
227         unsigned int columns_;
228         ///
229         PageSides sides_;
230         /// header depth to have numbering
231         int secnumdepth_;
232         /// header depth to appear in table of contents
233         int tocdepth_;
234         /// Can be LaTeX, DocBook, etc.
235         OutputType outputType_;
236         /** Base font. The paragraph and layout fonts are resolved against
237             this font. This has to be fully instantiated. Attributes
238             Font::INHERIT, Font::IGNORE, and Font::TOGGLE are
239             extremely illegal.
240         */
241         Font defaultfont_;
242         /// Text that dictates how wide the left margin is on the screen
243         docstring leftmargin_;
244
245         /// Text that dictates how wide the right margin is on the screen
246         docstring rightmargin_;
247
248         /// The type of command used to produce a title
249         TitleLatexType titletype_;
250         /// The name of the title command
251         std::string titlename_;
252
253         /// Paragraph styles used in this layout
254         LayoutList layoutlist_;
255
256         /// Input layouts available to this layout
257         mutable InsetLayouts insetlayoutlist_;
258
259         /// available types of float, eg. figure, algorithm.
260         boost::shared_ptr<FloatList> floatlist_;
261
262         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
263         boost::shared_ptr<Counters> counters_;
264
265         /// Has this layout file been loaded yet?
266         mutable bool loaded_;
267
268         /// Is the TeX class available?
269         bool texClassAvail_;
270
271         /// The minimal TocLevel of sectioning layouts
272         int min_toclevel_;
273         /// The maximal TocLevel of sectioning layouts
274         int max_toclevel_;
275 };
276
277
278 /// convert page sides option to text 1 or 2
279 std::ostream & operator<<(std::ostream & os, TextClass::PageSides p);
280
281 /** Shared pointer for possibly modular layout. Needed so that paste,
282  *  for example, will still be able to retain the pointer, even when
283  *  the buffer itself is closed.
284  */
285 typedef boost::shared_ptr<TextClass> TextClassPtr;
286
287
288 } // namespace lyx
289
290 #endif