2008-02-22 03:27:42 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file InsetLayout.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Martin Vermeer
|
|
|
|
* \author Richard Heck
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetLayout.h"
|
|
|
|
|
|
|
|
#include "Color.h"
|
|
|
|
#include "Font.h"
|
2008-02-22 03:39:10 +00:00
|
|
|
#include "Lexer.h"
|
2008-07-28 15:14:37 +00:00
|
|
|
#include "TextClass.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
|
2008-07-28 15:14:37 +00:00
|
|
|
#include "support/debug.h"
|
2008-02-22 03:27:42 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
InsetLayout::InsetLayout() :
|
|
|
|
name_(from_ascii("undefined")), labelstring_(from_ascii("UNDEFINED")),
|
2008-03-21 18:49:23 +00:00
|
|
|
decoration_(InsetLayout::Default),
|
2008-02-22 03:27:42 +00:00
|
|
|
font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error),
|
2008-10-05 19:38:22 +00:00
|
|
|
multipar_(false), custompars_(false), forceplain_(true),
|
|
|
|
passthru_(false), needprotect_(false), freespacing_(false),
|
|
|
|
keepempty_(false), forceltr_(false)
|
2008-02-22 03:27:42 +00:00
|
|
|
{
|
2008-10-05 19:38:22 +00:00
|
|
|
labelfont_.setColor(Color_error);
|
2008-02-22 03:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
namespace {
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
InsetLayout::InsetDecoration translateDecoration(std::string const & str)
|
|
|
|
{
|
2008-10-25 01:55:55 +00:00
|
|
|
if (str == "classic" || str == "Classic")
|
2008-04-03 20:55:09 +00:00
|
|
|
return InsetLayout::Classic;
|
2008-10-25 01:55:55 +00:00
|
|
|
if (str == "minimalistic" || str == "Minimalistic")
|
2008-04-03 20:55:09 +00:00
|
|
|
return InsetLayout::Minimalistic;
|
2008-10-25 01:55:55 +00:00
|
|
|
if (str == "conglomerate" || str == "Conglomerate")
|
2008-04-03 20:55:09 +00:00
|
|
|
return InsetLayout::Conglomerate;
|
|
|
|
return InsetLayout::Default;
|
|
|
|
}
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-02-22 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-28 15:14:37 +00:00
|
|
|
bool InsetLayout::read(Lexer & lex, TextClass & tclass)
|
2008-02-22 03:27:42 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
name_ = support::subst(lex.getDocString(), '_', ' ');
|
2008-10-06 03:16:26 +00:00
|
|
|
// FIXME We need to check for name_.empty() here, and
|
|
|
|
// take the same sort of action as in TextClass::read()
|
|
|
|
// if it is empty. Or, better, we could read name_ there,
|
|
|
|
// take action there, etc.
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
|
|
|
IL_BGCOLOR,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_COPYSTYLE,
|
2008-10-05 19:38:22 +00:00
|
|
|
IL_CUSTOMPARS,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_DECORATION,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_FONT,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_FORCELTR,
|
2008-10-05 19:38:22 +00:00
|
|
|
IL_FORCEPLAIN,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_FREESPACING,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_LABELFONT,
|
|
|
|
IL_LABELSTRING,
|
|
|
|
IL_LATEXNAME,
|
|
|
|
IL_LATEXPARAM,
|
|
|
|
IL_LATEXTYPE,
|
|
|
|
IL_LYXTYPE,
|
|
|
|
IL_KEEPEMPTY,
|
|
|
|
IL_MULTIPAR,
|
|
|
|
IL_NEEDPROTECT,
|
|
|
|
IL_PASSTHRU,
|
|
|
|
IL_PREAMBLE,
|
|
|
|
IL_REQUIRES,
|
|
|
|
IL_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword elementTags[] = {
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "bgcolor", IL_BGCOLOR },
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "copystyle", IL_COPYSTYLE },
|
|
|
|
{ "custompars", IL_CUSTOMPARS },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "decoration", IL_DECORATION },
|
|
|
|
{ "end", IL_END },
|
|
|
|
{ "font", IL_FONT },
|
|
|
|
{ "forceltr", IL_FORCELTR },
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "forceplain", IL_FORCEPLAIN },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "freespacing", IL_FREESPACING },
|
|
|
|
{ "keepempty", IL_KEEPEMPTY },
|
|
|
|
{ "labelfont", IL_LABELFONT },
|
|
|
|
{ "labelstring", IL_LABELSTRING },
|
|
|
|
{ "latexname", IL_LATEXNAME },
|
|
|
|
{ "latexparam", IL_LATEXPARAM },
|
|
|
|
{ "latextype", IL_LATEXTYPE },
|
|
|
|
{ "lyxtype", IL_LYXTYPE },
|
|
|
|
{ "multipar", IL_MULTIPAR },
|
|
|
|
{ "needprotect", IL_NEEDPROTECT },
|
|
|
|
{ "passthru", IL_PASSTHRU },
|
|
|
|
{ "preamble", IL_PREAMBLE },
|
|
|
|
{ "requires", IL_REQUIRES }
|
|
|
|
};
|
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.pushTable(elementTags);
|
2008-02-22 03:27:42 +00:00
|
|
|
|
|
|
|
FontInfo font = inherit_font;
|
|
|
|
labelfont_ = inherit_font;
|
2008-10-25 10:47:38 +00:00
|
|
|
bgcolor_ = Color_none;
|
2008-02-22 03:27:42 +00:00
|
|
|
bool getout = false;
|
2008-10-05 19:38:22 +00:00
|
|
|
// whether we've read the CustomPars or ForcePlain tag
|
|
|
|
// for issuing a warning in case MultiPars comes later
|
|
|
|
bool readCustomOrPlain = false;
|
2008-04-05 10:34:29 +00:00
|
|
|
|
|
|
|
string tmp;
|
|
|
|
while (!getout && lex.isOK()) {
|
|
|
|
int le = lex.lex();
|
2008-02-22 03:27:42 +00:00
|
|
|
switch (le) {
|
|
|
|
case Lexer::LEX_UNDEF:
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Unknown InsetLayout tag");
|
2008-02-22 03:27:42 +00:00
|
|
|
continue;
|
2008-04-05 21:24:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
}
|
2008-04-03 20:55:09 +00:00
|
|
|
switch (le) {
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_LYXTYPE:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> lyxtype_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LATEXTYPE:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> latextype_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LABELSTRING:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> labelstring_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_DECORATION:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> tmp;
|
|
|
|
decoration_ = translateDecoration(tmp);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LATEXNAME:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> latexname_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LATEXPARAM:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> tmp;
|
|
|
|
latexparam_ = support::subst(tmp, """, "\"");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LABELFONT:
|
2008-04-05 10:34:29 +00:00
|
|
|
labelfont_ = lyxRead(lex, inherit_font);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_FORCELTR:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> forceltr_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_MULTIPAR:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> multipar_;
|
2008-10-05 19:38:22 +00:00
|
|
|
// the defaults for these depend upon multipar_
|
|
|
|
if (readCustomOrPlain)
|
|
|
|
LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
|
|
|
|
"Previous value may be overwritten!");
|
|
|
|
readCustomOrPlain = false;
|
|
|
|
custompars_ = multipar_;
|
|
|
|
forceplain_ = !multipar_;
|
|
|
|
break;
|
|
|
|
case IL_CUSTOMPARS:
|
|
|
|
lex >> custompars_;
|
|
|
|
readCustomOrPlain = true;
|
|
|
|
break;
|
|
|
|
case IL_FORCEPLAIN:
|
|
|
|
lex >> forceplain_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_PASSTHRU:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> passthru_;
|
2008-10-05 19:38:22 +00:00
|
|
|
readCustomOrPlain = true;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_KEEPEMPTY:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> keepempty_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_FREESPACING:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> freespacing_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_NEEDPROTECT:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> needprotect_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2008-07-28 15:14:37 +00:00
|
|
|
case IL_COPYSTYLE: { // initialize with a known style
|
|
|
|
docstring style;
|
|
|
|
lex >> style;
|
|
|
|
style = support::subst(style, '_', ' ');
|
|
|
|
|
|
|
|
// We don't want to apply the algorithm in DocumentClass::insetLayout()
|
|
|
|
// here. So we do it the long way.
|
|
|
|
TextClass::InsetLayouts::const_iterator it =
|
|
|
|
tclass.insetLayouts().find(style);
|
|
|
|
if (it != tclass.insetLayouts().end()) {
|
|
|
|
docstring const tmpname = name_;
|
|
|
|
this->operator=(it->second);
|
|
|
|
name_ = tmpname;
|
|
|
|
} else {
|
|
|
|
LYXERR0("Cannot copy unknown InsetLayout `"
|
|
|
|
<< style << "'\n"
|
|
|
|
<< "All InsetLayouts so far:");
|
|
|
|
TextClass::InsetLayouts::const_iterator lit =
|
|
|
|
tclass.insetLayouts().begin();
|
|
|
|
TextClass::InsetLayouts::const_iterator len =
|
|
|
|
tclass.insetLayouts().end();
|
|
|
|
for (; lit != len; ++lit)
|
|
|
|
lyxerr << lit->second.name() << "\n";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_FONT: {
|
2008-04-05 10:34:29 +00:00
|
|
|
font_ = lyxRead(lex, inherit_font);
|
2008-03-03 04:19:50 +00:00
|
|
|
// If you want to define labelfont, you need to do so after
|
|
|
|
// font is defined.
|
|
|
|
labelfont_ = font_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-04-05 10:34:29 +00:00
|
|
|
case IL_BGCOLOR:
|
|
|
|
lex >> tmp;
|
|
|
|
bgcolor_ = lcolor.getFromLyXName(tmp);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_PREAMBLE:
|
2008-04-05 10:34:29 +00:00
|
|
|
preamble_ = lex.getLongString("EndPreamble");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_REQUIRES: {
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.eatLine();
|
2008-02-22 03:27:42 +00:00
|
|
|
vector<string> const req
|
2008-04-05 10:34:29 +00:00
|
|
|
= support::getVectorFromString(lex.getString());
|
2008-02-22 03:27:42 +00:00
|
|
|
requires_.insert(req.begin(), req.end());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IL_END:
|
|
|
|
getout = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here add element to list if getout == true
|
|
|
|
if (!getout)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The label font is generally used as-is without
|
|
|
|
// any realization against a given context.
|
|
|
|
labelfont_.realize(sane_font);
|
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.popTable();
|
2008-02-22 03:27:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace lyx
|