]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
779c06727e6cb20b648393972fe1edaeb8a50e84
[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::updateLabels(ParIterator const & it)
40 {
41         BufferParams const & bp = buffer().masterBuffer()->params();
42         Counters & cnts = bp.documentClass().counters();
43         Paragraph const & outer = it.paragraph();
44         InsetLayout const & il = getLayout();
45         docstring const & count = il.counter();
46         if (!outer.layout().intitle && cnts.hasCounter(count)) {
47                 cnts.step(count);
48                 custom_label_= translateIfPossible(il.labelstring()) 
49                         + ' ' + cnts.theCounter(count, outer.getParLanguage(bp)->code());
50                 setLabel(custom_label_);        
51         }
52         InsetCollapsable::updateLabels(it);
53 }
54
55
56 void InsetFoot::addToToc(DocIterator const & cpit)
57 {
58         DocIterator pit = cpit;
59         pit.push_back(CursorSlice(*this));
60
61         Toc & toc = buffer().tocBackend().toc("footnote");
62         docstring str;
63         str = custom_label_ + ": " + getNewLabel(str);
64         toc.push_back(TocItem(pit, 0, str));
65         // Proceed with the rest of the inset.
66         InsetFootlike::addToToc(cpit);
67 }
68
69
70 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
71 {
72         docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
73         if (!isOpen(bv))
74                 return custom_label_ + "\n" + default_tip;
75         return default_tip;
76 }
77
78
79 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
80 {
81         OutputParams runparams = runparams_in;
82         // footnotes in titling commands like \title have moving arguments
83         runparams.moving_arg |= runparams_in.intitle;
84
85         // in titling commands, \thanks should be used instead of \footnote.
86         // some classes (e.g. memoir) do not understand \footnote.
87         if (runparams_in.intitle)
88                 os << "%\n\\thanks{";
89         else
90                 os << "%\n\\footnote{";
91
92         int const i = InsetText::latex(os, runparams);
93         os << "%\n}";
94         runparams_in.encoding = runparams.encoding;
95
96         return i + 2;
97 }
98
99
100 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
101 {
102         os << '[' << buffer().B_("footnote") << ":\n";
103         InsetText::plaintext(os, runparams);
104         os << "\n]";
105
106         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
107 }
108
109
110 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
111 {
112         os << "<footnote>";
113         int const i = InsetText::docbook(os, runparams);
114         os << "</footnote>";
115
116         return i;
117 }
118
119 } // namespace lyx