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