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