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