X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCaptionable.cpp;h=474eaf059e7fa14ed022ae0cc0b0907b0e96493c;hb=8124e6c02ea1fd6779bb6c47ffe2bca2c8bd2d97;hp=467106fa43e3e10888b7d68e633a4ca03aa5e96a;hpb=c466baaa5b99e44ea25616556bd0918197f4b54c;p=lyx.git diff --git a/src/insets/InsetCaptionable.cpp b/src/insets/InsetCaptionable.cpp index 467106fa43..474eaf059e 100644 --- a/src/insets/InsetCaptionable.cpp +++ b/src/insets/InsetCaptionable.cpp @@ -13,9 +13,10 @@ #include +#include "InsetBox.h" #include "InsetCaptionable.h" - #include "InsetCaption.h" +#include "InsetLabel.h" #include "Buffer.h" #include "BufferParams.h" @@ -64,14 +65,59 @@ InsetCaption const * InsetCaptionable::getCaptionInset() const } } } - return 0; + return nullptr; +} + + +InsetLabel const * InsetCaptionable::getLabelInset() const +{ + // A wrong hypothesis would be to limit the search to the caption: it is most likely there, but not necessarily! + + // Iterate through the contents of the inset. + auto const end = paragraphs().end(); + for (auto par = paragraphs().begin(); par != end; ++par) { + for (pos_type pos = 0; pos < par->size(); ++pos) { + const Inset * inset = par->getInset(pos); + + // If this inset is a subfigure, skip it. Otherwise, you would return the label for the subfigure. + if (dynamic_cast(inset)) { + continue; + } + + // Maybe an inset is directly a label, in which case no more work is needed. + if (inset && dynamic_cast(inset)) + return dynamic_cast(inset); + + // More likely, the label is hidden in an inset of a paragraph (only if a subtype of InsetText). Thus, + // dig into that text. + if (!dynamic_cast(inset)) + continue; + + auto insetAsText = dynamic_cast(inset); + auto itIn = insetAsText->paragraphs().begin(); + auto endIn = insetAsText->paragraphs().end(); + for (; itIn != endIn; ++itIn) { + for (pos_type posIn = 0; posIn < itIn->size(); ++posIn) { + const Inset *insetIn = itIn->getInset(posIn); + if (insetIn && dynamic_cast(insetIn)) { + return dynamic_cast(insetIn); + } + } + } + + // Obviously, this solution does not scale with more levels of paragraphs and insets, but this should + // be enough: it is only used in captions. + } + } + + return nullptr; } docstring InsetCaptionable::getCaptionText(OutputParams const & runparams) const { InsetCaption const * ins = getCaptionInset(); - if (ins == 0) + if (!ins) return docstring(); odocstringstream ods; @@ -80,6 +126,19 @@ docstring InsetCaptionable::getCaptionText(OutputParams const & runparams) const } +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(); @@ -87,11 +146,11 @@ docstring InsetCaptionable::getCaptionHTML(OutputParams const & runparams) const return docstring(); odocstringstream ods; - XHTMLStream xs(ods); + XMLStream xs(ods); docstring def = ins->getCaptionAsHTML(xs, runparams); if (!def.empty()) // should already have been escaped - xs << XHTMLStream::ESCAPE_NONE << def << '\n'; + xs << XMLStream::ESCAPE_NONE << def << '\n'; return ods.str(); } @@ -114,7 +173,7 @@ void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active, 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(); @@ -131,7 +190,7 @@ void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype) // Tell captions what the current float is cnts.current_float(caption_type_); cnts.isSubfloat(subflt); - InsetCollapsible::updateBuffer(it, utype); + InsetCollapsible::updateBuffer(it, utype, deleted); // Restore counters cnts.current_float(saveflt); if (utype == OutputUpdate)