]> git.lyx.org Git - lyx.git/blob - src/Layout.h
f957f747304a85425b1142d2a701c54b3162c831
[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 /* Fixed 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(bool in_appendix) const 
89         { return in_appendix ? labelstring_appendix_ : labelstring_; }
90         ///
91         docstring const & endlabelstring() const { return endlabelstring_; }
92         ///
93         docstring const & category() const { return category_; }
94         ///
95         docstring const & preamble() const { return preamble_; }
96         /// Get language dependent macro definitions needed for this layout
97         /// for language \p lang
98         docstring const langpreamble(Language const * lang, bool const polyglossia) const;
99         /// Get language and babel dependent macro definitions needed for
100         /// this layout for language \p lang
101         docstring const babelpreamble(Language const * lang, bool const polyglossia) const;
102         ///
103         std::set<std::string> const & requires() const { return requires_; }
104         ///
105         std::string const & latexparam() const { return latexparam_; }
106         ///
107         std::string const & innertag() const { return innertag_; }
108         ///
109         std::string const & labeltag() const { return labeltag_; }
110         ///
111         std::string const & itemtag() const { return itemtag_; }
112         /// 
113         std::string const & htmltag() const;
114         /// 
115         std::string const & htmlattr() const;
116         /// 
117         std::string const & htmlitemtag() const;
118         /// 
119         std::string const & htmlitemattr() const;
120         /// 
121         std::string const & htmllabeltag() const;
122         /// 
123         std::string const & htmllabelattr() const;
124         ///
125         std::string defaultCSSClass() const;
126         ///
127         bool htmllabelfirst() const { return htmllabelfirst_; }
128         /// 
129         docstring htmlstyle() const;
130         /// 
131         docstring const & htmlpreamble() const { return htmlpreamble_; }
132         ///
133         bool htmltitle() const { return htmltitle_; }
134         ///
135         bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
136         ///
137         bool isCommand() const { return latextype == LATEX_COMMAND; }
138         ///
139         bool isEnvironment() const {
140                 return latextype == LATEX_ENVIRONMENT
141                         || latextype == LATEX_BIB_ENVIRONMENT
142                         || latextype == LATEX_ITEM_ENVIRONMENT
143                         || latextype == LATEX_LIST_ENVIRONMENT;
144         }
145
146         ///
147         bool operator==(Layout const &) const;
148         ///
149         bool operator!=(Layout const & rhs) const 
150                 { return !(*this == rhs); }
151
152         ////////////////////////////////////////////////////////////////
153         // members
154         ////////////////////////////////////////////////////////////////
155         /** Default font for this layout/environment.
156             The main font for this kind of environment. If an attribute has
157             INHERITED_*, it means that the value is specified by
158             the defaultfont for the entire layout. If we are nested, the
159             font is inherited from the font in the environment one level
160             up until the font is resolved. The values :IGNORE_*
161             and FONT_TOGGLE are illegal here.
162         */
163         FontInfo font;
164
165         /** Default font for labels.
166             Interpretation the same as for font above
167         */
168         FontInfo labelfont;
169
170         /** Resolved version of the font for this layout/environment.
171             This is a resolved version the default font. The font is resolved
172             against the defaultfont of the entire layout.
173         */
174         FontInfo resfont;
175
176         /** Resolved version of the font used for labels.
177             This is a resolved version the label font. The font is resolved
178             against the defaultfont of the entire layout.
179         */
180         FontInfo reslabelfont;
181
182         /// Text that dictates how wide the left margin is on the screen
183         docstring leftmargin;
184         /// Text that dictates how wide the right margin is on the screen
185         docstring rightmargin;
186         /// Text that dictates how much space to leave after a potential label
187         docstring labelsep;
188         /// Text that dictates how much space to leave before a potential label
189         docstring labelindent;
190         /// Text that dictates the width of the indentation of indented pars
191         docstring parindent;
192         ///
193         double parskip;
194         ///
195         double itemsep;
196         ///
197         double topsep;
198         ///
199         double bottomsep;
200         ///
201         double labelbottomsep;
202         ///
203         double parsep;
204         ///
205         Spacing spacing;
206         ///
207         LyXAlignment align;
208         ///
209         LyXAlignment alignpossible;
210         ///
211         LabelType labeltype;
212         ///
213         EndLabelType endlabeltype;
214         ///
215         MarginType margintype;
216         ///
217         bool newline_allowed;
218         ///
219         bool nextnoindent;
220         ///
221         bool free_spacing;
222         ///
223         bool pass_thru;
224         ///
225         bool parbreak_is_newline;
226         /// show this in toc
227         int toclevel;
228         /// special value of toclevel for non-section layouts
229         static const int NOT_IN_TOC;
230
231         /** true when the fragile commands in the paragraph need to be
232             \protect'ed. */
233         bool needprotect;
234         /// true when empty paragraphs should be kept.
235         bool keepempty;
236         /// Type of LaTeX object
237         LatexType latextype;
238         /// Does this object belong in the title part of the document?
239         bool intitle;
240         /// Is the content to go in the preamble rather than the body?
241         bool inpreamble;
242         /// Number of requried arguments for this command or environment
243         unsigned int reqargs;
244         /// Number of optional arguments for this command or environment
245         /// These MUST come at the beginning, so:
246         ///  \cmd[opt1][opt2]{req1}{here is the text from LyX}
247         /// is fine. But:
248         ///  \cmd[opt1]{req1}[opt2]{here is the text from LyX}
249         /// is not.
250         unsigned int optargs;
251         /// Which counter to step
252         docstring counter;
253         /// Prefix to use when creating labels
254         docstring refprefix;
255         /// Depth of XML command
256         int commanddepth;
257
258         /// Return a pointer on a new layout suitable to describe a caption.
259         /// FIXME: remove this eventually. This is only for tex2lyx
260         /// until it has proper support for the caption inset (JMarc)
261         static Layout * forCaption();
262
263         /// Is this spellchecked?
264         bool spellcheck;
265
266
267 private:
268         /// generates the default CSS for this layout
269         void makeDefaultCSS() const;
270         ///
271         std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
272         ///
273         std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
274         
275         /// Name of the layout/paragraph environment
276         docstring name_;
277
278         /// LaTeX name for environment
279         std::string latexname_;
280
281         /** Is this layout the default layout for an unknown layout? If
282          * so, its name will be displayed as xxx (unknown).
283          */
284         bool unknown_;
285
286         /** Name of an layout that has replaced this layout.
287             This is used to rename a layout, while keeping backward
288             compatibility
289         */
290         docstring obsoleted_by_;
291
292         /** Name of an layout which preamble must come before this one
293             This is used when the preamble snippet uses macros defined in
294             another preamble
295          */
296         docstring depends_on_;
297
298         /// Label string. "Abstract", "Reference", "Caption"...
299         docstring labelstring_;
300         ///
301         docstring endlabelstring_;
302         /// Label string inside appendix. "Appendix", ...
303         docstring labelstring_appendix_;
304         /// LaTeX parameter for environment
305         std::string latexparam_;
306         /// Internal tag to use (e.g., <title></title> for sect header)
307         std::string innertag_;
308         /// Internal tag to use (e.g. to surround varentrylist label)
309         std::string labeltag_;
310         /// Internal tag to surround the item text in a list.
311         std::string itemtag_;
312         /// The interpretation of this tag varies depending upon the latextype.
313         /// In an environment, it is the tag enclosing all content for this set of 
314         /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize, 
315         /// it would be: ul. (You get the idea.)
316         ///
317         /// For a command, it is the tag enclosing the content of the command.
318         /// So, for section, it might be: h2.
319         /// 
320         /// For the paragraph type, it is the tag that will enclose each paragraph.
321         ///
322         /// Defaults to "div".
323         mutable std::string htmltag_;
324         /// Additional attributes for inclusion with the start tag. Defaults
325         /// to: class="layoutname".
326         mutable std::string htmlattr_;
327         /// Tag for individual paragraphs in an environment. In lists, this
328         /// would be something like "li". But it also needs to be set for
329         /// quotation, e.g., since the paragraphs in a quote need to be 
330         /// in "p" tags. Default is "div".
331         /// Note that when I said "environment", I meant it: This has no
332         /// effect for LATEX_PARAGRAPH type layouts.
333         mutable std::string htmlitemtag_;
334         /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
335         mutable std::string htmlitemattr_;
336         /// Tag for labels, of whatever sort. One use for this is in setting
337         /// descriptions, in which case it would be: dt. Another use is to
338         /// customize the display of, say, the auto-generated label for 
339         /// sections. Defaults to "span".
340         /// If set to "NONE", this suppresses the printing of the label.
341         mutable std::string htmllabeltag_;
342         /// Attributes for the label. Defaults to: class="layoutname_label".
343         mutable std::string htmllabelattr_;
344         /// Whether to put the label before the item, or within the item.
345         /// I.e., do we have (true):
346         ///    <label>...</label><item>...</item>
347         /// or instead (false):
348         ///    <item><label>...</label>...</item>
349         /// The latter is the default.
350         bool htmllabelfirst_;
351         /// CSS information needed by this layout.
352         docstring htmlstyle_;
353         /// Should we generate the default CSS for this layout, even if HTMLStyle
354         /// has been given? Default is false.
355         /// Note that the default CSS is output first, then the user CSS, so it is
356         /// possible to override what one does not want.
357         bool htmlforcecss_;
358         /// A cache for the default style info so generated.
359         mutable docstring htmldefaultstyle_;
360         /// Any other info for the HTML header.
361         docstring htmlpreamble_;
362         /// Whether this is the <title> paragraph.
363         bool htmltitle_;
364         /// calculating this is expensive, so we cache it.
365         mutable std::string defaultcssclass_;
366         /// This is the `category' for this layout. The following are
367         /// recommended basic categories: FrontMatter, BackMatter, MainText,
368         /// Section, Starred, List, Theorem.
369         docstring category_;
370         /// Macro definitions needed for this layout
371         docstring preamble_;
372         /// Language dependent macro definitions needed for this layout
373         docstring langpreamble_;
374         /// Language and babel dependent macro definitions needed for this layout
375         docstring babelpreamble_;
376         /// Packages needed for this layout
377         std::set<std::string> requires_;
378 };
379
380 } // namespace lyx
381
382 #endif