]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Change the interface to a paragraph's layout. We still store a LayoutPtr, but now...
[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 "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 docstring InsetFoot::editMessage() const
44 {
45         return _("Opened Footnote Inset");
46 }
47
48
49 void InsetFoot::updateLabels(ParIterator const & it)
50 {
51         DocumentClass const & tclass = buffer().params().documentClass();
52         Counters & cnts = tclass.counters();
53         docstring const foot = from_ascii("footnote");
54         Paragraph const & outer =  it.paragraph();
55         if (!outer.layout().intitle && cnts.hasCounter(foot)) {
56                 cnts.step(foot);
57                 // FIXME: the counter should format itself.
58                 setLabel(support::bformat(from_ascii("%1$s %2$s"), 
59                                           getLayout(buffer().params()).labelstring(), 
60                                           cnts.theCounter(foot)));
61         
62         }
63         InsetCollapsable::updateLabels(it);
64 }
65
66
67 void InsetFoot::addToToc(ParConstIterator const & cpit) const
68 {
69         ParConstIterator pit = cpit;
70         pit.push_back(*this);
71
72         Toc & toc = buffer().tocBackend().toc("footnote");
73         // FIXME: we probably want the footnote number too.
74         docstring str;
75         str = getNewLabel(str);
76         toc.push_back(TocItem(pit, 0, str));
77 }
78
79
80 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
81 {
82         OutputParams runparams = runparams_in;
83         // footnotes in titling commands like \title have moving arguments
84         runparams.moving_arg |= runparams_in.intitle;
85
86         // in titling commands, \thanks should be used instead of \footnote.
87         // some classes (e.g. memoir) do not understand \footnote.
88         if (runparams_in.intitle)
89                 os << "%\n\\thanks{";
90         else
91                 os << "%\n\\footnote{";
92
93         int const i = InsetText::latex(os, runparams);
94         os << "%\n}";
95         runparams_in.encoding = runparams.encoding;
96
97         return i + 2;
98 }
99
100
101 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
102 {
103         os << '[' << buffer().B_("footnote") << ":\n";
104         InsetText::plaintext(os, runparams);
105         os << "\n]";
106
107         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
108 }
109
110
111 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
112 {
113         os << "<footnote>";
114         int const i = InsetText::docbook(os, runparams);
115         os << "</footnote>";
116
117         return i;
118 }
119
120
121 } // namespace lyx