On Sun, Aug 11, 2002 at 08:50:59PM +0900, Rob Lahaye wrote:

> Hi,
> 
> On the LyX canvas, figures are now numbered. But each figure gets the number
> one, "Figure 1". For some reason the figure numbers are not incremented.
> 
> However, the figures are correctly numbered in "Navigate->Figure".
> 
> Rob.
 
A partial fix attached.

This simplifies the code from 'one counter array per paragraph' to
'one counter array per buffer', as we discussed earlier Angus. Yes,
it does make things simpler, doesn't it?

Now also the Figure and Table counters increment... more than I 
bargained for :-( Haven't figured that one out yet.

Once we get that working, I suggest to remove the counter code from
paragraph again. Also the Counters::copy method can probably go. 
Angus, please merge in your clean-up patch too, and apply. No worse
than what we have now.

Martin

Index: buffer.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v
retrieving revision 1.365
diff -u -p -r1.365 buffer.C
--- buffer.C    2002/08/10 15:20:57     1.365
+++ buffer.C    2002/08/11 15:56:26
@@ -3867,6 +3877,10 @@ bool Buffer::isMultiLingual()
        return false;
 }
 
+Counters & Buffer::counters()
+{
+                   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.105
diff -u -p -r1.105 buffer.h
--- buffer.h    2002/08/04 23:11:47     1.105
+++ buffer.h    2002/08/11 15:56:27
@@ -316,6 +316,11 @@ public:
 
        /// Used when typesetting to place errorboxes.
        TexRow texrow;
+       /// Buffer-wide counter array
+       Counters & counters();
+       ///
+       Counters ctrs;
+       
 private:
        /// is save needed
        mutable bool lyx_clean;
Index: text2.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text2.C,v
retrieving revision 1.244
diff -u -p -r1.244 text2.C
--- text2.C     2002/08/10 15:21:05     1.244
+++ text2.C     2002/08/11 15:56:29
@@ -1213,26 +1219,21 @@ void LyXText::setParagraph(BufferView * 
 
 
 // set the counter of a paragraph. This includes the labels
-void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
+void LyXText::setCounter(Buffer * buf, Paragraph * par) 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 +1259,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 +1282,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 +1309,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);
@@ -1354,10 +1353,10 @@ void LyXText::setCounter(Buffer const * 
                                        = floatList.getType(tmp->type());
 
                                // Why doesn't it work? -- MV
-                               par->counters().step(fl.name());
+                               buf->counters().step(fl.name());
                                // We should get the correct number here too.
                                ostringstream o;
-                               o << fl.name() << " " << 
par->counters().value(fl.name()) << ":";
+                               o << fl.name() << " " << 
+buf->counters().value(fl.name()) << ":";
                                s = o.str();
                        } else {
                                /* par->SetLayout(0);
@@ -1371,7 +1370,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);
                }
        }
 }

Attachment: msg42392/pgp00000.pgp
Description: PGP signature

Reply via email to