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