]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
* GuiView.{cpp, h}:
[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         if (!isOpen())
86                 return custom_label_ + ": " + default_tip;
87         return default_tip;
88 }
89
90
91 int InsetFoot::latex(odocstream & os, 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(os, runparams);
105         os << "%\n}";
106         runparams_in.encoding = runparams.encoding;
107
108         return i + 2;
109 }
110
111
112 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
113 {
114         os << '[' << buffer().B_("footnote") << ":\n";
115         InsetText::plaintext(os, runparams);
116         os << "\n]";
117
118         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
119 }
120
121
122 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
123 {
124         os << "<footnote>";
125         int const i = InsetText::docbook(os, runparams);
126         os << "</footnote>";
127
128         return i;
129 }
130
131
132 } // namespace lyx