From 0e0a17ff0a25dcd55451f78fe062832c760658a9 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 1 Feb 2007 12:45:14 +0000 Subject: [PATCH] Fix lists of figures and tables. Prepare the code for user defined captions. * buffer_funcs.C::setCaptionLabels(): set the type as well as the custom label. * InsetCaption: - setType(): new method to set the type of the caption - setCustomLabel(): renamed from setLabel, translate if possible. - addToToc(): implement. - metrics(): use custom_label_ if defined. * InsetFloat::addToToc(): don't do anything. * InsetWrap::addToToc(): don't do anything. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17001 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer_funcs.C | 9 ++++++--- src/insets/insetcaption.C | 39 ++++++++++++++++++++++++++++++--------- src/insets/insetcaption.h | 10 ++++++++-- src/insets/insetfloat.C | 6 ++++++ src/insets/insetwrap.C | 15 ++------------- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 0429580415..f6d0d73a6c 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -363,8 +363,9 @@ void setCaptionLabels(InsetBase & inset, Floating const & fl, if (pars.empty()) return; - // FIXME UNICODE + string const & type = fl.type(); docstring const counter = from_ascii(fl.type()); + // FIXME UNICODE docstring const label = from_utf8(fl.name()); ParagraphList::iterator p = pars.begin(); @@ -381,8 +382,10 @@ void setCaptionLabels(InsetBase & inset, Floating const & fl, // We found a caption! counters.step(counter); int number = counters.value(counter); - static_cast(icap).setCount(number); - static_cast(icap).setLabel(label); + InsetCaption & ic = static_cast(icap); + ic.setType(type); + ic.setCount(number); + ic.setCustomLabel(label); } } } diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 8f2991a862..28ace2dc35 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -28,6 +28,7 @@ #include "metricsinfo.h" #include "output_latex.h" #include "paragraph.h" +#include "TocBackend.h" #include "frontends/FontMetrics.h" #include "frontends/Painter.h" @@ -38,18 +39,18 @@ #include -namespace lyx { - -using support::bformat; - using std::auto_ptr; using std::endl; using std::string; using std::ostream; +namespace lyx { + +using support::bformat; + InsetCaption::InsetCaption(BufferParams const & bp) - : InsetText(bp), textclass_(bp.getLyXTextClass()), counter_(-1) + : InsetText(bp), textclass_(bp.getLyXTextClass()) { setAutoBreakRows(true); setDrawFrame(true); @@ -93,20 +94,40 @@ void InsetCaption::cursorPos(BufferView const & bv, } -void InsetCaption::setLabel(docstring const & label) +void InsetCaption::setCustomLabel(docstring const & label) { - label_ = _(to_ascii(label)); + if (!support::isAscii(label) || label.empty()) + // This must be a user defined layout. We cannot translate + // this, since gettext accepts only ascii keys. + custom_label_ = label; + else + custom_label_ = _(to_ascii(label)); +} + + +void InsetCaption::addToToc(TocList & toclist, Buffer const & buf) const +{ + if (type_.empty()) + return; + + ParConstIterator pit = par_const_iterator_begin(*this); + + Toc & toc = toclist[type_]; + docstring const str = convert(counter_) + + ". " + pit->asString(buf, false); + toc.push_back(TocItem(pit, 0, str)); } bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const { mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; - if (counter_ < 0) + if (type_.empty()) full_label_ = _("Senseless!!! "); else { docstring const number = convert(counter_); - full_label_ = bformat(from_ascii("%1$s %2$s:"), label_, number); + docstring label = custom_label_.empty()? _(type_): custom_label_; + full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number); } labelwidth_ = theFontMetrics(mi.base.font).width(full_label_); dim.wid = labelwidth_; diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 0640bea9d6..52a8bf91af 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -67,7 +67,11 @@ public: /// void setCount(int c) { counter_ = c; } /// - void setLabel(docstring const & label); + void setType(std::string const & type) { type_ = type; } + /// + void setCustomLabel(docstring const & label); + /// + void addToToc(TocList &, Buffer const &) const; private: /// @@ -77,7 +81,9 @@ private: /// mutable int labelwidth_; /// - docstring label_; + std::string type_; + /// + docstring custom_label_; /// int counter_; /// diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 523602e993..54e38514e0 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -378,6 +378,12 @@ void InsetFloat::sideways(bool s, BufferParams const & bp) void InsetFloat::addToToc(TocList & toclist, Buffer const & buf) const { + // Is there a need to provide a list of float insets? + return; + + // Abdel (01/02/2006): I'll let this code for reference in case + // there's a need to do something similar for another kind of + // inset. ParConstIterator pit = par_const_iterator_begin(*this); ParConstIterator end = par_const_iterator_end(*this); diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 570802c50d..37390e519e 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -226,19 +226,8 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const void InsetWrap::addToToc(TocList & toclist, Buffer const & buf) const { - ParConstIterator pit = par_const_iterator_begin(*this); - ParConstIterator end = par_const_iterator_end(*this); - - // Find a caption layout in one of the (child inset's) pars - for (; pit != end; ++pit) { - if (pit->layout()->labeltype == LABEL_SENSITIVE) { - Toc & toc = toclist[params_.type]; - docstring const str = - convert(toc.size() + 1) - + ". " + pit->asString(buf, false); - toc.push_back(TocItem(pit, 0, str)); - } - } + // Is there a need to provide a list of wrap insets? + return; }