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)
109 LexerKeyword elementTags[] = {
110 { "bgcolor", IL_BGCOLOR },
111 { "copystyle", IL_COPYSTYLE },
112 { "counter", IL_COUNTER},
113 { "custompars", IL_CUSTOMPARS },
114 { "decoration", IL_DECORATION },
117 { "forceltr", IL_FORCELTR },
118 { "forceplain", IL_FORCEPLAIN },
119 { "freespacing", IL_FREESPACING },
120 { "htmlattr", IL_HTMLATTR },
121 { "htmlinnerattr", IL_HTMLINNERATTR},
122 { "htmlinnertag", IL_HTMLINNERTAG},
123 { "htmllabel", IL_HTMLLABEL },
124 { "htmlpreamble", IL_HTMLPREAMBLE },
125 { "htmlstyle", IL_HTMLSTYLE },
126 { "htmltag", IL_HTMLTAG },
127 { "intoc", IL_INTOC },
128 { "keepempty", IL_KEEPEMPTY },
129 { "labelfont", IL_LABELFONT },
130 { "labelstring", IL_LABELSTRING },
131 { "latexname", IL_LATEXNAME },
132 { "latexparam", IL_LATEXPARAM },
133 { "latextype", IL_LATEXTYPE },
134 { "lyxtype", IL_LYXTYPE },
135 { "multipar", IL_MULTIPAR },
136 { "needprotect", IL_NEEDPROTECT },
137 { "passthru", IL_PASSTHRU },
138 { "preamble", IL_PREAMBLE },
139 { "requires", IL_REQUIRES }
142 lex.pushTable(elementTags);
144 FontInfo font = inherit_font;
145 labelfont_ = inherit_font;
146 bgcolor_ = Color_none;
148 // whether we've read the CustomPars or ForcePlain tag
149 // for issuing a warning in case MultiPars comes later
150 bool readCustomOrPlain = false;
153 while (!getout && lex.isOK()) {
156 case Lexer::LEX_UNDEF:
157 lex.printError("Unknown InsetLayout tag");
164 // Perhaps a more elegant way to deal with the next two would be the
165 // way this sort of thing is handled in Layout::read(), namely, by
170 lyxtype_ = translateLyXType(lt);
171 if (lyxtype_ == NOLYXTYPE)
172 LYXERR0("Unknown LyXType `" << lt << "'.");
178 latextype_ = translateLaTeXType(lt);
179 if (latextype_ == ILT_ERROR)
180 LYXERR0("Unknown LaTeXType `" << lt << "'.");
188 decoration_ = translateDecoration(tmp);
195 latexparam_ = support::subst(tmp, """, "\"");
198 labelfont_ = lyxRead(lex, inherit_font);
208 // the defaults for these depend upon multipar_
209 if (readCustomOrPlain)
210 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
211 "Previous value may be overwritten!");
212 readCustomOrPlain = false;
213 custompars_ = multipar_;
214 forceplain_ = !multipar_;
221 readCustomOrPlain = true;
228 readCustomOrPlain = true;
239 case IL_COPYSTYLE: { // initialize with a known style
242 style = support::subst(style, '_', ' ');
244 // We don't want to apply the algorithm in DocumentClass::insetLayout()
245 // here. So we do it the long way.
246 TextClass::InsetLayouts::const_iterator it =
247 tclass.insetLayouts().find(style);
248 if (it != tclass.insetLayouts().end()) {
249 docstring const tmpname = name_;
250 this->operator=(it->second);
253 LYXERR0("Cannot copy unknown InsetLayout `"
255 << "All InsetLayouts so far:");
256 TextClass::InsetLayouts::const_iterator lit =
257 tclass.insetLayouts().begin();
258 TextClass::InsetLayouts::const_iterator len =
259 tclass.insetLayouts().end();
260 for (; lit != len; ++lit)
261 lyxerr << lit->second.name() << "\n";
267 font_ = lyxRead(lex, inherit_font);
268 // If you want to define labelfont, you need to do so after
275 bgcolor_ = lcolor.getFromLyXName(tmp);
278 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
286 case IL_HTMLINNERTAG:
287 lex >> htmlinnertag_;
289 case IL_HTMLINNERATTR:
290 lex >> htmlinnerattr_;
296 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
298 case IL_HTMLPREAMBLE:
299 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
303 vector<string> const req
304 = support::getVectorFromString(lex.getString());
305 requires_.insert(req.begin(), req.end());
314 // Here add element to list if getout == true
318 // The label font is generally used as-is without
319 // any realization against a given context.
320 labelfont_.realize(sane_font);
327 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
330 if (support::compare_ascii_no_case(str, "charstyle") == 0)
331 return InsetLayout::CHARSTYLE;
332 if (support::compare_ascii_no_case(str, "custom") == 0)
333 return InsetLayout::CUSTOM;
334 if (support::compare_ascii_no_case(str, "element") == 0)
335 return InsetLayout::ELEMENT;
336 if (support::compare_ascii_no_case(str, "end") == 0)
337 return InsetLayout::END;
338 if (support::compare_ascii_no_case(str, "standard") == 0)
339 return InsetLayout::STANDARD;
340 return InsetLayout::NOLYXTYPE;