]> git.lyx.org Git - lyx.git/blob - src/Layout.h
Fix bug 4212
[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 LYX_LAYOUT_H
15 #define LYX_LAYOUT_H
16
17 #include "Font.h"
18 #include "Spacing.h"
19 #include "support/docstring.h"
20
21 #include <string>
22
23
24 namespace lyx {
25
26 class Lexer;
27 class TextClass;
28
29
30 /// The different output types
31 enum OutputType {
32         ///
33         LATEX = 1,
34         ///
35         DOCBOOK,
36         ///
37         LITERATE
38 };
39
40
41 /// The different margin types
42 enum LYX_MARGIN_TYPE {
43         ///
44         MARGIN_MANUAL = 1,
45         ///
46         MARGIN_FIRST_DYNAMIC,
47         ///
48         MARGIN_DYNAMIC,
49         ///
50         MARGIN_STATIC,
51         ///
52         MARGIN_RIGHT_ADDRESS_BOX
53 };
54
55
56 ///
57 enum LyXAlignment {
58         ///
59         LYX_ALIGN_NONE = 0,
60         ///
61         LYX_ALIGN_BLOCK = 1,
62         ///
63         LYX_ALIGN_LEFT = 2,
64         ///
65         LYX_ALIGN_RIGHT = 4,
66         ///
67         LYX_ALIGN_CENTER = 8,
68         ///
69         LYX_ALIGN_LAYOUT = 16,
70         ///
71         LYX_ALIGN_SPECIAL = 32
72 };
73
74 ///
75 inline
76 void operator|=(LyXAlignment & la1, LyXAlignment la2) {
77         la1 = static_cast<LyXAlignment>(la1 | la2);
78 }
79
80
81 ///
82 inline
83 LyXAlignment operator|(LyXAlignment la1, LyXAlignment la2) {
84         return static_cast<LyXAlignment>(static_cast<int>(la1) | static_cast<int>(la2));
85 }
86
87
88 /// The different LaTeX-Types
89 enum LYX_LATEX_TYPES {
90         ///
91         LATEX_PARAGRAPH = 1,
92         ///
93         LATEX_COMMAND,
94         ///
95         LATEX_ENVIRONMENT,
96         ///
97         LATEX_ITEM_ENVIRONMENT,
98         ///
99         LATEX_BIB_ENVIRONMENT,
100         ///
101         LATEX_LIST_ENVIRONMENT
102 };
103
104
105 /// The different title types
106 enum LYX_TITLE_LATEX_TYPES {
107         ///
108         TITLE_COMMAND_AFTER = 1,
109         ///
110         TITLE_ENVIRONMENT
111 };
112
113
114 /// The different label types
115 enum LYX_LABEL_TYPES {
116         ///
117         LABEL_NO_LABEL,
118         ///
119         LABEL_MANUAL,
120         ///
121         LABEL_BIBLIO,
122         ///
123         LABEL_TOP_ENVIRONMENT,
124         ///
125         LABEL_CENTERED_TOP_ENVIRONMENT,
126
127         // the flushright labels following now must start with LABEL_STATIC
128         ///
129         LABEL_STATIC,
130         ///
131         LABEL_SENSITIVE,
132         ///
133         LABEL_COUNTER,
134         ///
135         LABEL_ENUMERATE,
136         ///
137         LABEL_ITEMIZE
138 };
139
140
141 ///
142 enum LYX_END_LABEL_TYPES {
143         ///
144         END_LABEL_NO_LABEL,
145         ///
146         END_LABEL_BOX,
147         ///
148         END_LABEL_FILLED_BOX,
149         ///
150         END_LABEL_STATIC,
151         ///
152         END_LABEL_ENUM_FIRST = END_LABEL_NO_LABEL,
153         ///
154         END_LABEL_ENUM_LAST = END_LABEL_STATIC
155 };
156
157 /* Fix labels are printed flushright, manual labels flushleft.
158  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
159  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
160  * This seems a funny restriction, but I think other combinations are
161  * not needed, so I will not change it yet.
162  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
163  */
164
165
166 /* There is a parindent and a parskip. Which one is used depends on the
167  * paragraph_separation-flag of the text-object.
168  * BUT: parindent is only thrown away, if a parskip is defined! So if you
169  * want a space between the paragraphs and a parindent at the same time,
170  * you should set parskip to zero and use topsep, parsep and bottomsep.
171  *
172  * The standard layout is an exception: its parindent is only set, if the
173  * previous paragraph is standard too. Well, this is LateX and it is good!
174  */
175
176 ///
177 class Layout {
178 public:
179         ///
180         Layout();
181         ///
182         bool read(Lexer &, TextClass const &);
183         ///
184         void readAlign(Lexer &);
185         ///
186         void readAlignPossible(Lexer &);
187         ///
188         void readLabelType(Lexer &);
189         ///
190         void readEndLabelType(Lexer &);
191         ///
192         void readMargin(Lexer &);
193         ///
194         void readLatexType(Lexer &);
195         ///
196         void readSpacing(Lexer &);
197         ///
198         docstring const & name() const;
199         ///
200         void setName(docstring const & n);
201         ///
202         docstring const & obsoleted_by() const;
203         ///
204         docstring const & depends_on() const;
205         ///
206         std::string const & latexname() const { return latexname_; }
207         ///
208         lyx::docstring const & labelstring() const { return labelstring_; }
209         ///
210         lyx::docstring const & endlabelstring() const { return endlabelstring_; }
211         ///
212         docstring const & preamble() const { return preamble_; }
213         ///
214         std::string const & latexparam() const { return latexparam_; }
215         ///
216         std::string const & innertag() const { return innertag_; }
217         ///
218         std::string const & labeltag() const { return labeltag_; }
219         ///
220         std::string const & itemtag() const { return itemtag_; }
221         ///
222         lyx::docstring const & labelstring_appendix() const {
223                 return labelstring_appendix_;
224         }
225         /** Default font for this layout/environment.
226             The main font for this kind of environment. If an attribute has
227             Font::INHERITED_*, it means that the value is specified by
228             the defaultfont for the entire layout. If we are nested, the
229             font is inherited from the font in the environment one level
230             up until the font is resolved. The values Font::IGNORE_*
231             and Font::TOGGLE are illegal here.
232         */
233         Font font;
234
235         /** Default font for labels.
236             Interpretation the same as for font above
237         */
238         Font labelfont;
239
240         /** Resolved version of the font for this layout/environment.
241             This is a resolved version the default font. The font is resolved
242             against the defaultfont of the entire layout.
243         */
244         Font resfont;
245
246         /** Resolved version of the font used for labels.
247             This is a resolved version the label font. The font is resolved
248             against the defaultfont of the entire layout.
249         */
250         Font reslabelfont;
251
252         /// Text that dictates how wide the left margin is on the screen
253         docstring leftmargin;
254         /// Text that dictates how wide the right margin is on the screen
255         docstring rightmargin;
256         /// Text that dictates how much space to leave after a potential label
257         docstring labelsep;
258         /// Text that dictates how much space to leave before a potential label
259         docstring labelindent;
260         /// Text that dictates the width of the indentation of indented pars
261         docstring parindent;
262         ///
263         double parskip;
264         ///
265         double itemsep;
266         ///
267         double topsep;
268         ///
269         double bottomsep;
270         ///
271         double labelbottomsep;
272         ///
273         double parsep;
274         ///
275         Spacing spacing;
276         ///
277         LyXAlignment align;
278         ///
279         LyXAlignment alignpossible;
280         ///
281         LYX_LABEL_TYPES labeltype;
282         ///
283         LYX_END_LABEL_TYPES endlabeltype;
284         ///
285         LYX_MARGIN_TYPE margintype;
286         ///
287         bool fill_top;
288         ///
289         bool fill_bottom;
290         ///
291         bool newline_allowed;
292         ///
293         bool nextnoindent;
294         ///
295         bool free_spacing;
296         ///
297         bool pass_thru;
298         /**
299          * Whether this layout was declared with "Environment xxx" as opposed
300          * to "Style xxx". This is part of some unfinished generic environment
301          * handling (see also InsetEnvironment) started by Andre. No layout
302          * that is shipped with LyX has this flag set.
303          * Don't confuse this with isEnvironment()!
304          */
305         bool is_environment;
306         /// show this in toc
307         int toclevel;
308         /// special value of toclevel for non-section layouts
309         static const int NOT_IN_TOC;
310         /// for new environment insets
311         std::string latexheader;
312         /// for new environment insets
313         std::string latexfooter;
314         /// for new environment insets
315         std::string latexparagraph;
316
317         /** true when the fragile commands in the paragraph need to be
318             \protect'ed. */
319         bool needprotect;
320         /// true when empty paragraphs should be kept.
321         bool keepempty;
322         ///
323         bool isParagraph() const {
324                 return latextype == LATEX_PARAGRAPH;
325         }
326         ///
327         bool isCommand() const {
328                 return latextype == LATEX_COMMAND;
329         }
330         ///
331         bool isEnvironment() const {
332                 return (latextype == LATEX_ENVIRONMENT
333                         || latextype == LATEX_BIB_ENVIRONMENT
334                         || latextype == LATEX_ITEM_ENVIRONMENT
335                         || latextype == LATEX_LIST_ENVIRONMENT);
336         }
337         /// Type of LaTeX object
338         LYX_LATEX_TYPES latextype;
339         /// Does this object belong in the title part of the document?
340         bool intitle;
341         /// Does this layout allow for an optional parameter?
342         int optionalargs;
343         /// Which counter to step
344         lyx::docstring counter;
345         /// Depth of XML command
346         int commanddepth;
347
348         /// Return a pointer on a new layout suitable to describe a caption.
349         /// FIXME: remove this eventually. This is only for tex2lyx
350         /// until it has proper support for the caption inset (JMarc)
351         static Layout * forCaption();
352
353 private:
354         /// Name of the layout/paragraph environment
355         docstring name_;
356
357         /** Name of an layout that has replaced this layout.
358             This is used to rename a layout, while keeping backward
359             compatibility
360         */
361         docstring obsoleted_by_;
362
363         /** Name of an layout which preamble must come before this one
364             This is used when the preamble snippet uses macros defined in
365             another preamble
366          */
367         docstring depends_on_;
368
369         /// LaTeX name for environment
370         std::string latexname_;
371         /// Label string. "Abstract", "Reference", "Caption"...
372         lyx::docstring labelstring_;
373         ///
374         lyx::docstring endlabelstring_;
375         /// Label string inside appendix. "Appendix", ...
376         lyx::docstring labelstring_appendix_;
377         /// LaTeX parameter for environment
378         std::string latexparam_;
379         /// Internal tag to use (e.g., <title></title> for sect header)
380         std::string innertag_;
381         /// Internal tag to use e.g. to surround varlistentry label)
382         std::string labeltag_;
383         /// Internal tag to surround the item text in a list)
384         std::string itemtag_;
385         /// Macro definitions needed for this layout
386         docstring preamble_;
387 };
388
389
390 } // namespace lyx
391
392 #endif