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")), labelstring_(from_ascii("UNDEFINED")),
35 decoration_(InsetLayout::Default),
36 font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error),
37 multipar_(false), custompars_(false), forceplain_(true),
38 passthru_(false), needprotect_(false), freespacing_(false),
39 keepempty_(false), forceltr_(false)
41 labelfont_.setColor(Color_error);
47 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
49 if (str == "classic" || str == "Classic")
50 return InsetLayout::Classic;
51 if (str == "minimalistic" || str == "Minimalistic")
52 return InsetLayout::Minimalistic;
53 if (str == "conglomerate" || str == "Conglomerate")
54 return InsetLayout::Conglomerate;
55 return InsetLayout::Default;
61 bool InsetLayout::read(Lexer & lex, TextClass & tclass)
63 name_ = support::subst(lex.getDocString(), '_', ' ');
64 // FIXME We need to check for name_.empty() here, and
65 // take the same sort of action as in TextClass::read()
66 // if it is empty. Or, better, we could read name_ there,
67 // take action there, etc.
94 LexerKeyword elementTags[] = {
95 { "bgcolor", IL_BGCOLOR },
96 { "copystyle", IL_COPYSTYLE },
97 { "custompars", IL_CUSTOMPARS },
98 { "decoration", IL_DECORATION },
101 { "forceltr", IL_FORCELTR },
102 { "forceplain", IL_FORCEPLAIN },
103 { "freespacing", IL_FREESPACING },
104 { "keepempty", IL_KEEPEMPTY },
105 { "labelfont", IL_LABELFONT },
106 { "labelstring", IL_LABELSTRING },
107 { "latexname", IL_LATEXNAME },
108 { "latexparam", IL_LATEXPARAM },
109 { "latextype", IL_LATEXTYPE },
110 { "lyxtype", IL_LYXTYPE },
111 { "multipar", IL_MULTIPAR },
112 { "needprotect", IL_NEEDPROTECT },
113 { "passthru", IL_PASSTHRU },
114 { "preamble", IL_PREAMBLE },
115 { "requires", IL_REQUIRES }
118 lex.pushTable(elementTags);
120 FontInfo font = inherit_font;
121 labelfont_ = inherit_font;
122 bgcolor_ = Color_none;
124 // whether we've read the CustomPars or ForcePlain tag
125 // for issuing a warning in case MultiPars comes later
126 bool readCustomOrPlain = false;
129 while (!getout && lex.isOK()) {
132 case Lexer::LEX_UNDEF:
133 lex.printError("Unknown InsetLayout tag");
150 decoration_ = translateDecoration(tmp);
157 latexparam_ = support::subst(tmp, """, "\"");
160 labelfont_ = lyxRead(lex, inherit_font);
167 // the defaults for these depend upon multipar_
168 if (readCustomOrPlain)
169 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
170 "Previous value may be overwritten!");
171 readCustomOrPlain = false;
172 custompars_ = multipar_;
173 forceplain_ = !multipar_;
177 readCustomOrPlain = true;
184 readCustomOrPlain = true;
195 case IL_COPYSTYLE: { // initialize with a known style
198 style = support::subst(style, '_', ' ');
200 // We don't want to apply the algorithm in DocumentClass::insetLayout()
201 // here. So we do it the long way.
202 TextClass::InsetLayouts::const_iterator it =
203 tclass.insetLayouts().find(style);
204 if (it != tclass.insetLayouts().end()) {
205 docstring const tmpname = name_;
206 this->operator=(it->second);
209 LYXERR0("Cannot copy unknown InsetLayout `"
211 << "All InsetLayouts so far:");
212 TextClass::InsetLayouts::const_iterator lit =
213 tclass.insetLayouts().begin();
214 TextClass::InsetLayouts::const_iterator len =
215 tclass.insetLayouts().end();
216 for (; lit != len; ++lit)
217 lyxerr << lit->second.name() << "\n";
223 font_ = lyxRead(lex, inherit_font);
224 // If you want to define labelfont, you need to do so after
231 bgcolor_ = lcolor.getFromLyXName(tmp);
234 preamble_ = lex.getLongString("EndPreamble");
238 vector<string> const req
239 = support::getVectorFromString(lex.getString());
240 requires_.insert(req.begin(), req.end());
249 // Here add element to list if getout == true
253 // The label font is generally used as-is without
254 // any realization against a given context.
255 labelfont_.realize(sane_font);