2015-09-02 18:53:13 +00:00
|
|
|
/**
|
|
|
|
* \file InsetCaptionable.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
|
|
|
* \author Guillaume Munch
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetCaptionable.h"
|
|
|
|
|
2016-09-23 22:49:00 +00:00
|
|
|
#include "InsetCaption.h"
|
|
|
|
|
2015-09-02 18:53:13 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "FloatList.h"
|
2016-09-23 22:49:00 +00:00
|
|
|
#include "InsetList.h"
|
|
|
|
#include "output_xhtml.h"
|
2015-09-02 18:53:13 +00:00
|
|
|
#include "TextClass.h"
|
|
|
|
#include "TocBackend.h"
|
|
|
|
|
2016-09-23 22:49:00 +00:00
|
|
|
#include "support/docstream.h"
|
|
|
|
|
2015-09-02 18:53:13 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCaptionable::setCaptionType(std::string const & type)
|
|
|
|
{
|
|
|
|
caption_type_ = type.empty() ? "senseless" : type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// common to InsetFloat and InsetWrap
|
|
|
|
docstring InsetCaptionable::floatName(string const & type) const
|
|
|
|
{
|
|
|
|
BufferParams const & bp = buffer().params();
|
|
|
|
FloatList const & floats = bp.documentClass().floats();
|
|
|
|
FloatList::const_iterator it = floats[type];
|
2015-10-04 18:38:47 +00:00
|
|
|
return (it == floats.end()) ? from_utf8(type) : bp.B_(it->second.name());
|
2015-09-02 18:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-23 22:49:00 +00:00
|
|
|
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::getCaptionHTML(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
InsetCaption const * ins = getCaptionInset();
|
|
|
|
if (ins == 0)
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
odocstringstream ods;
|
2019-05-09 23:35:40 +00:00
|
|
|
XMLStream xs(ods);
|
2016-09-23 22:49:00 +00:00
|
|
|
docstring def = ins->getCaptionAsHTML(xs, runparams);
|
|
|
|
if (!def.empty())
|
|
|
|
// should already have been escaped
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << XMLStream::ESCAPE_NONE << def << '\n';
|
2016-09-23 22:49:00 +00:00
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const
|
2015-09-02 18:53:13 +00:00
|
|
|
{
|
|
|
|
DocIterator pit = cpit;
|
|
|
|
pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
|
|
|
|
docstring str;
|
2015-09-27 06:05:00 +00:00
|
|
|
// Leave str empty if we generate for output (e.g. xhtml lists of figures).
|
|
|
|
// This ensures that there is a caption if and only if the string is
|
|
|
|
// non-empty.
|
|
|
|
if (utype != OutputUpdate)
|
|
|
|
text().forOutliner(str, TOC_ENTRY_LENGTH);
|
2017-01-13 10:06:48 +00:00
|
|
|
TocBuilder & b = backend.builder(caption_type_);
|
2016-06-02 20:40:11 +00:00
|
|
|
b.pushItem(pit, str, output_active);
|
2015-09-02 18:53:13 +00:00
|
|
|
// Proceed with the rest of the inset.
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::addToToc(cpit, output_active, utype, backend);
|
2016-06-02 20:40:11 +00:00
|
|
|
b.pop();
|
2015-09-02 18:53:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 12:23:01 +00:00
|
|
|
void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
|
2015-09-02 18:53:13 +00:00
|
|
|
{
|
|
|
|
Counters & cnts =
|
|
|
|
buffer().masterBuffer()->params().documentClass().counters();
|
|
|
|
string const saveflt = cnts.current_float();
|
|
|
|
bool const savesubflt = cnts.isSubfloat();
|
|
|
|
if (utype == OutputUpdate) {
|
|
|
|
// counters are local to the float
|
|
|
|
cnts.saveLastCounter();
|
|
|
|
}
|
|
|
|
bool const subflt = hasSubCaptions(it);
|
|
|
|
// floats can only embed subfloats of their own kind
|
|
|
|
if (subflt && !saveflt.empty() && saveflt != "senseless")
|
|
|
|
setCaptionType(saveflt);
|
|
|
|
// Tell captions what the current float is
|
|
|
|
cnts.current_float(caption_type_);
|
|
|
|
cnts.isSubfloat(subflt);
|
2020-03-06 12:23:01 +00:00
|
|
|
InsetCollapsible::updateBuffer(it, utype, deleted);
|
2015-09-02 18:53:13 +00:00
|
|
|
// Restore counters
|
|
|
|
cnts.current_float(saveflt);
|
|
|
|
if (utype == OutputUpdate)
|
|
|
|
cnts.restoreLastCounter();
|
|
|
|
cnts.isSubfloat(savesubflt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetCaptionable::insetAllowed(InsetCode c) const
|
|
|
|
{
|
2017-10-16 08:12:21 +00:00
|
|
|
return (c == CAPTION_CODE) || InsetCollapsible::insetAllowed(c);
|
2015-09-02 18:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|