]> git.lyx.org Git - lyx.git/blob - src/lyxtextclass.h
typos
[lyx.git] / src / lyxtextclass.h
1 // -*- C++ -*-
2 /**
3  * \file lyxtextclass.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 "lyxlayout.h"
14 #include "lyxlayout_ptr_fwd.h"
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <vector>
19
20
21 namespace lyx {
22
23 namespace support { class FileName; }
24
25 class LyXLex;
26 class Counters;
27 class FloatList;
28
29
30 ///
31 class CharStyle {
32 public:
33         std::string name;
34         std::string latextype;
35         std::string latexname;
36         std::string latexparam;
37         LyXFont font;
38         LyXFont labelfont;
39         docstring preamble;
40 };
41
42
43 /// List of semantically defined character style insets
44 typedef std::vector<CharStyle> CharStyles;
45
46
47 /// Stores the layout specification of a LyX document class.
48 class LyXTextClass {
49 public:
50         /// The individual styles comprising the document class
51         typedef std::vector<LyXLayout_ptr> LayoutList;
52         /// Enumerate the paragraph styles.
53         typedef LayoutList::const_iterator const_iterator;
54         /// Construct a layout with default values. Actual values loaded later.
55         explicit
56         LyXTextClass(std::string const & = std::string(),
57                      std::string const & = std::string(),
58                      std::string const & = std::string(),
59                      bool = false);
60
61         /// check whether the TeX class is available
62         bool isTeXClassAvailable() const;
63
64         /// paragraph styles begin iterator.
65         const_iterator begin() const { return layoutlist_.begin(); }
66         /// paragraph styles end iterator
67         const_iterator end() const { return layoutlist_.end(); }
68
69         /// Performs the read of the layout file.
70         bool read(support::FileName const & filename, bool merge = false);
71         ///
72         void readOutputType(LyXLex &);
73         ///
74         void readTitleType(LyXLex &);
75         ///
76         void readMaxCounter(LyXLex &);
77         ///
78         void readClassOptions(LyXLex &);
79         ///
80         void readCharStyle(LyXLex &, std::string const &);
81         ///
82         void readFloat(LyXLex &);
83         ///
84         void readCounter(LyXLex &);
85         ///
86         bool hasLayout(std::string const & name) const;
87
88         ///
89         LyXLayout_ptr const & operator[](std::string const & vname) const;
90
91         /// Sees to that the textclass structure has been loaded
92         bool load(std::string const & path = std::string()) const;
93         /// Has this layout file been loaded yet?
94         bool loaded() const { return loaded_; }
95
96         /// the list of floats defined in the document class
97         FloatList & floats();
98         /// the list of floats defined in the document class
99         FloatList const & floats() const;
100         /// The Counters present in this document class.
101         Counters & counters() const;
102         /// CharStyles of this doc class
103         CharStyles & charstyles() const { return charstylelist_; };
104         /// Retrieve element of name s:
105         CharStyles::iterator charstyle(std::string const & s) const;
106         ///
107         std::string const & defaultLayoutName() const;
108         ///
109         LyXLayout_ptr const & defaultLayout() const;
110         ///
111         std::string const & name() const;
112         ///
113         std::string const & latexname() const;
114         ///
115         std::string const & description() const;
116         ///
117         std::string const & opt_fontsize() const;
118         ///
119         std::string const & opt_pagestyle() const;
120         ///
121         std::string const & options() const;
122         ///
123         std::string const & class_header() const;
124         ///
125         std::string const & pagestyle() const;
126         ///
127         docstring const & preamble() const;
128
129         /// Packages that are already loaded by the class
130         enum Provides {
131                 ///
132                 nothing = 0,
133                 ///
134                 amsmath = 1,
135                 ///
136                 makeidx = 2,
137                 ///
138                 url = 4,
139                 ///
140                 natbib = 8
141         };
142         ///
143         bool provides(Provides p) const;
144
145         ///
146         unsigned int columns() const;
147         ///
148         enum PageSides {
149                 ///
150                 OneSide,
151                 ///
152                 TwoSides
153         };
154         ///
155         PageSides sides() const;
156         ///
157         int secnumdepth() const;
158         ///
159         int tocdepth() const;
160
161         /// Can be LaTeX, DocBook, etc.
162         OutputType outputType() const;
163
164         ///
165         LyXFont const & defaultfont() const;
166
167         /// Text that dictates how wide the left margin is on the screen
168         std::string const & leftmargin() const;
169
170         /// Text that dictates how wide the right margin is on the screen
171         std::string const & rightmargin() const;
172
173         /// The type of command used to produce a title
174         LYX_TITLE_LATEX_TYPES titletype() const;
175         /// The name of the title command
176         std::string const & titlename() const;
177
178         ///
179         int size() const;
180         /// The minimal TocLevel of sectioning layouts
181         int min_toclevel() const;
182         /// The maximal TocLevel of sectioning layouts
183         int max_toclevel() const;
184         /// returns true if the class has a ToC structure
185         bool hasTocLevels() const;
186 private:
187         ///
188         bool delete_layout(std::string const &);
189         ///
190         bool do_readStyle(LyXLex &, LyXLayout &);
191         /// Layout file name
192         std::string name_;
193         /// document class name
194         std::string latexname_;
195         /// document class description
196         std::string description_;
197         /// Specific class options
198         std::string opt_fontsize_;
199         ///
200         std::string opt_pagestyle_;
201         ///
202         std::string options_;
203         ///
204         std::string pagestyle_;
205         ///
206         std::string class_header_;
207         ///
208         std::string defaultlayout_;
209         /// preamble text to support layout styles
210         docstring preamble_;
211         /// latex packages loaded by document class.
212         Provides provides_;
213         ///
214         unsigned int columns_;
215         ///
216         PageSides sides_;
217         /// header depth to have numbering
218         int secnumdepth_;
219         /// header depth to appear in table of contents
220         int tocdepth_;
221         /// Can be LaTeX, DocBook, etc.
222         OutputType outputType_;
223         /** Base font. The paragraph and layout fonts are resolved against
224             this font. This has to be fully instantiated. Attributes
225             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
226             extremely illegal.
227         */
228         LyXFont defaultfont_;
229         /// Text that dictates how wide the left margin is on the screen
230         std::string leftmargin_;
231
232         /// Text that dictates how wide the right margin is on the screen
233         std::string rightmargin_;
234
235         /// The type of command used to produce a title
236         LYX_TITLE_LATEX_TYPES titletype_;
237         /// The name of the title command
238         std::string titlename_;
239
240         /// Paragraph styles used in this layout
241         LayoutList layoutlist_;
242         /// CharStyles available to this layout
243         mutable CharStyles charstylelist_;
244
245         /// available types of float, eg. figure, algorithm.
246         boost::shared_ptr<FloatList> floatlist_;
247
248         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
249         boost::shared_ptr<Counters> ctrs_;
250
251         /// Has this layout file been loaded yet?
252         mutable bool loaded_;
253
254         /// Is the TeX class available?
255         bool texClassAvail_;
256
257         /// The minimal TocLevel of sectioning layouts
258         int min_toclevel_;
259         /// The maximal TocLevel of sectioning layouts
260         int max_toclevel_;
261 };
262
263
264 /// Merge two different provides flags into one bit field record
265 inline
266 void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
267 {
268         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
269 }
270
271
272 /// convert page sides option to text 1 or 2
273 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);
274
275
276 } // namespace lyx
277
278 #endif