1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
13 #pragma implementation
21 #include "support/lstrings.h"
22 #include "support/LAssert.h"
34 void Counter::set(int v)
40 void Counter::addto(int v)
46 int Counter::value() const
64 string Counter::master() const
70 void Counter::setMaster(string const & m)
77 void Counters::newCounter(string const & newc)
79 // First check if newc already exist
80 CounterList::iterator cit = counterList.find(newc);
81 // if already exist give warning and return
82 if (cit != counterList.end()) {
83 lyxerr << "The new counter already exists." << endl;
90 void Counters::newCounter(string const & newc, string const & masterc)
92 // First check if newc already exists
93 CounterList::iterator cit = counterList.find(newc);
94 // if already existant give warning and return
95 if (cit != counterList.end()) {
96 lyxerr << "The new counter already exists." << endl;
99 // then check if masterc exists
100 CounterList::iterator it = counterList.find(masterc);
101 // if not give warning and return
102 if (it == counterList.end()) {
103 lyxerr << "The master counter does not exist." << endl;
107 counterList[newc].setMaster(masterc);
111 void Counters::set(string const & ctr, int val)
113 CounterList::iterator it = counterList.find(ctr);
114 if (it == counterList.end()) {
115 lyxerr << "set: Counter does not exist: " << ctr << endl;
122 void Counters::addto(string const & ctr, int val)
124 CounterList::iterator it = counterList.find(ctr);
125 if (it == counterList.end()) {
126 lyxerr << "addto: Counter does not exist: " << ctr << endl;
129 it->second.addto(val);
133 int Counters::value(string const & ctr) const
135 CounterList::const_iterator cit = counterList.find(ctr);
136 if (cit == counterList.end()) {
137 lyxerr << "value: Counter does not exist: " << ctr << endl;
140 return cit->second.value();
144 void Counters::step(string const & ctr)
146 CounterList::iterator it = counterList.find(ctr);
147 if (it == counterList.end()) {
148 lyxerr << "step: Counter does not exist: " << ctr << endl;
153 it = counterList.begin();
154 CounterList::iterator end = counterList.end();
155 for (; it != end; ++it) {
156 if (it->second.master() == ctr) {
163 void Counters::reset()
165 CounterList::iterator it = counterList.begin();
166 CounterList::iterator end = counterList.end();
167 for (; it != end; ++it) {
173 void Counters::reset(string const & match)
175 lyx::Assert(!match.empty());
177 CounterList::iterator it = counterList.begin();
178 CounterList::iterator end = counterList.end();
179 for (; it != end; ++it) {
180 if (it->first.find(match) != string::npos)
186 void Counters::copy(Counters & from, Counters & to, string const & match)
188 CounterList::iterator it = counterList.begin();
189 CounterList::iterator end = counterList.end();
190 for (; it != end; ++it) {
191 if (it->first.find(match) != string::npos || match == "") {
192 to.set(it->first, from.value(it->first));
201 char loweralphaCounter(int n)
211 char alphaCounter(int n)
221 char hebrewCounter(int n)
223 static const char hebrew[22] = {
224 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
225 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
236 string const romanCounter(int n)
238 static char const * roman[20] = {
239 "i", "ii", "iii", "iv", "v",
240 "vi", "vii", "viii", "ix", "x",
241 "xi", "xii", "xiii", "xiv", "xv",
242 "xvi", "xvii", "xviii", "xix", "xx"
253 string Counters::labelItem(string const & ctr,
254 string const & numbertype,
255 string const & langtype,
261 CounterList::iterator it = counterList.find(ctr);
262 if (it == counterList.end()) {
263 lyxerr << "Counter does not exist." << endl;
268 s << "." << value(ctr);
270 if (numbertype == "sectioning" || numbertype == "appendix") {
271 if (numbertype == "appendix") {
272 if (langtype == "hebrew") {
273 o << hebrewCounter(value(ctr));
275 o << alphaCounter(value(ctr));
277 } else o << value(ctr);
285 string Counters::numberLabel(string const & ctr,
286 string const & numbertype,
287 string const & langtype,
291 if (numbertype == "sectioning" || numbertype == "appendix") {
292 if (ctr == "chapter" && head == 0) {
293 s << labelItem("chapter", numbertype, langtype, true);
294 } else if (ctr == "section" && head <= 1) {
295 s << numberLabel("chapter", numbertype, langtype, head)
296 << labelItem("section", numbertype, langtype, head == 1);
297 } else if (ctr == "subsection" && head <= 2) {
298 s << numberLabel("section", numbertype, langtype, head)
299 << labelItem("subsection", numbertype, langtype, head == 2);
300 } else if (ctr == "subsubsection" && head <= 3) {
301 s << numberLabel("subsection", numbertype, langtype, head)
302 << labelItem("subsubsection", numbertype, langtype, head == 3);
303 } else if (ctr == "paragraph" && head <= 4) {
304 s << numberLabel("subsubsection", numbertype, langtype, head)
305 << labelItem("paragraph", numbertype, langtype, head == 4);
306 } else if (ctr == "subparagraph" && head <= 5) {
307 s << numberLabel("paragraph", numbertype, langtype, head)
308 << labelItem("subparagraph", numbertype, langtype, head == 5);
309 } else if (ctr == "figure" || ctr == "table") {
310 // figure, table, ...
311 lyxerr << "Counter:" << ctr << endl;
312 s << numberLabel("chapter", numbertype, langtype, head)
313 << labelItem(ctr, numbertype, langtype, head == 1);
316 } else if (numbertype == "enumeration") {
322 if (langtype == "hebrew") {
323 ei << '.' << value("enumi");
324 eii << '(' << hebrewCounter(value("enumii")) << ')';
325 eiii << '.' << romanCounter(value("enumiii"));
326 eiv << '.' << alphaCounter(value("enumiv"));
328 ei << value("enumi") << '.';
329 eii << '(' << loweralphaCounter(value("enumii")) << ')';
330 eiii << romanCounter(value("enumiii")) << '.';
331 eiv << alphaCounter(value("enumiv")) << '.';
333 if (ctr == "enumii") {
335 } else if (ctr == "enumi") {
337 } else if (ctr == "enumiii") {
339 } else if (ctr == "enumiv") {