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_(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 (support::compare_ascii_no_case(str, "classic") == 0)
50 return InsetLayout::CLASSIC;
51 if (support::compare_ascii_no_case(str, "minimalistic") == 0)
52 return InsetLayout::MINIMALISTIC;
53 if (support::compare_ascii_no_case(str, "conglomerate") == 0)
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");
142 lyxtype_ = translateLyXType(lt);
143 if (lyxtype_ == NOLYXTYPE)
144 LYXERR0("Unknown LyXType `" << lt << "'.");
155 decoration_ = translateDecoration(tmp);
162 latexparam_ = support::subst(tmp, """, "\"");
165 labelfont_ = lyxRead(lex, inherit_font);
172 // the defaults for these depend upon multipar_
173 if (readCustomOrPlain)
174 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
175 "Previous value may be overwritten!");
176 readCustomOrPlain = false;
177 custompars_ = multipar_;
178 forceplain_ = !multipar_;
182 readCustomOrPlain = true;
189 readCustomOrPlain = true;
200 case IL_COPYSTYLE: { // initialize with a known style
203 style = support::subst(style, '_', ' ');
205 // We don't want to apply the algorithm in DocumentClass::insetLayout()
206 // here. So we do it the long way.
207 TextClass::InsetLayouts::const_iterator it =
208 tclass.insetLayouts().find(style);
209 if (it != tclass.insetLayouts().end()) {
210 docstring const tmpname = name_;
211 this->operator=(it->second);
214 LYXERR0("Cannot copy unknown InsetLayout `"
216 << "All InsetLayouts so far:");
217 TextClass::InsetLayouts::const_iterator lit =
218 tclass.insetLayouts().begin();
219 TextClass::InsetLayouts::const_iterator len =
220 tclass.insetLayouts().end();
221 for (; lit != len; ++lit)
222 lyxerr << lit->second.name() << "\n";
228 font_ = lyxRead(lex, inherit_font);
229 // If you want to define labelfont, you need to do so after
236 bgcolor_ = lcolor.getFromLyXName(tmp);
239 preamble_ = lex.getLongString("EndPreamble");
243 vector<string> const req
244 = support::getVectorFromString(lex.getString());
245 requires_.insert(req.begin(), req.end());
254 // Here add element to list if getout == true
258 // The label font is generally used as-is without
259 // any realization against a given context.
260 labelfont_.realize(sane_font);
267 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
270 if (support::compare_ascii_no_case(str, "charstyle") == 0)
271 return InsetLayout::CHARSTYLE;
272 if (support::compare_ascii_no_case(str, "custom") == 0)
273 return InsetLayout::CUSTOM;
274 if (support::compare_ascii_no_case(str, "element") == 0)
275 return InsetLayout::ELEMENT;
276 if (support::compare_ascii_no_case(str, "end") == 0)
277 return InsetLayout::END;
278 if (support::compare_ascii_no_case(str, "standard") == 0)
279 return InsetLayout::STANDARD;
280 return InsetLayout::NOLYXTYPE;