]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Fix footnote output in tables outside floats and longtable header/footer
[lyx.git] / src / insets / InsetFoot.cpp
1 /**
2  * \file InsetFoot.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetFoot.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "Counters.h"
19 #include "Language.h"
20 #include "LaTeXFeatures.h"
21 #include "Layout.h"
22 #include "OutputParams.h"
23 #include "ParIterator.h"
24 #include "TextClass.h"
25 #include "TocBackend.h"
26
27 #include "support/debug.h"
28 #include "support/docstream.h"
29 #include "support/gettext.h"
30 #include "support/lstrings.h"
31
32 using namespace std;
33
34 namespace lyx {
35
36 InsetFoot::InsetFoot(Buffer * buf)
37         : InsetFootlike(buf), intitle_(false)
38 {}
39
40
41 docstring InsetFoot::layoutName() const
42 {
43         return intitle_ ? from_ascii("Foot:InTitle") : from_ascii("Foot");
44 }
45
46
47 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
48 {
49         BufferParams const & bp = buffer().masterBuffer()->params();
50         Counters & cnts = bp.documentClass().counters();
51         if (utype == OutputUpdate) {
52                 // the footnote counter is local to this inset
53                 cnts.saveLastCounter();
54         }
55
56         intitle_ = false;
57         for (size_type sl = 0 ; sl < it.depth() ; ++ sl) {
58                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
59                         intitle_ = true;
60                         break;
61                 }
62         }
63
64         Language const * lang = it.paragraph().getParLanguage(bp);
65         InsetLayout const & il = getLayout();
66         docstring const & count = il.counter();
67         custom_label_ = translateIfPossible(il.labelstring());
68         if (cnts.hasCounter(count))
69                 cnts.step(count, utype);
70         custom_label_ += ' ' + cnts.theCounter(count, lang->code());
71         setLabel(custom_label_);
72
73         InsetCollapsible::updateBuffer(it, utype);
74         if (utype == OutputUpdate)
75                 cnts.restoreLastCounter();
76 }
77
78
79 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
80 {
81         if (isOpen(bv))
82                 // this will give us something useful if there is no button
83                 return InsetCollapsible::toolTip(bv, x, y);
84         return toolTipText(custom_label_+ ": ");
85 }
86
87
88 int InsetFoot::plaintext(odocstringstream & os,
89         OutputParams const & runparams, size_t max_length) const
90 {
91         os << '[' << buffer().B_("footnote") << ":\n";
92         InsetText::plaintext(os, runparams, max_length);
93         os << "\n]";
94
95         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
96 }
97
98
99 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
100 {
101         os << "<footnote>";
102         int const i = InsetText::docbook(os, runparams);
103         os << "</footnote>";
104
105         return i;
106 }
107
108
109 void InsetFoot::validate(LaTeXFeatures & features) const
110 {
111         if (!features.saveNoteEnv().empty()) {
112                 features.require("footnote");
113                 features.addPreambleSnippet(
114                         from_ascii("\\makesavenoteenv{"
115                                    + features.saveNoteEnv()
116                                    + "}\n"));
117         }
118
119         InsetText::validate(features);
120 }
121
122 } // namespace lyx