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