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_(false), forceplain_(true),
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)
101 LexerKeyword elementTags[] = {
102 { "bgcolor", IL_BGCOLOR },
103 { "copystyle", IL_COPYSTYLE },
104 { "custompars", IL_CUSTOMPARS },
105 { "decoration", IL_DECORATION },
108 { "forceltr", IL_FORCELTR },
109 { "forceplain", IL_FORCEPLAIN },
110 { "freespacing", IL_FREESPACING },
111 { "intoc", IL_INTOC },
112 { "keepempty", IL_KEEPEMPTY },
113 { "labelfont", IL_LABELFONT },
114 { "labelstring", IL_LABELSTRING },
115 { "latexname", IL_LATEXNAME },
116 { "latexparam", IL_LATEXPARAM },
117 { "latextype", IL_LATEXTYPE },
118 { "lyxtype", IL_LYXTYPE },
119 { "multipar", IL_MULTIPAR },
120 { "needprotect", IL_NEEDPROTECT },
121 { "passthru", IL_PASSTHRU },
122 { "preamble", IL_PREAMBLE },
123 { "requires", IL_REQUIRES }
126 lex.pushTable(elementTags);
128 FontInfo font = inherit_font;
129 labelfont_ = inherit_font;
130 bgcolor_ = Color_none;
132 // whether we've read the CustomPars or ForcePlain tag
133 // for issuing a warning in case MultiPars comes later
134 bool readCustomOrPlain = false;
137 while (!getout && lex.isOK()) {
140 case Lexer::LEX_UNDEF:
141 lex.printError("Unknown InsetLayout tag");
148 // Perhaps a more elegant way to deal with the next two would be the
149 // way this sort of thing is handled in Layout::read(), namely, by
154 lyxtype_ = translateLyXType(lt);
155 if (lyxtype_ == NOLYXTYPE)
156 LYXERR0("Unknown LyXType `" << lt << "'.");
162 latextype_ = translateLaTeXType(lt);
163 if (latextype_ == ILT_ERROR)
164 LYXERR0("Unknown LaTeXType `" << lt << "'.");
172 decoration_ = translateDecoration(tmp);
179 latexparam_ = support::subst(tmp, """, "\"");
182 labelfont_ = lyxRead(lex, inherit_font);
192 // the defaults for these depend upon multipar_
193 if (readCustomOrPlain)
194 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
195 "Previous value may be overwritten!");
196 readCustomOrPlain = false;
197 custompars_ = multipar_;
198 forceplain_ = !multipar_;
202 readCustomOrPlain = true;
209 readCustomOrPlain = true;
220 case IL_COPYSTYLE: { // initialize with a known style
223 style = support::subst(style, '_', ' ');
225 // We don't want to apply the algorithm in DocumentClass::insetLayout()
226 // here. So we do it the long way.
227 TextClass::InsetLayouts::const_iterator it =
228 tclass.insetLayouts().find(style);
229 if (it != tclass.insetLayouts().end()) {
230 docstring const tmpname = name_;
231 this->operator=(it->second);
234 LYXERR0("Cannot copy unknown InsetLayout `"
236 << "All InsetLayouts so far:");
237 TextClass::InsetLayouts::const_iterator lit =
238 tclass.insetLayouts().begin();
239 TextClass::InsetLayouts::const_iterator len =
240 tclass.insetLayouts().end();
241 for (; lit != len; ++lit)
242 lyxerr << lit->second.name() << "\n";
248 font_ = lyxRead(lex, inherit_font);
249 // If you want to define labelfont, you need to do so after
256 bgcolor_ = lcolor.getFromLyXName(tmp);
259 preamble_ = lex.getLongString("EndPreamble");
263 vector<string> const req
264 = support::getVectorFromString(lex.getString());
265 requires_.insert(req.begin(), req.end());
274 // Here add element to list if getout == true
278 // The label font is generally used as-is without
279 // any realization against a given context.
280 labelfont_.realize(sane_font);
287 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
290 if (support::compare_ascii_no_case(str, "charstyle") == 0)
291 return InsetLayout::CHARSTYLE;
292 if (support::compare_ascii_no_case(str, "custom") == 0)
293 return InsetLayout::CUSTOM;
294 if (support::compare_ascii_no_case(str, "element") == 0)
295 return InsetLayout::ELEMENT;
296 if (support::compare_ascii_no_case(str, "end") == 0)
297 return InsetLayout::END;
298 if (support::compare_ascii_no_case(str, "standard") == 0)
299 return InsetLayout::STANDARD;
300 return InsetLayout::NOLYXTYPE;