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