Here it is. Tested as well as I could, but give it hell.
If still alive after that, commit it.

ChangeLog:

2002-08-12  Martin Vermeer <[EMAIL PROTECTED]>

        * buffer.C:
        buffer.h:
        lyxtext.h:
        paragraph.C:
        paragraph_pimpl.h:
        text.C:
        text2.C:
        undo_funcs.C: replaced per-paragraph counter logic by per-buffer, as
        suggested by Angus.
        Made updateCounter always count from start of buffer, and removed
        second argument (par).
        Reverted floats number display to '#'. Perhaps I'll try again when the
        code base is sanitized a bit.

Martin

-- 
Martin Vermeer  [EMAIL PROTECTED]
Helsinki University of Technology 
Department of Surveying
P.O. Box 1200, FIN-02015 HUT, Finland
:wq
Index: buffer.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v
retrieving revision 1.367
diff -u -p -r1.367 buffer.C
--- buffer.C    2002/08/12 00:15:16     1.367
+++ buffer.C    2002/08/12 14:09:34
@@ -3859,6 +3869,10 @@ bool Buffer::isMultiLingual()
        return false;
 }
 
+Counters & Buffer::counters() const
+{
+                   return ctrs;
+}
 
 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
        : par(paragraph)
Index: buffer.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.h,v
retrieving revision 1.107
diff -u -p -r1.107 buffer.h
--- buffer.h    2002/08/12 00:15:17     1.107
+++ buffer.h    2002/08/12 14:09:34
@@ -26,6 +26,7 @@
 #include "texrow.h"
 #include "ParagraphList.h"
 #include "paragraph.h"
+#include "counters.h"
 
 #include <boost/shared_ptr.hpp>
 
@@ -317,6 +318,11 @@ public:
 
        /// Used when typesetting to place errorboxes.
        TexRow texrow;
+       /// Buffer-wide counter array
+       Counters & counters() const;
+       ///
+       mutable Counters ctrs;
+       
 private:
        /// is save needed
        mutable bool lyx_clean;
Index: lyxtext.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxtext.h,v
retrieving revision 1.119
diff -u -p -r1.119 lyxtext.h
--- lyxtext.h   2002/08/09 02:50:19     1.119
+++ lyxtext.h   2002/08/12 14:09:36
@@ -618,7 +619,7 @@ private:
 public:
        /** Updates all counters starting BEHIND the row. Changed paragraphs
         * with a dynamic left margin will be rebroken. */
-       void updateCounters(BufferView *, Row * row) const;
+       void updateCounters(BufferView *) const;
 private:
        ///
        void setCounter(Buffer const *, Paragraph * par) const;
Index: paragraph.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/paragraph.C,v
retrieving revision 1.219
diff -u -p -r1.219 paragraph.C
--- paragraph.C 2002/08/11 20:34:20     1.219
+++ paragraph.C 2002/08/12 14:09:38
@@ -2057,7 +2139,3 @@ bool Paragraph::isFreeSpacing() const
 }
 
 
-Counters & Paragraph::counters()
-{
-       return pimpl_->ctrs;
-}
Index: paragraph_pimpl.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/paragraph_pimpl.h,v
retrieving revision 1.16
diff -u -p -r1.16 paragraph_pimpl.h
--- paragraph_pimpl.h   2002/08/11 20:34:20     1.16
+++ paragraph_pimpl.h   2002/08/12 14:09:38
@@ -145,8 +145,7 @@ struct Paragraph::Pimpl {
        static unsigned int paragraph_id;
        ///
        ParagraphParameters params;
-       ///
-       Counters ctrs;
+
 private:
        /// match a string against a particular point in the paragraph
        bool isTextAt(string const & str, lyx::pos_type pos) const;
Index: text.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text.C,v
retrieving revision 1.265
diff -u -p -r1.265 text.C
--- text.C      2002/08/10 15:21:03     1.265
+++ text.C      2002/08/12 14:09:44
@@ -1805,7 +1806,7 @@ void LyXText::breakParagraph(BufferView 
 
        insertParagraph(bview, cursor.par()->next(), cursor.row());
 
-       updateCounters(bview, cursor.row()->previous());
+       updateCounters(bview);
 
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
@@ -2818,7 +2819,7 @@ void LyXText::backspace(BufferView * bvi
 
                        // This rebuilds the rows.
                        appendParagraph(bview, cursor.row());
-                       updateCounters(bview, cursor.row());
+                       updateCounters(bview);
 
                        // the row may have changed, block, hfills etc.
                        setCursor(bview, cursor.par(), cursor.pos(), false);
Index: text2.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text2.C,v
retrieving revision 1.246
diff -u -p -r1.246 text2.C
--- text2.C     2002/08/12 00:15:17     1.246
+++ text2.C     2002/08/12 14:09:46
@@ -542,7 +546,7 @@ void LyXText::setLayout(BufferView * bvi
                  selection.start.pos(), false);
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos(), false);
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
@@ -619,7 +623,7 @@ void  LyXText::incDepth(BufferView * bvi
        setCursor(bview, selection.start.par(), selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@@ -676,7 +680,7 @@ void  LyXText::decDepth(BufferView * bvi
                  selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@@ -883,6 +887,7 @@ void LyXText::redoParagraphs(BufferView 
 
        if (tmprow && tmprow->next())
                setHeightOfRow(bview, tmprow->next());
+       updateCounters(bview);
 }
 
 
@@ -1218,21 +1225,16 @@ void LyXText::setCounter(Buffer const * 
        LyXTextClass const & textclass = buf->params.getLyXTextClass();
        LyXLayout_ptr const & layout = par->layout();
 
-       // copy the prev-counters to this one,
-       // unless this is the first paragraph
        if (par->previous()) {
 
-               par->counters().copy(par->previous()->counters(), par->counters(), "");
-
                par->params().appendix(par->previous()->params().appendix());
                if (!par->params().appendix() && par->params().startOfAppendix()) {
                        par->params().appendix(true);
-                       par->counters().reset();
+                       buf->counters().reset("");
                }
                par->enumdepth = par->previous()->enumdepth;
                par->itemdepth = par->previous()->itemdepth;
        } else {
-               par->counters().reset();
                par->params().appendix(par->params().startOfAppendix());
                par->enumdepth = 0;
                par->itemdepth = 0;
@@ -1258,8 +1260,6 @@ void LyXText::setCounter(Buffer const * 
            && par->previous()->getDepth() > par->getDepth()
            && layout->labeltype != LABEL_BIBLIO) {
                par->enumdepth = par->depthHook(par->getDepth())->enumdepth;
-               par->counters().set(par->counters().enums[par->enumdepth],
-                       
par->depthHook(par->getDepth())->counters().value(par->counters().enums[par->enumdepth]));
        }
 
        if (!par->params().labelString().empty()) {
@@ -1283,7 +1283,7 @@ void LyXText::setCounter(Buffer const * 
 
                if (i >= 0 && i<= buf->params.secnumdepth) {
 
-                       par->counters().step(par->counters().sects[i]);
+                       buf->counters().step(buf->counters().sects[i]);
 
                        // Is there a label? Useful for Chapter layout
                        if (!par->params().appendix()) {
@@ -1310,28 +1310,28 @@ void LyXText::setCounter(Buffer const * 
                                        langtype = "latin";
                        }
 
-                       s << par->counters().numberLabel(par->counters().sects[i],
+                       s << buf->counters().numberLabel(buf->counters().sects[i],
                                numbertype, langtype, head);
 
-                       par->params().labelString(par->params().labelString() 
+s.str().c_str());
+                       par->params().labelString(par->params().labelString() + 
+s.str().c_str());
                        // We really want to remove the c_str as soon as
                        // possible...
 
                        // reset enum counters
-                       par->counters().reset("enum");
+                       buf->counters().reset("enum");
                } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
-                       par->counters().reset("enum");
+                       buf->counters().reset("enum");
                } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
-                       par->counters().step(par->counters().enums[par->enumdepth]);
+                       buf->counters().step(buf->counters().enums[par->enumdepth]);
 
-                       s << 
par->counters().numberLabel(par->counters().enums[par->enumdepth],
+                       s << 
+buf->counters().numberLabel(buf->counters().enums[par->enumdepth],
                                "enumeration", langtype);
                        par->params().labelString(s.str().c_str());
 
                }
        } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
-               par->counters().step("bibitem");
-               int number = par->counters().value("bibitem");
+               buf->counters().step("bibitem");
+               int number = buf->counters().value("bibitem");
                if (!par->bibkey) {
                        InsetCommandParams p("bibitem" );
                        par->bibkey = new InsetBibKey(p);
@@ -1353,11 +1353,12 @@ void LyXText::setCounter(Buffer const * 
                                Floating const & fl
                                        = floatList.getType(tmp->type());
 
-                               // Why doesn't it work? -- MV
-                               par->counters().step(fl.name());
-                               // We should get the correct number here too.
+                               buf->counters().step(fl.name());
+                               
+                               // Doesn't work... yet.
                                ostringstream o;
-                               o << fl.name() << " " << 
par->counters().value(fl.name()) << ":";
+                               //o << fl.name() << " " << 
+buf->counters().value(fl.name()) << ":";
+                               o << fl.name() << " #:";
                                s = o.str();
                        } else {
                                /* par->SetLayout(0);
@@ -1371,7 +1372,7 @@ void LyXText::setCounter(Buffer const * 
                /* reset the enumeration counter. They are always resetted
                 * when there is any other layout between */
                for (int i = par->enumdepth + 1; i < 4; i++) {
-                       par->counters().set(par->counters().enums[i], 0);
+                       buf->counters().set(buf->counters().enums[i], 0);
                }
        }
 }
@@ -1379,21 +1380,18 @@ void LyXText::setCounter(Buffer const * 
 
 // Updates all counters BEHIND the row. Changed paragraphs
 // with a dynamic left margin will be rebroken.
-void LyXText::updateCounters(BufferView * bview, Row * row) const
+void LyXText::updateCounters(BufferView * bview) const
 {
        Paragraph * par;
-
-       if (!row) {
-               row = firstrow;
-               par = row->par();
-       } else {
-               par = row->par()->next();
-       }
+       
+       Row * row = firstrow;
+       par = row->par();
 
+       bview->buffer()->counters().reset("");
        while (par) {
                while (row->par() != par)
                        row = row->next();
-
+               
                setCounter(bview->buffer(), par);
 
                // now check for the headline layouts. remember that they
@@ -1520,7 +1518,7 @@ void LyXText::cutSelection(BufferView * 
 
        setCursor(bview, cursor.par(), cursor.pos());
        selection.cursor = cursor;
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
 }
 
 
@@ -1573,7 +1571,7 @@ void LyXText::pasteSelection(BufferView 
        selection.cursor = cursor;
        setCursor(bview, actpar, pos);
        setSelection(bview);
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
 }
 
 
@@ -2319,7 +2317,7 @@ bool LyXText::deleteEmptyParagraphMechan
                         * there is another layout before */
                        if (refresh_row->next()) {
                                breakAgain(bview, refresh_row->next());
-                               updateCounters(bview, refresh_row);
+                               updateCounters(bview);
                        }
                        setHeightOfRow(bview, refresh_row);
                } else {
@@ -2352,7 +2350,7 @@ bool LyXText::deleteEmptyParagraphMechan
                           there is another layout before */
                        if (refresh_row) {
                                breakAgain(bview, refresh_row);
-                               updateCounters(bview, refresh_row->previous());
+                               updateCounters(bview);
                        }
                }
 
@@ -2395,7 +2393,7 @@ void LyXText::toggleAppendix(BufferView 
        status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = 0;
        refresh_row = 0; // not needed for full update
-       updateCounters(bview, 0);
+       updateCounters(bview);
        setCursor(bview, cursor.par(), cursor.pos());
 }
 
Index: undo_funcs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/undo_funcs.C,v
retrieving revision 1.26
diff -u -p -r1.26 undo_funcs.C
--- undo_funcs.C        2002/07/25 11:39:38     1.26
+++ undo_funcs.C        2002/08/12 14:09:46
@@ -216,7 +216,7 @@ bool textHandleUndo(BufferView * bv, Und
                        // for an evt. new selection.
                        t->clearSelection();
                        t->selection.cursor = t->cursor;
-                       t->updateCounters(bv, t->cursor.row());
+                       t->updateCounters(bv);
                        bv->fitCursor();
                }
                bv->updateInset(it, false);
@@ -238,7 +238,7 @@ bool textHandleUndo(BufferView * bv, Und
                        // for an evt. new selection.
                        t->clearSelection();
                        t->selection.cursor = t->cursor;
-                       t->updateCounters(bv, t->cursor.row());
+                       t->updateCounters(bv);
                }
        }
 

Attachment: msg42476/pgp00000.pgp
Description: PGP signature

Reply via email to