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