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"
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
#include "ColorSet.h"
|
2008-02-22 03:27:42 +00:00
|
|
|
#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() :
|
2008-10-25 13:32:54 +00:00
|
|
|
name_(from_ascii("undefined")), lyxtype_(STANDARD),
|
2008-10-25 14:02:25 +00:00
|
|
|
labelstring_(from_ascii("UNDEFINED")), decoration_(DEFAULT),
|
|
|
|
latextype_(NOLATEXTYPE), font_(sane_font),
|
|
|
|
labelfont_(sane_font), bgcolor_(Color_error),
|
2009-07-14 21:08:48 +00:00
|
|
|
multipar_(false), custompars_(true), forceplain_(false),
|
2008-10-05 19:38:22 +00:00
|
|
|
passthru_(false), needprotect_(false), freespacing_(false),
|
2009-02-06 17:54:33 +00:00
|
|
|
keepempty_(false), forceltr_(false), intoc_(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 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "classic") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CLASSIC;
|
2008-10-25 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "minimalistic") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::MINIMALISTIC;
|
2008-10-25 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "conglomerate") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CONGLOMERATE;
|
|
|
|
return InsetLayout::DEFAULT;
|
2008-04-03 20:55:09 +00:00
|
|
|
}
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-10-25 14:02:25 +00:00
|
|
|
InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
|
|
|
|
{
|
|
|
|
if (support::compare_ascii_no_case(str, "command") == 0)
|
|
|
|
return InsetLayout::COMMAND;
|
|
|
|
if (support::compare_ascii_no_case(str, "environment") == 0)
|
|
|
|
return InsetLayout::ENVIRONMENT;
|
|
|
|
if (support::compare_ascii_no_case(str, "none") == 0)
|
|
|
|
return InsetLayout::NOLATEXTYPE;
|
|
|
|
return InsetLayout::ILT_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
} // namespace anon
|
2008-02-22 16:15:21 +00:00
|
|
|
|
|
|
|
|
2008-12-16 14:13:02 +00:00
|
|
|
bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
|
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,
|
2009-06-06 03:02:43 +00:00
|
|
|
IL_COUNTER,
|
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,
|
2009-06-05 17:36:51 +00:00
|
|
|
IL_HTMLTAG,
|
|
|
|
IL_HTMLATTR,
|
2009-06-06 03:02:43 +00:00
|
|
|
IL_HTMLINNERTAG,
|
|
|
|
IL_HTMLINNERATTR,
|
|
|
|
IL_HTMLLABEL,
|
2009-06-05 17:36:51 +00:00
|
|
|
IL_HTMLSTYLE,
|
2009-06-05 19:42:56 +00:00
|
|
|
IL_HTMLPREAMBLE,
|
2009-02-06 17:54:33 +00:00
|
|
|
IL_INTOC,
|
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 },
|
2009-06-06 03:02:43 +00:00
|
|
|
{ "counter", IL_COUNTER},
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "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 },
|
2009-06-05 17:36:51 +00:00
|
|
|
{ "htmlattr", IL_HTMLATTR },
|
2009-06-06 03:02:43 +00:00
|
|
|
{ "htmlinnerattr", IL_HTMLINNERATTR},
|
|
|
|
{ "htmlinnertag", IL_HTMLINNERTAG},
|
|
|
|
{ "htmllabel", IL_HTMLLABEL },
|
2009-06-05 19:42:56 +00:00
|
|
|
{ "htmlpreamble", IL_HTMLPREAMBLE },
|
2009-06-05 17:36:51 +00:00
|
|
|
{ "htmlstyle", IL_HTMLSTYLE },
|
|
|
|
{ "htmltag", IL_HTMLTAG },
|
2009-02-06 17:54:33 +00:00
|
|
|
{ "intoc", IL_INTOC },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "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-10-25 15:25:46 +00:00
|
|
|
// FIXME
|
2008-12-16 14:13:02 +00:00
|
|
|
// Perhaps a more elegant way to deal with the next two would be the
|
2008-10-25 15:25:46 +00:00
|
|
|
// way this sort of thing is handled in Layout::read(), namely, by
|
|
|
|
// using the Lexer.
|
2008-10-25 13:32:54 +00:00
|
|
|
case IL_LYXTYPE: {
|
|
|
|
string lt;
|
|
|
|
lex >> lt;
|
|
|
|
lyxtype_ = translateLyXType(lt);
|
|
|
|
if (lyxtype_ == NOLYXTYPE)
|
|
|
|
LYXERR0("Unknown LyXType `" << lt << "'.");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2008-10-25 13:32:54 +00:00
|
|
|
}
|
2008-10-25 14:02:25 +00:00
|
|
|
case IL_LATEXTYPE: {
|
|
|
|
string lt;
|
|
|
|
lex >> lt;
|
|
|
|
latextype_ = translateLaTeXType(lt);
|
|
|
|
if (latextype_ == ILT_ERROR)
|
|
|
|
LYXERR0("Unknown LaTeXType `" << lt << "'.");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2008-10-25 14:02:25 +00:00
|
|
|
}
|
2008-02-22 03:27:42 +00:00
|
|
|
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;
|
2009-02-06 17:54:33 +00:00
|
|
|
case IL_INTOC:
|
|
|
|
lex >> intoc_;
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
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;
|
2009-06-06 03:02:43 +00:00
|
|
|
case IL_COUNTER:
|
|
|
|
lex >> counter_;
|
|
|
|
break;
|
2008-10-05 19:38:22 +00:00
|
|
|
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:
|
2009-06-03 23:44:31 +00:00
|
|
|
preamble_ = from_utf8(lex.getLongString("EndPreamble"));
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2009-06-05 17:36:51 +00:00
|
|
|
case IL_HTMLTAG:
|
|
|
|
lex >> htmltag_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLATTR:
|
|
|
|
lex >> htmlattr_;
|
|
|
|
break;
|
2009-06-06 03:02:43 +00:00
|
|
|
case IL_HTMLINNERTAG:
|
|
|
|
lex >> htmlinnertag_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLINNERATTR:
|
|
|
|
lex >> htmlinnerattr_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLLABEL:
|
|
|
|
lex >> htmllabel_;
|
|
|
|
break;
|
2009-06-05 17:36:51 +00:00
|
|
|
case IL_HTMLSTYLE:
|
|
|
|
htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
|
|
|
|
break;
|
2009-06-05 19:42:56 +00:00
|
|
|
case IL_HTMLPREAMBLE:
|
|
|
|
htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-25 13:32:54 +00:00
|
|
|
|
|
|
|
InsetLayout::InsetLyXType translateLyXType(std::string const & str)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (support::compare_ascii_no_case(str, "charstyle") == 0)
|
|
|
|
return InsetLayout::CHARSTYLE;
|
|
|
|
if (support::compare_ascii_no_case(str, "custom") == 0)
|
|
|
|
return InsetLayout::CUSTOM;
|
|
|
|
if (support::compare_ascii_no_case(str, "element") == 0)
|
|
|
|
return InsetLayout::ELEMENT;
|
|
|
|
if (support::compare_ascii_no_case(str, "end") == 0)
|
|
|
|
return InsetLayout::END;
|
|
|
|
if (support::compare_ascii_no_case(str, "standard") == 0)
|
|
|
|
return InsetLayout::STANDARD;
|
|
|
|
return InsetLayout::NOLYXTYPE;
|
|
|
|
}
|
|
|
|
|
2008-02-22 03:27:42 +00:00
|
|
|
} //namespace lyx
|