]> git.lyx.org Git - features.git/commitdiff
Slight improvement to caption inset
authorMartin Vermeer <martin.vermeer@hut.fi>
Sun, 28 May 2006 17:02:57 +0000 (17:02 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Sun, 28 May 2006 17:02:57 +0000 (17:02 +0000)
* insetcaption.C
(InsetCaption::setLabel): added
(InsetCaption::metrics): modified
(InsetCaption::draw): modified

* insetcaption.h
(descendable): added
(setCount): added

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13946 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/insetcaption.C
src/insets/insetcaption.h

index b205fbe123318295f1170076936134ed641abd48..c91d771b05f6520acc05d1b30f88f92ebabf5a6c 100644 (file)
@@ -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, int x, int y) const
        // 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 8fd7a28972d85ab1178856588f680fd25e2d0aaf..13ee45dc5674a14a0dade0358b63417c19535603 100644 (file)
@@ -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,7 +56,11 @@ 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;
        ///
@@ -62,6 +68,8 @@ private:
        ///
        mutable int labelwidth_;
        ///
+       mutable int counter_;
+       ///
        LyXTextClass const & textclass_;
 };