X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCaptionable.cpp;h=467106fa43e3e10888b7d68e633a4ca03aa5e96a;hb=2777b51c587cb061b3214c670a3cc4b357528e6c;hp=c105d5ed99fbe047961dd63764648860d3bb97b4;hpb=aedc6720c7477ffc44d2ebb6c62540c22dd364b1;p=lyx.git diff --git a/src/insets/InsetCaptionable.cpp b/src/insets/InsetCaptionable.cpp index c105d5ed99..467106fa43 100644 --- a/src/insets/InsetCaptionable.cpp +++ b/src/insets/InsetCaptionable.cpp @@ -15,13 +15,19 @@ #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; @@ -44,8 +50,54 @@ docstring InsetCaptionable::floatName(string const & type) const } +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(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::getCaptionHTML(OutputParams const & runparams) const +{ + InsetCaption const * ins = getCaptionInset(); + if (ins == 0) + return docstring(); + + odocstringstream ods; + XHTMLStream xs(ods); + docstring def = ins->getCaptionAsHTML(xs, runparams); + if (!def.empty()) + // should already have been escaped + xs << XHTMLStream::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(*this))); @@ -55,10 +107,10 @@ void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active, // non-empty. if (utype != OutputUpdate) text().forOutliner(str, TOC_ENTRY_LENGTH); - TocBuilder & b = buffer().tocBackend().builder(caption_type_); + 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); + InsetCollapsible::addToToc(cpit, output_active, utype, backend); b.pop(); } @@ -79,7 +131,7 @@ void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype) // Tell captions what the current float is cnts.current_float(caption_type_); cnts.isSubfloat(subflt); - InsetCollapsable::updateBuffer(it, utype); + InsetCollapsible::updateBuffer(it, utype); // Restore counters cnts.current_float(saveflt); if (utype == OutputUpdate) @@ -90,7 +142,7 @@ void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype) bool InsetCaptionable::insetAllowed(InsetCode c) const { - return (c == CAPTION_CODE) || InsetCollapsable::insetAllowed(c); + return (c == CAPTION_CODE) || InsetCollapsible::insetAllowed(c); }