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