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