I will presently commit the attached patch to insetcaption.[Ch]. This
prepares the way for switching to caption insets. It still doesn't enable
them... I have a separate patch in the pipeline for this.

- Martin

Index: insetcaption.C
===================================================================
--- insetcaption.C      (revision 13930)
+++ insetcaption.C      (working copy)
@@ -89,9 +89,40 @@ void InsetCaption::cursorPos
 }
 
 
+void InsetCaption::setLabel(LCursor & cur) const
+{
+       // Set caption label _only_ if the cursor is in _this_ float:
+       if (cur.top().text() == &text_) {
+               string s; 
+               size_t i = cur.depth();
+                       while (i > 0) {
+                               --i;
+                               InsetBase * const in = &cur[i].inset();
+                               if (in->lyxCode() == InsetBase::FLOAT_CODE
+                                   || in->lyxCode() == InsetBase::WRAP_CODE) {
+                                       s = in->getInsetName();
+                                       break;
+                               }
+                       }
+               Floating const & fl = textclass_.floats().getType(s);
+               s = fl.name();
+               string num;
+               if (s.empty())
+                       s = "Senseless";
+               else 
+                       num = convert<string>(counter_);
+
+               // Generate the label
+               label = bformat("%1$s %2$s:", _(s), num);
+       }
+}
+
+
 void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+       LCursor cur = mi.base.bv->cursor();
+       setLabel(cur);
        labelwidth_ = font_metrics::width(label, mi.base.font);
        dim.wid = labelwidth_;
        Dimension textdim;
@@ -118,30 +149,7 @@ void InsetCaption::draw(PainterInfo & pi
        // See if we can find the name of the float this caption
        // belongs to.
        LCursor cur = pi.base.bv->cursor();
-       // Set caption label _only_ if the cursor is in _this_ float:
-       if (cur.top().text() == &text_) {
-               string s; 
-               size_t i = cur.depth();
-                       while (i > 0) {
-                               --i;
-                               InsetBase * const in = &cur[i].inset();
-                               if (in->lyxCode() == InsetBase::FLOAT_CODE
-                                   || in->lyxCode() == InsetBase::WRAP_CODE) {
-                                       s = in->getInsetName();
-                                       break;
-                               }
-                       }
-               Floating const & fl = textclass_.floats().getType(s);
-               s = fl.name();
-               string num;
-               if (s.empty())
-                       s = "Senseless";
-               else
-                       num = 
convert<string>(textclass_.counters().value(fl.type()));
-
-               // Generate the label
-               label = bformat("%1$s %2$s:", _(s), num);
-       }
+       setLabel(cur);
 
        labelwidth_ = font_metrics::width(label, pi.base.font);
        pi.pain.text(x, y, label, pi.base.font);
Index: insetcaption.h
===================================================================
--- insetcaption.h      (revision 13930)
+++ insetcaption.h      (working copy)
@@ -38,6 +38,8 @@ public:
        virtual void cursorPos 
                (CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
+       bool descendable() const { return true; }
+       ///
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        virtual void draw(PainterInfo & pi, int x, int y) const;
@@ -54,14 +56,20 @@ public:
        ///
        int docbook(Buffer const & buf, std::ostream & os,
                    OutputParams const & runparams) const;
+       ///
+       void setCount(int c) { counter_ = c; }
 private:
        ///
+       void setLabel(LCursor & cur) const;
+       ///
        virtual std::auto_ptr<InsetBase> doClone() const;
        ///
        mutable std::string label;
        ///
        mutable int labelwidth_;
        ///
+       mutable int counter_;
+       ///
        LyXTextClass const & textclass_;
 };
 

Attachment: pgpI895rq0keH.pgp
Description: PGP signature

Reply via email to