#include "Layout.h"
#include "TextClass.h"
#include "Lexer.h"
-#include "debug.h"
+#include "Font.h"
+#include "support/debug.h"
#include "support/lstrings.h"
+#include <ostream>
-namespace lyx {
-
-using support::subst;
-using support::trim;
+using namespace std;
+using namespace lyx::support;
-using std::endl;
-using std::string;
+namespace lyx {
/// Special value of toclevel for layouts that to not belong in a TOC
const int Layout::NOT_IN_TOC = -1000;
LT_ALIGNPOSSIBLE,
LT_MARGIN,
LT_BOTTOMSEP,
+ LT_CATEGORY,
LT_COMMANDDEPTH,
LT_COPYSTYLE,
LT_DEPENDSON,
LT_PARSKIP,
//LT_PLAIN,
LT_PREAMBLE,
+ LT_REQUIRES,
LT_RIGHTMARGIN,
LT_SPACING,
LT_TOPSEP,
/////////////////////
-// Constructor for layout
-Layout::Layout ()
+Layout::Layout()
{
margintype = MARGIN_STATIC;
latextype = LATEX_PARAGRAPH;
optionalargs = 0;
needprotect = false;
keepempty = false;
- font = Font(Font::ALL_INHERIT);
- labelfont = Font(Font::ALL_INHERIT);
- resfont = Font(Font::ALL_SANE);
- reslabelfont = Font(Font::ALL_SANE);
+ font = inherit_font;
+ labelfont = inherit_font;
+ resfont = sane_font;
+ reslabelfont = sane_font;
nextnoindent = false;
parskip = 0.0;
itemsep = 0;
labelbottomsep = 0.0;
parsep = 0;
align = LYX_ALIGN_BLOCK;
- alignpossible = LYX_ALIGN_BLOCK;
+ alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
labeltype = LABEL_NO_LABEL;
endlabeltype = END_LABEL_NO_LABEL;
// Should or should not. That is the question.
}
-// Reads a layout definition from file
bool Layout::read(Lexer & lexrc, TextClass const & tclass)
{
// This table is sorted alphabetically [asierra 30March96]
- keyword_item layoutTags[] = {
+ LexerKeyword layoutTags[] = {
{ "align", LT_ALIGN },
{ "alignpossible", LT_ALIGNPOSSIBLE },
{ "bottomsep", LT_BOTTOMSEP },
+ { "category", LT_CATEGORY },
{ "commanddepth", LT_COMMANDDEPTH },
{ "copystyle", LT_COPYSTYLE },
{ "dependson", LT_DEPENDSON },
{ "parskip", LT_PARSKIP },
{ "passthru", LT_PASS_THRU },
{ "preamble", LT_PREAMBLE },
+ { "requires", LT_REQUIRES },
{ "rightmargin", LT_RIGHTMARGIN },
{ "spacing", LT_SPACING },
{ "textfont", LT_TEXTFONT },
bool error = false;
bool finished = false;
- lexrc.pushTable(layoutTags, LT_INTITLE);
+ lexrc.pushTable(layoutTags);
// parse style section
while (!finished && lexrc.isOK() && !error) {
int le = lexrc.lex();
finished = true;
break;
+ case LT_CATEGORY:
+ if (lexrc.next())
+ category_ = lexrc.getDocString();
+ break;
+
case LT_COPYSTYLE: // initialize with a known style
if (lexrc.next()) {
docstring const style = subst(lexrc.getDocString(),
if (tclass.hasLayout(style)) {
docstring const tmpname = name_;
- this->operator=(*tclass[style]);
+ this->operator=(tclass[style]);
name_ = tmpname;
} else {
lyxerr << "Cannot copy unknown style `"
<< to_utf8(style) << "'\n"
<< "All layouts so far:"
<< endl;
- TextClass::const_iterator it =
- tclass.begin();
- TextClass::const_iterator end =
- tclass.end();
- for (; it != end; ++it) {
- lyxerr << to_utf8((*it)->name())
- << endl;
- }
+ DocumentClass::const_iterator lit = tclass.begin();
+ DocumentClass::const_iterator len = tclass.end();
+ for (; lit != len; ++lit)
+ lyxerr << to_utf8(lit->name()) << endl;
//lexrc.printError("Cannot copy known "
// "style `$$Token'");
if (tclass.hasLayout(style)) {
docstring const tmpname = name_;
- this->operator=(*tclass[style]);
+ this->operator=(tclass[style]);
name_ = tmpname;
if (obsoleted_by().empty())
obsoleted_by_ = style;
break;
case LT_FONT:
- font.lyxRead(lexrc);
- labelfont= font;
+ font = lyxRead(lexrc, font);
+ labelfont = font;
break;
case LT_TEXTFONT:
- font.lyxRead(lexrc);
+ font = lyxRead(lexrc, font);
break;
case LT_LABELFONT:
- labelfont.lyxRead(lexrc);
+ labelfont = lyxRead(lexrc, labelfont);
break;
case LT_NEXTNOINDENT: // Indent next paragraph?
case LT_LEFTMARGIN: // left margin type
if (lexrc.next())
- leftmargin = lexrc.getString();
+ leftmargin = lexrc.getDocString();
break;
case LT_RIGHTMARGIN: // right margin type
if (lexrc.next())
- rightmargin = lexrc.getString();
+ rightmargin = lexrc.getDocString();
break;
case LT_LABELINDENT: // label indenting flag
if (lexrc.next())
- labelindent = lexrc.getString();
+ labelindent = lexrc.getDocString();
break;
case LT_PARINDENT: // paragraph indent. flag
if (lexrc.next())
- parindent = lexrc.getString();
+ parindent = lexrc.getDocString();
break;
case LT_PARSKIP: // paragraph skip size
case LT_LABELSEP: // label separator
if (lexrc.next()) {
- labelsep = subst(lexrc.getString(), 'x', ' ');
+ labelsep = from_utf8(subst(lexrc.getString(), 'x', ' '));
}
break;
case LT_SPACING: // setspace.sty
readSpacing(lexrc);
break;
+
+ case LT_REQUIRES:
+ lexrc.eatLine();
+ vector<string> const req =
+ getVectorFromString(lexrc.getString());
+ requires_.insert(req.begin(), req.end());
+ break;
+
}
}
lexrc.popTable();
- return error;
+ return !error;
}
void Layout::readAlign(Lexer & lexrc)
{
- keyword_item alignTags[] = {
+ LexerKeyword alignTags[] = {
{ "block", AT_BLOCK },
{ "center", AT_CENTER },
{ "layout", AT_LAYOUT },
void Layout::readAlignPossible(Lexer & lexrc)
{
- keyword_item alignTags[] = {
+ LexerKeyword alignTags[] = {
{ "block", AT_BLOCK },
{ "center", AT_CENTER },
{ "layout", AT_LAYOUT },
{ "right", AT_RIGHT }
};
- lexrc.pushTable(alignTags, AT_LAYOUT);
- alignpossible = LYX_ALIGN_NONE;
- int lineno = lexrc.getLineNo();
+ lexrc.pushTable(alignTags);
+ alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
+ int lineno = lexrc.lineNumber();
do {
int le = lexrc.lex();
switch (le) {
alignpossible |= LYX_ALIGN_LAYOUT;
break;
}
- } while (lineno == lexrc.getLineNo());
+ } while (lineno == lexrc.lineNumber());
lexrc.popTable();
}
void Layout::readLabelType(Lexer & lexrc)
{
- keyword_item labelTypeTags[] = {
+ LexerKeyword labelTypeTags[] = {
{ "bibliography", LA_BIBLIO },
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
{ "counter", LA_COUNTER },
}
-namespace {
-
-keyword_item endlabelTypeTags[] = {
+static LexerKeyword endlabelTypeTags[] =
+{
{ "box", END_LABEL_BOX },
{ "filled_box", END_LABEL_FILLED_BOX },
{ "no_label", END_LABEL_NO_LABEL },
{ "static", END_LABEL_STATIC }
};
-} // namespace anon
-
void Layout::readEndLabelType(Lexer & lexrc)
{
case END_LABEL_BOX:
case END_LABEL_FILLED_BOX:
case END_LABEL_NO_LABEL:
- endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
+ endlabeltype = static_cast<EndLabelType>(le);
break;
default:
lyxerr << "Unhandled value " << le
void Layout::readMargin(Lexer & lexrc)
{
- keyword_item marginTags[] = {
+ LexerKeyword marginTags[] = {
{ "dynamic", MARGIN_DYNAMIC },
{ "first_dynamic", MARGIN_FIRST_DYNAMIC },
{ "manual", MARGIN_MANUAL },
case MARGIN_DYNAMIC:
case MARGIN_FIRST_DYNAMIC:
case MARGIN_RIGHT_ADDRESS_BOX:
- margintype = static_cast<LYX_MARGIN_TYPE>(le);
+ margintype = static_cast<MarginType>(le);
break;
default:
lyxerr << "Unhandled value " << le
void Layout::readLatexType(Lexer & lexrc)
{
- keyword_item latexTypeTags[] = {
+ LexerKeyword latexTypeTags[] = {
{ "bib_environment", LATEX_BIB_ENVIRONMENT },
{ "command", LATEX_COMMAND },
{ "environment", LATEX_ENVIRONMENT },
case LATEX_ITEM_ENVIRONMENT:
case LATEX_BIB_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
- latextype = static_cast<LYX_LATEX_TYPES>(le);
+ latextype = static_cast<LatexType>(le);
break;
default:
lyxerr << "Unhandled value " << le
void Layout::readSpacing(Lexer & lexrc)
{
- keyword_item spacingTags[] = {
+ LexerKeyword spacingTags[] = {
{"double", ST_SPACING_DOUBLE },
{"onehalf", ST_SPACING_ONEHALF },
{"other", ST_OTHER },
}
-void Layout::setName(docstring const & n)
+void Layout::setName(docstring const & name)
{
- name_ = n;
+ name_ = name;
}
}
+bool Layout::operator==(Layout const & rhs) const
+{
+ // This is enough for the applications we actually make,
+ // at least at the moment. But we could check more.
+ return name() == rhs.name()
+ && latexname() == rhs.latexname()
+ && latextype == rhs.latextype;
+}
+
+
Layout * Layout::forCaption()
{
Layout * lay = new Layout();
return lay;
}
-
-
} // namespace lyx