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"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "FloatList.h"
22 #include "TextClass.h"
23 #include "TocBackend.h"
31 void InsetCaptionable::setCaptionType(std::string const & type)
33 caption_type_ = type.empty() ? "senseless" : type;
37 /// common to InsetFloat and InsetWrap
38 docstring InsetCaptionable::floatName(string const & type) const
40 BufferParams const & bp = buffer().params();
41 FloatList const & floats = bp.documentClass().floats();
42 FloatList::const_iterator it = floats[type];
43 return (it == floats.end()) ? from_utf8(type) : bp.B_(it->second.name());
47 void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
48 UpdateType utype) const
50 DocIterator pit = cpit;
51 pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
53 // Leave str empty if we generate for output (e.g. xhtml lists of figures).
54 // This ensures that there is a caption if and only if the string is
56 if (utype != OutputUpdate)
57 text().forOutliner(str, TOC_ENTRY_LENGTH);
58 shared_ptr<TocBuilder> b = buffer().tocBackend().builder(caption_type_);
59 b->pushItem(pit, str, output_active);
60 // Proceed with the rest of the inset.
61 InsetCollapsable::addToToc(cpit, output_active, utype);
65 void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype)
68 buffer().masterBuffer()->params().documentClass().counters();
69 string const saveflt = cnts.current_float();
70 bool const savesubflt = cnts.isSubfloat();
71 if (utype == OutputUpdate) {
72 // counters are local to the float
73 cnts.saveLastCounter();
75 bool const subflt = hasSubCaptions(it);
76 // floats can only embed subfloats of their own kind
77 if (subflt && !saveflt.empty() && saveflt != "senseless")
78 setCaptionType(saveflt);
79 // Tell captions what the current float is
80 cnts.current_float(caption_type_);
81 cnts.isSubfloat(subflt);
82 InsetCollapsable::updateBuffer(it, utype);
84 cnts.current_float(saveflt);
85 if (utype == OutputUpdate)
86 cnts.restoreLastCounter();
87 cnts.isSubfloat(savesubflt);
91 bool InsetCaptionable::insetAllowed(InsetCode c) const
93 return (c == CAPTION_CODE) || InsetCollapsable::insetAllowed(c);