3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "InsetFoot.h"
17 #include "BufferParams.h"
19 #include "support/gettext.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"
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/lstrings.h"
39 InsetFoot::InsetFoot(Buffer const & buf)
44 docstring InsetFoot::editMessage() const
46 return _("Opened Footnote Inset");
50 void InsetFoot::updateLabels(ParIterator const & it)
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)) {
58 // FIXME: the counter should format itself.
59 custom_label_= support::bformat(from_ascii("%1$s %2$s"),
60 getLayout(buffer().params()).labelstring(),
61 cnts.theCounter(foot));
62 setLabel(custom_label_);
65 InsetCollapsable::updateLabels(it);
69 void InsetFoot::addToToc(ParConstIterator const & cpit) const
71 ParConstIterator pit = cpit;
74 Toc & toc = buffer().tocBackend().toc("footnote");
75 // FIXME: we probably want the footnote number too.
77 str = custom_label_ + ": " + getNewLabel(str);
78 toc.push_back(TocItem(pit, 0, str));
82 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
84 docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
85 OutputParams rp(&buffer().params().encoding());
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;
98 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
100 OutputParams runparams = runparams_in;
101 // footnotes in titling commands like \title have moving arguments
102 runparams.moving_arg |= runparams_in.intitle;
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{";
109 os << "%\n\\footnote{";
111 int const i = InsetText::latex(os, runparams);
113 runparams_in.encoding = runparams.encoding;
119 int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const
121 os << '[' << buffer().B_("footnote") << ":\n";
122 InsetText::plaintext(os, runparams);
125 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
129 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
132 int const i = InsetText::docbook(os, runparams);