4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Martin Vermeer
8 * \author Richard Kimberly Heck
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_LAYOUT_H
14 #define INSET_LAYOUT_H
16 #include "ColorCode.h"
20 #include "support/docstring.h"
31 enum class InsetDecoration : int {
38 enum class InsetLyXType : int {
46 enum class InsetLaTeXType : int {
58 InsetLayout() { labelfont_.setColor(Color_insetlabel); }
60 bool read(Lexer & lexrc, TextClass const & tclass,
61 bool validating = false);
63 docstring name() const { return name_; }
65 void setName(docstring const & n) { name_ = n; }
67 InsetLyXType lyxtype() const { return lyxtype_; }
69 docstring labelstring() const { return labelstring_; }
71 docstring menustring() const { return menustring_; }
73 bool contentaslabel() const { return contentaslabel_; }
75 InsetDecoration decoration() const { return decoration_; }
77 InsetLaTeXType latextype() const { return latextype_; }
79 std::string latexname() const { return latexname_; }
81 std::string latexparam() const { return latexparam_; }
83 docstring leftdelim() const { return leftdelim_; }
85 docstring rightdelim() const { return rightdelim_; }
87 bool inheritFont() const { return inheritfont_; }
89 FontInfo font() const { return font_; }
91 FontInfo labelfont() const { return labelfont_; }
93 ColorCode bgcolor() const { return bgcolor_; }
95 Layout::LaTeXArgMap const & latexargs() const { return latexargs_; }
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
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;
108 int requiredArgs() const;
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
115 docstring const babelpreamble() const { return babelpreamble_; }
117 bool fixedwidthpreambleencoding() const { return fixedwidthpreambleencoding_; }
119 docstring counter() const { return counter_; }
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_; }
128 std::string const & htmlclass() const;
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}
140 /// FIXME Could we get this from the layout?
141 std::string const & htmllabel() const { return htmllabel_; }
143 inline std::string htmllabeltag() const { return "span"; }
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_; }
159 std::string docbooktag() const { return docbooktag_; }
161 std::string docbooktagtype() const;
163 std::string docbookattr() const { return docbookattr_; }
165 std::string docbookinnertag() const { return docbookinnertag_; }
167 std::string docbookinnertagtype() const;
169 std::string docbookinnerattr() const { return docbookinnerattr_; }
171 std::string const & docbookininfo() const;
173 bool docbooksection() const { return docbooksection_; }
175 bool docbooknotinpara() const { return docbooknotinpara_; }
177 bool docbookargumentbeforemaintag() const { return docbookargumentbeforemaintag_; }
179 bool docbookargumentaftermaintag() const { return docbookargumentaftermaintag_; }
181 std::string docbookwrappertag() const { return docbookwrappertag_; }
183 std::string docbookwrappertagtype() const;
185 std::string docbookwrapperattr() const { return docbookwrapperattr_; }
187 std::string docbookitemwrappertag() const { return docbookitemwrappertag_; }
189 std::string docbookitemwrappertagtype() const;
191 std::string docbookitemwrapperattr() const { return docbookitemwrapperattr_; }
193 std::string docbookitemtag() const { return docbookitemtag_; }
195 std::string docbookitemtagtype() const;
197 std::string docbookitemattr() const { return docbookitemattr_; }
199 bool docbooknofontinside() const { return docbooknofontinside_; }
201 bool docbookrenderasimage() const { return docbookrenderasimage_; }
203 std::set<std::string> required() const { return required_; }
205 bool isMultiPar() const { return multipar_; }
207 bool forcePlainLayout() const { return forceplain_; }
209 bool allowParagraphCustomization() const { return custompars_; }
211 bool isPassThru() const { return passthru_; }
213 docstring passThruChars() const { return passthru_chars_; }
215 std::string newlineCmd() const { return newline_cmd_; }
217 bool parbreakIsNewline() const { return parbreakisnewline_; }
219 bool parbreakIgnored() const { return parbreakignored_; }
221 bool isNeedProtect() const { return needprotect_; }
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_; }
228 bool isFreeSpacing() const { return freespacing_; }
230 bool isKeepEmpty() const { return keepempty_; }
232 bool forceLTR() const { return forceltr_; }
234 bool forceOwnlines() const { return forceownlines_; }
236 bool isInToc() const { return intoc_; }
238 bool spellcheck() const { return spellcheck_; }
240 bool resetsFont() const { return resetsfont_; }
242 bool isDisplay() const { return display_; }
244 bool forceLocalFontSwitch() const { return forcelocalfontswitch_; }
246 docstring const & obsoleted_by() const { return obsoleted_by_; }
248 bool addToToc() const { return add_to_toc_; }
250 std::string tocType() const { return toc_type_; }
252 bool isTocCaption() const { return is_toc_caption_; }
254 bool editExternally () const { return edit_external_; }
256 std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; }
258 std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
261 void makeDefaultCSS() const;
263 std::string defaultCSSClass() const;
265 void readArgument(Lexer &);
267 docstring name_ = from_ascii("undefined");
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'.
273 InsetLyXType lyxtype_ = InsetLyXType::STANDARD;
275 docstring labelstring_ = from_ascii("UNDEFINED");
277 docstring menustring_;
279 bool contentaslabel_ = false;
281 InsetDecoration decoration_ = InsetDecoration::DEFAULT;
283 InsetLaTeXType latextype_ = InsetLaTeXType::NOLATEXTYPE;
285 std::string latexname_;
287 std::string latexparam_;
289 docstring leftdelim_;
291 docstring rightdelim_;
293 FontInfo font_ = inherit_font;
295 FontInfo labelfont_ = sane_font;
297 bool inheritfont_ = true;
299 ColorCode bgcolor_ = Color_error;
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_;
309 bool fixedwidthpreambleencoding_ = false;
311 docstring refprefix_;
313 mutable std::string htmltag_;
315 mutable std::string htmlattr_;
317 mutable std::string htmlclass_;
319 mutable std::string htmlfullattrs_;
321 std::string htmlinnertag_;
323 mutable std::string htmlinnerattr_;
325 std::string htmllabel_;
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;
336 docstring htmlpreamble_;
338 bool htmlisblock_ = true;
340 std::string docbooktag_;
342 mutable std::string docbooktagtype_;
344 std::string docbookattr_;
346 std::string docbookinnertag_;
348 mutable std::string docbookinnertagtype_;
350 std::string docbookinnerattr_;
352 mutable std::string docbookininfo_;
354 bool docbooknotinpara_ = false;
356 bool docbookargumentbeforemaintag_ = false;
358 bool docbookargumentaftermaintag_ = false;
360 bool docbooksection_ = false;
362 std::string docbookwrappertag_;
364 mutable std::string docbookwrappertagtype_;
366 std::string docbookwrapperattr_;
368 std::string docbookitemtag_;
370 mutable std::string docbookitemtagtype_;
372 std::string docbookitemattr_;
374 std::string docbookitemwrappertag_;
376 mutable std::string docbookitemwrappertagtype_;
378 std::string docbookitemwrapperattr_;
380 bool docbooknofontinside_ = false;
382 bool docbookrenderasimage_ = false;
384 std::set<std::string> required_;
386 bool multipar_ = true;
388 bool custompars_ = true;
390 bool forceplain_ = false;
392 bool passthru_ = false;
394 docstring passthru_chars_;
396 std::string newline_cmd_;
398 bool parbreakisnewline_ = false;
400 bool parbreakignored_ = false;
402 bool freespacing_ = false;
404 bool keepempty_ = false;
406 bool forceltr_ = false;
408 bool forceownlines_ = false;
410 bool needprotect_ = false;
412 bool needcprotect_ = false;
414 bool needmboxprotect_ = false;
415 /// should the contents be written to TOC strings?
417 /// check spelling of this inset?
418 bool spellcheck_ = true;
420 bool resetsfont_ = false;
422 bool display_ = true;
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
429 docstring obsoleted_by_;
431 Layout::LaTeXArgMap latexargs_;
433 Layout::LaTeXArgMap postcommandargs_;
435 bool add_to_toc_ = false;
437 std::string toc_type_;
439 bool is_toc_caption_ = false;
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_;
449 InsetLyXType translateLyXType(std::string const & str);
450 InsetDecoration translateDecoration(std::string const & str);