]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
a2a0099fa9d0f828788976240fce81389b85f1a3
[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)
65 {
66         DocIterator pit = cpit;
67         pit.push_back(CursorSlice(*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, toolTipText(docstring(), 3, 60)));
73         // Proceed with the rest of the inset.
74         InsetFootlike::addToToc(cpit);
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 int InsetFoot::latex(odocstream & 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         // in titling commands, \thanks should be used instead of \footnote.
94         // some classes (e.g. memoir) do not understand \footnote.
95         if (runparams_in.intitle)
96                 os << "%\n\\thanks{";
97         else
98                 os << "%\n\\footnote{";
99
100         int const i = InsetText::latex(os, runparams);
101         os << "%\n}";
102         runparams_in.encoding = runparams.encoding;
103
104         return i + 2;
105 }
106
107
108 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
109 {
110         os << '[' << buffer().B_("footnote") << ":\n";
111         InsetText::plaintext(os, runparams);
112         os << "\n]";
113
114         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
115 }
116
117
118 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
119 {
120         os << "<footnote>";
121         int const i = InsetText::docbook(os, runparams);
122         os << "</footnote>";
123
124         return i;
125 }
126
127 } // namespace lyx