]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Amend 207eaeee9071cb
[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 #include "InsetBox.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Counters.h"
20 #include "Language.h"
21 #include "LaTeXFeatures.h"
22 #include "Layout.h"
23 #include "output_docbook.h"
24 #include "ParIterator.h"
25 #include "TextClass.h"
26 #include "TocBackend.h"
27
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/gettext.h"
31 #include "support/lstrings.h"
32
33 using namespace std;
34
35 namespace lyx {
36
37 InsetFoot::InsetFoot(Buffer * buf)
38         : InsetFootlike(buf), intitle_(false), infloattable_(false)
39 {}
40
41
42 docstring InsetFoot::layoutName() const
43 {
44         if (intitle_)
45                 return from_ascii("Foot:InTitle");
46         else if (infloattable_)
47                 return from_ascii("Foot:InFloatTable");
48         return from_ascii("Foot");
49 }
50
51
52 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
53 {
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();
59         }
60
61         intitle_ = false;
62         infloattable_ = false;
63         bool intable = false;
64         if (it.innerInsetOfType(TABULAR_CODE) != 0)
65                 intable = true;
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;
75         }
76         for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
77                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
78                         intitle_ = true;
79                         break;
80                 }
81         }
82
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());
87
88         int val = cnts.value(count);
89         if (cnts.hasCounter(count)) {
90                 cnts.step(count, utype);
91                 if (!custom_label_.empty())
92                         custom_label_ += ' ';
93                 custom_label_ += cnts.theCounter(count, lang->code());
94                 if (deleted)
95                         // un-step after deleted counter
96                         cnts.set(count, val);
97         } else
98                 custom_label_ += ' ' + from_ascii("#");
99         setLabel(custom_label_);
100
101         InsetCollapsible::updateBuffer(it, utype, deleted);
102         if (utype == OutputUpdate)
103                 cnts.restoreLastCounter();
104 }
105
106
107 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
108 {
109         if (isOpen(bv))
110                 // this will give us something useful if there is no button
111                 return InsetCollapsible::toolTip(bv, x, y);
112         return toolTipText(custom_label_+ " ");
113 }
114
115
116 void InsetFoot::latex(otexstream & os, OutputParams const & runparams) const
117 {
118         // We need to maintain the runparams values set
119         // by InsetText::latex. hence we use no copy
120         runparams.inFootnote = true;
121         InsetText::latex(os, runparams);
122         runparams.inFootnote = false;
123 }
124
125
126 int InsetFoot::plaintext(odocstringstream & os,
127         OutputParams const & runparams, size_t max_length) const
128 {
129         os << '[' << buffer().B_("footnote") << ":\n";
130         InsetText::plaintext(os, runparams, max_length);
131         os << "\n]";
132
133         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
134 }
135
136
137 void InsetFoot::docbook(XMLStream & xs, OutputParams const & runparams) const
138 {
139         OutputParams rp = runparams;
140         rp.docbook_force_pars = true;
141         rp.docbook_in_par = false;
142         rp.docbook_consider_allow_multi_par = false;
143         rp.docbook_make_pars = true;
144         InsetText::docbook(xs, rp);
145 }
146
147
148 void InsetFoot::validate(LaTeXFeatures & features) const
149 {
150         // Use footnote package to provide footnotes in tables
151         // unless an alternative approach is built in the class.
152         if (!features.saveNoteEnv().empty()
153             && !features.isProvided("footnote-alternative")) {
154                 features.require("footnote");
155                 features.addPreambleSnippet(
156                         from_ascii("\\makesavenoteenv{"
157                                    + features.saveNoteEnv()
158                                    + "}\n"));
159         }
160
161         InsetText::validate(features);
162 }
163
164 } // namespace lyx