]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
d320476733a531ff6c6cf3ca25c73a5a70dbc603
[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/docstream.h"
30 #include "support/lstrings.h"
31
32 #include <ostream>
33
34 using namespace std;
35
36 namespace lyx {
37
38
39 InsetFoot::InsetFoot(Buffer const & buf)
40         : InsetFootlike(buf)
41 {}
42
43
44 docstring InsetFoot::editMessage() const
45 {
46         return _("Opened Footnote Inset");
47 }
48
49
50 void InsetFoot::updateLabels(ParIterator const & it)
51 {
52         DocumentClass const & tclass = buffer().params().documentClass();
53         Counters & cnts = tclass.counters();
54         docstring const foot = from_ascii("footnote");
55         Paragraph const & outer =  it.paragraph();
56         if (!outer.layout().intitle && cnts.hasCounter(foot)) {
57                 cnts.step(foot);
58                 // FIXME: the counter should format itself.
59                 custom_label_= support::bformat(from_utf8("%1$s %2$s"),
60                                           translateIfPossible(getLayout(buffer().params()).labelstring()),
61                                           cnts.theCounter(foot));
62                 setLabel(custom_label_);
63         
64         }
65         InsetCollapsable::updateLabels(it);
66 }
67
68
69 void InsetFoot::addToToc(ParConstIterator const & cpit) const
70 {
71         ParConstIterator pit = cpit;
72         pit.push_back(*this);
73
74         Toc & toc = buffer().tocBackend().toc("footnote");
75         // FIXME: we probably want the footnote number too.
76         docstring str;
77         str = custom_label_ + ": " + getNewLabel(str);
78         toc.push_back(TocItem(pit, 0, str));
79 }
80
81
82 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
83 {
84         docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
85         OutputParams rp(&buffer().params().encoding());
86         odocstringstream ods;
87         InsetText::plaintext(ods, rp);
88         docstring foot_tip = custom_label_ + ": " + ods.str();
89         // shorten it if necessary
90         if (foot_tip.size() > 200)
91                 foot_tip = foot_tip.substr(0, 200) + "...";
92         if (!isOpen() && !foot_tip.empty())
93                 return foot_tip + '\n' + default_tip;
94         return default_tip;
95 }
96
97
98 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
99 {
100         OutputParams runparams = runparams_in;
101         // footnotes in titling commands like \title have moving arguments
102         runparams.moving_arg |= runparams_in.intitle;
103
104         // in titling commands, \thanks should be used instead of \footnote.
105         // some classes (e.g. memoir) do not understand \footnote.
106         if (runparams_in.intitle)
107                 os << "%\n\\thanks{";
108         else
109                 os << "%\n\\footnote{";
110
111         int const i = InsetText::latex(os, runparams);
112         os << "%\n}";
113         runparams_in.encoding = runparams.encoding;
114
115         return i + 2;
116 }
117
118
119 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
120 {
121         os << '[' << buffer().B_("footnote") << ":\n";
122         InsetText::plaintext(os, runparams);
123         os << "\n]";
124
125         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
126 }
127
128
129 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
130 {
131         os << "<footnote>";
132         int const i = InsetText::docbook(os, runparams);
133         os << "</footnote>";
134
135         return i;
136 }
137
138
139 } // namespace lyx