]> git.lyx.org Git - features.git/commitdiff
Fix lists of figures and tables. Prepare the code for user defined captions.
authorAbdelrazak Younes <younes@lyx.org>
Thu, 1 Feb 2007 12:45:14 +0000 (12:45 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 1 Feb 2007 12:45:14 +0000 (12:45 +0000)
* 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
src/insets/insetcaption.C
src/insets/insetcaption.h
src/insets/insetfloat.C
src/insets/insetwrap.C

index 0429580415ee70e8396f74b1f0cfb8181c12e715..f6d0d73a6c1280f0c46b03d0299fd840894865ad 100644 (file)
@@ -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<InsetCaption &>(icap).setCount(number);
-                               static_cast<InsetCaption &>(icap).setLabel(label);
+                               InsetCaption & ic = static_cast<InsetCaption &>(icap);
+                               ic.setType(type);
+                               ic.setCount(number);
+                               ic.setCustomLabel(label);
                        }
                }
        }
index 8f2991a862d4b5927ed653e0cc5a8d3c9165239f..28ace2dc354a14052967df311b923daaf0949608 100644 (file)
@@ -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"
 #include <sstream>
 
 
-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<docstring>(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<docstring>(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_;
index 0640bea9d69caf13ecb5f2270fd137d19dcb92dd..52a8bf91afb23d2adfd17e340cd6e43c008b61d9 100644 (file)
@@ -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_;
        ///
index 523602e99361a87d2c99d5aaa6e250bb88961eca..54e38514e0d28a2a85eff8ba04c66d53906d7ec2 100644 (file)
@@ -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);
 
index 570802c50d70b6371f71452d6cf531b577cd2b32..37390e519eeaadd4b0463dd305ffababbdc220b6 100644 (file)
@@ -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<docstring>(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;
 }