]> git.lyx.org Git - features.git/blob - src/insets/InsetLayout.h
DocBook: add inner tags for layouts.
[features.git] / src / insets / InsetLayout.h
1 // -*- C++ -*-
2 /**
3  * \file InsetLayout.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Martin Vermeer
8  * \author Richard Kimberly Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_LAYOUT_H
14 #define INSET_LAYOUT_H
15
16 #include "ColorCode.h"
17 #include "FontInfo.h"
18 #include "Layout.h"
19
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
31 enum class InsetDecoration : int {
32         CLASSIC,
33         MINIMALISTIC,
34         CONGLOMERATE,
35         DEFAULT
36 };
37
38 enum class InsetLyXType : int {
39         NOLYXTYPE,
40         CHARSTYLE,
41         CUSTOM,
42         END,
43         STANDARD
44 };
45
46 enum class InsetLaTeXType : int {
47         NOLATEXTYPE,
48         COMMAND,
49         ENVIRONMENT,
50         ILT_ERROR
51 };
52
53
54 ///
55 class InsetLayout {
56 public:
57         ///
58         InsetLayout() { labelfont_.setColor(Color_error); }
59         ///
60         bool read(Lexer & lexrc, TextClass const & tclass,
61                         bool validating = false);
62         ///
63         docstring name() const { return name_; }
64         ///
65         void setName(docstring const & n) { name_ = n; }
66         ///
67         InsetLyXType lyxtype() const { return lyxtype_; }
68         ///
69         docstring labelstring() const { return labelstring_; }
70         ///
71         docstring menustring() const { return menustring_; }
72         ///
73         bool contentaslabel() const { return contentaslabel_; }
74         ///
75         InsetDecoration decoration() const { return decoration_; }
76         ///
77         InsetLaTeXType latextype() const { return latextype_; }
78         ///
79         std::string latexname() const { return latexname_; }
80         ///
81         std::string latexparam() const { return latexparam_; }
82         ///
83         docstring leftdelim() const { return leftdelim_; }
84         ///
85         docstring rightdelim() const { return rightdelim_; }
86         ///
87         FontInfo font() const { return font_; }
88         ///
89         FontInfo labelfont() const { return labelfont_; }
90         ///
91         ColorCode bgcolor() const { return bgcolor_; }
92         ///
93         Layout::LaTeXArgMap const & latexargs() const { return latexargs_; }
94         ///
95         Layout::LaTeXArgMap const & postcommandargs() const { return postcommandargs_; }
96         /// Returns latexargs() + postcommandargs().
97         /// But note that it returns a *copy*, not a reference, so do not do
98         /// anything like:
99         ///   Layout::LaTeXArgMap::iterator it = args().begin();
100         ///   Layout::LaTeXArgMap::iterator en = args().end();
101         /// Those are iterators for different containers.
102         Layout::LaTeXArgMap args() const;
103         ///
104         int optArgs() const;
105         ///
106         int requiredArgs() const;
107         ///
108         docstring preamble() const { return preamble_; }
109         /// Get language dependent macro definitions needed for this inset
110         docstring const langpreamble() const { return langpreamble_; }
111         /// Get language and babel dependent macro definitions needed for
112         /// this inset
113         docstring const babelpreamble() const { return babelpreamble_; }
114         ///
115         bool fixedwidthpreambleencoding() const { return fixedwidthpreambleencoding_; }
116         ///
117         docstring counter() const { return counter_; }
118         ///
119         docstring refprefix() const { return refprefix_; }
120         /// The tag enclosing all the material in this inset. Default is "span".
121         std::string const & htmltag() const;
122         /// Additional attributes for inclusion with the start tag. Default (if
123         /// a tag is provided) is: class="name".
124         std::string const & htmlattr() const;
125         /// Tag for individual paragraphs in the inset. Default is none.
126         std::string const & htmlinnertag() const { return htmlinnertag_; }
127         /// Attributes for that tag. Default (if a tag is provided) is:
128         /// class="name_inner".
129         std::string const & htmlinnerattr() const;
130         /// A label for this environment, possibly including a reference
131         /// to a counter. E.g., for footnote, it might be:
132         ///    \arabic{footnote}
133         /// No default.
134         /// FIXME Could we get this from the layout?
135         std::string const & htmllabel() const { return htmllabel_; }
136         ///
137         inline std::string htmllabeltag() const { return "span"; }
138         ///
139         std::string htmllabelattr() const
140                 { return "class=\"" + defaultCSSClass() + "_label\""; }
141         /// CSS associated with this inset.
142         docstring htmlstyle() const;
143         /// Additional material for the header.
144         docstring htmlpreamble() const { return htmlpreamble_; }
145         /// Whether this inset represents a "block" of material, i.e., a set
146         /// of paragraphs of its own (true), or should be run into the previous
147         /// paragraph (false). Examples:
148         ///   For branches, this is false.
149         ///   For footnotes, this is true.
150         /// Defaults to true.
151         bool htmlisblock() const { return htmlisblock_; }
152         ///
153         std::string docbooktag() const { return docbooktag_; }
154         ///
155         std::string docbooktagtype() const;
156         ///
157         std::string docbookattr() const { return docbookattr_; }
158         ///
159         std::string docbookinnertag() const { return docbookinnertag_; }
160         ///
161         std::string docbookinnertagtype() const;
162         ///
163         std::string docbookinnerattr() const { return docbookinnerattr_; }
164         ///
165         std::string const & docbookininfo() const;
166         ///
167         bool docbooksection() const { return docbooksection_; }
168         ///
169         bool docbooknotinpara() const { return docbooknotinpara_; }
170         ///
171         bool docbookargumentbeforemaintag() const { return docbookargumentbeforemaintag_; }
172         ///
173         bool docbookargumentaftermaintag() const { return docbookargumentaftermaintag_; }
174         ///
175         std::string docbookwrappertag() const { return docbookwrappertag_; }
176         ///
177         std::string docbookwrappertagtype() const;
178         ///
179         std::string docbookwrapperattr() const { return docbookwrapperattr_; }
180         ///
181         std::string docbookitemwrappertag() const { return docbookitemwrappertag_; }
182         ///
183         std::string docbookitemwrappertagtype() const;
184         ///
185         std::string docbookitemwrapperattr() const { return docbookitemwrapperattr_; }
186         ///
187         std::string docbookitemtag() const { return docbookitemtag_; }
188         ///
189         std::string docbookitemtagtype() const;
190         ///
191         std::string docbookitemattr() const { return docbookitemattr_; }
192         ///
193         bool docbooknofontinside() const { return docbooknofontinside_; }
194         ///
195         std::set<std::string> required() const { return required_; }
196         ///
197         bool isMultiPar() const { return multipar_; }
198         ///
199         bool forcePlainLayout() const { return forceplain_; }
200         ///
201         bool allowParagraphCustomization() const { return custompars_; }
202         ///
203         bool isPassThru() const { return passthru_; }
204         ///
205         docstring passThruChars() const { return passthru_chars_; }
206         ///
207         std::string newlineCmd() const { return newline_cmd_; }
208         ///
209         bool parbreakIsNewline() const { return parbreakisnewline_; }
210         ///
211         bool parbreakIgnored() const { return parbreakignored_; }
212         ///
213         bool isNeedProtect() const { return needprotect_; }
214         ///
215         bool needsCProtect() const { return needcprotect_; }
216         /// Protection of some elements such as \ref and \cite
217         /// in \mbox (needed by commands building on soul or ulem)
218         bool isNeedMBoxProtect() const { return needmboxprotect_; }
219         ///
220         bool isFreeSpacing() const { return freespacing_; }
221         ///
222         bool isKeepEmpty() const { return keepempty_; }
223         ///
224         bool forceLTR() const { return forceltr_; }
225         ///
226         bool forceOwnlines() const { return forceownlines_; }
227         ///
228         bool isInToc() const { return intoc_; }
229         ///
230         bool spellcheck() const { return spellcheck_; }
231         ///
232         bool resetsFont() const { return resetsfont_; }
233         ///
234         bool isDisplay() const { return display_; }
235         ///
236         bool forceLocalFontSwitch() const { return forcelocalfontswitch_; }
237         ///
238         docstring const & obsoleted_by() const { return obsoleted_by_; }
239         ///
240         bool addToToc() const { return add_to_toc_; }
241         ///
242         std::string tocType() const { return toc_type_; }
243         ///
244         bool isTocCaption() const { return is_toc_caption_; }
245         ///
246         bool editExternally () const { return edit_external_; }
247 private:
248         ///
249         void makeDefaultCSS() const;
250         ///
251         std::string defaultCSSClass() const;
252         ///
253         void readArgument(Lexer &);
254         ///
255         docstring name_ = from_ascii("undefined");
256         /**
257                 * This is only used (at present) to decide where to put them on the menus.
258                 * Values are 'charstyle', 'custom' (things that by default look like a
259                 * footnote), 'standard'.
260                 */
261         InsetLyXType lyxtype_ = InsetLyXType::STANDARD;
262         ///
263         docstring labelstring_ = from_ascii("UNDEFINED");
264         ///
265         docstring menustring_;
266         ///
267         bool contentaslabel_ = false;
268         ///
269         InsetDecoration decoration_ = InsetDecoration::DEFAULT;
270         ///
271         InsetLaTeXType latextype_ = InsetLaTeXType::NOLATEXTYPE;
272         ///
273         std::string latexname_;
274         ///
275         std::string latexparam_;
276         ///
277         docstring leftdelim_;
278         ///
279         docstring rightdelim_;
280         ///
281         FontInfo font_ = inherit_font;
282         ///
283         FontInfo labelfont_ = sane_font;
284         ///
285         ColorCode bgcolor_ = Color_error;
286         ///
287         docstring counter_;
288         ///
289         docstring preamble_;
290         /// Language dependent macro definitions needed for this inset
291         docstring langpreamble_;
292         /// Language and babel dependent macro definitions needed for this inset
293         docstring babelpreamble_;
294         ///
295         bool fixedwidthpreambleencoding_ = false;
296         ///
297         docstring refprefix_;
298         ///
299         mutable std::string htmltag_;
300         ///
301         mutable std::string htmlattr_;
302         ///
303         std::string htmlinnertag_;
304         ///
305         mutable std::string htmlinnerattr_;
306         ///
307         std::string htmllabel_;
308         ///
309         docstring htmlstyle_;
310         /// Cache for default CSS info for this inset.
311         mutable docstring htmldefaultstyle_;
312         /// Cache for default CSS class.
313         mutable std::string defaultcssclass_;
314         /// Whether to force generation of default CSS even if some is given.
315         /// False by default.
316         bool htmlforcecss_ = false;
317         ///
318         docstring htmlpreamble_;
319         ///
320         bool htmlisblock_ = true;
321         ///
322         std::string docbooktag_;
323         ///
324         mutable std::string docbooktagtype_;
325         ///
326         std::string docbookattr_;
327         ///
328         std::string docbookinnertag_;
329         ///
330         mutable std::string docbookinnertagtype_;
331         ///
332         std::string docbookinnerattr_;
333         ///
334         mutable std::string docbookininfo_;
335         ///
336         bool docbooknotinpara_ = false;
337         ///
338         bool docbookargumentbeforemaintag_ = false;
339     ///
340     bool docbookargumentaftermaintag_ = false;
341         ///
342         bool docbooksection_ = false;
343         ///
344         std::string docbookwrappertag_;
345         ///
346         mutable std::string docbookwrappertagtype_;
347         ///
348         std::string docbookwrapperattr_;
349         ///
350         std::string docbookitemtag_;
351         ///
352         mutable std::string docbookitemtagtype_;
353         ///
354         std::string docbookitemattr_;
355         ///
356         std::string docbookitemwrappertag_;
357         ///
358         mutable std::string docbookitemwrappertagtype_;
359         ///
360         std::string docbookitemwrapperattr_;
361         ///
362         bool docbooknofontinside_ = false;
363         ///
364         std::set<std::string> required_;
365         ///
366         bool multipar_ = true;
367         ///
368         bool custompars_ = true;
369         ///
370         bool forceplain_ = false;
371         ///
372         bool passthru_ = false;
373         ///
374         docstring passthru_chars_;
375         ///
376         std::string newline_cmd_;
377         ///
378         bool parbreakisnewline_ = false;
379         ///
380         bool parbreakignored_ = false;
381         ///
382         bool freespacing_ = false;
383         ///
384         bool keepempty_ = false;
385         ///
386         bool forceltr_ = false;
387         ///
388         bool forceownlines_ = false;
389         ///
390         bool needprotect_ = false;
391         ///
392         bool needcprotect_ = false;
393         ///
394         bool needmboxprotect_ = false;
395         /// should the contents be written to TOC strings?
396         bool intoc_ = false;
397         /// check spelling of this inset?
398         bool spellcheck_ = true;
399         ///
400         bool resetsfont_ = false;
401         ///
402         bool display_ = true;
403         ///
404         bool forcelocalfontswitch_ = false;
405         /** Name of an insetlayout that has replaced this insetlayout.
406             This is used to rename an insetlayout, while keeping backward
407             compatibility
408         */
409         docstring obsoleted_by_;
410         ///
411         Layout::LaTeXArgMap latexargs_;
412         ///
413         Layout::LaTeXArgMap postcommandargs_;
414         ///
415         bool add_to_toc_ = false;
416         ///
417         std::string toc_type_;
418         ///
419         bool is_toc_caption_ = false;
420         ///
421         bool edit_external_ = false;
422 };
423
424 ///
425 InsetLyXType translateLyXType(std::string const & str);
426 InsetDecoration translateDecoration(std::string const & str);
427
428 } // namespace lyx
429
430 #endif