]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Fix crash on recursive include (bug #8994)
[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 "Layout.h"
21 #include "OutputParams.h"
22 #include "ParIterator.h"
23 #include "TextClass.h"
24 #include "TocBackend.h"
25
26 #include "support/debug.h"
27 #include "support/docstream.h"
28 #include "support/gettext.h"
29
30 using namespace std;
31
32 namespace lyx {
33
34 InsetFoot::InsetFoot(Buffer * buf)
35         : InsetFootlike(buf)
36 {}
37
38
39 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
40 {
41         BufferParams const & bp = buffer().masterBuffer()->params();
42         Counters & cnts = bp.documentClass().counters();
43         if (utype == OutputUpdate) {
44                 // the footnote counter is local to this inset
45                 cnts.saveLastCounter();
46         }
47         Paragraph const & outer = it.paragraph();
48         if (!outer.layout().intitle) {
49                 InsetLayout const & il = getLayout();
50                 docstring const & count = il.counter();
51                 custom_label_ = translateIfPossible(il.labelstring());
52                 if (cnts.hasCounter(count))
53                         cnts.step(count, utype);
54                 custom_label_ += ' ' +
55                         cnts.theCounter(count, outer.getParLanguage(bp)->code());
56                 setLabel(custom_label_);
57         }
58         InsetCollapsable::updateBuffer(it, utype);
59         if (utype == OutputUpdate)
60                 cnts.restoreLastCounter();      
61 }
62
63
64 void InsetFoot::addToToc(DocIterator const & cpit, bool output_active) const
65 {
66         DocIterator pit = cpit;
67         pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
68
69         Toc & toc = buffer().tocBackend().toc("footnote");
70         docstring str = custom_label_ + ": ";
71         text().forToc(str, TOC_ENTRY_LENGTH);
72         toc.push_back(TocItem(pit, 0, str, output_active, toolTipText(docstring(), 3, 60)));
73         // Proceed with the rest of the inset.
74         InsetFootlike::addToToc(cpit, output_active);
75 }
76
77
78 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
79 {
80         if (isOpen(bv))
81                 // this will give us something useful if there is no button
82                 return InsetCollapsable::toolTip(bv, x, y);
83         return toolTipText(custom_label_+ ": ");
84 }
85
86
87 void InsetFoot::latex(otexstream & os, OutputParams const & runparams_in) const
88 {
89         OutputParams runparams = runparams_in;
90         // footnotes in titling commands like \title have moving arguments
91         runparams.moving_arg |= runparams_in.intitle;
92
93         os << safebreakln;
94         if (runparams.lastid != -1)
95                 os.texrow().start(runparams.lastid, runparams.lastpos);
96
97         // in titling commands, \thanks should be used instead of \footnote.
98         // some classes (e.g. memoir) do not understand \footnote.
99         if (runparams_in.intitle)
100                 os << "\\thanks{";
101         else
102                 os << "\\footnote{";
103
104         InsetText::latex(os, runparams);
105         os << "%\n}";
106         runparams_in.encoding = runparams.encoding;
107 }
108
109
110 int InsetFoot::plaintext(odocstringstream & os,
111         OutputParams const & runparams, size_t max_length) const
112 {
113         os << '[' << buffer().B_("footnote") << ":\n";
114         InsetText::plaintext(os, runparams, max_length);
115         os << "\n]";
116
117         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
118 }
119
120
121 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
122 {
123         os << "<footnote>";
124         int const i = InsetText::docbook(os, runparams);
125         os << "</footnote>";
126
127         return i;
128 }
129
130 } // namespace lyx