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