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];
44 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
48 void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
49 UpdateType utype) const
51 DocIterator pit = cpit;
52 pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
54 // Leave str empty if we generate for output (e.g. xhtml lists of figures).
55 // This ensures that there is a caption if and only if the string is
57 if (utype != OutputUpdate)
58 text().forOutliner(str, TOC_ENTRY_LENGTH);
59 shared_ptr<TocBuilder> b = buffer().tocBackend().builder(caption_type_);
60 b->pushItem(pit, str, output_active);
61 // Proceed with the rest of the inset.
62 InsetCollapsable::addToToc(cpit, output_active, utype);
66 void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype)
69 buffer().masterBuffer()->params().documentClass().counters();
70 string const saveflt = cnts.current_float();
71 bool const savesubflt = cnts.isSubfloat();
72 if (utype == OutputUpdate) {
73 // counters are local to the float
74 cnts.saveLastCounter();
76 bool const subflt = hasSubCaptions(it);
77 // floats can only embed subfloats of their own kind
78 if (subflt && !saveflt.empty() && saveflt != "senseless")
79 setCaptionType(saveflt);
80 // Tell captions what the current float is
81 cnts.current_float(caption_type_);
82 cnts.isSubfloat(subflt);
83 InsetCollapsable::updateBuffer(it, utype);
85 cnts.current_float(saveflt);
86 if (utype == OutputUpdate)
87 cnts.restoreLastCounter();
88 cnts.isSubfloat(savesubflt);
92 bool InsetCaptionable::insetAllowed(InsetCode c) const
94 return (c == CAPTION_CODE) || InsetCollapsable::insetAllowed(c);