lyx_mirror/src/layout.C

1170 lines
29 KiB
C++
Raw Normal View History

/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-1999 The LyX Team.
*
* ====================================================== */
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include <algorithm>
#include "definitions.h"
#include "layout.h"
#include "lyxlex.h"
#include "support/filetools.h"
#include "lyx_gui_misc.h"
#include "debug.h"
#include "gettext.h"
#include "support/LAssert.h"
// Global variable: textclass table.
LyXTextClassList textclasslist;
// Reads the style files
void LyXSetStyle()
{
lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
if (!textclasslist.Read()) {
lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
"during parsing.\n Exiting." << endl;
exit(1);
}
lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
}
// The order of the LayoutTags enum is no more important. [asierra300396]
// Tags indexes.
enum LayoutTags {
LT_ALIGN, LT_ALIGNPOSSIBLE,
LT_BLOCK, LT_MARGIN,
LT_BOTTOMSEP, LT_CENTER, LT_CENTERED_TOP_ENVIRONMENT, LT_COLUMNS,
LT_COPYSTYLE, LT_OBSOLETEDBY,
LT_COMMAND, LT_COUNTER_CHAPTER, LT_COUNTER_ENUMI, LT_COUNTER_ENUMII,
LT_COUNTER_ENUMIII, LT_COUNTER_ENUMIV, LT_COUNTER_PARAGRAPH,
LT_COUNTER_SECTION, LT_COUNTER_SUBPARAGRAPH, LT_COUNTER_SUBSECTION,
LT_COUNTER_SUBSUBSECTION, LT_DEFAULTFONT, LT_DYNAMIC, LT_EMPTY,
LT_END, LT_ENVIRONMENT, LT_ENVIRONMENT_DEFAULT,
LT_FANCYHDR, LT_FILL_BOTTOM, LT_FILL_TOP, LT_FIRST_COUNTER,
LT_FIRST_DYNAMIC, LT_FONT, LT_FREE_SPACING, LT_HEADINGS, LT_INPUT,
LT_ITEM_ENVIRONMENT, LT_ITEMSEP, LT_KEEPEMPTY,
LT_LABEL_BOTTOMSEP, LT_LABELFONT, LT_TEXTFONT,
LT_LABELINDENT, LT_LABELSEP, LT_LABELSTRING,
LT_LABELSTRING_APPENDIX, LT_LABELTYPE,
LT_LATEXNAME, LT_LATEXPARAM, LT_LATEXTYPE, LT_LAYOUT, LT_LEFT,
LT_LEFTMARGIN,
LT_LIST_ENVIRONMENT , LT_MANUAL, LT_MAXCOUNTER,
LT_NEED_PROTECT, LT_NEWLINE,
LT_NEXTNOINDENT, LT_NO_LABEL, LT_NOSTYLE,
LT_PAGESTYLE, LT_PARAGRAPH,
LT_PARINDENT, LT_PARSEP, LT_PARSKIP, LT_PLAIN, LT_PREAMBLE,
LT_PROVIDESAMSMATH, LT_PROVIDESMAKEIDX, LT_PROVIDESURL, LT_RIGHT,
LT_RIGHT_ADDRESS_BOX, LT_RIGHTMARGIN, LT_SENSITIVE, LT_SIDES,
LT_SPACING, LT_SPACING_SINGLE, LT_SPACING_ONEHALF,
LT_SPACING_DOUBLE, LT_OTHER, LT_CLASSOPTIONS, LT_FONTSIZE,
LT_STATIC, LT_STYLE, LT_TOP_ENVIRONMENT, LT_TOPSEP, LT_BIBLIO,
LT_INTITLE, LT_SECNUMDEPTH, LT_TOCDEPTH,
LT_OUTPUTTYPE, LT_OTLATEX, LT_OTLINUXDOC, LT_OTDOCBOOK, LT_OTLITERATE
};
// This table is sorted alphabetically [asierra 30March96]
static keyword_item layoutTags[] = {
{ "align", LT_ALIGN },
{ "alignpossible", LT_ALIGNPOSSIBLE },
{ "bibliography", LT_BIBLIO },
{ "block", LT_BLOCK },
{ "bottomsep", LT_BOTTOMSEP },
{ "center", LT_CENTER },
{ "centered_top_environment", LT_CENTERED_TOP_ENVIRONMENT },
{ "classoptions", LT_CLASSOPTIONS },
{ "columns", LT_COLUMNS },
{ "command", LT_COMMAND },
{ "copystyle", LT_COPYSTYLE },
{ "counter_chapter", LT_COUNTER_CHAPTER },
{ "counter_enumi", LT_COUNTER_ENUMI },
{ "counter_enumii", LT_COUNTER_ENUMII },
{ "counter_enumiii", LT_COUNTER_ENUMIII },
{ "counter_enumiv", LT_COUNTER_ENUMIV },
{ "counter_paragraph", LT_COUNTER_PARAGRAPH },
{ "counter_section", LT_COUNTER_SECTION },
{ "counter_subparagraph", LT_COUNTER_SUBPARAGRAPH },
{ "counter_subsection", LT_COUNTER_SUBSECTION },
{ "counter_subsubsection", LT_COUNTER_SUBSUBSECTION },
{ "defaultfont", LT_DEFAULTFONT },
{ "docbook", LT_OTDOCBOOK },
{ "double", LT_SPACING_DOUBLE },
{ "dynamic", LT_DYNAMIC },
{ "empty", LT_EMPTY },
{ "end", LT_END },
{ "environment", LT_ENVIRONMENT },
{ "environment_default", LT_ENVIRONMENT_DEFAULT },
{ "fancyhdr", LT_FANCYHDR },
{ "fill_bottom", LT_FILL_BOTTOM },
{ "fill_top", LT_FILL_TOP },
{ "first_counter", LT_FIRST_COUNTER },
{ "first_dynamic", LT_FIRST_DYNAMIC },
{ "font", LT_FONT },
{ "fontsize", LT_FONTSIZE },
{ "freespacing", LT_FREE_SPACING },
{ "headings", LT_HEADINGS },
{ "input", LT_INPUT },
{ "intitle", LT_INTITLE },
{ "item_environment", LT_ITEM_ENVIRONMENT },
{ "itemsep", LT_ITEMSEP },
{ "keepempty", LT_KEEPEMPTY },
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
{ "labelfont", LT_LABELFONT },
{ "labelindent", LT_LABELINDENT },
{ "labelsep", LT_LABELSEP },
{ "labelstring", LT_LABELSTRING },
{ "labelstringappendix", LT_LABELSTRING_APPENDIX },
{ "labeltype", LT_LABELTYPE },
{ "latex", LT_OTLATEX },
{ "latexname", LT_LATEXNAME },
{ "latexparam", LT_LATEXPARAM }, //arrae970411
{ "latextype", LT_LATEXTYPE },
{ "layout", LT_LAYOUT },
{ "left", LT_LEFT },
{ "leftmargin", LT_LEFTMARGIN },
{ "linuxdoc", LT_OTLINUXDOC },
{ "list_environment", LT_LIST_ENVIRONMENT },
{ "literate", LT_OTLITERATE },
{ "manual", LT_MANUAL },
{ "margin", LT_MARGIN },
{ "maxcounter", LT_MAXCOUNTER },
{ "needprotect", LT_NEED_PROTECT },
{ "newline", LT_NEWLINE },
{ "nextnoindent", LT_NEXTNOINDENT },
{ "no_label", LT_NO_LABEL },
{ "nostyle", LT_NOSTYLE },
{ "obsoletedby", LT_OBSOLETEDBY },
{ "onehalf", LT_SPACING_ONEHALF },
{ "other", LT_OTHER },
{ "outputtype", LT_OUTPUTTYPE },
{ "pagestyle", LT_PAGESTYLE },
{ "paragraph", LT_PARAGRAPH },
{ "parindent", LT_PARINDENT },
{ "parsep", LT_PARSEP },
{ "parskip", LT_PARSKIP },
{ "plain", LT_PLAIN },
{ "preamble", LT_PREAMBLE },
{ "providesamsmath", LT_PROVIDESAMSMATH },
{ "providesmakeidx", LT_PROVIDESMAKEIDX },
{ "providesurl", LT_PROVIDESURL },
{ "right", LT_RIGHT },
{ "right_address_box", LT_RIGHT_ADDRESS_BOX },
{ "rightmargin", LT_RIGHTMARGIN },
{ "secnumdepth", LT_SECNUMDEPTH },
{ "sensitive", LT_SENSITIVE },
{ "sides", LT_SIDES },
{ "single", LT_SPACING_SINGLE },
{ "spacing", LT_SPACING },
{ "static", LT_STATIC },
{ "style", LT_STYLE },
{ "textfont", LT_TEXTFONT },
{ "tocdepth", LT_TOCDEPTH },
{ "top_environment", LT_TOP_ENVIRONMENT },
{ "topsep", LT_TOPSEP }
};
/////////////////////
// Constructor for layout
LyXLayout::LyXLayout ()
{
margintype = MARGIN_STATIC;
latextype = LATEX_PARAGRAPH;
intitle = false;
needprotect = false;
keepempty = false;
font = LyXFont(LyXFont::ALL_INHERIT);
labelfont = LyXFont(LyXFont::ALL_INHERIT);
resfont = LyXFont(LyXFont::ALL_SANE);
reslabelfont = LyXFont(LyXFont::ALL_SANE);
nextnoindent = false;
parskip = 0.0;
itemsep = 0;
topsep = 0.0;
bottomsep = 0.0;
labelbottomsep = 0.0;
parsep = 0;
align = LYX_ALIGN_BLOCK;
alignpossible = LYX_ALIGN_BLOCK;
labeltype = LABEL_NO_LABEL;
// Should or should not. That is the question.
// spacing.set(Spacing::OneHalf);
fill_top = false;
fill_bottom = false;
newline_allowed = true;
free_spacing = false;
}
// Reads a layout definition from file
bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
{
bool error = false;
bool finished = false;
// parse style section
while (!finished && lexrc.IsOK() && !error) {
switch(lexrc.lex()) {
case -2:
break;
case -1: // parse error
lexrc.printError("Unknown tag `$$Token'");
error = true;
break;
case LT_END: // end of structure
finished = true;
break;
case LT_COPYSTYLE: // initialize with a known style
if (lexrc.next()) {
if (tclass.hasLayout(lexrc.GetString())) {
string tmpname = name_;
this->operator=(tclass.GetLayout(lexrc.GetString()));
name_ = tmpname;
} else {
lexrc.printError("Cannot copy known "
"style `$$Token'");
}
}
break;
case LT_OBSOLETEDBY: // replace with a known style
if (lexrc.next()) {
if (tclass.hasLayout(lexrc.GetString())) {
string tmpname = name_;
this->operator=(tclass.GetLayout(lexrc.GetString()));
name_ = tmpname;
if (obsoleted_by().empty())
obsoleted_by_ = lexrc.GetString();
} else {
lexrc.printError("Cannot replace with"
" unknown style "
"`$$Token'");
}
}
break;
case LT_MARGIN: // Margin style definition.
switch(lexrc.lex()) {
case LT_STATIC:
margintype = MARGIN_STATIC;
break;
case LT_MANUAL:
margintype = MARGIN_MANUAL;
break;
case LT_DYNAMIC:
margintype = MARGIN_DYNAMIC;
break;
case LT_FIRST_DYNAMIC:
margintype = MARGIN_FIRST_DYNAMIC;
break;
case LT_RIGHT_ADDRESS_BOX:
margintype = MARGIN_RIGHT_ADDRESS_BOX;
break;
default:
lexrc.printError("Unknown margin type `$$Token'");
break;
}
break;
case LT_LATEXTYPE: // Latex style definition.
switch (lexrc.lex()) {
case LT_PARAGRAPH:
latextype=LATEX_PARAGRAPH;
break;
case LT_COMMAND:
latextype=LATEX_COMMAND;
break;
case LT_ENVIRONMENT:
latextype=LATEX_ENVIRONMENT;
break;
case LT_ITEM_ENVIRONMENT:
latextype=LATEX_ITEM_ENVIRONMENT;
break;
case LT_LIST_ENVIRONMENT:
latextype=LATEX_LIST_ENVIRONMENT;
break;
default:
lexrc.printError("Unknown latextype `$$Token'");
break;
}
break;
case LT_INTITLE:
intitle = lexrc.next() && lexrc.GetInteger();
break;
case LT_NEED_PROTECT:
needprotect = lexrc.next() && lexrc.GetInteger();
break;
case LT_KEEPEMPTY:
keepempty = lexrc.next() && lexrc.GetInteger();
break;
case LT_FONT:
font.lyxRead(lexrc);
labelfont=font;
break;
case LT_TEXTFONT:
font.lyxRead(lexrc);
break;
case LT_LABELFONT:
labelfont.lyxRead(lexrc);
break;
case LT_NEXTNOINDENT: // Indent next paragraph?
if (lexrc.next() && lexrc.GetInteger())
nextnoindent = true;
else
nextnoindent = false;
break;
case LT_LATEXNAME:
if (lexrc.next())
latexname_ = lexrc.GetString();
break;
case LT_LATEXPARAM:
if (lexrc.next())
latexparam_ = lexrc.GetString();
break;
case LT_PREAMBLE:
preamble_ = lexrc.getLongString("EndPreamble");
break;
case LT_LABELTYPE:
switch (lexrc.lex()) {
case LT_NO_LABEL:
labeltype = LABEL_NO_LABEL;
break;
case LT_MANUAL:
labeltype = LABEL_MANUAL;
break;
case LT_TOP_ENVIRONMENT:
labeltype = LABEL_TOP_ENVIRONMENT;
break;
case LT_CENTERED_TOP_ENVIRONMENT:
labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
break;
case LT_STATIC:
labeltype = LABEL_STATIC;
break;
case LT_SENSITIVE:
labeltype = LABEL_SENSITIVE;
break;
case LT_COUNTER_CHAPTER:
labeltype = LABEL_COUNTER_CHAPTER;
break;
case LT_COUNTER_SECTION:
labeltype = LABEL_COUNTER_SECTION;
break;
case LT_COUNTER_SUBSECTION:
labeltype = LABEL_COUNTER_SUBSECTION;
break;
case LT_COUNTER_SUBSUBSECTION:
labeltype = LABEL_COUNTER_SUBSUBSECTION;
break;
case LT_COUNTER_PARAGRAPH:
labeltype = LABEL_COUNTER_PARAGRAPH;
break;
case LT_COUNTER_SUBPARAGRAPH:
labeltype = LABEL_COUNTER_SUBPARAGRAPH;
break;
case LT_COUNTER_ENUMI:
labeltype = LABEL_COUNTER_ENUMI;
break;
case LT_COUNTER_ENUMII:
labeltype = LABEL_COUNTER_ENUMII;
break;
case LT_COUNTER_ENUMIII:
labeltype = LABEL_COUNTER_ENUMIII;
break;
case LT_COUNTER_ENUMIV:
labeltype = LABEL_COUNTER_ENUMIV;
break;
case LT_BIBLIO:
labeltype = LABEL_BIBLIO;
break;
default:
lexrc.printError("Unknown labeltype `$$Token'");
}
break;
case LT_LEFTMARGIN: // left margin type
if (lexrc.next())
leftmargin = lexrc.GetString();
break;
case LT_RIGHTMARGIN: // right margin type
if (lexrc.next())
rightmargin = lexrc.GetString();
break;
case LT_LABELINDENT: // label indenting flag
if (lexrc.next())
labelindent = lexrc.GetString();
break;
case LT_PARINDENT: // paragraph indent. flag
if (lexrc.next())
parindent = lexrc.GetString();
break;
case LT_PARSKIP: // paragraph skip size
if (lexrc.next())
parskip = lexrc.GetFloat();
break;
case LT_ITEMSEP: // item separation size
if (lexrc.next())
itemsep = lexrc.GetFloat();
break;
case LT_TOPSEP: // top separation size
if (lexrc.next())
topsep = lexrc.GetFloat();
break;
case LT_BOTTOMSEP: // bottom separation size
if (lexrc.next())
bottomsep = lexrc.GetFloat();
break;
case LT_LABEL_BOTTOMSEP: // label bottom separation size
if (lexrc.next())
labelbottomsep = lexrc.GetFloat();
break;
case LT_LABELSEP: // label separator
if (lexrc.next()) {
labelsep = subst(lexrc.GetString(), 'x', ' ');
}
break;
case LT_PARSEP: // par. separation size
if (lexrc.next())
parsep = lexrc.GetFloat();
break;
case LT_FILL_TOP: // fill top flag
if (lexrc.next())
fill_top = lexrc.GetInteger();
break;
case LT_FILL_BOTTOM: // fill bottom flag
if (lexrc.next())
fill_bottom = lexrc.GetInteger();
break;
case LT_NEWLINE: // newlines allowed?
if (lexrc.next())
newline_allowed = lexrc.GetInteger();
break;
case LT_ALIGN: // paragraph align
switch (lexrc.lex()) {
case LT_BLOCK:
align = LYX_ALIGN_BLOCK;
break;
case LT_LEFT:
align = LYX_ALIGN_LEFT;
break;
case LT_RIGHT:
align = LYX_ALIGN_RIGHT;
break;
case LT_CENTER:
align = LYX_ALIGN_CENTER;
break;
case LT_LAYOUT:
align = LYX_ALIGN_LAYOUT;
break;
default:
lexrc.printError("Unknown alignment `$$Token'");
}
break;
case LT_ALIGNPOSSIBLE: // paragraph allowed align
{ alignpossible = LYX_ALIGN_NONE;
int lineno = lexrc.GetLineNo();
do {
switch (lexrc.lex()) {
case LT_BLOCK:
alignpossible |= LYX_ALIGN_BLOCK;
break;
case LT_LEFT:
alignpossible |= LYX_ALIGN_LEFT;
break;
case LT_RIGHT:
alignpossible |= LYX_ALIGN_RIGHT;
break;
case LT_CENTER:
alignpossible |= LYX_ALIGN_CENTER;
break;
case LT_LAYOUT:
alignpossible |= LYX_ALIGN_LAYOUT;
break;
default:
lexrc.printError("Unknown alignment `$$Token'");
}
} while (lineno == lexrc.GetLineNo());
break;
}
case LT_LABELSTRING: // label string definition
if (lexrc.next())
labelstring_ = lexrc.GetString();
break;
case LT_LABELSTRING_APPENDIX: // label string appendix definition
if (lexrc.next())
labelstring_appendix_ = lexrc.GetString();
break;
case LT_FREE_SPACING: // Allow for free spacing.
if (lexrc.next())
free_spacing = lexrc.GetInteger();
break;
case LT_SPACING: // setspace.sty
switch(lexrc.lex()) {
case LT_SPACING_SINGLE:
spacing.set(Spacing::Single);
break;
case LT_SPACING_ONEHALF:
spacing.set(Spacing::Onehalf);
break;
case LT_SPACING_DOUBLE:
spacing.set(Spacing::Double);
break;
case LT_OTHER:
lexrc.next();
spacing.set(Spacing::Other, lexrc.GetFloat());
break;
default:
lexrc.printError("Unknown spacing `$$Token'");
}
break;
default: /* context error */
lexrc.printError("Tag `$$Token' is not "
"allowed in layout");
error = true;
break;
}
}
return error;
}
/* ******************************************************************* */
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
string const & desc)
: name_(fn), latexname_(cln), description_(desc)
{
outputType_ = LATEX;
columns_ = 1;
sides_ = OneSide;
secnumdepth_ = 3;
tocdepth_ = 3;
pagestyle_ = "default";
maxcounter_ = LABEL_COUNTER_CHAPTER;
defaultfont_ = LyXFont(LyXFont::ALL_SANE);
opt_fontsize_ = "10|11|12";
opt_pagestyle_ = "empty|plain|headings|fancy";
provides_ = nothing;
loaded = false;
}
bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
{
lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
if (!lay.Read(lexrc, *this)) {
// Reslove fonts
lay.resfont = lay.font;
lay.resfont.realize(defaultfont());
lay.reslabelfont = lay.labelfont;
lay.reslabelfont.realize(defaultfont());
return false; // no errors
}
lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
return true;
}
// Reads a textclass structure from file.
bool LyXTextClass::Read(string const & filename, bool merge)
{
if (!merge)
lyxerr[Debug::TCLASS] << "Reading textclass "
<< MakeDisplayPath(filename)
<< endl;
else
lyxerr[Debug::TCLASS] << "Reading input file "
<< MakeDisplayPath(filename)
<< endl;
LyXLex lexrc(layoutTags, sizeof(layoutTags)/sizeof(keyword_item));
bool error = false;
lexrc.setFile(filename);
if (!lexrc.IsOK()) error = true;
// parsing
while (lexrc.IsOK() && !error) {
switch(lexrc.lex()) {
case -2:
break;
case -1:
lexrc.printError("Unknown tag `$$Token'");
error = true;
break;
case LT_OUTPUTTYPE: // output type definition
switch(lexrc.lex()) {
case LT_OTLATEX:
outputType_ = LATEX;
break;
case LT_OTLINUXDOC:
outputType_ = LINUXDOC;
break;
case LT_OTDOCBOOK:
outputType_ = DOCBOOK;
break;
case LT_OTLITERATE:
outputType_ = LITERATE;
break;
default:
lexrc.printError("Unknown output type `$$Token'");
break;
}
break;
case LT_INPUT: // Include file
if (lexrc.next()) {
string tmp = LibFileSearch("layouts",
lexrc.GetString(),
"layout");
if (Read(tmp, true)) {
lexrc.printError("Error reading input"
"file: "+tmp);
error = true;
}
}
break;
case LT_STYLE:
if (lexrc.next()) {
string name = subst(lexrc.GetString(),
'_', ' ');
if (hasLayout(name)) {
LyXLayout & lay = GetLayout(name);
error = do_readStyle(lexrc, lay);
} else {
LyXLayout lay;
lay.name(name);
if (!(error =do_readStyle(lexrc, lay)))
layoutlist.push_back(lay);
}
}
else {
lexrc.printError("No name given for style: `$$Token'.");
error = true;
}
break;
case LT_NOSTYLE:
if (lexrc.next()) {
string style = subst(lexrc.GetString(),
'_', ' ');
if (!delete_layout(style))
lexrc.printError("Cannot delete style"
" `$$Token'");
}
break;
case LT_COLUMNS:
if (lexrc.next())
columns_ = lexrc.GetInteger();
break;
case LT_SIDES:
if (lexrc.next()) {
switch(lexrc.GetInteger()) {
case 1: sides_ = OneSide; break;
case 2: sides_ = TwoSides; break;
default:
lyxerr << "Impossible number of page"
" sides, setting to one."
<< endl;
sides_ = OneSide;
break;
}
}
break;
case LT_PAGESTYLE:
lexrc.next();
pagestyle_ = strip(lexrc.GetString());
break;
case LT_DEFAULTFONT:
defaultfont_.lyxRead(lexrc);
if (!defaultfont_.resolved()) {
lexrc.printError("Warning: defaultfont should "
"be fully instantiated!");
defaultfont_.realize(LyXFont::ALL_SANE);
}
break;
case LT_MAXCOUNTER:
switch (lexrc.lex()) {
case LT_COUNTER_CHAPTER:
maxcounter_ = LABEL_COUNTER_CHAPTER;
break;
case LT_COUNTER_SECTION:
maxcounter_ = LABEL_COUNTER_SECTION;
break;
case LT_COUNTER_SUBSECTION:
maxcounter_ = LABEL_COUNTER_SUBSECTION;
break;
case LT_COUNTER_SUBSUBSECTION:
maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
break;
case LT_COUNTER_PARAGRAPH:
maxcounter_ = LABEL_COUNTER_PARAGRAPH;
break;
case LT_COUNTER_SUBPARAGRAPH:
maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
break;
case LT_COUNTER_ENUMI:
maxcounter_ = LABEL_COUNTER_ENUMI;
break;
case LT_COUNTER_ENUMII:
maxcounter_ = LABEL_COUNTER_ENUMII;
break;
case LT_COUNTER_ENUMIII:
maxcounter_ = LABEL_COUNTER_ENUMIII;
break;
case LT_COUNTER_ENUMIV:
maxcounter_ = LABEL_COUNTER_ENUMIV;
break;
}
break;
case LT_SECNUMDEPTH:
lexrc.next();
secnumdepth_ = lexrc.GetInteger();
break;
case LT_TOCDEPTH:
lexrc.next();
tocdepth_ = lexrc.GetInteger();
break;
// First step to support options
case LT_CLASSOPTIONS:
{
bool getout = true;
while (getout && lexrc.IsOK()) {
switch (lexrc.lex()) {
case LT_FONTSIZE:
lexrc.next();
opt_fontsize_ = strip(lexrc.GetString());
break;
case LT_PAGESTYLE:
lexrc.next();
opt_pagestyle_ = strip(lexrc.GetString());
break;
case LT_OTHER:
lexrc.next();
options_ = lexrc.GetString();
break;
case LT_END: getout = false; break;
default:
lexrc.printError("Out of context tag `$$Token'");
break;
}
}
break;
}
case LT_PREAMBLE:
preamble_ = lexrc.getLongString("EndPreamble");
break;
case LT_PROVIDESAMSMATH:
if (lexrc.next() && lexrc.GetInteger())
provides_ |= amsmath;
break;
case LT_PROVIDESMAKEIDX:
if (lexrc.next() && lexrc.GetInteger())
provides_ |= makeidx;
break;
case LT_PROVIDESURL:
if (lexrc.next() && lexrc.GetInteger())
provides_ = url;
break;
case LT_LEFTMARGIN: // left margin type
if (lexrc.next())
leftmargin_ = lexrc.GetString();
break;
case LT_RIGHTMARGIN: // right margin type
if (lexrc.next())
rightmargin_ = lexrc.GetString();
break;
default:
lexrc.printError("Out of context tag `$$Token'");
break;
}
}
if (!merge) { // we are at top level here.
lyxerr[Debug::TCLASS] << "Finished reading textclass "
<< MakeDisplayPath(filename)
<< endl;
} else
lyxerr[Debug::TCLASS] << "Finished reading input file "
<< MakeDisplayPath(filename)
<< endl;
return error;
}
bool LyXTextClass::hasLayout(string const & name) const
{
for (LayoutList::const_iterator cit = layoutlist.begin();
cit != layoutlist.end(); ++cit) {
if ((*cit).name() == name)
return true;
}
return false;
}
LyXLayout const & LyXTextClass::GetLayout (string const & name) const
{
for (LayoutList::const_iterator cit = layoutlist.begin();
cit != layoutlist.end(); ++cit) {
if ((*cit).name() == name)
return (*cit);
}
Assert(false); // we actually require the name to exist.
return layoutlist.front();
}
LyXLayout & LyXTextClass::GetLayout(string const & name)
{
for (LayoutList::iterator it = layoutlist.begin();
it != layoutlist.end(); ++it) {
if ((*it).name() == name)
return (*it);
}
Assert(false); // we actually require the name to exist.
return layoutlist.front();
}
bool LyXTextClass::delete_layout (string const & name)
{
for(LayoutList::iterator it = layoutlist.begin();
it != layoutlist.end(); ++it) {
if ((*it).name() == name) {
layoutlist.erase(it);
return true;
}
}
return false;
}
// Load textclass info if not loaded yet
void LyXTextClass::load()
{
if (loaded) return;
// Read style-file
string real_file = LibFileSearch("layouts", name_, "layout");
if (Read(real_file)) {
lyxerr << "Error reading `"
<< MakeDisplayPath(real_file)
<< "'\n(Check `" << name_
<< "')\nCheck your installation and "
"try Options/Reconfigure..." << endl;
}
loaded = true;
}
//////////////////////////////////////////
// Gets textclass number from name
pair<bool, LyXTextClassList::ClassList::size_type>
LyXTextClassList::NumberOfClass(string const & textclass) const
{
for (ClassList::const_iterator cit = classlist.begin();
cit != classlist.end(); ++cit) {
if ((*cit).name() == textclass)
return make_pair(true, cit - classlist.begin());
}
return make_pair(false, 0);
}
// Gets layout structure from style number and textclass number
LyXLayout const &
LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass,
LyXTextClass::LayoutList::size_type layout) const
{
classlist[textclass].load();
if (layout < classlist[textclass].numLayouts())
return classlist[textclass][layout];
return classlist[textclass][0];
}
// Gets layout number from name and textclass number
pair<bool, LyXTextClass::LayoutList::size_type>
LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclass, string const & name) const
{
classlist[textclass].load();
for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
if (classlist[textclass][i].name() == name)
return make_pair(true, i);
}
if (name == "dummy")
return make_pair(true, LYX_DUMMY_LAYOUT);
return make_pair(false, 0); // not found
}
// Gets a layout (style) name from layout number and textclass number
string const &
LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass,
LyXTextClass::LayoutList::size_type layout) const
{
static string dummy("dummy");
static string end("@@end@@");
classlist[textclass].load();
if (layout < classlist[textclass].numLayouts())
return classlist[textclass][layout].name();
else if (layout == LYX_DUMMY_LAYOUT)
return dummy;
else
return end;
}
// Gets a textclass name from number
string const &
LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) const
{
static string dummy("dummy");
static string end("@@end@@");
if (classlist.size() == 0) {
if (number == 0) return dummy;
else return end;
}
if (number < classlist.size())
return classlist[number].name();
else
return end;
}
// Gets a textclass latexname from number
string const &
LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number) const
{
static string dummy("dummy");
static string end("@@end@@");
classlist[number].load();
if (classlist.size() == 0) {
if (number == 0) return dummy;
else return end;
}
if (number < classlist.size())
return classlist[number].latexname();
else
return end;
}
// Gets a textclass description from number
string const &
LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) const
{
static string dummy("dummy");
static string end("@@end@@");
if (classlist.size() == 0) {
if (number == 0) return dummy;
else return end;
}
if (number < classlist.size())
return classlist[number].description();
else
return end;
}
// Gets a textclass structure from number
LyXTextClass const &
LyXTextClassList::TextClass(LyXTextClassList::ClassList::size_type textclass) const
{
classlist[textclass].load();
if (textclass < classlist.size())
return classlist[textclass];
else
return classlist[0];
}
void LyXTextClassList::Add(LyXTextClass const & t)
{
classlist.push_back(t);
}
// used when sorting the textclass list.
class less_textclass_desc {
public:
int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
return tc1.description() < tc2.description();
}
};
// Reads LyX textclass definitions according to textclass config file
bool LyXTextClassList::Read ()
{
LyXLex lex(0, 0);
string real_file = LibFileSearch("", "textclass.lst");
lyxerr[Debug::TCLASS] << "Reading textclasses from "
<< real_file << endl;
if (real_file.empty()) {
lyxerr << "LyXTextClassList::Read: unable to find "
"textclass file `" << MakeDisplayPath(real_file, 1000)
<< "'. Exiting." << endl;
WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
_("Check that the file \"textclass.lst\""),
_("is installed correctly. Sorry, has to exit :-("));
return false;
// This causes LyX to end... Not a desirable behaviour. Lgb
// What do you propose? That the user gets a file dialog
// and is allowed to hunt for the file? (Asger)
}
lex.setFile(real_file);
if (!lex.IsOK()) {
lyxerr << "LyXTextClassList::Read: unable to open "
"textclass file `" << MakeDisplayPath(real_file, 1000)
<< "\'\nCheck your installation. LyX can't continue."
<< endl;
return false;
}
bool finished = false;
string fname, clname, desc;
// Parse config-file
while (lex.IsOK() && !finished) {
switch (lex.lex()) {
case LyXLex::LEX_FEOF:
finished = true;
break;
default:
fname = lex.GetString();
lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
if (lex.next()) {
clname = lex.GetString();
lyxerr[Debug::TCLASS]
<< "Clname: " << clname << endl;
if (lex.next()) {
desc = lex.GetString();
lyxerr[Debug::TCLASS]
<< "Desc: " << desc << endl;
// This code is run when we have
// fname, clname and desc
LyXTextClass tmpl(fname,
clname,
desc);
if (lyxerr.
debugging(Debug::TCLASS)) {
tmpl.load();
}
Add (tmpl);
}
}
}
}
if (classlist.size() == 0) {
lyxerr << "LyXTextClassList::Read: no textclass found!"
<< endl;
WriteAlert(_("LyX wasn't able to find any layout description!"),
_("Check the contents of the file \"textclass.lst\""),
_("Sorry, has to exit :-("));
return false;
}
// Ok everything loaded ok, now sort the list.
sort(classlist.begin(), classlist.end(), less_textclass_desc());
return true;
}
/* Load textclass
Returns false if this fails
*/
bool
LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const
{
bool result = true;
if (number < classlist.size()) {
classlist[number].load();
if (classlist[number].numLayouts() == 0) {
result = false;
}
} else {
result = false;
}
return result;
}