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