]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
a2b6cbf26c6a6cb56a2080875405e00661fe90f0
[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 #include "debug.h"
14
15 #include "InsetFoot.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Counters.h"
20 #include "gettext.h"
21 // 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
26 #include "support/convert.h"
27 #include "support/std_ostream.h"
28 #include "support/lstrings.h"
29
30 namespace lyx {
31
32 using std::string;
33 using std::auto_ptr;
34 using std::ostream;
35
36
37 InsetFoot::InsetFoot(BufferParams const & bp)
38         : InsetFootlike(bp)
39 {
40         setLayout(bp);
41 }
42
43
44 InsetFoot::InsetFoot(InsetFoot const & in)
45         : InsetFootlike(in)
46 {}
47
48
49 auto_ptr<Inset> InsetFoot::doClone() const
50 {
51         return auto_ptr<Inset>(new InsetFoot(*this));
52 }
53
54
55 docstring const InsetFoot::editMessage() const
56 {
57         return _("Opened Footnote Inset");
58 }
59
60
61 void InsetFoot::updateLabels(Buffer const & buf, ParIterator const & it)
62 {
63         TextClass const & tclass = buf.params().getTextClass();
64         Counters & cnts = tclass.counters();
65         docstring const & foot = from_ascii("footnote");
66         Paragraph const & outer =  it.paragraph();
67         if (!outer.layout()->intitle && cnts.hasCounter(foot)) {
68                 cnts.step(foot);
69                 //FIXME: the counter should format itself.
70                 setLabel(support::bformat(from_ascii("%1$s %2$s"), 
71                                           getLayout(buf.params()).labelstring, 
72                                           convert<docstring>(cnts.value(foot))));
73         
74         }
75         InsetCollapsable::updateLabels(buf, it);
76 }
77
78 int InsetFoot::latex(Buffer const & buf, odocstream & os,
79                      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(buf, os, runparams);
93         os << "%\n}";
94         runparams_in.encoding = runparams.encoding;
95
96         return i + 2;
97 }
98
99
100 int InsetFoot::plaintext(Buffer const & buf, odocstream & os,
101                          OutputParams const & runparams) const
102 {
103         os << '[' << buf.B_("footnote") << ":\n";
104         InsetText::plaintext(buf, os, runparams);
105         os << "\n]";
106
107         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
108 }
109
110
111 int InsetFoot::docbook(Buffer const & buf, odocstream & os,
112                        OutputParams const & runparams) const
113 {
114         os << "<footnote>";
115         int const i = InsetText::docbook(buf, os, runparams);
116         os << "</footnote>";
117
118         return i;
119 }
120
121
122 } // namespace lyx