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
20 #include "support/lstrings.h"
32 void Counter::set(int v)
38 void Counter::addto(int v)
44 int Counter::value() const
61 string Counter::master() const
66 void Counter::setMaster(string const & m)
74 // Ehh, should this take a textclass arg?
76 // Sectioning counters:
78 newCounter("chapter");
79 newCounter("section", "chapter");
80 newCounter("subsection", "section");
81 newCounter("subsubsection", "subsection");
82 newCounter("paragraph", "subsubsection");
83 newCounter("subparagraph", "paragraph");
85 sects.push_back("chapter");
86 sects.push_back("section");
87 sects.push_back("subsection");
88 sects.push_back("subsubsection");
89 sects.push_back("paragraph");
90 sects.push_back("subparagraph");
92 // Enumeration counters:
94 newCounter("enumii", "enumi");
95 newCounter("enumiii", "enumii");
96 newCounter("enumiv", "enumiii");
98 enums.push_back("enumi");
99 enums.push_back("enumii");
100 enums.push_back("enumiii");
101 enums.push_back("enumiv");
104 newCounter("bibitem");
107 newCounter("Figure");
112 void Counters::newCounter(string const & newc)
114 // First check if newc already exist
115 CounterList::iterator cit = counterList.find(newc);
116 // if already exist give warning and return
117 if (cit != counterList.end()) {
118 lyxerr << "The new counter already exists." << endl;
122 cit = counterList.find(newc);
123 cit->second.setMaster("");
127 void Counters::newCounter(string const & newc, string const & masterc)
129 // First check if newc already exists
130 CounterList::iterator cit = counterList.find(newc);
131 // if already existant give warning and return
132 if (cit != counterList.end()) {
133 lyxerr << "The new counter already exists." << endl;
136 // then check if masterc exists
137 CounterList::iterator it = counterList.find(masterc);
138 // if not give warning and return
139 if (it == counterList.end()) {
140 lyxerr << "The master counter does not exist." << endl;
145 cit = counterList.find(newc);
146 cit->second.setMaster(masterc);
150 void Counters::set(string const & ctr, int val)
152 CounterList::iterator it = counterList.find(ctr);
153 if (it == counterList.end()) {
154 lyxerr << "set: Counter does not exist: " << ctr << endl;
161 void Counters::addto(string const & ctr, int val)
163 CounterList::iterator it = counterList.find(ctr);
164 if (it == counterList.end()) {
165 lyxerr << "addto: Counter does not exist: " << ctr << endl;
168 it->second.addto(val);
172 int Counters::value(string const & ctr) const
174 CounterList::const_iterator cit = counterList.find(ctr);
175 if (cit == counterList.end()) {
176 lyxerr << "value: Counter does not exist: " << ctr << endl;
179 return cit->second.value();
183 void Counters::step(string const & ctr)
185 CounterList::iterator it = counterList.find(ctr);
186 if (it == counterList.end()) {
187 lyxerr << "step: Counter does not exist: " << ctr << endl;
192 it = counterList.begin();
193 CounterList::iterator end = counterList.end();
194 for (; it != end; ++it) {
195 if (it->second.master() == ctr) {
201 void Counters::reset(string const & match)
203 CounterList::iterator it = counterList.begin();
204 CounterList::iterator end = counterList.end();
205 for (; it != end; ++it) {
206 if (it->first.find(match) != string::npos || match == "")
211 void Counters::copy(Counters & from, Counters & to, string const & match)
213 CounterList::iterator it = counterList.begin();
214 CounterList::iterator end = counterList.end();
215 for (; it != end; ++it) {
216 if (it->first.find(match) != string::npos || match == "") {
217 to.set(it->first, from.value(it->first));
226 char loweralphaCounter(int n)
235 char alphaCounter(int n)
244 char hebrewCounter(int n)
246 static const char hebrew[22] = {
247 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
248 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
258 string const romanCounter(int n)
260 static char const * roman[20] = {
261 "i", "ii", "iii", "iv", "v",
262 "vi", "vii", "viii", "ix", "x",
263 "xi", "xii", "xiii", "xiv", "xv",
264 "xvi", "xvii", "xviii", "xix", "xx"
274 string Counters::labelItem(string const & ctr,
275 string const & numbertype,
276 string const & langtype,
280 CounterList::iterator it = counterList.find(ctr);
281 if (it == counterList.end()) {
282 lyxerr << "Counter does not exist." << endl;
285 string mstr = it->second.master();
287 s << "." << value(ctr);
289 if (numbertype == "sectioning" || numbertype == "appendix") {
290 if (numbertype == "appendix") {
291 if (langtype == "hebrew") {
292 o << hebrewCounter(value(ctr));
294 o << alphaCounter(value(ctr));
296 } else o << value(ctr);
303 string Counters::numberLabel(string const & ctr,
304 string const & numbertype,
305 string const & langtype,
309 if (numbertype == "sectioning" || numbertype == "appendix") {
310 if (ctr == "chapter" && head == 0) {
311 s << labelItem("chapter", numbertype, langtype, true);
312 } else if (ctr == "section" && head <= 1) {
313 s << numberLabel("chapter", numbertype, langtype, head)
314 << labelItem("section", numbertype, langtype, head == 1);
315 } else if (ctr == "subsection" && head <= 2) {
316 s << numberLabel("section", numbertype, langtype, head)
317 << labelItem("subsection", numbertype, langtype, head == 2);
318 } else if (ctr == "subsubsection" && head <= 3) {
319 s << numberLabel("subsection", numbertype, langtype, head)
320 << labelItem("subsubsection", numbertype, langtype, head == 3);
321 } else if (ctr == "paragraph" && head <= 4) {
322 s << numberLabel("subsubsection", numbertype, langtype, head)
323 << labelItem("paragraph", numbertype, langtype, head == 4);
324 } else if (ctr == "subparagraph" && head <= 5) {
325 s << numberLabel("paragraph", numbertype, langtype, head)
326 << labelItem("subparagraph", numbertype, langtype, head == 5);
327 } else if (ctr == "Figure" || ctr == "Table") {
328 // figure, table, ...
329 lyxerr << "Counter:" << ctr << endl;
330 s << numberLabel("chapter", numbertype, langtype, head)
331 << labelItem(ctr, numbertype, langtype, head == 1);
334 } else if (numbertype == "enumeration") {
335 ostringstream ei, eii, eiii, eiv;
336 //string ei, eiii, eiv;
338 if (langtype == "hebrew") {
339 ei << '.' << value("enumi");
340 eii << '(' << hebrewCounter(value("enumii")) << ')';
341 eiii << '.' << romanCounter(value("enumiii"));
342 eiv << '.' << alphaCounter(value("enumiv"));
344 ei << value("enumi") << '.';
345 eii << '(' << loweralphaCounter(value("enumii")) << ')';
346 eiii << romanCounter(value("enumiii")) << '.';
347 eiv << alphaCounter(value("enumiv")) << '.';
349 if (ctr == "enumii") {
351 } else if (ctr == "enumi") {
353 } else if (ctr == "enumiii") {
355 } else if (ctr == "enumiv") {