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