]> git.lyx.org Git - lyx.git/blob - src/Layout.h
fa4bdc2da23f3f8da951ee5bf071e82ad0101689
[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 Lexer;
28 class TextClass;
29
30 /* Fix labels are printed flushright, manual labels flushleft.
31  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
32  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
33  * This seems a funny restriction, but I think other combinations are
34  * not needed, so I will not change it yet.
35  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
36  */
37
38
39 /* There is a parindent and a parskip. Which one is used depends on the
40  * paragraph_separation-flag of the text-object.
41  * BUT: parindent is only thrown away, if a parskip is defined! So if you
42  * want a space between the paragraphs and a parindent at the same time,
43  * you should set parskip to zero and use topsep, parsep and bottomsep.
44  *
45  * The standard layout is an exception: its parindent is only set, if the
46  * previous paragraph is standard too. Well, this is LateX and it is good!
47  */
48
49 ///
50 class Layout {
51 public:
52         ///
53         Layout();
54         /// Reads a layout definition from file
55         bool read(Lexer &, TextClass const &);
56         ///
57         void readAlign(Lexer &);
58         ///
59         void readAlignPossible(Lexer &);
60         ///
61         void readLabelType(Lexer &);
62         ///
63         void readEndLabelType(Lexer &);
64         ///
65         void readMargin(Lexer &);
66         ///
67         void readLatexType(Lexer &);
68         ///
69         void readSpacing(Lexer &);
70         ///
71         docstring const & name() const;
72         ///
73         void setName(docstring const & n);
74         ///
75         docstring const & obsoleted_by() const;
76         ///
77         docstring const & depends_on() const;
78         ///
79         std::string const & latexname() const { return latexname_; }
80         ///
81         docstring const & labelstring() const { return labelstring_; }
82         ///
83         docstring const & endlabelstring() const { return endlabelstring_; }
84         ///
85         docstring const & preamble() const { return preamble_; }
86         ///
87         std::set<std::string> const & requires() const { return requires_; }
88         ///
89         std::string const & latexparam() const { return latexparam_; }
90         ///
91         std::string const & innertag() const { return innertag_; }
92         ///
93         std::string const & labeltag() const { return labeltag_; }
94         ///
95         std::string const & itemtag() const { return itemtag_; }
96         ///
97         docstring const & labelstring_appendix() const {
98                 return labelstring_appendix_;
99         }
100         /** Default font for this layout/environment.
101             The main font for this kind of environment. If an attribute has
102             INHERITED_*, it means that the value is specified by
103             the defaultfont for the entire layout. If we are nested, the
104             font is inherited from the font in the environment one level
105             up until the font is resolved. The values :IGNORE_*
106             and FONT_TOGGLE are illegal here.
107         */
108         FontInfo font;
109
110         /** Default font for labels.
111             Interpretation the same as for font above
112         */
113         FontInfo labelfont;
114
115         /** Resolved version of the font for this layout/environment.
116             This is a resolved version the default font. The font is resolved
117             against the defaultfont of the entire layout.
118         */
119         FontInfo resfont;
120
121         /** Resolved version of the font used for labels.
122             This is a resolved version the label font. The font is resolved
123             against the defaultfont of the entire layout.
124         */
125         FontInfo reslabelfont;
126
127         /// Text that dictates how wide the left margin is on the screen
128         docstring leftmargin;
129         /// Text that dictates how wide the right margin is on the screen
130         docstring rightmargin;
131         /// Text that dictates how much space to leave after a potential label
132         docstring labelsep;
133         /// Text that dictates how much space to leave before a potential label
134         docstring labelindent;
135         /// Text that dictates the width of the indentation of indented pars
136         docstring parindent;
137         ///
138         double parskip;
139         ///
140         double itemsep;
141         ///
142         double topsep;
143         ///
144         double bottomsep;
145         ///
146         double labelbottomsep;
147         ///
148         double parsep;
149         ///
150         Spacing spacing;
151         ///
152         LyXAlignment align;
153         ///
154         LyXAlignment alignpossible;
155         ///
156         LabelType labeltype;
157         ///
158         EndLabelType endlabeltype;
159         ///
160         MarginType margintype;
161         ///
162         bool fill_top;
163         ///
164         bool fill_bottom;
165         ///
166         bool newline_allowed;
167         ///
168         bool nextnoindent;
169         ///
170         bool free_spacing;
171         ///
172         bool pass_thru;
173         /**
174          * Whether this layout was declared with "Environment xxx" as opposed
175          * to "Style xxx". This is part of some unfinished generic environment
176          * handling (see also InsetEnvironment) started by Andre. No layout
177          * that is shipped with LyX has this flag set.
178          * Don't confuse this with isEnvironment()!
179          */
180         bool is_environment;
181         /// show this in toc
182         int toclevel;
183         /// special value of toclevel for non-section layouts
184         static const int NOT_IN_TOC;
185         /// for new environment insets
186         std::string latexheader;
187         /// for new environment insets
188         std::string latexfooter;
189         /// for new environment insets
190         std::string latexparagraph;
191
192         /** true when the fragile commands in the paragraph need to be
193             \protect'ed. */
194         bool needprotect;
195         /// true when empty paragraphs should be kept.
196         bool keepempty;
197         ///
198         bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
199         ///
200         bool isCommand() const { return latextype == LATEX_COMMAND; }
201         ///
202         bool isEnvironment() const {
203                 return latextype == LATEX_ENVIRONMENT
204                         || latextype == LATEX_BIB_ENVIRONMENT
205                         || latextype == LATEX_ITEM_ENVIRONMENT
206                         || latextype == LATEX_LIST_ENVIRONMENT;
207         }
208         /// Type of LaTeX object
209         LatexType latextype;
210         /// Does this object belong in the title part of the document?
211         bool intitle;
212         /// Does this layout allow for an optional parameter?
213         int optionalargs;
214         /// Which counter to step
215         docstring counter;
216         /// Depth of XML command
217         int commanddepth;
218
219         /// Return a pointer on a new layout suitable to describe a caption.
220         /// FIXME: remove this eventually. This is only for tex2lyx
221         /// until it has proper support for the caption inset (JMarc)
222         static Layout * forCaption();
223
224 private:
225         /// Name of the layout/paragraph environment
226         docstring name_;
227
228         /** Name of an layout that has replaced this layout.
229             This is used to rename a layout, while keeping backward
230             compatibility
231         */
232         docstring obsoleted_by_;
233
234         /** Name of an layout which preamble must come before this one
235             This is used when the preamble snippet uses macros defined in
236             another preamble
237          */
238         docstring depends_on_;
239
240         /// LaTeX name for environment
241         std::string latexname_;
242         /// Label string. "Abstract", "Reference", "Caption"...
243         docstring labelstring_;
244         ///
245         docstring endlabelstring_;
246         /// Label string inside appendix. "Appendix", ...
247         docstring labelstring_appendix_;
248         /// LaTeX parameter for environment
249         std::string latexparam_;
250         /// Internal tag to use (e.g., <title></title> for sect header)
251         std::string innertag_;
252         /// Internal tag to use e.g. to surround varlistentry label)
253         std::string labeltag_;
254         /// Internal tag to surround the item text in a list)
255         std::string itemtag_;
256         /// Macro definitions needed for this layout
257         docstring preamble_;
258         /// Packages needed for this layout
259         std::set<std::string> requires_;
260 };
261
262 } // namespace lyx
263
264 #endif