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"
29 namespace support { class Lexer; }
31 enum class InsetDecoration : int {
38 enum class InsetLyXType : int {
46 enum class InsetLaTeXType : int {
58 InsetLayout() { labelfont_.setColor(Color_insetlabel); }
60 bool read(support::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 docstring noPassThruChars() const { return no_passthru_chars_; }
217 std::string newlineCmd() const { return newline_cmd_; }
219 bool parbreakIsNewline() const { return parbreakisnewline_; }
221 bool parbreakIgnored() const { return parbreakignored_; }
223 bool isNeedProtect() const { return needprotect_; }
225 bool needsCProtect() const { return needcprotect_; }
227 bool noCProtect() const { return nocprotect_; }
228 /// Protection of some elements such as \ref and \cite
229 /// in \mbox (needed by commands building on soul or ulem)
230 bool isNeedMBoxProtect() const { return needmboxprotect_; }
232 bool isFreeSpacing() const { return freespacing_; }
234 bool isKeepEmpty() const { return keepempty_; }
236 bool forceLTR() const { return forceltr_; }
238 bool forceOwnlines() const { return forceownlines_; }
240 bool isInToc() const { return intoc_; }
242 bool spellcheck() const { return spellcheck_; }
244 bool resetsFont() const { return resetsfont_; }
246 bool isDisplay() const { return display_; }
248 bool forceLocalFontSwitch() const { return forcelocalfontswitch_; }
250 docstring const & obsoleted_by() const { return obsoleted_by_; }
252 bool addToToc() const { return add_to_toc_; }
254 std::string tocType() const { return toc_type_; }
256 bool isTocCaption() const { return is_toc_caption_; }
258 bool editExternally () const { return edit_external_; }
260 std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; }
262 std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
264 int allowedOccurrences() const { return allowed_occurrences_; }
266 bool allowedOccurrencesPerItem() const { return allowed_occurrences_per_item_; }
269 void makeDefaultCSS() const;
271 std::string defaultCSSClass() const;
273 void readArgument(support::Lexer &);
275 docstring name_ = from_ascii("undefined");
277 * This is only used (at present) to decide where to put them on the menus.
278 * Values are 'charstyle', 'custom' (things that by default look like a
279 * footnote), 'standard'.
281 InsetLyXType lyxtype_ = InsetLyXType::STANDARD;
283 docstring labelstring_ = from_ascii("UNDEFINED");
285 docstring menustring_;
287 bool contentaslabel_ = false;
289 InsetDecoration decoration_ = InsetDecoration::DEFAULT;
291 InsetLaTeXType latextype_ = InsetLaTeXType::NOLATEXTYPE;
293 std::string latexname_;
295 std::string latexparam_;
297 docstring leftdelim_;
299 docstring rightdelim_;
301 FontInfo font_ = inherit_font;
303 FontInfo labelfont_ = sane_font;
305 bool inheritfont_ = true;
307 ColorCode bgcolor_ = Color_error;
312 /// Language dependent macro definitions needed for this inset
313 docstring langpreamble_;
314 /// Language and babel dependent macro definitions needed for this inset
315 docstring babelpreamble_;
317 bool fixedwidthpreambleencoding_ = false;
319 docstring refprefix_;
321 mutable std::string htmltag_;
323 mutable std::string htmlattr_;
325 mutable std::string htmlclass_;
327 mutable std::string htmlfullattrs_;
329 std::string htmlinnertag_;
331 mutable std::string htmlinnerattr_;
333 std::string htmllabel_;
335 docstring htmlstyle_;
336 /// Cache for default CSS info for this inset.
337 mutable docstring htmldefaultstyle_;
338 /// Cache for default CSS class.
339 mutable std::string defaultcssclass_;
340 /// Whether to force generation of default CSS even if some is given.
341 /// False by default.
342 bool htmlforcecss_ = false;
344 docstring htmlpreamble_;
346 bool htmlisblock_ = true;
348 std::string docbooktag_;
350 mutable std::string docbooktagtype_;
352 std::string docbookattr_;
354 std::string docbookinnertag_;
356 mutable std::string docbookinnertagtype_;
358 std::string docbookinnerattr_;
360 mutable std::string docbookininfo_;
362 bool docbooknotinpara_ = false;
364 bool docbookargumentbeforemaintag_ = false;
366 bool docbookargumentaftermaintag_ = false;
368 bool docbooksection_ = false;
370 std::string docbookwrappertag_;
372 mutable std::string docbookwrappertagtype_;
374 std::string docbookwrapperattr_;
376 std::string docbookitemtag_;
378 mutable std::string docbookitemtagtype_;
380 std::string docbookitemattr_;
382 std::string docbookitemwrappertag_;
384 mutable std::string docbookitemwrappertagtype_;
386 std::string docbookitemwrapperattr_;
388 bool docbooknofontinside_ = false;
390 bool docbookrenderasimage_ = false;
392 std::set<std::string> required_;
394 bool multipar_ = true;
396 bool custompars_ = true;
398 bool forceplain_ = false;
400 bool passthru_ = false;
402 docstring passthru_chars_;
404 docstring no_passthru_chars_;
406 std::string newline_cmd_;
408 bool parbreakisnewline_ = false;
410 bool parbreakignored_ = false;
412 bool freespacing_ = false;
414 bool keepempty_ = false;
416 bool forceltr_ = false;
418 bool forceownlines_ = false;
420 bool needprotect_ = false;
422 bool needcprotect_ = false;
424 bool nocprotect_ = false;
426 bool needmboxprotect_ = false;
427 /// should the contents be written to TOC strings?
429 /// check spelling of this inset?
430 bool spellcheck_ = true;
432 bool resetsfont_ = false;
434 bool display_ = true;
436 bool forcelocalfontswitch_ = false;
437 /** Name of an insetlayout that has replaced this insetlayout.
438 This is used to rename an insetlayout, while keeping backward
441 docstring obsoleted_by_;
443 Layout::LaTeXArgMap latexargs_;
445 Layout::LaTeXArgMap postcommandargs_;
447 bool add_to_toc_ = false;
449 std::string toc_type_;
451 bool is_toc_caption_ = false;
453 bool edit_external_ = false;
454 /// Insets that can hold insets with this InsetLayout
455 std::set<docstring> allowed_in_insets_;
456 /// Layouts that can hold insets with this InsetLayout
457 std::set<docstring> allowed_in_layouts_;
459 int allowed_occurrences_ = -1;
461 bool allowed_occurrences_per_item_ = false;
465 InsetLyXType translateLyXType(std::string const & str);
466 InsetDecoration translateDecoration(std::string const & str);