]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Remove all BufferParam arguments in InsetXXX methods (since insets know about their...
[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 #include "support/lstrings.h"
30
31 using namespace std;
32
33 namespace lyx {
34
35 using support::bformat;
36
37 InsetFoot::InsetFoot(Buffer const & buf)
38         : InsetFootlike(buf)
39 {}
40
41
42 docstring InsetFoot::editMessage() const
43 {
44         return _("Opened Footnote Inset");
45 }
46
47
48 void InsetFoot::updateLabels(ParIterator const & it)
49 {
50         BufferParams const & bp = buffer().masterBuffer()->params();
51         Counters & cnts = bp.documentClass().counters();
52         docstring const foot = from_ascii("footnote");
53         Paragraph const & outer =  it.paragraph();
54         if (!outer.layout().intitle && cnts.hasCounter(foot)) {
55                 cnts.step(foot);
56                 // FIXME: the counter should format itself.
57                 custom_label_= bformat(from_utf8("%1$s %2$s"),
58                                        translateIfPossible(getLayout().labelstring()),
59                                        cnts.theCounter(foot, outer.getParLanguage(bp)->code()));
60                 setLabel(custom_label_);
61         
62         }
63         InsetCollapsable::updateLabels(it);
64 }
65
66
67 void InsetFoot::addToToc(DocIterator const & cpit)
68 {
69         DocIterator pit = cpit;
70         pit.push_back(CursorSlice(*this));
71
72         Toc & toc = buffer().tocBackend().toc("footnote");
73         docstring str;
74         str = custom_label_ + ": " + getNewLabel(str);
75         toc.push_back(TocItem(pit, 0, str));
76         // Proceed with the rest of the inset.
77         InsetFootlike::addToToc(cpit);
78 }
79
80
81 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
82 {
83         docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
84         if (!isOpen(bv))
85                 return custom_label_ + "\n" + default_tip;
86         return default_tip;
87 }
88
89
90 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
91 {
92         OutputParams runparams = runparams_in;
93         // footnotes in titling commands like \title have moving arguments
94         runparams.moving_arg |= runparams_in.intitle;
95
96         // in titling commands, \thanks should be used instead of \footnote.
97         // some classes (e.g. memoir) do not understand \footnote.
98         if (runparams_in.intitle)
99                 os << "%\n\\thanks{";
100         else
101                 os << "%\n\\footnote{";
102
103         int const i = InsetText::latex(os, runparams);
104         os << "%\n}";
105         runparams_in.encoding = runparams.encoding;
106
107         return i + 2;
108 }
109
110
111 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
112 {
113         os << '[' << buffer().B_("footnote") << ":\n";
114         InsetText::plaintext(os, runparams);
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