]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Handle the case of TeX fonts LuaTeX
[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 #include "support/lstrings.h"
30
31 using namespace std;
32
33 namespace lyx {
34
35 InsetFoot::InsetFoot(Buffer * buf)
36         : InsetFootlike(buf), intitle_(false)
37 {}
38
39
40 docstring InsetFoot::layoutName() const
41 {
42         return intitle_ ? from_ascii("Foot:InTitle") : from_ascii("Foot");
43 }
44
45
46 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype)
47 {
48         BufferParams const & bp = buffer().masterBuffer()->params();
49         Counters & cnts = bp.documentClass().counters();
50         if (utype == OutputUpdate) {
51                 // the footnote counter is local to this inset
52                 cnts.saveLastCounter();
53         }
54
55         intitle_ = false;
56         for (size_type sl = 0 ; sl < it.depth() ; ++ sl) {
57                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
58                         intitle_ = true;
59                         break;
60                 }
61         }
62
63         Language const * lang = it.paragraph().getParLanguage(bp);
64         InsetLayout const & il = getLayout();
65         docstring const & count = il.counter();
66         custom_label_ = translateIfPossible(il.labelstring());
67         if (cnts.hasCounter(count))
68                 cnts.step(count, utype);
69         custom_label_ += ' ' + cnts.theCounter(count, lang->code());
70         setLabel(custom_label_);
71
72         InsetCollapsable::updateBuffer(it, utype);
73         if (utype == OutputUpdate)
74                 cnts.restoreLastCounter();
75 }
76
77
78 void InsetFoot::addToToc(DocIterator const & cpit, bool output_active,
79                                                  UpdateType utype) const
80 {
81         DocIterator pit = cpit;
82         pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
83         
84         docstring str;
85         text().forOutliner(str, TOC_ENTRY_LENGTH);
86         str = custom_label_ + ": " + str;
87         
88         shared_ptr<Toc> toc = buffer().tocBackend().toc("footnote");
89         toc->push_back(TocItem(pit, 0, str, output_active));
90         
91         // Proceed with the rest of the inset.
92         InsetFootlike::addToToc(cpit, output_active, utype);
93 }
94
95
96 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
97 {
98         if (isOpen(bv))
99                 // this will give us something useful if there is no button
100                 return InsetCollapsable::toolTip(bv, x, y);
101         return toolTipText(custom_label_+ ": ");
102 }
103
104
105 int InsetFoot::plaintext(odocstringstream & os,
106         OutputParams const & runparams, size_t max_length) const
107 {
108         os << '[' << buffer().B_("footnote") << ":\n";
109         InsetText::plaintext(os, runparams, max_length);
110         os << "\n]";
111
112         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
113 }
114
115
116 int InsetFoot::docbook(odocstream & os, OutputParams const & runparams) const
117 {
118         os << "<footnote>";
119         int const i = InsetText::docbook(os, runparams);
120         os << "</footnote>";
121
122         return i;
123 }
124
125 } // namespace lyx