From: Martin Vermeer Date: Sun, 28 May 2006 17:02:57 +0000 (+0000) Subject: Slight improvement to caption inset X-Git-Tag: 1.6.10~13184 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=32a51961ae373c46f9cde06db3ccfe0a70bd6052;p=features.git Slight improvement to caption inset * 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 --- diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index b205fbe123..c91d771b05 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -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(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(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); diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 8fd7a28972..13ee45dc56 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -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 doClone() const; /// @@ -62,6 +68,8 @@ private: /// mutable int labelwidth_; /// + mutable int counter_; + /// LyXTextClass const & textclass_; };