mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
the automatic label patch
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7739 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
757df94b07
commit
92a24f6f99
@ -655,7 +655,7 @@ void BufferView::Pimpl::workAreaResize()
|
||||
|
||||
void BufferView::Pimpl::update()
|
||||
{
|
||||
lyxerr << "BufferView::update()" << endl;
|
||||
//lyxerr << "BufferView::update()" << endl;
|
||||
// fix cursor coordinate cache in case something went wrong
|
||||
if (bv_->getLyXText()) {
|
||||
// check needed to survive LyX startup
|
||||
|
@ -53,7 +53,7 @@ Bullet::Bullet(int f, int c, int s)
|
||||
|
||||
|
||||
Bullet::Bullet(string const & t)
|
||||
: font(MIN), character(MIN), size(MIN), user_text(1), text(t)
|
||||
: font(MIN), character(MIN), size(MIN), user_text(1), text(t)
|
||||
{
|
||||
testInvariant();
|
||||
}
|
||||
|
@ -1,3 +1,17 @@
|
||||
|
||||
2003-09-12 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* BufferView_pimpl.C:
|
||||
* Bullet.C:
|
||||
* layout.h:
|
||||
* lyxfunc.C:
|
||||
* lyxlayout.[Ch]:
|
||||
* lyxtextclass.C:
|
||||
* rowpainter.C:
|
||||
* text.C:
|
||||
* text2.C:
|
||||
* Counters.[Ch]: finish the 'automatic counters' job
|
||||
|
||||
2003-09-12 Juergen Spitzmueller <j.spitzmueller@gmx.de>
|
||||
|
||||
* aspell.C: include <boost/assert.cpp> (compile fix)
|
||||
|
187
src/counters.C
187
src/counters.C
@ -5,6 +5,7 @@
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author Martin Vermeer
|
||||
* \author André Pönitz
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -12,17 +13,15 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "counters.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/std_sstream.h"
|
||||
#include "support/tostr.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
using std::endl;
|
||||
|
||||
using std::ostringstream;
|
||||
|
||||
|
||||
@ -74,7 +73,6 @@ void Counter::setMaster(string const & m)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Counters::newCounter(string const & newc)
|
||||
{
|
||||
// First check if newc already exist
|
||||
@ -198,27 +196,22 @@ void Counters::copy(Counters & from, Counters & to, string const & match)
|
||||
|
||||
namespace {
|
||||
|
||||
inline
|
||||
char loweralphaCounter(int n)
|
||||
{
|
||||
if (n < 1 || n > 26)
|
||||
if (n < 1 || n > 26)
|
||||
return '?';
|
||||
else
|
||||
return 'a' + n - 1;
|
||||
return 'a' + n - 1;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
char alphaCounter(int n)
|
||||
{
|
||||
if (n < 1 || n > 26)
|
||||
return '?';
|
||||
else
|
||||
return 'A' + n - 1;
|
||||
return 'A' + n - 1;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
char hebrewCounter(int n)
|
||||
{
|
||||
static const char hebrew[22] = {
|
||||
@ -226,15 +219,14 @@ char hebrewCounter(int n)
|
||||
'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
|
||||
'÷', 'ø', 'ù', 'ú'
|
||||
};
|
||||
|
||||
if (n < 1 || n > 22)
|
||||
return '?';
|
||||
else
|
||||
return hebrew[n-1];
|
||||
return hebrew[n - 1];
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
string const romanCounter(int n)
|
||||
string const lowerromanCounter(int n)
|
||||
{
|
||||
static char const * roman[20] = {
|
||||
"i", "ii", "iii", "iv", "v",
|
||||
@ -242,107 +234,104 @@ string const romanCounter(int n)
|
||||
"xi", "xii", "xiii", "xiv", "xv",
|
||||
"xvi", "xvii", "xviii", "xix", "xx"
|
||||
};
|
||||
|
||||
if (n < 1 || n > 20)
|
||||
return "??";
|
||||
else
|
||||
return roman[n-1];
|
||||
return roman[n - 1];
|
||||
}
|
||||
|
||||
|
||||
string const romanCounter(int n)
|
||||
{
|
||||
static char const * roman[20] = {
|
||||
"I", "II", "III", "IV", "V",
|
||||
"VI", "VII", "VIII", "IX", "X",
|
||||
"XI", "XII", "XIII", "XIV", "XV",
|
||||
"XVI", "XVII", "XVIII", "XIX", "XX"
|
||||
};
|
||||
|
||||
if (n < 1 || n > 20)
|
||||
return "??";
|
||||
return roman[n - 1];
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
string Counters::labelItem(string const & ctr,
|
||||
string const & numbertype,
|
||||
string const & langtype,
|
||||
bool first)
|
||||
string Counters::labelItem(string const & ctr, string const & numbertype)
|
||||
{
|
||||
ostringstream s;
|
||||
ostringstream o;
|
||||
|
||||
CounterList::iterator it = counterList.find(ctr);
|
||||
if (it == counterList.end()) {
|
||||
lyxerr << "Counter does not exist." << endl;
|
||||
if (counterList.find(ctr) == counterList.end()) {
|
||||
lyxerr << "Counter " << ctr << " does not exist." << endl;
|
||||
return string();
|
||||
}
|
||||
|
||||
if (!first) {
|
||||
s << '.' << value(ctr);
|
||||
} else {
|
||||
if (numbertype == "sectioning" || numbertype == "appendix") {
|
||||
if (numbertype == "appendix") {
|
||||
if (langtype == "hebrew") {
|
||||
o << hebrewCounter(value(ctr));
|
||||
} else {
|
||||
o << alphaCounter(value(ctr));
|
||||
}
|
||||
} else o << value(ctr);
|
||||
}
|
||||
s << o.str();
|
||||
}
|
||||
if (numbertype == "hebrew")
|
||||
return string(1, hebrewCounter(value(ctr)));
|
||||
|
||||
return STRCONV(s.str());
|
||||
if (numbertype == "alph")
|
||||
return string(1, loweralphaCounter(value(ctr)));
|
||||
|
||||
if (numbertype == "Alph")
|
||||
return string(1, alphaCounter(value(ctr)));
|
||||
|
||||
if (numbertype == "roman")
|
||||
return lowerromanCounter(value(ctr));
|
||||
|
||||
if (numbertype == "Roman")
|
||||
return romanCounter(value(ctr));
|
||||
|
||||
return tostr(value(ctr));
|
||||
}
|
||||
|
||||
|
||||
string Counters::numberLabel(string const & ctr,
|
||||
string const & numbertype,
|
||||
string const & langtype,
|
||||
int head)
|
||||
string Counters::counterLabel(string const & format)
|
||||
{
|
||||
ostringstream s;
|
||||
string label = format;
|
||||
while (true) {
|
||||
size_t const i = label.find('\\', 0);
|
||||
if (i == string::npos)
|
||||
break;
|
||||
size_t const j = label.find('{', i + 1);
|
||||
if (j == string::npos)
|
||||
break;
|
||||
size_t const k = label.find('}', j + 1);
|
||||
if (k == string::npos)
|
||||
break;
|
||||
string const numbertype(label, i + 1, j - i - 1);
|
||||
string const counter(label, j + 1, k - j - 1);
|
||||
string const rep = labelItem(counter, numbertype);
|
||||
label = string(label, 0, i) + rep + string(label, k + 1, string::npos);
|
||||
//lyxerr << " : " << " (" << counter << ","
|
||||
// << numbertype << ") -> " << label << endl;
|
||||
}
|
||||
//lyxerr << "counterLabel: " << format << " -> " << label << endl;
|
||||
return label;
|
||||
}
|
||||
|
||||
if (numbertype == "sectioning" || numbertype == "appendix") {
|
||||
if (ctr == "chapter" && head == 0) {
|
||||
s << labelItem("chapter", numbertype, langtype, true);
|
||||
} else if (ctr == "section" && head <= 1) {
|
||||
s << numberLabel("chapter", numbertype, langtype, head)
|
||||
<< labelItem("section", numbertype, langtype, head == 1);
|
||||
} else if (ctr == "subsection" && head <= 2) {
|
||||
s << numberLabel("section", numbertype, langtype, head)
|
||||
<< labelItem("subsection", numbertype, langtype, head == 2);
|
||||
} else if (ctr == "subsubsection" && head <= 3) {
|
||||
s << numberLabel("subsection", numbertype, langtype, head)
|
||||
<< labelItem("subsubsection", numbertype, langtype, head == 3);
|
||||
} else if (ctr == "paragraph" && head <= 4) {
|
||||
s << numberLabel("subsubsection", numbertype, langtype, head)
|
||||
<< labelItem("paragraph", numbertype, langtype, head == 4);
|
||||
} else if (ctr == "subparagraph" && head <= 5) {
|
||||
s << numberLabel("paragraph", numbertype, langtype, head)
|
||||
<< labelItem("subparagraph", numbertype, langtype, head == 5);
|
||||
} else if (ctr == "figure" || ctr == "table") {
|
||||
// figure, table, ...
|
||||
lyxerr << "Counter:" << ctr << endl;
|
||||
s << numberLabel("chapter", numbertype, langtype, head)
|
||||
<< labelItem(ctr, numbertype, langtype, head == 1);
|
||||
}
|
||||
|
||||
} else if (numbertype == "enumeration") {
|
||||
ostringstream ei;
|
||||
ostringstream eii;
|
||||
ostringstream eiii;
|
||||
ostringstream eiv;
|
||||
string Counters::enumLabel(string const & ctr, string const & langtype)
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
if (langtype == "hebrew") {
|
||||
ei << '.' << value("enumi");
|
||||
eii << '(' << hebrewCounter(value("enumii")) << ')';
|
||||
eiii << '.' << romanCounter(value("enumiii"));
|
||||
eiv << '.' << alphaCounter(value("enumiv"));
|
||||
} else {
|
||||
ei << value("enumi") << '.';
|
||||
eii << '(' << loweralphaCounter(value("enumii")) << ')';
|
||||
eiii << romanCounter(value("enumiii")) << '.';
|
||||
eiv << alphaCounter(value("enumiv")) << '.';
|
||||
}
|
||||
if (ctr == "enumii") {
|
||||
s << eii.str();
|
||||
} else if (ctr == "enumi") {
|
||||
s << ei.str();
|
||||
} else if (ctr == "enumiii") {
|
||||
s << eiii.str();
|
||||
} else if (ctr == "enumiv") {
|
||||
s << eiv.str();
|
||||
}
|
||||
if (langtype == "hebrew") {
|
||||
if (ctr == "enumi")
|
||||
os << '.' << value("enumi");
|
||||
else if (ctr == "enumii")
|
||||
os << '(' << hebrewCounter(value("enumii")) << ')';
|
||||
else if (ctr == "enumiii")
|
||||
os << '.' << lowerromanCounter(value("enumiii"));
|
||||
else if (ctr == "enumiv")
|
||||
os << '.' << alphaCounter(value("enumiv"));
|
||||
} else {
|
||||
if (ctr == "enumi")
|
||||
os << value("enumi") << '.';
|
||||
else if (ctr == "enumii")
|
||||
os << '(' << loweralphaCounter(value("enumii")) << ')';
|
||||
else if (ctr == "enumiii")
|
||||
os << lowerromanCounter(value("enumiii")) << '.';
|
||||
else if (ctr == "enumiv")
|
||||
os << alphaCounter(value("enumiv")) << '.';
|
||||
}
|
||||
|
||||
return STRCONV(s.str());
|
||||
return STRCONV(os.str());
|
||||
}
|
||||
|
@ -74,21 +74,15 @@ public:
|
||||
/// Copy counters whose name matches match from the &from to
|
||||
/// the &to array of counters. Empty string matches all.
|
||||
void copy(Counters & from, Counters & to, string const & match = string());
|
||||
/// A numeric label's single item, like .1 for subsection number in
|
||||
/// the 2.1.4 subsubsection number label. "first" indicates if this
|
||||
/// is the first item to be displayed, usually chapter or section.
|
||||
string labelItem(string const & ctr,
|
||||
string const & labeltype,
|
||||
string const & langtype = "latin",
|
||||
bool first = false);
|
||||
/// A complete numeric label, like 2.1.4 for a subsubsection.
|
||||
/// "head" indicates sequence number of first item to be
|
||||
/// displayed, e.g. 0 for chapter, 1 for section.
|
||||
string numberLabel(string const & ctr,
|
||||
string const & labeltype,
|
||||
string const & langtype = "latin",
|
||||
int head = 0);
|
||||
/// A complete expanded label, like 2.1.4 for a subsubsection
|
||||
/// according to the given format
|
||||
string counterLabel(string const & format);
|
||||
/// A complete label, like 1.a for enumerations
|
||||
string enumLabel(string const & ctr, string const & langtype = "latin");
|
||||
private:
|
||||
/// A counter label's single item, 1 for subsection number in
|
||||
/// the 2.1.4 subsubsection number label.
|
||||
string labelItem(string const & ctr, string const & numbertype);
|
||||
/// Maps counter (layout) names to actual counters.
|
||||
typedef std::map<string, Counter> CounterList;
|
||||
/// Instantiate.
|
||||
|
20
src/layout.h
20
src/layout.h
@ -111,25 +111,11 @@ enum LYX_LABEL_TYPES {
|
||||
///
|
||||
LABEL_SENSITIVE,
|
||||
///
|
||||
LABEL_COUNTER_CHAPTER,
|
||||
LABEL_COUNTER,
|
||||
///
|
||||
LABEL_COUNTER_SECTION,
|
||||
LABEL_ENUMERATE,
|
||||
///
|
||||
LABEL_COUNTER_SUBSECTION,
|
||||
///
|
||||
LABEL_COUNTER_SUBSUBSECTION,
|
||||
///
|
||||
LABEL_COUNTER_PARAGRAPH,
|
||||
///
|
||||
LABEL_COUNTER_SUBPARAGRAPH,
|
||||
///
|
||||
LABEL_COUNTER_ENUMI,
|
||||
///
|
||||
LABEL_COUNTER_ENUMII,
|
||||
///
|
||||
LABEL_COUNTER_ENUMIII,
|
||||
///
|
||||
LABEL_COUNTER_ENUMIV
|
||||
LABEL_ITEMIZE
|
||||
};
|
||||
|
||||
|
||||
|
@ -1668,8 +1668,7 @@ exit_with_message:
|
||||
|
||||
if (view()->available()) {
|
||||
if (view()->fitCursor()) {
|
||||
lyxerr << "LyXFunc->fitCursor->update" << endl;
|
||||
|
||||
//lyxerr << "LyXFunc->fitCursor->update" << endl;
|
||||
view()->update();
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ enum LayoutTags {
|
||||
LT_LABELSEP,
|
||||
LT_LABELSTRING,
|
||||
LT_LABELSTRING_APPENDIX,
|
||||
LT_LABELCOUNTER,
|
||||
LT_LABELTYPE,
|
||||
LT_ENDLABELSTRING,
|
||||
LT_ENDLABELTYPE,
|
||||
@ -118,7 +119,7 @@ LyXLayout::LyXLayout ()
|
||||
|
||||
|
||||
// Reads a layout definition from file
|
||||
bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
|
||||
bool LyXLayout::Read(LyXLex & lexrc, LyXTextClass const & tclass)
|
||||
{
|
||||
// This table is sorted alphabetically [asierra 30March96]
|
||||
keyword_item layoutTags[] = {
|
||||
@ -138,6 +139,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
|
||||
{ "itemsep", LT_ITEMSEP },
|
||||
{ "keepempty", LT_KEEPEMPTY },
|
||||
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
|
||||
{ "labelcounter", LT_LABELCOUNTER },
|
||||
{ "labelfont", LT_LABELFONT },
|
||||
{ "labelindent", LT_LABELINDENT },
|
||||
{ "labelsep", LT_LABELSEP },
|
||||
@ -420,6 +422,11 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
|
||||
labelstring_appendix_ = trim(lexrc.getString());
|
||||
break;
|
||||
|
||||
case LT_LABELCOUNTER: // name of counter to use
|
||||
if (lexrc.next())
|
||||
counter = trim(lexrc.getString());
|
||||
break;
|
||||
|
||||
case LT_FREE_SPACING: // Allow for free spacing.
|
||||
if (lexrc.next())
|
||||
free_spacing = lexrc.getInteger();
|
||||
@ -436,6 +443,9 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
|
||||
}
|
||||
}
|
||||
lexrc.popTable();
|
||||
|
||||
if (labelstring_appendix_.empty())
|
||||
labelstring_appendix_ = labelstring_;
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -537,16 +547,9 @@ enum LabelTypeTags {
|
||||
LA_CENTERED_TOP_ENVIRONMENT,
|
||||
LA_STATIC,
|
||||
LA_SENSITIVE,
|
||||
LA_COUNTER_CHAPTER,
|
||||
LA_COUNTER_SECTION,
|
||||
LA_COUNTER_SUBSECTION,
|
||||
LA_COUNTER_SUBSUBSECTION,
|
||||
LA_COUNTER_PARAGRAPH,
|
||||
LA_COUNTER_SUBPARAGRAPH,
|
||||
LA_COUNTER_ENUMI,
|
||||
LA_COUNTER_ENUMII,
|
||||
LA_COUNTER_ENUMIII,
|
||||
LA_COUNTER_ENUMIV,
|
||||
LA_COUNTER,
|
||||
LA_ENUMERATE,
|
||||
LA_ITEMIZE,
|
||||
LA_BIBLIO
|
||||
};
|
||||
|
||||
@ -556,16 +559,9 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
|
||||
keyword_item labelTypeTags[] = {
|
||||
{ "bibliography", LA_BIBLIO },
|
||||
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
|
||||
{ "counter_chapter", LA_COUNTER_CHAPTER },
|
||||
{ "counter_enumi", LA_COUNTER_ENUMI },
|
||||
{ "counter_enumii", LA_COUNTER_ENUMII },
|
||||
{ "counter_enumiii", LA_COUNTER_ENUMIII },
|
||||
{ "counter_enumiv", LA_COUNTER_ENUMIV },
|
||||
{ "counter_paragraph", LA_COUNTER_PARAGRAPH },
|
||||
{ "counter_section", LA_COUNTER_SECTION },
|
||||
{ "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
|
||||
{ "counter_subsection", LA_COUNTER_SUBSECTION },
|
||||
{ "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
|
||||
{ "counter", LA_COUNTER },
|
||||
{ "enumerate", LA_ENUMERATE },
|
||||
{ "itemize", LA_ITEMIZE },
|
||||
{ "manual", LA_MANUAL },
|
||||
{ "no_label", LA_NO_LABEL },
|
||||
{ "sensitive", LA_SENSITIVE },
|
||||
@ -600,35 +596,14 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
|
||||
case LA_SENSITIVE:
|
||||
labeltype = LABEL_SENSITIVE;
|
||||
break;
|
||||
case LA_COUNTER_CHAPTER:
|
||||
labeltype = LABEL_COUNTER_CHAPTER;
|
||||
case LA_COUNTER:
|
||||
labeltype = LABEL_COUNTER;
|
||||
break;
|
||||
case LA_COUNTER_SECTION:
|
||||
labeltype = LABEL_COUNTER_SECTION;
|
||||
case LA_ENUMERATE:
|
||||
labeltype = LABEL_ENUMERATE;
|
||||
break;
|
||||
case LA_COUNTER_SUBSECTION:
|
||||
labeltype = LABEL_COUNTER_SUBSECTION;
|
||||
break;
|
||||
case LA_COUNTER_SUBSUBSECTION:
|
||||
labeltype = LABEL_COUNTER_SUBSUBSECTION;
|
||||
break;
|
||||
case LA_COUNTER_PARAGRAPH:
|
||||
labeltype = LABEL_COUNTER_PARAGRAPH;
|
||||
break;
|
||||
case LA_COUNTER_SUBPARAGRAPH:
|
||||
labeltype = LABEL_COUNTER_SUBPARAGRAPH;
|
||||
break;
|
||||
case LA_COUNTER_ENUMI:
|
||||
labeltype = LABEL_COUNTER_ENUMI;
|
||||
break;
|
||||
case LA_COUNTER_ENUMII:
|
||||
labeltype = LABEL_COUNTER_ENUMII;
|
||||
break;
|
||||
case LA_COUNTER_ENUMIII:
|
||||
labeltype = LABEL_COUNTER_ENUMIII;
|
||||
break;
|
||||
case LA_COUNTER_ENUMIV:
|
||||
labeltype = LABEL_COUNTER_ENUMIV;
|
||||
case LA_ITEMIZE:
|
||||
labeltype = LABEL_ITEMIZE;
|
||||
break;
|
||||
case LA_BIBLIO:
|
||||
labeltype = LABEL_BIBLIO;
|
||||
|
@ -173,6 +173,8 @@ public:
|
||||
bool intitle;
|
||||
/// Does this layout allow for an optional parameter?
|
||||
int optionalargs;
|
||||
/// Which counter to step
|
||||
string counter;
|
||||
|
||||
private:
|
||||
/// Name of the layout/paragraph environment
|
||||
|
@ -67,7 +67,7 @@ LyXTextClass::LyXTextClass(string const & fn, string const & cln,
|
||||
secnumdepth_ = 3;
|
||||
tocdepth_ = 3;
|
||||
pagestyle_ = "default";
|
||||
maxcounter_ = LABEL_COUNTER_CHAPTER;
|
||||
maxcounter_ = 4;
|
||||
defaultfont_ = LyXFont(LyXFont::ALL_SANE);
|
||||
opt_fontsize_ = "10|11|12";
|
||||
opt_pagestyle_ = "empty|plain|headings|fancy";
|
||||
@ -300,7 +300,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
|
||||
break;
|
||||
|
||||
case TC_MAXCOUNTER:
|
||||
readMaxCounter(lexrc);
|
||||
lexrc.next();
|
||||
maxcounter_ = lexrc.getInteger();
|
||||
break;
|
||||
|
||||
case TC_SECNUMDEPTH:
|
||||
@ -463,67 +464,6 @@ enum MaxCounterTags {
|
||||
};
|
||||
|
||||
|
||||
void LyXTextClass::readMaxCounter(LyXLex & lexrc)
|
||||
{
|
||||
keyword_item maxCounterTags[] = {
|
||||
{"counter_chapter", MC_COUNTER_CHAPTER },
|
||||
{"counter_enumi", MC_COUNTER_ENUMI },
|
||||
{"counter_enumii", MC_COUNTER_ENUMII },
|
||||
{"counter_enumiii", MC_COUNTER_ENUMIII },
|
||||
{"counter_enumiv", MC_COUNTER_ENUMIV },
|
||||
{"counter_paragraph", MC_COUNTER_PARAGRAPH },
|
||||
{"counter_section", MC_COUNTER_SECTION },
|
||||
{"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
|
||||
{"counter_subsection", MC_COUNTER_SUBSECTION },
|
||||
{"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
|
||||
};
|
||||
|
||||
pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
|
||||
|
||||
int le = lexrc.lex();
|
||||
switch (le) {
|
||||
case LyXLex::LEX_UNDEF:
|
||||
lexrc.printError("Unknown MaxCounter tag `$$Token'");
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (static_cast<MaxCounterTags>(le)) {
|
||||
case MC_COUNTER_CHAPTER:
|
||||
maxcounter_ = LABEL_COUNTER_CHAPTER;
|
||||
break;
|
||||
case MC_COUNTER_SECTION:
|
||||
maxcounter_ = LABEL_COUNTER_SECTION;
|
||||
break;
|
||||
case MC_COUNTER_SUBSECTION:
|
||||
maxcounter_ = LABEL_COUNTER_SUBSECTION;
|
||||
break;
|
||||
case MC_COUNTER_SUBSUBSECTION:
|
||||
maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
|
||||
break;
|
||||
case MC_COUNTER_PARAGRAPH:
|
||||
maxcounter_ = LABEL_COUNTER_PARAGRAPH;
|
||||
break;
|
||||
case MC_COUNTER_SUBPARAGRAPH:
|
||||
maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
|
||||
break;
|
||||
case MC_COUNTER_ENUMI:
|
||||
maxcounter_ = LABEL_COUNTER_ENUMI;
|
||||
break;
|
||||
case MC_COUNTER_ENUMII:
|
||||
maxcounter_ = LABEL_COUNTER_ENUMII;
|
||||
break;
|
||||
case MC_COUNTER_ENUMIII:
|
||||
maxcounter_ = LABEL_COUNTER_ENUMIII;
|
||||
break;
|
||||
case MC_COUNTER_ENUMIV:
|
||||
maxcounter_ = LABEL_COUNTER_ENUMIV;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum ClassOptionsTags {
|
||||
CO_FONTSIZE = 1,
|
||||
CO_PAGESTYLE,
|
||||
@ -718,7 +658,7 @@ void LyXTextClass::readCounter(LyXLex & lexrc)
|
||||
}
|
||||
}
|
||||
|
||||
// Here if have a full float if getout == true
|
||||
// Here if have a full counter if getout == true
|
||||
if (getout) {
|
||||
if (within.empty()) {
|
||||
ctrs_->newCounter(name);
|
||||
|
@ -742,7 +742,7 @@ void RowPainter::paintFirst()
|
||||
// this is special code for the chapter layout. This is
|
||||
// printed in an extra row and has a pagebreak at
|
||||
// the top.
|
||||
if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
|
||||
if (layout->counter == "chapter") {
|
||||
if (buffer.params().secnumdepth >= 0) {
|
||||
float spacing_val = 1.0;
|
||||
if (!parparams.spacing().isDefault()) {
|
||||
|
@ -1030,9 +1030,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
|
||||
|
||||
// This is special code for the chapter, since the label of this
|
||||
// layout is printed in an extra row
|
||||
if (layout->labeltype == LABEL_COUNTER_CHAPTER
|
||||
&& bufparams.secnumdepth >= 0)
|
||||
{
|
||||
if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
|
||||
float spacing_val = 1.0;
|
||||
if (!pit->params().spacing().isDefault()) {
|
||||
spacing_val = pit->params().spacing().getValue();
|
||||
|
164
src/text2.C
164
src/text2.C
@ -25,6 +25,7 @@
|
||||
#include "buffer_funcs.h"
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Bullet.h"
|
||||
#include "counters.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "debug.h"
|
||||
@ -53,17 +54,15 @@
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/textutils.h"
|
||||
#include "support/tostr.h"
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
using lyx::pos_type;
|
||||
|
||||
using lyx::support::bformat;
|
||||
|
||||
using std::endl;
|
||||
|
||||
using std::ostringstream;
|
||||
|
||||
|
||||
@ -834,6 +833,32 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
string expandLabel(LyXTextClass const & textclass,
|
||||
LyXLayout_ptr const & layout, bool appendix)
|
||||
{
|
||||
string fmt = appendix ?
|
||||
layout->labelstring_appendix() : layout->labelstring();
|
||||
|
||||
// handle 'inherited level parts' in 'fmt',
|
||||
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
||||
size_t const i = fmt.find('@', 0);
|
||||
if (i != string::npos) {
|
||||
size_t const j = fmt.find('@', i + 1);
|
||||
if (j != string::npos) {
|
||||
string parent(fmt, i + 1, j - i - 1);
|
||||
string label = expandLabel(textclass, textclass[parent], appendix);
|
||||
fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
return textclass.counters().counterLabel(fmt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// set the counter of a paragraph. This includes the labels
|
||||
void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
||||
{
|
||||
@ -842,7 +867,6 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
||||
LyXLayout_ptr const & layout = pit->layout();
|
||||
|
||||
if (pit != ownerParagraphs().begin()) {
|
||||
|
||||
pit->params().appendix(boost::prior(pit)->params().appendix());
|
||||
if (!pit->params().appendix() &&
|
||||
pit->params().startOfAppendix()) {
|
||||
@ -858,30 +882,37 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
||||
}
|
||||
|
||||
// Maybe we have to increment the enumeration depth.
|
||||
// BUT, enumeration in a footnote is considered in isolation from its
|
||||
// surrounding paragraph so don't increment if this is the
|
||||
// first line of the footnote
|
||||
// AND, bibliographies can't have their depth changed ie. they
|
||||
// Bibliographies can't have their depth changed ie. they
|
||||
// are always of depth 0
|
||||
if (pit != ownerParagraphs().begin()
|
||||
&& boost::prior(pit)->getDepth() < pit->getDepth()
|
||||
&& boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
|
||||
&& boost::prior(pit)->layout()->labeltype == LABEL_ENUMERATE
|
||||
&& pit->enumdepth < 3
|
||||
&& layout->labeltype != LABEL_BIBLIO) {
|
||||
pit->enumdepth++;
|
||||
}
|
||||
|
||||
// Maybe we have to increment the enumeration depth.
|
||||
// Bibliographies can't have their depth changed ie. they
|
||||
// are always of depth 0
|
||||
if (pit != ownerParagraphs().begin()
|
||||
&& boost::prior(pit)->getDepth() < pit->getDepth()
|
||||
&& boost::prior(pit)->layout()->labeltype == LABEL_ITEMIZE
|
||||
&& pit->itemdepth < 3
|
||||
&& layout->labeltype != LABEL_BIBLIO) {
|
||||
pit->itemdepth++;
|
||||
}
|
||||
|
||||
// Maybe we have to decrement the enumeration depth, see note above
|
||||
if (pit != ownerParagraphs().begin()
|
||||
&& boost::prior(pit)->getDepth() > pit->getDepth()
|
||||
&& layout->labeltype != LABEL_BIBLIO) {
|
||||
pit->enumdepth = depthHook(pit, ownerParagraphs(),
|
||||
pit->getDepth())->enumdepth;
|
||||
pit->getDepth())->enumdepth;
|
||||
}
|
||||
|
||||
if (!pit->params().labelString().empty()) {
|
||||
pit->params().labelString(string());
|
||||
}
|
||||
// erase what was there before
|
||||
pit->params().labelString(string());
|
||||
|
||||
if (layout->margintype == MARGIN_MANUAL) {
|
||||
if (pit->params().labelWidthString().empty())
|
||||
@ -891,75 +922,46 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
||||
}
|
||||
|
||||
// is it a layout that has an automatic label?
|
||||
if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
|
||||
int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
|
||||
if (layout->labeltype == LABEL_COUNTER) {
|
||||
BufferParams const & bufparams = buf.params();
|
||||
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
||||
textclass.counters().step(layout->counter);
|
||||
string label = expandLabel(textclass, layout, pit->params().appendix());
|
||||
pit->params().labelString(label);
|
||||
textclass.counters().reset("enum");
|
||||
} else if (layout->labeltype == LABEL_ITEMIZE) {
|
||||
// At some point of time we should do something more clever here,
|
||||
// like:
|
||||
// pit->params().labelString(
|
||||
// bufparams.user_defined_bullet(pit->itemdepth).getText());
|
||||
// for now, use a static label
|
||||
pit->params().labelString("*");
|
||||
textclass.counters().reset("enum");
|
||||
} else if (layout->labeltype == LABEL_ENUMERATE) {
|
||||
// FIXME
|
||||
// Yes I know this is a really, really! bad solution
|
||||
// (Lgb)
|
||||
string enumcounter = "enum";
|
||||
|
||||
ostringstream s;
|
||||
|
||||
if (i >= 0 && i <= bufparams.secnumdepth) {
|
||||
string numbertype;
|
||||
string langtype;
|
||||
|
||||
textclass.counters().step(layout->latexname());
|
||||
|
||||
// Is there a label? Useful for Chapter layout
|
||||
if (!pit->params().appendix()) {
|
||||
s << buf.B_(layout->labelstring());
|
||||
} else {
|
||||
s << buf.B_(layout->labelstring_appendix());
|
||||
}
|
||||
|
||||
// Use of an integer is here less than elegant. For now.
|
||||
int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
|
||||
if (!pit->params().appendix()) {
|
||||
numbertype = "sectioning";
|
||||
} else {
|
||||
numbertype = "appendix";
|
||||
if (pit->isRightToLeftPar(bufparams))
|
||||
langtype = "hebrew";
|
||||
else
|
||||
langtype = "latin";
|
||||
}
|
||||
|
||||
s << " "
|
||||
<< textclass.counters()
|
||||
.numberLabel(layout->latexname(),
|
||||
numbertype, langtype, head);
|
||||
|
||||
pit->params().labelString(STRCONV(s.str()));
|
||||
|
||||
// reset enum counters
|
||||
textclass.counters().reset("enum");
|
||||
} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
|
||||
textclass.counters().reset("enum");
|
||||
} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
|
||||
// FIXME
|
||||
// Yes I know this is a really, really! bad solution
|
||||
// (Lgb)
|
||||
string enumcounter("enum");
|
||||
|
||||
switch (pit->enumdepth) {
|
||||
case 2:
|
||||
enumcounter += 'i';
|
||||
case 1:
|
||||
enumcounter += 'i';
|
||||
case 0:
|
||||
enumcounter += 'i';
|
||||
break;
|
||||
case 3:
|
||||
enumcounter += "iv";
|
||||
break;
|
||||
default:
|
||||
// not a valid enumdepth...
|
||||
break;
|
||||
}
|
||||
|
||||
textclass.counters().step(enumcounter);
|
||||
|
||||
s << textclass.counters()
|
||||
.numberLabel(enumcounter, "enumeration");
|
||||
pit->params().labelString(STRCONV(s.str()));
|
||||
switch (pit->enumdepth) {
|
||||
case 2:
|
||||
enumcounter += 'i';
|
||||
case 1:
|
||||
enumcounter += 'i';
|
||||
case 0:
|
||||
enumcounter += 'i';
|
||||
break;
|
||||
case 3:
|
||||
enumcounter += "iv";
|
||||
break;
|
||||
default:
|
||||
// not a valid enumdepth...
|
||||
break;
|
||||
}
|
||||
|
||||
textclass.counters().step(enumcounter);
|
||||
|
||||
pit->params().labelString(textclass.counters().enumLabel(enumcounter));
|
||||
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
||||
textclass.counters().step("bibitem");
|
||||
int number = textclass.counters().value("bibitem");
|
||||
|
@ -74,13 +74,13 @@ TocList const getTocList(Buffer const & buf)
|
||||
ParConstIterator pit = buf.par_iterator_begin();
|
||||
ParConstIterator end = buf.par_iterator_end();
|
||||
for (; pit != end; ++pit) {
|
||||
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning bogus type (Lgb)
|
||||
#endif
|
||||
char const labeltype = pit->layout()->labeltype;
|
||||
|
||||
if (labeltype >= LABEL_COUNTER_CHAPTER
|
||||
&& labeltype <= LABEL_COUNTER_CHAPTER + bufparams.tocdepth) {
|
||||
if (labeltype >= LABEL_COUNTER
|
||||
&& labeltype <= LABEL_COUNTER + bufparams.tocdepth) {
|
||||
// insert this into the table of contents
|
||||
const int depth = max(0, labeltype - textclass.maxcounter());
|
||||
TocItem const item(pit->id(), depth,
|
||||
|
Loading…
Reference in New Issue
Block a user