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), passthru_(false), needprotect_(false),
38 freespacing_(false), keepempty_(false), forceltr_(false)
40 labelfont_.setColor(Color_error);
46 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
49 return InsetLayout::Classic;
50 if (str == "minimalistic")
51 return InsetLayout::Minimalistic;
52 if (str == "conglomerate")
53 return InsetLayout::Conglomerate;
54 return InsetLayout::Default;
60 bool InsetLayout::read(Lexer & lex, TextClass & tclass)
62 name_ = support::subst(lex.getDocString(), '_', ' ');
87 LexerKeyword elementTags[] = {
88 { "bgcolor", IL_BGCOLOR },
89 { "copystyle", IL_COPYSTYLE},
90 { "decoration", IL_DECORATION },
93 { "forceltr", IL_FORCELTR },
94 { "freespacing", IL_FREESPACING },
95 { "keepempty", IL_KEEPEMPTY },
96 { "labelfont", IL_LABELFONT },
97 { "labelstring", IL_LABELSTRING },
98 { "latexname", IL_LATEXNAME },
99 { "latexparam", IL_LATEXPARAM },
100 { "latextype", IL_LATEXTYPE },
101 { "lyxtype", IL_LYXTYPE },
102 { "multipar", IL_MULTIPAR },
103 { "needprotect", IL_NEEDPROTECT },
104 { "passthru", IL_PASSTHRU },
105 { "preamble", IL_PREAMBLE },
106 { "requires", IL_REQUIRES }
109 lex.pushTable(elementTags);
111 FontInfo font = inherit_font;
112 labelfont_ = inherit_font;
113 bgcolor_ = Color_background;
117 while (!getout && lex.isOK()) {
120 case Lexer::LEX_UNDEF:
121 lex.printError("Unknown InsetLayout tag");
138 decoration_ = translateDecoration(tmp);
145 latexparam_ = support::subst(tmp, """, "\"");
148 labelfont_ = lyxRead(lex, inherit_font);
168 case IL_COPYSTYLE: { // initialize with a known style
171 style = support::subst(style, '_', ' ');
173 // We don't want to apply the algorithm in DocumentClass::insetLayout()
174 // here. So we do it the long way.
175 TextClass::InsetLayouts::const_iterator it =
176 tclass.insetLayouts().find(style);
177 if (it != tclass.insetLayouts().end()) {
178 docstring const tmpname = name_;
179 this->operator=(it->second);
182 LYXERR0("Cannot copy unknown InsetLayout `"
184 << "All InsetLayouts so far:");
185 TextClass::InsetLayouts::const_iterator lit =
186 tclass.insetLayouts().begin();
187 TextClass::InsetLayouts::const_iterator len =
188 tclass.insetLayouts().end();
189 for (; lit != len; ++lit)
190 lyxerr << lit->second.name() << "\n";
196 font_ = lyxRead(lex, inherit_font);
197 // If you want to define labelfont, you need to do so after
204 bgcolor_ = lcolor.getFromLyXName(tmp);
207 preamble_ = lex.getLongString("EndPreamble");
211 vector<string> const req
212 = support::getVectorFromString(lex.getString());
213 requires_.insert(req.begin(), req.end());
222 // Here add element to list if getout == true
226 // The label font is generally used as-is without
227 // any realization against a given context.
228 labelfont_.realize(sane_font);