Attached the patch representing my work on the counters.[hC] classes,
with a view to using them in short title insets.

Currently these classes don't actually do anything yet; next (inbetween
holidays) I will have to look at actually creating these insets for 
sectioning headers (cf. my earlier insetshortheader.[Ch] stuff), displaying 
the section number on the button. 

As this doesn't actually do anything (just compiles), I suppose it
could just as well be applied to CVS -- for future reference :-)
Assuming of course that I am on the right track with this. Learning all
the time!

Martin
-- 
Martin Vermeer  [EMAIL PROTECTED]
Helsinki University of Technology 
Department of Surveying
P.O. Box 1200, FIN-02015 HUT, Finland
:wq
Index: counters.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/counters.C,v
retrieving revision 1.7
diff -u -p -r1.7 counters.C
--- counters.C  2002/03/21 17:25:09     1.7
+++ counters.C  2002/06/25 11:41:30
@@ -17,10 +17,10 @@
 
 #include "counters.h"
 #include "debug.h"
+#include "support/lstrings.h"
 
 using std::endl;
 
-
 Counter::Counter()
 {
        reset();
@@ -48,7 +48,7 @@ int Counter::value() const
 void Counter::step()
 {
        ++value_;
-       onstep.emit();
+       //onstep.emit();
 }
 
 
@@ -57,7 +57,42 @@ void Counter::reset()
        value_ = 0;
 }
 
+string Counter::master() const
+{
+       return master_;
+}
+
+void Counter::setMaster(string const & m)
+{
+       master_ = m;
+}
+
+
+Counters::Counters()
+{
+       // 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");
+
+       // Enumeration counters:
+       newCounter("emumi");
+       newCounter("emumii", "enumi");
+       newCounter("enumiii", "enumii");
+       newCounter("enumiv", "enumiii");
 
+       // Float counters:
+       newCounter("figure");
+       newCounter("table");
+}
+
+
 Counters::~Counters()
 {
        // We need this since we store the Counter's as pointers in
@@ -73,36 +108,35 @@ void Counters::newCounter(string const &
 {
        // 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;
+       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] = new Counter;
+    cit->second->setMaster(masterc);
 }
 
 
@@ -147,4 +181,125 @@ void Counters::step(string const & ctr)
                return;
        }
        it->second->step();
+       if (it->second->master() != "") {
+               set(it->second->master(), 0);
+       }
+}
+
+inline
+char Counters::loweralphaCounter(int n)
+{
+       if (n < 1 || n > 26)
+               return '?';
+       else
+               return 'a' + n - 1;
+}
+
+inline
+char Counters::alphaCounter(int n)
+{
+       if (n < 1 || n > 26)
+               return '?';
+       else
+               return 'A' + n - 1;
+}
+
+
+inline
+char Counters::hebrewCounter(int n)
+{
+       static const char hebrew[22] = {
+               'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
+               'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
+               '÷', 'ø', 'ù', 'ú'
+       };
+       if (n < 1 || n > 22)
+               return '?';
+       else
+               return hebrew[n-1];
+}
+
+
+inline
+string const Counters::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];
+}
+
+
+string Counters::numberlabel(string const & ctr,
+               string const & numbertype, 
+               string const & langtype)
+{
+       ostringstream s, o;
+       if (numbertype == "sectioning" || numbertype == "appendix") {
+               string chap; 
+               int sec, ssec, sssec, par, spar;
+               if (numbertype == "appendix") {
+                       if (langtype == "hebrew") {
+                               o << hebrewCounter(value("chapter"));
+                       } else {
+                               o << alphaCounter(value("chapter"));
+                       }
+               } else o << value("chapter");
+               chap = o.str();
+               sec = value("section");
+               ssec = value("subsection");
+               sssec = value("subsubsection");
+               par = value("paragraph");
+               spar = value("subparagraph");
+
+               if (ctr == "chapter") {
+                       s << chap;
+               } else if (ctr == "section") {
+                       s << chap << '.' << sec;
+               } else if (ctr == "subsection") {
+                       s << chap << '.' << sec << '.' << ssec;
+               } else if (ctr == "subsubsection") {
+                       s << chap << '.' 
+                         << sec << '.' << ssec << '.' << sssec;
+               } else if (ctr == "paragraph") {
+                       s << chap << '.' 
+                         << sec << '.' << ssec << '.' << sssec 
+                         << '.' << par;
+               } else if (ctr == "subparagraph") {
+                       s << chap << '.' 
+                         << sec << '.' << ssec << '.' << sssec 
+                         << '.' << par << '.' << spar;
+               }
+       
+       } else if (numbertype == "enumeration") {
+               string eii, eiii, eiv;
+               char ei;
+               if (langtype == "hebrew") {
+                       ei = hebrewCounter(value("enumi"));
+                       eii = '.' + romanCounter(value("enumii"));
+                       eiii = '.' + alphaCounter(value("enumiii"));
+                       eiv = '.' + value("enumiv");
+               } else {
+                       ei = loweralphaCounter(value("enumi"));
+                       eii = romanCounter(value("enumii")) + '.';
+                       eiii = alphaCounter(value("enumiii")) + '.';
+                       eiv = value("enumiv") + '.';
+               }
+               if (ctr == "enumi") { 
+                       s << '(' << ei << ')'; 
+               } else if (ctr == "enumii") {
+                       s << eii;       
+               } else if (ctr == "enumiii") {
+                       s << eiii;
+               } else if (ctr == "enumiv") {
+                       s << eiv;
+               }
+       }
+       return s.str();
 }
Index: counters.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/counters.h,v
retrieving revision 1.7
diff -u -p -r1.7 counters.h
--- counters.h  2002/05/29 16:20:57     1.7
+++ counters.h  2002/06/25 11:41:30
@@ -19,14 +19,10 @@
 #endif
 
 #include "LString.h"
-
-#include <boost/signals/signal0.hpp>
-#include <boost/signals/trackable.hpp>
-
 #include <map>
 
 ///
-class Counter : public boost::trackable {
+class Counter {
 public:
        ///
        Counter();
@@ -40,11 +36,16 @@ public:
        void step();
        ///
        void reset();
+       ///
+       string master() const;
        ///
-       boost::signal0<void> onstep;
+       void setMaster(string const & m);
+       
 private:
        ///
        int value_;
+       ///
+       string master_;
 };
 
 
@@ -54,6 +55,8 @@ private:
 class Counters {
 public:
        ///
+       Counters();
+       ///     
        ~Counters();
        ///
        void newCounter(string const & newc);
@@ -68,11 +71,25 @@ public:
        ///
        void step(string const & ctr);
        // string refstep(string const & cou);
+       ///
+       string numberlabel(string const & ctr,
+                       string const & labeltype, 
+                       string const & langtype = "latin");
+
 private:
        ///
        typedef std::map<string, Counter*> CounterList;
        ///
        CounterList counterList;
+
+       ///
+       char loweralphaCounter(int);
+       ///
+       char alphaCounter(int);
+       ///
+       char hebrewCounter(int);
+       ///
+       string const romanCounter(int);
 };
 
 #endif

Attachment: msg39816/pgp00000.pgp
Description: PGP signature

Reply via email to