2 * \file InsetCaptionable.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Lars Gullik Bjønnes
9 * \author Guillaume Munch
11 * Full author contact details are available in file CREDITS.
16 #include "InsetCaptionable.h"
18 #include "InsetCaption.h"
21 #include "BufferParams.h"
22 #include "BufferView.h"
23 #include "FloatList.h"
24 #include "InsetList.h"
25 #include "output_xhtml.h"
26 #include "TextClass.h"
27 #include "TocBackend.h"
29 #include "support/docstream.h"
37 void InsetCaptionable::setCaptionType(std::string const & type)
39 caption_type_ = type.empty() ? "senseless" : type;
43 /// common to InsetFloat and InsetWrap
44 docstring InsetCaptionable::floatName(string const & type) const
46 BufferParams const & bp = buffer().params();
47 FloatList const & floats = bp.documentClass().floats();
48 FloatList::const_iterator it = floats[type];
49 return (it == floats.end()) ? from_utf8(type) : bp.B_(it->second.name());
53 InsetCaption const * InsetCaptionable::getCaptionInset() const
55 ParagraphList::const_iterator pit = paragraphs().begin();
56 for (; pit != paragraphs().end(); ++pit) {
57 InsetList::const_iterator it = pit->insetList().begin();
58 for (; it != pit->insetList().end(); ++it) {
59 Inset & inset = *it->inset;
60 if (inset.lyxCode() == CAPTION_CODE) {
61 InsetCaption const * ins =
62 static_cast<InsetCaption const *>(it->inset);
71 docstring InsetCaptionable::getCaptionText(OutputParams const & runparams) const
73 InsetCaption const * ins = getCaptionInset();
78 ins->getCaptionAsPlaintext(ods, runparams);
83 docstring InsetCaptionable::getCaptionDocBook(OutputParams const & runparams) const
85 InsetCaption const * ins = getCaptionInset();
91 ins->getCaptionAsDocBook(xs, runparams);
96 docstring InsetCaptionable::getCaptionHTML(OutputParams const & runparams) const
98 InsetCaption const * ins = getCaptionInset();
102 odocstringstream ods;
104 docstring def = ins->getCaptionAsHTML(xs, runparams);
106 // should already have been escaped
107 xs << XMLStream::ESCAPE_NONE << def << '\n';
112 void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
113 UpdateType utype, TocBackend & backend) const
115 DocIterator pit = cpit;
116 pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
118 // Leave str empty if we generate for output (e.g. xhtml lists of figures).
119 // This ensures that there is a caption if and only if the string is
121 if (utype != OutputUpdate)
122 text().forOutliner(str, TOC_ENTRY_LENGTH);
123 TocBuilder & b = backend.builder(caption_type_);
124 b.pushItem(pit, str, output_active);
125 // Proceed with the rest of the inset.
126 InsetCollapsible::addToToc(cpit, output_active, utype, backend);
130 void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
133 buffer().masterBuffer()->params().documentClass().counters();
134 string const saveflt = cnts.current_float();
135 bool const savesubflt = cnts.isSubfloat();
136 if (utype == OutputUpdate) {
137 // counters are local to the float
138 cnts.saveLastCounter();
140 bool const subflt = hasSubCaptions(it);
141 // floats can only embed subfloats of their own kind
142 if (subflt && !saveflt.empty() && saveflt != "senseless")
143 setCaptionType(saveflt);
144 // Tell captions what the current float is
145 cnts.current_float(caption_type_);
146 cnts.isSubfloat(subflt);
147 InsetCollapsible::updateBuffer(it, utype, deleted);
149 cnts.current_float(saveflt);
150 if (utype == OutputUpdate)
151 cnts.restoreLastCounter();
152 cnts.isSubfloat(savesubflt);
156 bool InsetCaptionable::insetAllowed(InsetCode c) const
158 return (c == CAPTION_CODE) || InsetCollapsible::insetAllowed(c);