]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
9df6f5d590f60073648efd7bc38475951f4c3244
[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 "Language.h"
20 #include "Layout.h"
21 #include "OutputParams.h"
22 #include "ParIterator.h"
23 #include "TextClass.h"
24 #include "TocBackend.h"
25
26 #include "support/debug.h"
27 #include "support/docstream.h"
28 #include "support/gettext.h"
29
30 using namespace std;
31
32 namespace lyx {
33
34 InsetFoot::InsetFoot(Buffer * buf)
35         : InsetFootlike(buf), intitle_(false)
36 {}
37
38
39 docstring InsetFoot::layoutName() const
40 {
41         return intitle_ ? from_ascii("Foot:InTitle") : from_ascii("Foot");
42 }
43
44
45 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
46 {
47         BufferParams const & bp = buffer().masterBuffer()->params();
48         Counters & cnts = bp.documentClass().counters();
49         if (utype == OutputUpdate) {
50                 // the footnote counter is local to this inset
51                 cnts.saveLastCounter();
52         }
53
54         intitle_ = false;
55         for (size_type sl = 0 ; sl < it.depth() ; ++ sl) {
56                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
57                         intitle_ = true;
58                         break;
59                 }
60         }
61
62         Language const * lang = it.paragraph().getParLanguage(bp);
63         InsetLayout const & il = getLayout();
64         docstring const & count = il.counter();
65         custom_label_ = translateIfPossible(il.labelstring());
66         if (cnts.hasCounter(count))
67                 cnts.step(count, utype);
68         custom_label_ += ' ' + cnts.theCounter(count, lang->code());
69         setLabel(custom_label_);
70
71         InsetCollapsable::updateBuffer(it, utype);
72         if (utype == OutputUpdate)
73                 cnts.restoreLastCounter();
74 }
75
76
77 void InsetFoot::addToToc(DocIterator const & cpit, bool output_active) const
78 {
79         DocIterator pit = cpit;
80         pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
81
82         Toc & toc = buffer().tocBackend().toc("footnote");
83         docstring str = custom_label_ + ": ";
84         text().forOutliner(str, TOC_ENTRY_LENGTH);
85         toc.push_back(TocItem(pit, 0, str, output_active, toolTipText(docstring(), 3, 60)));
86         // Proceed with the rest of the inset.
87         InsetFootlike::addToToc(cpit, output_active);
88 }
89
90
91 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
92 {
93         if (isOpen(bv))
94                 // this will give us something useful if there is no button
95                 return InsetCollapsable::toolTip(bv, x, y);
96         return toolTipText(custom_label_+ ": ");
97 }
98
99
100 int InsetFoot::plaintext(odocstringstream & os,
101         OutputParams const & runparams, size_t max_length) const
102 {
103         os << '[' << buffer().B_("footnote") << ":\n";
104         InsetText::plaintext(os, runparams, max_length);
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 } // namespace lyx