]> git.lyx.org Git - lyx.git/blob - src/Layout.h
Fix compilation on win
[lyx.git] / src / Layout.h
1 // -*- C++ -*-
2 /**
3  * \file Layout.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author André Pönitz
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LAYOUT_H
15 #define LAYOUT_H
16
17 #include "FontInfo.h"
18 #include "LayoutEnums.h"
19 #include "Spacing.h"
20 #include "support/docstring.h"
21
22 #include <set>
23 #include <string>
24
25 namespace lyx {
26
27 class Language;
28 class Lexer;
29 class TextClass;
30
31 /* Fix labels are printed flushright, manual labels flushleft.
32  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
33  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
34  * This seems a funny restriction, but I think other combinations are
35  * not needed, so I will not change it yet.
36  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
37  */
38
39
40 /* There is a parindent and a parskip. Which one is used depends on the
41  * paragraph_separation-flag of the text-object.
42  * BUT: parindent is only thrown away, if a parskip is defined! So if you
43  * want a space between the paragraphs and a parindent at the same time,
44  * you should set parskip to zero and use topsep, parsep and bottomsep.
45  *
46  * The standard layout is an exception: its parindent is only set, if the
47  * previous paragraph is standard too. Well, this is LateX and it is good!
48  */
49
50 ///
51 class Layout {
52 public:
53         ///
54         Layout();
55         /// is this layout a default layout created for an unknown layout
56         bool isUnknown() const { return unknown_; }
57         void setUnknown(bool unknown) { unknown_ = unknown; }
58         /// Reads a layout definition from file
59         /// \return true on success.
60         bool read(Lexer &, TextClass const &);
61         ///
62         void readAlign(Lexer &);
63         ///
64         void readAlignPossible(Lexer &);
65         ///
66         void readLabelType(Lexer &);
67         ///
68         void readEndLabelType(Lexer &);
69         ///
70         void readMargin(Lexer &);
71         ///
72         void readLatexType(Lexer &);
73         ///
74         void readSpacing(Lexer &);
75         ///
76         docstring const & name() const { return name_; };
77         ///
78         void setName(docstring const & n) { name_ = n; }
79         ///
80         docstring const & obsoleted_by() const { return obsoleted_by_; }
81         ///
82         docstring const & depends_on() const { return depends_on_; }
83         ///
84         std::string const & latexname() const { return latexname_; }
85         ///
86         void setLatexName(std::string const & n) { latexname_ = n; }
87         ///
88         docstring const & labelstring() const { return labelstring_; }
89         ///
90         docstring const & endlabelstring() const { return endlabelstring_; }
91         ///
92         docstring const & category() const { return category_; }
93         ///
94         docstring const & preamble() const { return preamble_; }
95         /// Get language dependent macro definitions needed for this layout
96         /// for language \p lang
97         docstring const langpreamble(Language const * lang) const;
98         /// Get language and babel dependent macro definitions needed for
99         /// this layout for language \p lang
100         docstring const babelpreamble(Language const * lang) const;
101         ///
102         std::set<std::string> const & requires() const { return requires_; }
103         ///
104         std::string const & latexparam() const { return latexparam_; }
105         ///
106         std::string const & innertag() const { return innertag_; }
107         ///
108         std::string const & labeltag() const { return labeltag_; }
109         ///
110         std::string const & itemtag() const { return itemtag_; }
111         /// 
112         std::string const & htmltag() const { return htmltag_; }
113         /// 
114         std::string const & htmlattr() const { return htmlattr_; }
115         /// 
116         std::string const & htmlitem() const { return htmlitem_; }
117         /// 
118         std::string const & htmlitemattr() const { return htmlitemattr_; }
119         /// 
120         std::string const & htmllabel() const { return htmllabel_; }
121         /// 
122         std::string const & htmllabelattr() const { return htmllabelattr_; }
123         /// 
124         docstring const & htmlstyle() const { return htmlstyle_; }
125         /// 
126         docstring const & htmlpreamble() const { return htmlpreamble_; }
127         ///
128         docstring const & labelstring_appendix() const {
129                 return labelstring_appendix_;
130         }
131         ///
132         bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
133         ///
134         bool isCommand() const { return latextype == LATEX_COMMAND; }
135         ///
136         bool isEnvironment() const {
137                 return latextype == LATEX_ENVIRONMENT
138                         || latextype == LATEX_BIB_ENVIRONMENT
139                         || latextype == LATEX_ITEM_ENVIRONMENT
140                         || latextype == LATEX_LIST_ENVIRONMENT;
141         }
142
143         ///
144         bool operator==(Layout const &) const;
145         ///
146         bool operator!=(Layout const & rhs) const 
147                 { return !(*this == rhs); }
148
149         ////////////////////////////////////////////////////////////////
150         // members
151         ////////////////////////////////////////////////////////////////
152         /** Default font for this layout/environment.
153             The main font for this kind of environment. If an attribute has
154             INHERITED_*, it means that the value is specified by
155             the defaultfont for the entire layout. If we are nested, the
156             font is inherited from the font in the environment one level
157             up until the font is resolved. The values :IGNORE_*
158             and FONT_TOGGLE are illegal here.
159         */
160         FontInfo font;
161
162         /** Default font for labels.
163             Interpretation the same as for font above
164         */
165         FontInfo labelfont;
166
167         /** Resolved version of the font for this layout/environment.
168             This is a resolved version the default font. The font is resolved
169             against the defaultfont of the entire layout.
170         */
171         FontInfo resfont;
172
173         /** Resolved version of the font used for labels.
174             This is a resolved version the label font. The font is resolved
175             against the defaultfont of the entire layout.
176         */
177         FontInfo reslabelfont;
178
179         /// Text that dictates how wide the left margin is on the screen
180         docstring leftmargin;
181         /// Text that dictates how wide the right margin is on the screen
182         docstring rightmargin;
183         /// Text that dictates how much space to leave after a potential label
184         docstring labelsep;
185         /// Text that dictates how much space to leave before a potential label
186         docstring labelindent;
187         /// Text that dictates the width of the indentation of indented pars
188         docstring parindent;
189         ///
190         double parskip;
191         ///
192         double itemsep;
193         ///
194         double topsep;
195         ///
196         double bottomsep;
197         ///
198         double labelbottomsep;
199         ///
200         double parsep;
201         ///
202         Spacing spacing;
203         ///
204         LyXAlignment align;
205         ///
206         LyXAlignment alignpossible;
207         ///
208         LabelType labeltype;
209         ///
210         EndLabelType endlabeltype;
211         ///
212         MarginType margintype;
213         ///
214         bool fill_top;
215         ///
216         bool fill_bottom;
217         ///
218         bool newline_allowed;
219         ///
220         bool nextnoindent;
221         ///
222         bool free_spacing;
223         ///
224         bool pass_thru;
225         /// show this in toc
226         int toclevel;
227         /// special value of toclevel for non-section layouts
228         static const int NOT_IN_TOC;
229
230         /** true when the fragile commands in the paragraph need to be
231             \protect'ed. */
232         bool needprotect;
233         /// true when empty paragraphs should be kept.
234         bool keepempty;
235         /// Type of LaTeX object
236         LatexType latextype;
237         /// Does this object belong in the title part of the document?
238         bool intitle;
239         /// Does this layout allow for an optional parameter?
240         int optionalargs;
241         /// Which counter to step
242         docstring counter;
243         /// Depth of XML command
244         int commanddepth;
245
246         /// Return a pointer on a new layout suitable to describe a caption.
247         /// FIXME: remove this eventually. This is only for tex2lyx
248         /// until it has proper support for the caption inset (JMarc)
249         static Layout * forCaption();
250
251
252 private:
253         /// Name of the layout/paragraph environment
254         docstring name_;
255
256         /// LaTeX name for environment
257         std::string latexname_;
258
259         /** Is this layout the default layout for an unknown layout? If
260          * so, its name will be displayed as xxx (unknown).
261          */
262         bool unknown_;
263
264         /** Name of an layout that has replaced this layout.
265             This is used to rename a layout, while keeping backward
266             compatibility
267         */
268         docstring obsoleted_by_;
269
270         /** Name of an layout which preamble must come before this one
271             This is used when the preamble snippet uses macros defined in
272             another preamble
273          */
274         docstring depends_on_;
275
276         /// Label string. "Abstract", "Reference", "Caption"...
277         docstring labelstring_;
278         ///
279         docstring endlabelstring_;
280         /// Label string inside appendix. "Appendix", ...
281         docstring labelstring_appendix_;
282         /// LaTeX parameter for environment
283         std::string latexparam_;
284         /// Internal tag to use (e.g., <title></title> for sect header)
285         std::string innertag_;
286         /// Internal tag to use e.g. to surround varlistentry label)
287         std::string labeltag_;
288         /// Internal tag to surround the item text in a list)
289         std::string itemtag_;
290         /// Tag for HTML output, e.g., h2.
291         std::string htmltag_;
292         /// Additional attributes for inclusion with the start tag, 
293         /// e.g.: class='section'.
294         std::string htmlattr_;
295         /// Tag for individual paragraphs in an environment. In lists, this
296         /// would be something like "li". But it also needs to be set for
297         /// quotation, e.g., since the paragraphs in a quote need to be 
298         /// in "p" tags.
299         std::string htmlitem_;
300         /// Attributes for htmlitem_
301         std::string htmlitemattr_;
302         /// Tag for labels, of whatever sort. One use for this is in setting
303         /// descriptions, in which case it would be: dt. Another use is to
304         /// customize the display of, say, the auto-generated label for 
305         /// sections (in that case, it might be: span).
306         std::string htmllabel_;
307         /// Attributes for the label.
308         std::string htmllabelattr_;
309         /// CSS information needed by this layout.
310         docstring htmlstyle_;
311         /// Any other info for the HTML header.
312         docstring htmlpreamble_;
313         /// This is the `category' for this layout. The following are
314         /// recommended basic categories: FrontMatter, BackMatter, MainText,
315         /// Section, Starred, List, Theorem.
316         docstring category_;
317         /// Macro definitions needed for this layout
318         docstring preamble_;
319         /// Language dependent macro definitions needed for this layout
320         docstring langpreamble_;
321         /// Language and babel dependent macro definitions needed for this layout
322         docstring babelpreamble_;
323         /// Packages needed for this layout
324         std::set<std::string> requires_;
325 };
326
327 } // namespace lyx
328
329 #endif