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