From 960db78b52f3938c4c1757b435c6dfe8f4b2e937 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 6 Aug 2002 22:40:59 +0000 Subject: [PATCH] My simple testing of Martins patch, shows that it works as expected. Applied. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4883 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 72 +++++++----- src/Makefile.am | 4 +- src/counters.C | 268 ++++++++++++++++++++++++++++++++++++++----- src/counters.h | 41 +++++-- src/paragraph.C | 25 ----- src/paragraph.h | 11 +- src/text2.C | 293 ++++++++---------------------------------------- 7 files changed, 364 insertions(+), 350 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 49c4851369..4997ae06e1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2002-08-06 Martin Vermeer + + * counters.[Ch] + * text2.C + * paragraph.[Ch] + * makefile.am: move counters functionality over from + text2.C/paragraph.[Ch] to counters.[Ch], and make proper C++. + 2002-08-06 John Levon * WordLangTuple.h: new file for word + language code tuple @@ -27,70 +35,78 @@ 2002-08-06 John Levon * pspell.C: fix a crash, and allow new aspell to work - + 2002-08-06 John Levon * lyxfunc.C: * kbmap.C: small cleanup - + * vspace.h: * vspace.C: add const - + 2002-08-05 John Levon * LyXAction.C: back to tabular-insert - + 2002-08-04 John Levon * BufferView.h: * BufferView.C: cosmetic change - + * BufferView_pimpl.C: s/IGNORE_CODE/NOTE_CODE/ - + * bufferlist.C: * buffer.h: * buffer.C: * lyxcb.h: * lyxcb.C: - * lyxserver.C: - * lyxvc.C: - * vc-backend.C: + * lyxserver.C: + * lyxvc.C: + * vc-backend.C: * BufferView2.C: purge all "Lyx" not "LyX" strings - + * lyxcursor.h: * lyxcursor.C: attempt to add some documentation - + * lyxfunc.C: * commandtags.h: - * LyXAction.C: - * ToolbarDefaults.C: + * LyXAction.C: + * ToolbarDefaults.C: * BufferView_pimpl.C: remove LFUN_DIALOG_TABULAR_INSERT and merge with LFUN_TABULAR_INSERT - * Makefile.am: + * Makefile.am: * SpellBase.h: * ispell.h: - * ispell.C: + * ispell.C: * pspell.h: * pspell.C: split up i/pspell implementations into separate files, many cleanups - * lyxlex.C: unrevert, with a proper fix for prefix.length() == 0 - + * lyxlex.C: unrevert, with a proper fix for prefix.length() == 0 + * text2.C: some cleanup - + * lyxfunc.C: don't check for isp_command == "none" any more, it didn't make any sense - + +2002-08-06 Martin Vermeer + + * counters.[Ch] + * text2.C + * paragraph.[Ch] + * makefile.am: move counters functionality over + from text2.C/paragraph.[Ch] to counters.[Ch], and + make proper C++. 2002-08-02 John Levon * buffer.C: s/lyxconvert/lyx2lyx/ - + 2002-08-02 Angus Leeming * lyxlex.C: revert John's change as it breaks reading of the user preamble. - + 2002-08-02 Angus Leeming * importer.C (Import): @@ -100,14 +116,14 @@ 2002-08-02 John Levon * lyxlex.C: small cleanup - + 2002-08-02 John Levon * text2.C (status): small cleanup, no logic change - + 2002-08-01 John Levon - * buffer.h: + * buffer.h: * buffer.C (writeFile): don't output alerts, caller handles this @@ -120,20 +136,20 @@ * lyxserver.C: don't let incidental errors get in the way (errno) - + 2002-07-30 John Levon * lyxfunc.C: disable character dialog in ERT inset (partial fix) - + 2002-07-30 John Levon * lyxserver.h: * lyxserver.C: remove I/O callback too - + 2002-07-30 Jean-Marc Lasgouttes * lyxfunc.C (getStatus): disable LFUN_LATEX_LOG when there is no - log. + log. 2002-07-29 Lars Gullik Bjønnes diff --git a/src/Makefile.am b/src/Makefile.am index 079da02496..cd8cab4bdf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,8 +35,6 @@ EXTRA_DIST = config.h.in stamp-h.in cheaders ext_l10n.h version.C.in \ Sectioning.C \ Variables.C \ Variables.h \ - counters.C \ - counters.h \ tracer.C \ tracer.h @@ -109,6 +107,8 @@ lyx_SOURCES = \ config.h.in \ converter.C \ converter.h \ + counters.C \ + counters.h \ debug.C \ debug.h \ encoding.C \ diff --git a/src/counters.C b/src/counters.C index af660bf46d..c54f0c06e5 100644 --- a/src/counters.C +++ b/src/counters.C @@ -17,8 +17,10 @@ #include "counters.h" #include "debug.h" +#include "support/lstrings.h" using std::endl; +using std::vector; Counter::Counter() @@ -48,7 +50,6 @@ int Counter::value() const void Counter::step() { ++value_; - onstep.emit(); } @@ -57,15 +58,54 @@ void Counter::reset() value_ = 0; } +string Counter::master() const +{ + return master_; +} + +void Counter::setMaster(string const & m) +{ + master_ = m; +} + -Counters::~Counters() +Counters::Counters() { - // We need this since we store the Counter's as pointers in - // the counterList. - for (CounterList::iterator it = counterList.begin(); - it != counterList.end(); - ++it) - delete it->second; + // Ehh, should this take a textclass arg? + + // Sectioning counters: + newCounter("part"); + newCounter("chapter"); + newCounter("section", "chapter"); + newCounter("subsection", "section"); + newCounter("subsubsection", "subsection"); + newCounter("paragraph", "subsubsection"); + newCounter("subparagraph", "paragraph"); + + sects.push_back("chapter"); + sects.push_back("section"); + sects.push_back("subsection"); + sects.push_back("subsubsection"); + sects.push_back("paragraph"); + sects.push_back("subparagraph"); + + // Enumeration counters: + newCounter("enumi"); + newCounter("enumii", "enumi"); + newCounter("enumiii", "enumii"); + newCounter("enumiv", "enumiii"); + + enums.push_back("enumi"); + enums.push_back("enumii"); + enums.push_back("enumiii"); + enums.push_back("enumiv"); + + // Biblio: + newCounter("bibitem"); + + // Float counters: + newCounter("Figure"); + newCounter("Table"); } @@ -73,36 +113,37 @@ void Counters::newCounter(string const & newc) { // First check if newc already exist CounterList::iterator cit = counterList.find(newc); - // if alrady exist give warning and return + // if already exist give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exist." << endl; + lyxerr << "The new counter already exists." << endl; return; } - counterList[newc] = new Counter; + counterList[newc]; + cit = counterList.find(newc); + cit->second.setMaster(""); } -void Counters::newCounter(string const & newc, string const & oldc) +void Counters::newCounter(string const & newc, string const & masterc) { - // First check if newc already exist + // First check if newc already exists CounterList::iterator cit = counterList.find(newc); // if already existant give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exist." << endl; + lyxerr << "The new counter already exists." << endl; return; } - // then check if oldc exist - CounterList::iterator it = counterList.find(oldc); + // then check if masterc exists + CounterList::iterator it = counterList.find(masterc); // if not give warning and return if (it == counterList.end()) { - lyxerr << "The old counter does not exist." << endl; + lyxerr << "The master counter does not exist." << endl; return; } - Counter * tmp = new Counter; - it->second->onstep.connect(SigC::slot(tmp, - &Counter::reset)); - counterList[newc] = tmp; + counterList[newc]; + cit = counterList.find(newc); + cit->second.setMaster(masterc); } @@ -110,10 +151,10 @@ void Counters::set(string const & ctr, int val) { CounterList::iterator it = counterList.find(ctr); if (it == counterList.end()) { - lyxerr << "Counter does not exist." << endl; + lyxerr << "set: Counter does not exist: " << ctr << endl; return; } - it->second->set(val); + it->second.set(val); } @@ -121,10 +162,10 @@ void Counters::addto(string const & ctr, int val) { CounterList::iterator it = counterList.find(ctr); if (it == counterList.end()) { - lyxerr << "Counter does not exist." << endl; + lyxerr << "addto: Counter does not exist: " << ctr << endl; return; } - it->second->addto(val); + it->second.addto(val); } @@ -132,10 +173,10 @@ int Counters::value(string const & ctr) const { CounterList::const_iterator cit = counterList.find(ctr); if (cit == counterList.end()) { - lyxerr << "Counter does not exist." << endl; + lyxerr << "value: Counter does not exist: " << ctr << endl; return 0; } - return cit->second->value(); + return cit->second.value(); } @@ -143,8 +184,177 @@ void Counters::step(string const & ctr) { CounterList::iterator it = counterList.find(ctr); if (it == counterList.end()) { - lyxerr << "Counter does not exist." << endl; + lyxerr << "step: Counter does not exist: " << ctr << endl; return; } - it->second->step(); + + it->second.step(); + it = counterList.begin(); + CounterList::iterator end = counterList.end(); + for (; it != end; ++it) { + if (it->second.master() == ctr) { + it->second.reset(); + } + } +} + +void Counters::reset(string const & match) +{ + CounterList::iterator it = counterList.begin(); + CounterList::iterator end = counterList.end(); + for (; it != end; ++it) { + if (it->first.find(match) != string::npos || match == "") + it->second.reset(); + } +} + +void Counters::copy(Counters & from, Counters & to, string const & match) +{ + CounterList::iterator it = counterList.begin(); + CounterList::iterator end = counterList.end(); + for (; it != end; ++it) { + if (it->first.find(match) != string::npos || match == "") { + to.set(it->first, from.value(it->first)); + } + } +} + + +namespace { + +inline +char loweralphaCounter(int n) +{ + if (n < 1 || n > 26) + return '?'; + else + return 'a' + n - 1; +} + +inline +char alphaCounter(int n) +{ + if (n < 1 || n > 26) + return '?'; + else + return 'A' + n - 1; +} + +inline +char hebrewCounter(int n) +{ + static const char hebrew[22] = { + 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', + 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö', + '÷', 'ø', 'ù', 'ú' + }; + if (n < 1 || n > 22) + return '?'; + else + return hebrew[n-1]; +} + +inline +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 "??"; + else + return roman[n-1]; +} + +} // namespace anon + +string Counters::labelItem(string const & ctr, + string const & numbertype, + string const & langtype, + bool first) +{ + ostringstream s, o; + CounterList::iterator it = counterList.find(ctr); + if (it == counterList.end()) { + lyxerr << "Counter does not exist." << endl; + return ""; + } + string mstr = it->second.master(); + 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(); + } + return s.str(); +} + +string Counters::numberLabel(string const & ctr, + string const & numbertype, + string const & langtype, + int head) +{ + ostringstream s, o; + 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, eii, eiii, eiv; + //string ei, eiii, eiv; + //char eii; + 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(); + } + } + return s.str(); } diff --git a/src/counters.h b/src/counters.h index 7f73d4eb1f..d737f995bd 100644 --- a/src/counters.h +++ b/src/counters.h @@ -19,14 +19,11 @@ #endif #include "LString.h" - -#include -#include - #include +#include /// -class Counter : public boost::trackable { +class Counter { public: /// Counter(); @@ -41,10 +38,15 @@ public: /// void reset(); /// - boost::signal0 onstep; -private: + string master() const; + /// + void setMaster(string const & m); /// + +private: int value_; + /// + string master_; }; @@ -54,7 +56,9 @@ private: class Counters { public: /// - ~Counters(); + Counters(); + /// + //~Counters(); /// void newCounter(string const & newc); /// @@ -67,12 +71,29 @@ public: int value(string const & ctr) const; /// void step(string const & ctr); - // string refstep(string const & cou); + /// + void reset(string const & match = ""); + /// + void copy(Counters & from, Counters & to, string const & match = ""); + /// + string labelItem(string const & ctr, + string const & labeltype, + string const & langtype = "latin", + bool first = false); + /// + string numberLabel(string const & ctr, + string const & labeltype, + string const & langtype = "latin", + int head = 0); + /// + std::vector enums, sects; + private: /// - typedef std::map CounterList; + typedef std::map CounterList; /// CounterList counterList; + }; #endif diff --git a/src/paragraph.C b/src/paragraph.C index 9b537fba1b..b6d9bf5218 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -77,8 +77,6 @@ extern BufferView * current_view; Paragraph::Paragraph() : pimpl_(new Paragraph::Pimpl(this)) { - for (int i = 0; i < 10; ++i) - setCounter(i, 0); next_ = 0; previous_ = 0; enumdepth = 0; @@ -92,8 +90,6 @@ Paragraph::Paragraph() Paragraph::Paragraph(Paragraph * par) : pimpl_(new Paragraph::Pimpl(this)) { - for (int i = 0; i < 10; ++i) - setCounter(i, 0); enumdepth = 0; itemdepth = 0; @@ -113,8 +109,6 @@ Paragraph::Paragraph(Paragraph * par) Paragraph::Paragraph(Paragraph const & lp, bool same_ids) : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids)) { - for (int i = 0; i < 10; ++i) - setCounter(i, 0); enumdepth = 0; itemdepth = 0; next_ = 0; @@ -2154,25 +2148,6 @@ void Paragraph::clearContents() pimpl_->clear(); } - -void Paragraph::setCounter(int i, int v) -{ - pimpl_->counter_[i] = v; -} - - -int Paragraph::getCounter(int i) const -{ - return pimpl_->counter_[i]; -} - - -void Paragraph::incCounter(int i) -{ - pimpl_->counter_[i]++; -} - - void Paragraph::setChar(pos_type pos, value_type c) { pimpl_->setChar(pos, c); diff --git a/src/paragraph.h b/src/paragraph.h index f7fc207b2b..76e8e9f7a2 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -19,6 +19,7 @@ #include "insets/inset.h" // Just for Inset::Code #include "lyxfont.h" // Just for LyXFont::FONT_SIZE #include "support/types.h" +#include "counters.h" class ParagraphParameters; class BufferParams; @@ -169,13 +170,6 @@ public: /// void layout(LyXLayout_ptr const & new_layout); - /// - void setCounter(int i, int v); - /// - int getCounter(int i) const; - /// - void incCounter(int i); - /// char enumdepth; @@ -401,6 +395,9 @@ public: /// returns inset iterator of the first inset at or after pos. inset_iterator InsetIterator(lyx::pos_type pos); + /// + Counters ctrs; + private: /// if anything uses this we don't want it to. Paragraph(Paragraph const &); diff --git a/src/text2.C b/src/text2.C index 4d725b75df..839f7ce6cb 100644 --- a/src/text2.C +++ b/src/text2.C @@ -32,6 +32,7 @@ #include "FloatList.h" #include "language.h" #include "ParagraphParameters.h" +#include "counters.h" #include "insets/inseterror.h" #include "insets/insetbib.h" @@ -387,7 +388,7 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par, Row * row) const { insertRow(row, par, 0); /* insert a new row, starting - * at postition 0 */ + * at position 0 */ setCounter(bview->buffer(), par); // set the counters @@ -1211,60 +1212,6 @@ void LyXText::setParagraph(BufferView * bview, } -char loweralphaCounter(int n) -{ - if (n < 1 || n > 26) - return '?'; - else - return 'a' + n - 1; -} - - -namespace { - -inline -char alphaCounter(int n) -{ - if (n < 1 || n > 26) - return '?'; - else - return 'A' + n - 1; -} - - -inline -char hebrewCounter(int n) -{ - static const char hebrew[22] = { - 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', - 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö', - '÷', 'ø', 'ù', 'ú' - }; - if (n < 1 || n > 22) - return '?'; - else - return hebrew[n-1]; -} - - -inline -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 "??"; - else - return roman[n-1]; -} - -} // namespace anon - - // set the counter of a paragraph. This includes the labels void LyXText::setCounter(Buffer const * buf, Paragraph * par) const { @@ -1274,22 +1221,18 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const // copy the prev-counters to this one, // unless this is the first paragraph if (par->previous()) { - for (int i = 0; i < 10; ++i) { - par->setCounter(i, par->previous()->getFirstCounter(i)); - } + + par->ctrs.copy(par->previous()->ctrs, par->ctrs, ""); + par->params().appendix(par->previous()->params().appendix()); if (!par->params().appendix() && par->params().startOfAppendix()) { par->params().appendix(true); - for (int i = 0; i < 10; ++i) { - par->setCounter(i, 0); - } + par->ctrs.reset(""); } par->enumdepth = par->previous()->enumdepth; par->itemdepth = par->previous()->itemdepth; } else { - for (int i = 0; i < 10; ++i) { - par->setCounter(i, 0); - } + par->ctrs.reset(""); par->params().appendix(par->params().startOfAppendix()); par->enumdepth = 0; par->itemdepth = 0; @@ -1315,11 +1258,8 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const && par->previous()->getDepth() > par->getDepth() && layout->labeltype != LABEL_BIBLIO) { par->enumdepth = par->depthHook(par->getDepth())->enumdepth; - par->setCounter(6 + par->enumdepth, - par->depthHook(par->getDepth())->getCounter(6 + par->enumdepth)); - // reset the counters.A depth change is like a breaking layout - for (int i = 6 + par->enumdepth + 1; i < 10; ++i) - par->setCounter(i, 0); + par->ctrs.set(par->ctrs.enums[par->enumdepth], + par->depthHook(par->getDepth())->ctrs.value(par->ctrs.enums[par->enumdepth])); } if (!par->params().labelString().empty()) { @@ -1333,13 +1273,17 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const } else { par->setLabelWidthString(string()); } - + // is it a layout that has an automatic label? if (layout->labeltype >= LABEL_COUNTER_CHAPTER) { int i = layout->labeltype - LABEL_COUNTER_CHAPTER; + string numbertype, langtype; + ostringstream s; + if (i >= 0 && i<= buf->params.secnumdepth) { - par->incCounter(i); // increment the counter + + par->ctrs.step(par->ctrs.sects[i]); // Is there a label? Useful for Chapter layout if (!par->params().appendix()) { @@ -1354,195 +1298,40 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const par->params().labelString(string()); } - ostringstream s; - + // Use if an integer is here less than elegant. For now. + int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER; if (!par->params().appendix()) { - switch (2 * LABEL_COUNTER_CHAPTER - - textclass.maxcounter() + i) { - case LABEL_COUNTER_CHAPTER: - s << par->getCounter(i); - break; - case LABEL_COUNTER_SECTION: - s << par->getCounter(i - 1) << '.' - << par->getCounter(i); - break; - case LABEL_COUNTER_SUBSECTION: - s << par->getCounter(i - 2) << '.' - << par->getCounter(i - 1) << '.' - << par->getCounter(i); - break; - case LABEL_COUNTER_SUBSUBSECTION: - s << par->getCounter(i - 3) << '.' - << par->getCounter(i - 2) << '.' - << par->getCounter(i - 1) << '.' - << par->getCounter(i); - - break; - case LABEL_COUNTER_PARAGRAPH: - s << par->getCounter(i - 4) << '.' - << par->getCounter(i - 3) << '.' - << par->getCounter(i - 2) << '.' - << par->getCounter(i - 1) << '.' - << par->getCounter(i); - break; - case LABEL_COUNTER_SUBPARAGRAPH: - s << par->getCounter(i - 5) << '.' - << par->getCounter(i - 4) << '.' - << par->getCounter(i - 3) << '.' - << par->getCounter(i - 2) << '.' - << par->getCounter(i - 1) << '.' - << par->getCounter(i); - - break; - default: - // Can this ever be reached? And in the - // case it is, how can this be correct? - // (Lgb) - s << par->getCounter(i) << '.'; - break; - } - } else { // appendix - switch (2 * LABEL_COUNTER_CHAPTER - textclass.maxcounter() + i) { - case LABEL_COUNTER_CHAPTER: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i)); - else - s << alphaCounter(par->getCounter(i)); - break; - case LABEL_COUNTER_SECTION: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i - 1)); - else - s << alphaCounter(par->getCounter(i - 1)); - - s << '.' - << par->getCounter(i); - - break; - case LABEL_COUNTER_SUBSECTION: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i - 2)); - else - s << alphaCounter(par->getCounter(i - 2)); - - s << '.' - << par->getCounter(i-1) << '.' - << par->getCounter(i); - - break; - case LABEL_COUNTER_SUBSUBSECTION: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i-3)); - else - s << alphaCounter(par->getCounter(i-3)); - - s << '.' - << par->getCounter(i-2) << '.' - << par->getCounter(i-1) << '.' - << par->getCounter(i); - - break; - case LABEL_COUNTER_PARAGRAPH: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i-4)); - else - s << alphaCounter(par->getCounter(i-4)); - - s << '.' - << par->getCounter(i-3) << '.' - << par->getCounter(i-2) << '.' - << par->getCounter(i-1) << '.' - << par->getCounter(i); - - break; - case LABEL_COUNTER_SUBPARAGRAPH: - if (par->isRightToLeftPar(buf->params)) - s << hebrewCounter(par->getCounter(i-5)); - else - s << alphaCounter(par->getCounter(i-5)); - - s << '.' - << par->getCounter(i-4) << '.' - << par->getCounter(i-3) << '.' - << par->getCounter(i-2) << '.' - << par->getCounter(i-1) << '.' - << par->getCounter(i); - - break; - default: - // Can this ever be reached? And in the - // case it is, how can this be correct? - // (Lgb) - s << par->getCounter(i) << '.'; - - break; - } + numbertype = "sectioning"; + } else { + numbertype = "appendix"; + if (par->isRightToLeftPar(buf->params)) + langtype = "hebrew"; + else + langtype = "latin"; } + + s << par->ctrs.numberLabel(par->ctrs.sects[i], + numbertype, langtype, head); par->params().labelString(par->params().labelString() +s.str().c_str()); // We really want to remove the c_str as soon as // possible... - for (i++; i < 10; ++i) { - // reset the following counters - par->setCounter(i, 0); - } + // reset enum counters + par->ctrs.reset("enum"); } else if (layout->labeltype < LABEL_COUNTER_ENUMI) { - for (i++; i < 10; ++i) { - // reset the following counters - par->setCounter(i, 0); - } + par->ctrs.reset("enum"); } else if (layout->labeltype == LABEL_COUNTER_ENUMI) { - par->incCounter(i + par->enumdepth); - int number = par->getCounter(i + par->enumdepth); - - ostringstream s; - - switch (par->enumdepth) { - case 1: - if (par->isRightToLeftPar(buf->params)) - s << '(' - << hebrewCounter(number) - << ')'; - else - s << '(' - << loweralphaCounter(number) - << ')'; - break; - case 2: - if (par->isRightToLeftPar(buf->params)) - s << '.' << romanCounter(number); - else - s << romanCounter(number) << '.'; - break; - case 3: - if (par->isRightToLeftPar(buf->params)) - s << '.' - << alphaCounter(number); - else - s << alphaCounter(number) - << '.'; - break; - default: - if (par->isRightToLeftPar(buf->params)) - s << '.' << number; - else - s << number << '.'; - break; - } + par->ctrs.step(par->ctrs.enums[par->enumdepth]); + s << par->ctrs.numberLabel(par->ctrs.enums[par->enumdepth], + "enumeration", langtype); par->params().labelString(s.str().c_str()); - for (i += par->enumdepth + 1; i < 10; ++i) { - // reset the following counters - par->setCounter(i, 0); - } - } } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 - int i = LABEL_COUNTER_ENUMI - LABEL_COUNTER_CHAPTER + par->enumdepth; - par->incCounter(i); - int number = par->getCounter(i); + par->ctrs.step("bibitem"); + int number = par->ctrs.value("bibitem"); if (!par->bibkey) { InsetCommandParams p("bibitem" ); par->bibkey = new InsetBibKey(p); @@ -1563,8 +1352,13 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const InsetFloat * tmp = static_cast(par->inInset()->owner()); Floating const & fl = floatList.getType(tmp->type()); + + // Why doesn't it work? -- MV + par->ctrs.step(fl.name()); // We should get the correct number here too. - s = fl.name() + " #:"; + ostringstream o; + o << fl.name() << " " << par->ctrs.value(fl.name()) << ":"; + s = o.str(); } else { /* par->SetLayout(0); s = layout->labelstring; */ @@ -1576,8 +1370,9 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const /* reset the enumeration counter. They are always resetted * when there is any other layout between */ - for (int i = 6 + par->enumdepth; i < 10; ++i) - par->setCounter(i, 0); + for (int i = par->enumdepth + 1; i < 4; i++) { + par->ctrs.set(par->ctrs.enums[i], 0); + } } } -- 2.39.2