]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Allow footnotes in floating tables via tablefootnote package
[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), infloattable_(false)
38 {}
39
40
41 docstring InsetFoot::layoutName() const
42 {
43         if (intitle_)
44                 return from_ascii("Foot:InTitle");
45         else if (infloattable_)
46                 return from_ascii("Foot:InFloatTable");
47         return from_ascii("Foot");
48 }
49
50
51 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
52 {
53         BufferParams const & bp = buffer().masterBuffer()->params();
54         Counters & cnts = bp.documentClass().counters();
55         if (utype == OutputUpdate) {
56                 // the footnote counter is local to this inset
57                 cnts.saveLastCounter();
58         }
59
60         intitle_ = false;
61         infloattable_ = false;
62         bool intable = false;
63         if (it.innerInsetOfType(TABULAR_CODE) != 0)
64                 intable = true;
65         if (it.innerInsetOfType(FLOAT_CODE) != 0)
66                 infloattable_ = intable;
67         for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
68                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
69                         intitle_ = true;
70                         break;
71                 }
72         }
73
74         Language const * lang = it.paragraph().getParLanguage(bp);
75         InsetLayout const & il = getLayout();
76         docstring const & count = il.counter();
77         custom_label_ = translateIfPossible(il.labelstring());
78         if (cnts.hasCounter(count))
79                 cnts.step(count, utype);
80         custom_label_ += ' ' + cnts.theCounter(count, lang->code());
81         setLabel(custom_label_);
82
83         InsetCollapsible::updateBuffer(it, utype);
84         if (utype == OutputUpdate)
85                 cnts.restoreLastCounter();
86 }
87
88
89 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
90 {
91         if (isOpen(bv))
92                 // this will give us something useful if there is no button
93                 return InsetCollapsible::toolTip(bv, x, y);
94         return toolTipText(custom_label_+ ": ");
95 }
96
97
98 int InsetFoot::plaintext(odocstringstream & os,
99         OutputParams const & runparams, size_t max_length) const
100 {
101         os << '[' << buffer().B_("footnote") << ":\n";
102         InsetText::plaintext(os, runparams, max_length);
103         os << "\n]";
104
105         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
106 }
107
108
109 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
110 {
111         os << "<footnote>";
112         int const i = InsetText::docbook(os, runparams);
113         os << "</footnote>";
114
115         return i;
116 }
117
118
119 void InsetFoot::validate(LaTeXFeatures & features) const
120 {
121         if (!features.saveNoteEnv().empty()) {
122                 features.require("footnote");
123                 features.addPreambleSnippet(
124                         from_ascii("\\makesavenoteenv{"
125                                    + features.saveNoteEnv()
126                                    + "}\n"));
127         }
128
129         InsetText::validate(features);
130 }
131
132 } // namespace lyx