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