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