]> git.lyx.org Git - lyx.git/blob - src/lyxtextclass.h
don't rm emergency saves ever
[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 "LString.h"
15 #include "lyxlayout_ptr_fwd.h"
16
17 #include "support/types.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include <vector>
22
23 class LyXLex;
24 class Counters;
25 class FloatList;
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         LyXLayout_ptr const & getEnv(string const & vname) const;
70
71         /// Sees to that the textclass structure has been loaded
72         bool load() const;
73
74         /// the list of floats defined in the document class
75         FloatList & floats();
76         /// the list of floats defined in the document class
77         FloatList const & floats() const;
78         /// The Counters present in this document class.
79         Counters & counters() const;
80         ///
81         string const & defaultLayoutName() const;
82         ///
83         LyXLayout_ptr const & defaultLayout() const;
84         ///
85         string const & name() const;
86         ///
87         string const & latexname() const;
88         ///
89         string const & description() const;
90         ///
91         string const & opt_fontsize() const;
92         ///
93         string const & opt_pagestyle() const;
94         ///
95         string const & options() const;
96         ///
97         string const & pagestyle() const;
98         ///
99         string const & preamble() const;
100
101         /// Packages that are already loaded by the class
102         enum Provides {
103                 ///
104                 nothing = 0,
105                 ///
106                 amsmath = 1,
107                 ///
108                 makeidx = 2,
109                 ///
110                 url = 4,
111                 ///
112                 natbib = 8
113         };
114         ///
115         bool provides(Provides p) const;
116
117         ///
118         unsigned int columns() const;
119         ///
120         enum PageSides {
121                 ///
122                 OneSide,
123                 ///
124                 TwoSides
125         };
126         ///
127         PageSides sides() const;
128         ///
129         int secnumdepth() const;
130         ///
131         int tocdepth() const;
132
133         /// Can be LaTeX, LinuxDoc, etc.
134         OutputType outputType() const;
135
136         ///
137         LyXFont const & defaultfont() const;
138
139         /// Text that dictates how wide the left margin is on the screen
140         string const & leftmargin() const;
141
142         /// Text that dictates how wide the right margin is on the screen
143         string const & rightmargin() const;
144         ///
145         int maxcounter() const;
146
147         /// The type of command used to produce a title
148         LYX_TITLE_LATEX_TYPES titletype() const;
149         /// The name of the title command
150         string const & titlename() const;
151
152         ///
153         int size() const;
154 private:
155         ///
156         bool delete_layout(string const &);
157         ///
158         bool delete_env(string const &);
159         ///
160         bool do_readStyle(LyXLex &, LyXLayout &);
161         /// Layout file name
162         string name_;
163         /// document class name
164         string latexname_;
165         /// document class description
166         string description_;
167         /// Specific class options
168         string opt_fontsize_;
169         ///
170         string opt_pagestyle_;
171         ///
172         string options_;
173         ///
174         string pagestyle_;
175         ///
176         string defaultlayout_;
177         /// preamble text to support layout styles
178         string preamble_;
179         /// latex packages loaded by document class.
180         Provides provides_;
181         ///
182         unsigned int columns_;
183         ///
184         PageSides sides_;
185         /// header depth to have numbering
186         int secnumdepth_;
187         /// header depth to appear in table of contents
188         int tocdepth_;
189         /// Can be LaTeX, LinuxDoc, etc.
190         OutputType outputType_;
191         /** Base font. The paragraph and layout fonts are resolved against
192             this font. This has to be fully instantiated. Attributes
193             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
194             extremely illegal.
195         */
196         LyXFont defaultfont_;
197         /// Text that dictates how wide the left margin is on the screen
198         string leftmargin_;
199
200         /// Text that dictates how wide the right margin is on the screen
201         string rightmargin_;
202         /// highest header level used in this layout.
203         int maxcounter_; // add approp. signedness
204
205         /// The type of command used to produce a title
206         LYX_TITLE_LATEX_TYPES titletype_;
207         /// The name of the title command
208         string titlename_;
209
210         /// Paragraph styles used in this layout
211         LayoutList layoutlist_;
212
213         /// Environment styles used in this layout
214         LayoutList envlist_;
215
216         /// available types of float, eg. figure, algorithm.
217         boost::shared_ptr<FloatList> floatlist_;
218
219         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
220         boost::shared_ptr<Counters> ctrs_;
221
222         /// Has this layout file been loaded yet?
223         mutable bool loaded;
224
225         /// Is the TeX class available?
226         bool texClassAvail_;
227 };
228
229
230 /// Merge two different provides flags into one bit field record
231 inline
232 void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
233 {
234         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
235 }
236
237
238 /// convert page sides option to text 1 or 2
239 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);
240
241 #endif