3 * \file InsetLayout.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Martin Vermeer
10 * Full author contact details are available in file CREDITS.
15 #include "InsetLayout.h"
20 #include "TextClass.h"
22 #include "support/debug.h"
23 #include "support/lstrings.h"
33 InsetLayout::InsetLayout() :
34 name_(from_ascii("undefined")), lyxtype_(STANDARD),
35 labelstring_(from_ascii("UNDEFINED")), decoration_(DEFAULT),
36 latextype_(NOLATEXTYPE), font_(sane_font),
37 labelfont_(sane_font), bgcolor_(Color_error),
38 multipar_(false), custompars_(true), forceplain_(false),
39 passthru_(false), needprotect_(false), freespacing_(false),
40 keepempty_(false), forceltr_(false), intoc_(false)
42 labelfont_.setColor(Color_error);
48 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
50 if (support::compare_ascii_no_case(str, "classic") == 0)
51 return InsetLayout::CLASSIC;
52 if (support::compare_ascii_no_case(str, "minimalistic") == 0)
53 return InsetLayout::MINIMALISTIC;
54 if (support::compare_ascii_no_case(str, "conglomerate") == 0)
55 return InsetLayout::CONGLOMERATE;
56 return InsetLayout::DEFAULT;
59 InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
61 if (support::compare_ascii_no_case(str, "command") == 0)
62 return InsetLayout::COMMAND;
63 if (support::compare_ascii_no_case(str, "environment") == 0)
64 return InsetLayout::ENVIRONMENT;
65 if (support::compare_ascii_no_case(str, "none") == 0)
66 return InsetLayout::NOLATEXTYPE;
67 return InsetLayout::ILT_ERROR;
73 bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
110 LexerKeyword elementTags[] = {
111 { "bgcolor", IL_BGCOLOR },
112 { "copystyle", IL_COPYSTYLE },
113 { "counter", IL_COUNTER},
114 { "custompars", IL_CUSTOMPARS },
115 { "decoration", IL_DECORATION },
118 { "forceltr", IL_FORCELTR },
119 { "forceplain", IL_FORCEPLAIN },
120 { "freespacing", IL_FREESPACING },
121 { "htmlattr", IL_HTMLATTR },
122 { "htmlinnerattr", IL_HTMLINNERATTR},
123 { "htmlinnertag", IL_HTMLINNERTAG},
124 { "htmlisblock", IL_HTMLISBLOCK},
125 { "htmllabel", IL_HTMLLABEL },
126 { "htmlpreamble", IL_HTMLPREAMBLE },
127 { "htmlstyle", IL_HTMLSTYLE },
128 { "htmltag", IL_HTMLTAG },
129 { "intoc", IL_INTOC },
130 { "keepempty", IL_KEEPEMPTY },
131 { "labelfont", IL_LABELFONT },
132 { "labelstring", IL_LABELSTRING },
133 { "latexname", IL_LATEXNAME },
134 { "latexparam", IL_LATEXPARAM },
135 { "latextype", IL_LATEXTYPE },
136 { "lyxtype", IL_LYXTYPE },
137 { "multipar", IL_MULTIPAR },
138 { "needprotect", IL_NEEDPROTECT },
139 { "passthru", IL_PASSTHRU },
140 { "preamble", IL_PREAMBLE },
141 { "requires", IL_REQUIRES }
144 lex.pushTable(elementTags);
146 FontInfo font = inherit_font;
147 labelfont_ = inherit_font;
148 bgcolor_ = Color_none;
150 // whether we've read the CustomPars or ForcePlain tag
151 // for issuing a warning in case MultiPars comes later
152 bool readCustomOrPlain = false;
155 while (!getout && lex.isOK()) {
158 case Lexer::LEX_UNDEF:
159 lex.printError("Unknown InsetLayout tag");
166 // Perhaps a more elegant way to deal with the next two would be the
167 // way this sort of thing is handled in Layout::read(), namely, by
172 lyxtype_ = translateLyXType(lt);
173 if (lyxtype_ == NOLYXTYPE)
174 LYXERR0("Unknown LyXType `" << lt << "'.");
180 latextype_ = translateLaTeXType(lt);
181 if (latextype_ == ILT_ERROR)
182 LYXERR0("Unknown LaTeXType `" << lt << "'.");
190 decoration_ = translateDecoration(tmp);
197 latexparam_ = support::subst(tmp, """, "\"");
200 labelfont_ = lyxRead(lex, inherit_font);
210 // the defaults for these depend upon multipar_
211 if (readCustomOrPlain)
212 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
213 "Previous value may be overwritten!");
214 readCustomOrPlain = false;
215 custompars_ = multipar_;
216 forceplain_ = !multipar_;
223 readCustomOrPlain = true;
230 readCustomOrPlain = true;
241 case IL_COPYSTYLE: { // initialize with a known style
244 style = support::subst(style, '_', ' ');
246 // We don't want to apply the algorithm in DocumentClass::insetLayout()
247 // here. So we do it the long way.
248 TextClass::InsetLayouts::const_iterator it =
249 tclass.insetLayouts().find(style);
250 if (it != tclass.insetLayouts().end()) {
251 docstring const tmpname = name_;
252 this->operator=(it->second);
255 LYXERR0("Cannot copy unknown InsetLayout `"
257 << "All InsetLayouts so far:");
258 TextClass::InsetLayouts::const_iterator lit =
259 tclass.insetLayouts().begin();
260 TextClass::InsetLayouts::const_iterator len =
261 tclass.insetLayouts().end();
262 for (; lit != len; ++lit)
263 lyxerr << lit->second.name() << "\n";
269 font_ = lyxRead(lex, inherit_font);
270 // If you want to define labelfont, you need to do so after
277 bgcolor_ = lcolor.getFromLyXName(tmp);
280 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
288 case IL_HTMLINNERTAG:
289 lex >> htmlinnertag_;
291 case IL_HTMLINNERATTR:
292 lex >> htmlinnerattr_;
301 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
303 case IL_HTMLPREAMBLE:
304 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
308 vector<string> const req
309 = support::getVectorFromString(lex.getString());
310 requires_.insert(req.begin(), req.end());
319 // Here add element to list if getout == true
323 // The label font is generally used as-is without
324 // any realization against a given context.
325 labelfont_.realize(sane_font);
332 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
335 if (support::compare_ascii_no_case(str, "charstyle") == 0)
336 return InsetLayout::CHARSTYLE;
337 if (support::compare_ascii_no_case(str, "custom") == 0)
338 return InsetLayout::CUSTOM;
339 if (support::compare_ascii_no_case(str, "element") == 0)
340 return InsetLayout::ELEMENT;
341 if (support::compare_ascii_no_case(str, "end") == 0)
342 return InsetLayout::END;
343 if (support::compare_ascii_no_case(str, "standard") == 0)
344 return InsetLayout::STANDARD;
345 return InsetLayout::NOLYXTYPE;