]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFoot.cpp
Improve handling of top and bottom margin
[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 #include "InsetBox.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Counters.h"
20 #include "Language.h"
21 #include "LaTeXFeatures.h"
22 #include "Layout.h"
23 #include "OutputParams.h"
24 #include "output_docbook.h"
25 #include "ParIterator.h"
26 #include "TextClass.h"
27 #include "TocBackend.h"
28
29 #include "support/debug.h"
30 #include "support/docstream.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
33
34 using namespace std;
35
36 namespace lyx {
37
38 InsetFoot::InsetFoot(Buffer * buf)
39         : InsetFootlike(buf), intitle_(false), infloattable_(false)
40 {}
41
42
43 docstring InsetFoot::layoutName() const
44 {
45         if (intitle_)
46                 return from_ascii("Foot:InTitle");
47         else if (infloattable_)
48                 return from_ascii("Foot:InFloatTable");
49         return from_ascii("Foot");
50 }
51
52
53 void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
54 {
55         BufferParams const & bp = buffer().masterBuffer()->params();
56         Counters & cnts = bp.documentClass().counters();
57         if (utype == OutputUpdate) {
58                 // the footnote counter is local to this inset
59                 cnts.saveLastCounter();
60         }
61
62         intitle_ = false;
63         infloattable_ = false;
64         bool intable = false;
65         if (it.innerInsetOfType(TABULAR_CODE) != 0)
66                 intable = true;
67         if (it.innerInsetOfType(FLOAT_CODE) != 0)
68                 infloattable_ = intable;
69         // If we are in a table in a float, but the table is also in a minipage,
70         // we do not use tablefootnote, since minipages provide their own footnotes.
71         if (intable && infloattable_ && it.innerInsetOfType(BOX_CODE) != 0) {
72                 InsetBoxParams const & boxp =
73                                 static_cast<InsetBox*>(it.innerInsetOfType(BOX_CODE))->params();
74                 if (boxp.inner_box && !boxp.use_parbox && !boxp.use_makebox)
75                         infloattable_ = false;
76         }
77         for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
78                 if (it[sl].text() && it[sl].paragraph().layout().intitle) {
79                         intitle_ = true;
80                         break;
81                 }
82         }
83
84         Language const * lang = it.paragraph().getParLanguage(bp);
85         InsetLayout const & il = getLayout();
86         docstring const & count = il.counter();
87         custom_label_ = translateIfPossible(il.labelstring());
88
89         int val = cnts.value(count);
90         if (cnts.hasCounter(count)) {
91                 cnts.step(count, utype);
92                 custom_label_ += ' ' + cnts.theCounter(count, lang->code());
93                 if (deleted)
94                         // un-step after deleted counter
95                         cnts.set(count, val);
96         } else
97                 custom_label_ += ' ' + from_ascii("#");
98         setLabel(custom_label_);
99
100         InsetCollapsible::updateBuffer(it, utype, deleted);
101         if (utype == OutputUpdate)
102                 cnts.restoreLastCounter();
103 }
104
105
106 docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
107 {
108         if (isOpen(bv))
109                 // this will give us something useful if there is no button
110                 return InsetCollapsible::toolTip(bv, x, y);
111         return toolTipText(custom_label_+ ": ");
112 }
113
114
115 int InsetFoot::plaintext(odocstringstream & os,
116         OutputParams const & runparams, size_t max_length) const
117 {
118         os << '[' << buffer().B_("footnote") << ":\n";
119         InsetText::plaintext(os, runparams, max_length);
120         os << "\n]";
121
122         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
123 }
124
125
126 void InsetFoot::docbook(XMLStream & xs, OutputParams const & runparams) const
127 {
128         OutputParams rp = runparams;
129         rp.docbook_force_pars = true;
130         rp.docbook_in_par = false;
131         InsetText::docbook(xs, rp);
132 }
133
134
135 void InsetFoot::validate(LaTeXFeatures & features) const
136 {
137         // Use footnote package to provide footnotes in tables
138         // unless an alternative approach is built in the class.
139         if (!features.saveNoteEnv().empty()
140             && !features.isProvided("footnote-alternative")) {
141                 features.require("footnote");
142                 features.addPreambleSnippet(
143                         from_ascii("\\makesavenoteenv{"
144                                    + features.saveNoteEnv()
145                                    + "}\n"));
146         }
147
148         InsetText::validate(features);
149 }
150
151 } // namespace lyx