]> git.lyx.org Git - features.git/blob - src/insets/InsetFoot.cpp
try to pass a Buffer & to inset construction if some buffer(param)
[features.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 "support/gettext.h"
20 #include "Layout.h"
21 // FIXME: the following is needed just to get the layout of the enclosing
22 // paragraph. This seems a bit too much to me (JMarc)
23 #include "OutputParams.h"
24 #include "ParIterator.h"
25 #include "TextClass.h"
26 #include "TocBackend.h"
27
28 #include "support/debug.h"
29 #include "support/lstrings.h"
30
31 #include <ostream>
32
33 using namespace std;
34
35 namespace lyx {
36
37
38 InsetFoot::InsetFoot(Buffer const & buf)
39         : InsetFootlike(buf)
40 {}
41
42
43 InsetFoot::InsetFoot(InsetFoot const & in)
44         : InsetFootlike(in)
45 {}
46
47
48 docstring InsetFoot::editMessage() const
49 {
50         return _("Opened Footnote Inset");
51 }
52
53
54 void InsetFoot::updateLabels(ParIterator const & it)
55 {
56         DocumentClass const & tclass = buffer().params().documentClass();
57         Counters & cnts = tclass.counters();
58         docstring const foot = from_ascii("footnote");
59         Paragraph const & outer =  it.paragraph();
60         if (!outer.layout()->intitle && cnts.hasCounter(foot)) {
61                 cnts.step(foot);
62                 // FIXME: the counter should format itself.
63                 setLabel(support::bformat(from_ascii("%1$s %2$s"), 
64                                           getLayout(buffer().params()).labelstring(), 
65                                           cnts.theCounter(foot)));
66         
67         }
68         InsetCollapsable::updateLabels(it);
69 }
70
71
72 void InsetFoot::addToToc(ParConstIterator const & cpit) const
73 {
74         ParConstIterator pit = cpit;
75         pit.push_back(*this);
76
77         Toc & toc = buffer().tocBackend().toc("footnote");
78         // FIXME: we probably want the footnote number too.
79         docstring str;
80         str = getNewLabel(str);
81         toc.push_back(TocItem(pit, 0, str));
82 }
83
84
85 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
86 {
87         OutputParams runparams = runparams_in;
88         // footnotes in titling commands like \title have moving arguments
89         runparams.moving_arg |= runparams_in.intitle;
90
91         // in titling commands, \thanks should be used instead of \footnote.
92         // some classes (e.g. memoir) do not understand \footnote.
93         if (runparams_in.intitle)
94                 os << "%\n\\thanks{";
95         else
96                 os << "%\n\\footnote{";
97
98         int const i = InsetText::latex(os, runparams);
99         os << "%\n}";
100         runparams_in.encoding = runparams.encoding;
101
102         return i + 2;
103 }
104
105
106 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
107 {
108         os << '[' << buffer().B_("footnote") << ":\n";
109         InsetText::plaintext(os, runparams);
110         os << "\n]";
111
112         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
113 }
114
115
116 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
117 {
118         os << "<footnote>";
119         int const i = InsetText::docbook(os, runparams);
120         os << "</footnote>";
121
122         return i;
123 }
124
125
126 } // namespace lyx