}
+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;
// 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);
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;
///
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 int labelwidth_;
///
+ mutable int counter_;
+ ///
LyXTextClass const & textclass_;
};