#include "InsetCaptionable.h"
+#include "InsetCaption.h"
+
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "FloatList.h"
+#include "InsetList.h"
+#include "output_xhtml.h"
#include "TextClass.h"
#include "TocBackend.h"
+#include "support/docstream.h"
+
using namespace std;
}
+InsetCaption const * InsetCaptionable::getCaptionInset() const
+{
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ for (; pit != paragraphs().end(); ++pit) {
+ InsetList::const_iterator it = pit->insetList().begin();
+ for (; it != pit->insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == CAPTION_CODE) {
+ InsetCaption const * ins =
+ static_cast<InsetCaption const *>(it->inset);
+ return ins;
+ }
+ }
+ }
+ return 0;
+}
+
+
+docstring InsetCaptionable::getCaptionText(OutputParams const & runparams) const
+{
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == 0)
+ return docstring();
+
+ odocstringstream ods;
+ ins->getCaptionAsPlaintext(ods, runparams);
+ return ods.str();
+}
+
+
+docstring InsetCaptionable::getCaptionDocBook(OutputParams const & runparams) const
+{
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == nullptr)
+ return docstring();
+
+ odocstringstream ods;
+ XMLStream xs(ods);
+ ins->getCaptionAsDocBook(xs, runparams);
+ return ods.str();
+}
+
+
+docstring InsetCaptionable::getCaptionHTML(OutputParams const & runparams) const
+{
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == 0)
+ return docstring();
+
+ odocstringstream ods;
+ XMLStream xs(ods);
+ docstring def = ins->getCaptionAsHTML(xs, runparams);
+ if (!def.empty())
+ // should already have been escaped
+ xs << XMLStream::ESCAPE_NONE << def << '\n';
+ return ods.str();
+}
+
+
void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
- UpdateType utype) const
+ UpdateType utype, TocBackend & backend) const
{
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
// non-empty.
if (utype != OutputUpdate)
text().forOutliner(str, TOC_ENTRY_LENGTH);
- shared_ptr<TocBuilder> b = buffer().tocBackend().builder(caption_type_);
- b->pushItem(pit, str, output_active);
+ TocBuilder & b = backend.builder(caption_type_);
+ b.pushItem(pit, str, output_active);
// Proceed with the rest of the inset.
- InsetCollapsable::addToToc(cpit, output_active, utype);
- b->pop();
+ InsetCollapsible::addToToc(cpit, output_active, utype, backend);
+ b.pop();
}
-void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype)
+void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
{
Counters & cnts =
buffer().masterBuffer()->params().documentClass().counters();
// Tell captions what the current float is
cnts.current_float(caption_type_);
cnts.isSubfloat(subflt);
- InsetCollapsable::updateBuffer(it, utype);
+ InsetCollapsible::updateBuffer(it, utype, deleted);
// Restore counters
cnts.current_float(saveflt);
if (utype == OutputUpdate)
bool InsetCaptionable::insetAllowed(InsetCode c) const
{
- return (c == CAPTION_CODE) || InsetCollapsable::insetAllowed(c);
+ return (c == CAPTION_CODE) || InsetCollapsible::insetAllowed(c);
}