3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "InsetFoot.h"
18 #include "BufferParams.h"
21 #include "LaTeXFeatures.h"
23 #include "OutputParams.h"
24 #include "ParIterator.h"
25 #include "TextClass.h"
26 #include "TocBackend.h"
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/gettext.h"
31 #include "support/lstrings.h"
37 InsetFoot::InsetFoot(Buffer * buf)
38 : InsetFootlike(buf), intitle_(false), infloattable_(false)
42 docstring InsetFoot::layoutName() const
45 return from_ascii("Foot:InTitle");
46 else if (infloattable_)
47 return from_ascii("Foot:InFloatTable");
48 return from_ascii("Foot");
52 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
54 BufferParams const & bp = buffer().masterBuffer()->params();
55 Counters & cnts = bp.documentClass().counters();
56 if (utype == OutputUpdate) {
57 // the footnote counter is local to this inset
58 cnts.saveLastCounter();
62 infloattable_ = false;
64 if (it.innerInsetOfType(TABULAR_CODE) != 0)
66 if (it.innerInsetOfType(FLOAT_CODE) != 0)
67 infloattable_ = intable;
68 // If we are in a table in a float, but the table is also in a minipage,
69 // we do not use tablefootnote, since minipages provide their own footnotes.
70 if (intable && infloattable_ && it.innerInsetOfType(BOX_CODE) != 0) {
71 InsetBoxParams const & boxp =
72 static_cast<InsetBox*>(it.innerInsetOfType(BOX_CODE))->params();
73 if (boxp.inner_box && !boxp.use_parbox && !boxp.use_makebox)
74 infloattable_ = false;
76 for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
77 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
83 Language const * lang = it.paragraph().getParLanguage(bp);
84 InsetLayout const & il = getLayout();
85 docstring const & count = il.counter();
86 custom_label_ = translateIfPossible(il.labelstring());
88 Paragraph const & par = it.paragraph();
89 if (!par.isDeleted(it.pos())) {
90 if (cnts.hasCounter(count))
91 cnts.step(count, utype);
92 custom_label_ += ' ' + cnts.theCounter(count, lang->code());
94 custom_label_ += ' ' + from_ascii("#");
95 setLabel(custom_label_);
97 InsetCollapsible::updateBuffer(it, utype);
98 if (utype == OutputUpdate)
99 cnts.restoreLastCounter();
103 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
106 // this will give us something useful if there is no button
107 return InsetCollapsible::toolTip(bv, x, y);
108 return toolTipText(custom_label_+ ": ");
112 int InsetFoot::plaintext(odocstringstream & os,
113 OutputParams const & runparams, size_t max_length) const
115 os << '[' << buffer().B_("footnote") << ":\n";
116 InsetText::plaintext(os, runparams, max_length);
119 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
123 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
126 int const i = InsetText::docbook(os, runparams);
133 void InsetFoot::validate(LaTeXFeatures & features) const
135 // Use footnote package to provide footnotes in tables
136 // unless an alternative approach is built in the class.
137 if (!features.saveNoteEnv().empty()
138 && !features.isProvided("footnote-alternative")) {
139 features.require("footnote");
140 features.addPreambleSnippet(
141 from_ascii("\\makesavenoteenv{"
142 + features.saveNoteEnv()
146 InsetText::validate(features);