]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCaptionable.cpp
Fix date inset except on windows (bug 9925)
[lyx.git] / src / insets / InsetCaptionable.cpp
1 /**
2  * \file InsetCaptionable.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Guillaume Munch
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "InsetCaptionable.h"
17
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "FloatList.h"
22 #include "TextClass.h"
23 #include "TocBackend.h"
24
25 using namespace std;
26
27
28 namespace lyx {
29
30
31 void InsetCaptionable::setCaptionType(std::string const & type)
32 {
33         caption_type_ = type.empty() ? "senseless" : type;
34 }
35
36
37 /// common to InsetFloat and InsetWrap
38 docstring InsetCaptionable::floatName(string const & type) const
39 {
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());
44 }
45
46
47 void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
48                                                                 UpdateType utype) const
49 {
50         DocIterator pit = cpit;
51         pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
52         docstring str;
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
55         // non-empty.
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);
62         b->pop();
63 }
64
65 void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype)
66 {
67         Counters & cnts =
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();
74         }
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);
83         // Restore counters
84         cnts.current_float(saveflt);
85         if (utype == OutputUpdate)
86                 cnts.restoreLastCounter();
87         cnts.isSubfloat(savesubflt);
88 }
89
90
91 bool InsetCaptionable::insetAllowed(InsetCode c) const
92 {
93         return (c == CAPTION_CODE) || InsetCollapsable::insetAllowed(c);
94 }
95
96
97 } // namespace lyx