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:
André Pönitz 2003-09-12 17:13:22 +00:00
parent 757df94b07
commit 92a24f6f99
14 changed files with 233 additions and 334 deletions

View File

@ -655,7 +655,7 @@ void BufferView::Pimpl::workAreaResize()
void BufferView::Pimpl::update() void BufferView::Pimpl::update()
{ {
lyxerr << "BufferView::update()" << endl; //lyxerr << "BufferView::update()" << endl;
// fix cursor coordinate cache in case something went wrong // fix cursor coordinate cache in case something went wrong
if (bv_->getLyXText()) { if (bv_->getLyXText()) {
// check needed to survive LyX startup // check needed to survive LyX startup

View File

@ -53,7 +53,7 @@ Bullet::Bullet(int f, int c, int s)
Bullet::Bullet(string const & t) 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(); testInvariant();
} }

View File

@ -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> 2003-09-12 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* aspell.C: include <boost/assert.cpp> (compile fix) * aspell.C: include <boost/assert.cpp> (compile fix)

View File

@ -5,6 +5,7 @@
* *
* \author Lars Gullik Bjønnes * \author Lars Gullik Bjønnes
* \author Martin Vermeer * \author Martin Vermeer
* \author André Pönitz
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -12,17 +13,15 @@
#include <config.h> #include <config.h>
#include "counters.h" #include "counters.h"
#include "debug.h" #include "debug.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/std_sstream.h"
#include "support/tostr.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include "support/std_sstream.h"
using std::endl; using std::endl;
using std::ostringstream; using std::ostringstream;
@ -74,7 +73,6 @@ void Counter::setMaster(string const & m)
} }
void Counters::newCounter(string const & newc) void Counters::newCounter(string const & newc)
{ {
// First check if newc already exist // First check if newc already exist
@ -198,27 +196,22 @@ void Counters::copy(Counters & from, Counters & to, string const & match)
namespace { namespace {
inline
char loweralphaCounter(int n) char loweralphaCounter(int n)
{ {
if (n < 1 || n > 26) if (n < 1 || n > 26)
return '?'; return '?';
else return 'a' + n - 1;
return 'a' + n - 1;
} }
inline
char alphaCounter(int n) char alphaCounter(int n)
{ {
if (n < 1 || n > 26) if (n < 1 || n > 26)
return '?'; return '?';
else return 'A' + n - 1;
return 'A' + n - 1;
} }
inline
char hebrewCounter(int n) char hebrewCounter(int n)
{ {
static const char hebrew[22] = { static const char hebrew[22] = {
@ -226,15 +219,14 @@ char hebrewCounter(int n)
'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö', 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
'÷', 'ø', 'ù', 'ú' '÷', 'ø', 'ù', 'ú'
}; };
if (n < 1 || n > 22) if (n < 1 || n > 22)
return '?'; return '?';
else return hebrew[n - 1];
return hebrew[n-1];
} }
inline string const lowerromanCounter(int n)
string const romanCounter(int n)
{ {
static char const * roman[20] = { static char const * roman[20] = {
"i", "ii", "iii", "iv", "v", "i", "ii", "iii", "iv", "v",
@ -242,107 +234,104 @@ string const romanCounter(int n)
"xi", "xii", "xiii", "xiv", "xv", "xi", "xii", "xiii", "xiv", "xv",
"xvi", "xvii", "xviii", "xix", "xx" "xvi", "xvii", "xviii", "xix", "xx"
}; };
if (n < 1 || n > 20) if (n < 1 || n > 20)
return "??"; 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 } // namespace anon
string Counters::labelItem(string const & ctr, string Counters::labelItem(string const & ctr, string const & numbertype)
string const & numbertype,
string const & langtype,
bool first)
{ {
ostringstream s; if (counterList.find(ctr) == counterList.end()) {
ostringstream o; lyxerr << "Counter " << ctr << " does not exist." << endl;
CounterList::iterator it = counterList.find(ctr);
if (it == counterList.end()) {
lyxerr << "Counter does not exist." << endl;
return string(); return string();
} }
if (!first) { if (numbertype == "hebrew")
s << '.' << value(ctr); return string(1, hebrewCounter(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();
}
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 Counters::counterLabel(string const & format)
string const & numbertype,
string const & langtype,
int head)
{ {
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") { string Counters::enumLabel(string const & ctr, string const & langtype)
ostringstream ei; {
ostringstream eii; ostringstream os;
ostringstream eiii;
ostringstream eiv;
if (langtype == "hebrew") { if (langtype == "hebrew") {
ei << '.' << value("enumi"); if (ctr == "enumi")
eii << '(' << hebrewCounter(value("enumii")) << ')'; os << '.' << value("enumi");
eiii << '.' << romanCounter(value("enumiii")); else if (ctr == "enumii")
eiv << '.' << alphaCounter(value("enumiv")); os << '(' << hebrewCounter(value("enumii")) << ')';
} else { else if (ctr == "enumiii")
ei << value("enumi") << '.'; os << '.' << lowerromanCounter(value("enumiii"));
eii << '(' << loweralphaCounter(value("enumii")) << ')'; else if (ctr == "enumiv")
eiii << romanCounter(value("enumiii")) << '.'; os << '.' << alphaCounter(value("enumiv"));
eiv << alphaCounter(value("enumiv")) << '.'; } else {
} if (ctr == "enumi")
if (ctr == "enumii") { os << value("enumi") << '.';
s << eii.str(); else if (ctr == "enumii")
} else if (ctr == "enumi") { os << '(' << loweralphaCounter(value("enumii")) << ')';
s << ei.str(); else if (ctr == "enumiii")
} else if (ctr == "enumiii") { os << lowerromanCounter(value("enumiii")) << '.';
s << eiii.str(); else if (ctr == "enumiv")
} else if (ctr == "enumiv") { os << alphaCounter(value("enumiv")) << '.';
s << eiv.str();
}
} }
return STRCONV(s.str()); return STRCONV(os.str());
} }

View File

@ -74,21 +74,15 @@ public:
/// Copy counters whose name matches match from the &from to /// Copy counters whose name matches match from the &from to
/// the &to array of counters. Empty string matches all. /// the &to array of counters. Empty string matches all.
void copy(Counters & from, Counters & to, string const & match = string()); void copy(Counters & from, Counters & to, string const & match = string());
/// A numeric label's single item, like .1 for subsection number in /// A complete expanded label, like 2.1.4 for a subsubsection
/// the 2.1.4 subsubsection number label. "first" indicates if this /// according to the given format
/// is the first item to be displayed, usually chapter or section. string counterLabel(string const & format);
string labelItem(string const & ctr, /// A complete label, like 1.a for enumerations
string const & labeltype, string enumLabel(string const & ctr, string const & langtype = "latin");
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);
private: 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. /// Maps counter (layout) names to actual counters.
typedef std::map<string, Counter> CounterList; typedef std::map<string, Counter> CounterList;
/// Instantiate. /// Instantiate.

View File

@ -111,25 +111,11 @@ enum LYX_LABEL_TYPES {
/// ///
LABEL_SENSITIVE, LABEL_SENSITIVE,
/// ///
LABEL_COUNTER_CHAPTER, LABEL_COUNTER,
/// ///
LABEL_COUNTER_SECTION, LABEL_ENUMERATE,
/// ///
LABEL_COUNTER_SUBSECTION, LABEL_ITEMIZE
///
LABEL_COUNTER_SUBSUBSECTION,
///
LABEL_COUNTER_PARAGRAPH,
///
LABEL_COUNTER_SUBPARAGRAPH,
///
LABEL_COUNTER_ENUMI,
///
LABEL_COUNTER_ENUMII,
///
LABEL_COUNTER_ENUMIII,
///
LABEL_COUNTER_ENUMIV
}; };

View File

@ -1668,8 +1668,7 @@ exit_with_message:
if (view()->available()) { if (view()->available()) {
if (view()->fitCursor()) { if (view()->fitCursor()) {
lyxerr << "LyXFunc->fitCursor->update" << endl; //lyxerr << "LyXFunc->fitCursor->update" << endl;
view()->update(); view()->update();
} }

View File

@ -55,6 +55,7 @@ enum LayoutTags {
LT_LABELSEP, LT_LABELSEP,
LT_LABELSTRING, LT_LABELSTRING,
LT_LABELSTRING_APPENDIX, LT_LABELSTRING_APPENDIX,
LT_LABELCOUNTER,
LT_LABELTYPE, LT_LABELTYPE,
LT_ENDLABELSTRING, LT_ENDLABELSTRING,
LT_ENDLABELTYPE, LT_ENDLABELTYPE,
@ -118,7 +119,7 @@ LyXLayout::LyXLayout ()
// Reads a layout definition from file // 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] // This table is sorted alphabetically [asierra 30March96]
keyword_item layoutTags[] = { keyword_item layoutTags[] = {
@ -138,6 +139,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
{ "itemsep", LT_ITEMSEP }, { "itemsep", LT_ITEMSEP },
{ "keepempty", LT_KEEPEMPTY }, { "keepempty", LT_KEEPEMPTY },
{ "labelbottomsep", LT_LABEL_BOTTOMSEP }, { "labelbottomsep", LT_LABEL_BOTTOMSEP },
{ "labelcounter", LT_LABELCOUNTER },
{ "labelfont", LT_LABELFONT }, { "labelfont", LT_LABELFONT },
{ "labelindent", LT_LABELINDENT }, { "labelindent", LT_LABELINDENT },
{ "labelsep", LT_LABELSEP }, { "labelsep", LT_LABELSEP },
@ -420,6 +422,11 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
labelstring_appendix_ = trim(lexrc.getString()); labelstring_appendix_ = trim(lexrc.getString());
break; 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. case LT_FREE_SPACING: // Allow for free spacing.
if (lexrc.next()) if (lexrc.next())
free_spacing = lexrc.getInteger(); free_spacing = lexrc.getInteger();
@ -436,6 +443,9 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
} }
} }
lexrc.popTable(); lexrc.popTable();
if (labelstring_appendix_.empty())
labelstring_appendix_ = labelstring_;
return error; return error;
} }
@ -537,16 +547,9 @@ enum LabelTypeTags {
LA_CENTERED_TOP_ENVIRONMENT, LA_CENTERED_TOP_ENVIRONMENT,
LA_STATIC, LA_STATIC,
LA_SENSITIVE, LA_SENSITIVE,
LA_COUNTER_CHAPTER, LA_COUNTER,
LA_COUNTER_SECTION, LA_ENUMERATE,
LA_COUNTER_SUBSECTION, LA_ITEMIZE,
LA_COUNTER_SUBSUBSECTION,
LA_COUNTER_PARAGRAPH,
LA_COUNTER_SUBPARAGRAPH,
LA_COUNTER_ENUMI,
LA_COUNTER_ENUMII,
LA_COUNTER_ENUMIII,
LA_COUNTER_ENUMIV,
LA_BIBLIO LA_BIBLIO
}; };
@ -556,16 +559,9 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
keyword_item labelTypeTags[] = { keyword_item labelTypeTags[] = {
{ "bibliography", LA_BIBLIO }, { "bibliography", LA_BIBLIO },
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT }, { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
{ "counter_chapter", LA_COUNTER_CHAPTER }, { "counter", LA_COUNTER },
{ "counter_enumi", LA_COUNTER_ENUMI }, { "enumerate", LA_ENUMERATE },
{ "counter_enumii", LA_COUNTER_ENUMII }, { "itemize", LA_ITEMIZE },
{ "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 },
{ "manual", LA_MANUAL }, { "manual", LA_MANUAL },
{ "no_label", LA_NO_LABEL }, { "no_label", LA_NO_LABEL },
{ "sensitive", LA_SENSITIVE }, { "sensitive", LA_SENSITIVE },
@ -600,35 +596,14 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
case LA_SENSITIVE: case LA_SENSITIVE:
labeltype = LABEL_SENSITIVE; labeltype = LABEL_SENSITIVE;
break; break;
case LA_COUNTER_CHAPTER: case LA_COUNTER:
labeltype = LABEL_COUNTER_CHAPTER; labeltype = LABEL_COUNTER;
break; break;
case LA_COUNTER_SECTION: case LA_ENUMERATE:
labeltype = LABEL_COUNTER_SECTION; labeltype = LABEL_ENUMERATE;
break; break;
case LA_COUNTER_SUBSECTION: case LA_ITEMIZE:
labeltype = LABEL_COUNTER_SUBSECTION; labeltype = LABEL_ITEMIZE;
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;
break; break;
case LA_BIBLIO: case LA_BIBLIO:
labeltype = LABEL_BIBLIO; labeltype = LABEL_BIBLIO;

View File

@ -173,6 +173,8 @@ public:
bool intitle; bool intitle;
/// Does this layout allow for an optional parameter? /// Does this layout allow for an optional parameter?
int optionalargs; int optionalargs;
/// Which counter to step
string counter;
private: private:
/// Name of the layout/paragraph environment /// Name of the layout/paragraph environment

View File

@ -67,7 +67,7 @@ LyXTextClass::LyXTextClass(string const & fn, string const & cln,
secnumdepth_ = 3; secnumdepth_ = 3;
tocdepth_ = 3; tocdepth_ = 3;
pagestyle_ = "default"; pagestyle_ = "default";
maxcounter_ = LABEL_COUNTER_CHAPTER; maxcounter_ = 4;
defaultfont_ = LyXFont(LyXFont::ALL_SANE); defaultfont_ = LyXFont(LyXFont::ALL_SANE);
opt_fontsize_ = "10|11|12"; opt_fontsize_ = "10|11|12";
opt_pagestyle_ = "empty|plain|headings|fancy"; opt_pagestyle_ = "empty|plain|headings|fancy";
@ -300,7 +300,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
break; break;
case TC_MAXCOUNTER: case TC_MAXCOUNTER:
readMaxCounter(lexrc); lexrc.next();
maxcounter_ = lexrc.getInteger();
break; break;
case TC_SECNUMDEPTH: 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 { enum ClassOptionsTags {
CO_FONTSIZE = 1, CO_FONTSIZE = 1,
CO_PAGESTYLE, 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 (getout) {
if (within.empty()) { if (within.empty()) {
ctrs_->newCounter(name); ctrs_->newCounter(name);

View File

@ -742,7 +742,7 @@ void RowPainter::paintFirst()
// this is special code for the chapter layout. This is // this is special code for the chapter layout. This is
// printed in an extra row and has a pagebreak at // printed in an extra row and has a pagebreak at
// the top. // the top.
if (layout->labeltype == LABEL_COUNTER_CHAPTER) { if (layout->counter == "chapter") {
if (buffer.params().secnumdepth >= 0) { if (buffer.params().secnumdepth >= 0) {
float spacing_val = 1.0; float spacing_val = 1.0;
if (!parparams.spacing().isDefault()) { if (!parparams.spacing().isDefault()) {

View File

@ -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 // This is special code for the chapter, since the label of this
// layout is printed in an extra row // layout is printed in an extra row
if (layout->labeltype == LABEL_COUNTER_CHAPTER if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
&& bufparams.secnumdepth >= 0)
{
float spacing_val = 1.0; float spacing_val = 1.0;
if (!pit->params().spacing().isDefault()) { if (!pit->params().spacing().isDefault()) {
spacing_val = pit->params().spacing().getValue(); spacing_val = pit->params().spacing().getValue();

View File

@ -25,6 +25,7 @@
#include "buffer_funcs.h" #include "buffer_funcs.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Bullet.h"
#include "counters.h" #include "counters.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
@ -53,17 +54,15 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/textutils.h" #include "support/textutils.h"
#include "support/tostr.h"
#include "support/std_sstream.h"
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include "support/std_sstream.h"
using lyx::pos_type; using lyx::pos_type;
using lyx::support::bformat; using lyx::support::bformat;
using std::endl; using std::endl;
using std::ostringstream; 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 // set the counter of a paragraph. This includes the labels
void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit) 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(); LyXLayout_ptr const & layout = pit->layout();
if (pit != ownerParagraphs().begin()) { if (pit != ownerParagraphs().begin()) {
pit->params().appendix(boost::prior(pit)->params().appendix()); pit->params().appendix(boost::prior(pit)->params().appendix());
if (!pit->params().appendix() && if (!pit->params().appendix() &&
pit->params().startOfAppendix()) { pit->params().startOfAppendix()) {
@ -858,30 +882,37 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
} }
// Maybe we have to increment the enumeration depth. // Maybe we have to increment the enumeration depth.
// BUT, enumeration in a footnote is considered in isolation from its // Bibliographies can't have their depth changed ie. they
// 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
// are always of depth 0 // are always of depth 0
if (pit != ownerParagraphs().begin() if (pit != ownerParagraphs().begin()
&& boost::prior(pit)->getDepth() < pit->getDepth() && boost::prior(pit)->getDepth() < pit->getDepth()
&& boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI && boost::prior(pit)->layout()->labeltype == LABEL_ENUMERATE
&& pit->enumdepth < 3 && pit->enumdepth < 3
&& layout->labeltype != LABEL_BIBLIO) { && layout->labeltype != LABEL_BIBLIO) {
pit->enumdepth++; 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 // Maybe we have to decrement the enumeration depth, see note above
if (pit != ownerParagraphs().begin() if (pit != ownerParagraphs().begin()
&& boost::prior(pit)->getDepth() > pit->getDepth() && boost::prior(pit)->getDepth() > pit->getDepth()
&& layout->labeltype != LABEL_BIBLIO) { && layout->labeltype != LABEL_BIBLIO) {
pit->enumdepth = depthHook(pit, ownerParagraphs(), pit->enumdepth = depthHook(pit, ownerParagraphs(),
pit->getDepth())->enumdepth; pit->getDepth())->enumdepth;
} }
if (!pit->params().labelString().empty()) { // erase what was there before
pit->params().labelString(string()); pit->params().labelString(string());
}
if (layout->margintype == MARGIN_MANUAL) { if (layout->margintype == MARGIN_MANUAL) {
if (pit->params().labelWidthString().empty()) 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? // is it a layout that has an automatic label?
if (layout->labeltype >= LABEL_COUNTER_CHAPTER) { if (layout->labeltype == LABEL_COUNTER) {
int const i = layout->labeltype - LABEL_COUNTER_CHAPTER; 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; switch (pit->enumdepth) {
case 2:
if (i >= 0 && i <= bufparams.secnumdepth) { enumcounter += 'i';
string numbertype; case 1:
string langtype; enumcounter += 'i';
case 0:
textclass.counters().step(layout->latexname()); enumcounter += 'i';
break;
// Is there a label? Useful for Chapter layout case 3:
if (!pit->params().appendix()) { enumcounter += "iv";
s << buf.B_(layout->labelstring()); break;
} else { default:
s << buf.B_(layout->labelstring_appendix()); // not a valid enumdepth...
} break;
// 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()));
} }
textclass.counters().step(enumcounter);
pit->params().labelString(textclass.counters().enumLabel(enumcounter));
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
textclass.counters().step("bibitem"); textclass.counters().step("bibitem");
int number = textclass.counters().value("bibitem"); int number = textclass.counters().value("bibitem");

View File

@ -74,13 +74,13 @@ TocList const getTocList(Buffer const & buf)
ParConstIterator pit = buf.par_iterator_begin(); ParConstIterator pit = buf.par_iterator_begin();
ParConstIterator end = buf.par_iterator_end(); ParConstIterator end = buf.par_iterator_end();
for (; pit != end; ++pit) { for (; pit != end; ++pit) {
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
#warning bogus type (Lgb) #warning bogus type (Lgb)
#endif #endif
char const labeltype = pit->layout()->labeltype; char const labeltype = pit->layout()->labeltype;
if (labeltype >= LABEL_COUNTER
if (labeltype >= LABEL_COUNTER_CHAPTER && labeltype <= LABEL_COUNTER + bufparams.tocdepth) {
&& labeltype <= LABEL_COUNTER_CHAPTER + bufparams.tocdepth) {
// insert this into the table of contents // insert this into the table of contents
const int depth = max(0, labeltype - textclass.maxcounter()); const int depth = max(0, labeltype - textclass.maxcounter());
TocItem const item(pit->id(), depth, TocItem const item(pit->id(), depth,