]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCollapsable.cpp
Merge branch 'master' into biblatex2
[lyx.git] / src / insets / InsetCollapsable.cpp
index 38c744efd184c0382a161b9d1b0ec78e457e62c3..fa9f01056ab685e00ae67280e2faafa1541dec5f 100644 (file)
@@ -24,6 +24,7 @@
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "TocBackend.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -258,7 +259,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                view_[&bv].button_dim_.y2 = 0;
        }
 
-       Dimension const textdim = InsetText::dimension(bv);
+       Dimension const textdim = dimensionHelper(bv);
        int const baseline = y;
        int textx, texty;
        Geometry g = geometry(bv);
@@ -366,7 +367,7 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
                status_ = Open;
 
        InsetText::cursorPos(bv, sl, boundary, x, y);
-       Dimension const textdim = InsetText::dimension(bv);
+       Dimension const textdim = dimensionHelper(bv);
 
        switch (geometry(bv)) {
        case LeftButton:
@@ -576,11 +577,18 @@ void InsetCollapsable::setLabel(docstring const & l)
 }
 
 
-docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const
+docstring InsetCollapsable::getLabel() const
 {
        InsetLayout const & il = getLayout();
-       docstring const label = labelstring_.empty() ?
+       return labelstring_.empty() ?
                translateIfPossible(il.labelstring()) : labelstring_;
+}
+
+
+docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const
+{
+       InsetLayout const & il = getLayout();
+       docstring const label = getLabel();
        if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
                return label;
        return getNewLabel(label);
@@ -653,4 +661,30 @@ bool InsetCollapsable::canPaintChange(BufferView const & bv) const
 }
 
 
+void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active,
+                                UpdateType utype) const
+{
+       bool doing_output = output_active && producesOutput();
+       InsetLayout const & layout = getLayout();
+       if (layout.addToToc()) {
+               TocBuilder & b = buffer().tocBackend().builder(layout.tocType());
+               // Cursor inside the inset
+               DocIterator pit = cpit;
+               pit.push_back(CursorSlice(const_cast<InsetCollapsable &>(*this)));
+               docstring const label = getLabel();
+               b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active);
+               // Proceed with the rest of the inset.
+               InsetText::addToToc(cpit, doing_output, utype);
+               if (layout.isTocCaption()) {
+                       docstring str;
+                       text().forOutliner(str, TOC_ENTRY_LENGTH);
+                       b.argumentItem(str);
+               }
+               b.pop();
+       } else
+               InsetText::addToToc(cpit, doing_output, utype);
+}
+
+
+
 } // namespace lyx