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