2 * \file InsetFloatList.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "InsetFloatList.h"
16 #include "BufferParams.h"
17 #include "DispatchResult.h"
19 #include "FloatList.h"
20 #include "FuncRequest.h"
22 #include "LaTeXFeatures.h"
24 #include "MetricsInfo.h"
25 #include "Paragraph.h"
26 #include "output_xhtml.h"
27 #include "TextClass.h"
28 #include "TocBackend.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
37 using namespace lyx::support;
42 InsetFloatList::InsetFloatList(Buffer * buf)
43 : InsetCommand(buf, InsetCommandParams(FLOAT_LIST_CODE), "toc")
47 InsetFloatList::InsetFloatList(Buffer * buf, string const & type)
48 : InsetCommand(buf, InsetCommandParams(FLOAT_LIST_CODE), "toc")
50 setParam("type", from_ascii(type));
54 ParamInfo const & InsetFloatList::findInfo(string const & /* cmdName */)
56 static ParamInfo param_info_;
57 if (param_info_.empty()) {
58 param_info_.add("type", ParamInfo::LATEX_REQUIRED);
65 bool InsetFloatList::isCompatibleCommand(string const & s)
67 string str = s.substr(0, 6);
68 return str == "listof";
72 docstring InsetFloatList::screenLabel() const
74 FloatList const & floats = buffer().params().documentClass().floats();
75 FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
76 if (it != floats.end())
77 return buffer().B_(it->second.listName());
79 return _("ERROR: Nonexistent float type!");
83 void InsetFloatList::write(ostream & os) const
85 os << "FloatList " << to_ascii(getParam("type")) << "\n";
89 void InsetFloatList::read(Lexer & lex)
91 lex.setContext("InsetFloatList::read");
92 FloatList const & floats = buffer().params().documentClass().floats();
96 setParam("type", lex.getDocString());
97 LYXERR(Debug::INSETS, "FloatList::float_type: "
98 << to_ascii(getParam("type")));
99 if (!floats.typeExist(to_ascii(getParam("type"))))
100 lex.printError("Unknown float type");
102 lex.printError("Parse error");
107 token = lex.getString();
108 if (token == "\\end_inset")
111 if (token != "\\end_inset") {
112 lex.printError("Missing \\end_inset at this point.");
117 int InsetFloatList::latex(odocstream & os, OutputParams const &) const
119 FloatList const & floats = buffer().params().documentClass().floats();
120 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
122 if (cit != floats.end()) {
123 os << cit->second.listCommand(buffer().params().language->code());
125 os << "%%\\listof{" << getParam("type") << "}{"
126 << bformat(_("List of %1$s"), getParam("type"))
133 int InsetFloatList::plaintext(odocstream & os, OutputParams const &) const
135 os << screenLabel() << "\n\n";
137 buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
139 return PLAINTEXT_NEWLINE;
143 docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams const &) const {
144 FloatList const & floats = buffer().params().documentClass().floats();
145 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
147 if (cit == floats.end()) {
148 LYXERR0("Unknown float type `" << getParam("type") << "' in IFL::xhtml.");
154 if (!cit->second.needsFloatPkg()) {
155 // Only two different types allowed here:
156 string const type = cit->second.floattype();
157 if (type == "table") {
159 toclabel = _("List of Tables");
160 } else if (type == "figure") {
162 toclabel = _("List of Figures");
164 LYXERR0("Unknown Builtin Float!");
168 toctype = to_utf8(getParam("type"));
169 toclabel = buffer().B_(cit->second.listName());
172 // FIXME Do we need to check if it exists? If so, we need a new
173 // routine in TocBackend to do that.
174 Toc const & toc = buffer().tocBackend().toc(toctype);
178 // we want to look like a chapter, section, or whatever.
179 // so we're going to look for the layout with the minimum toclevel
180 // number > 0---because we don't want Part.
181 // we'll take the first one, just because.
182 // FIXME This could be specified in the layout file.
183 DocumentClass const & dc = buffer().params().documentClass();
184 TextClass::LayoutList::const_iterator lit = dc.begin();
185 TextClass::LayoutList::const_iterator len = dc.end();
187 Layout const * lay = NULL;
188 for (; lit != len; ++lit) {
189 int const level = lit->toclevel;
190 if (level > 0 && (level == Layout::NOT_IN_TOC || level >= minlevel))
196 string const tocclass = lay ? " " + lay->defaultCSSClass(): "";
197 string const tocattr = "class='tochead + toc-" + toctype + " " + tocclass + "'";
199 // we'll use our own stream, because we are going to defer everything.
200 // that's how we deal with the fact that we're probably inside a standard
201 // paragraph, and we don't want to be.
202 odocstringstream ods;
205 xs << html::StartTag("div", "class='toc'");
206 xs << html::StartTag("div", tocattr)
208 << html::EndTag("div");
210 Toc::const_iterator it = toc.begin();
211 Toc::const_iterator const en = toc.end();
212 for (; it != en; ++it) {
213 Paragraph const & par = it->dit().innerParagraph();
214 string const attr = "class='lyxtoc-" + toctype + "'";
216 xs << html::StartTag("div", attr);
217 string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
218 xs << it->str() << " "
219 << html::StartTag("a", parattr)
221 // There ought to be a simple way to customize this.
222 << XHTMLStream::NextRaw() << "⇘"
223 << html::EndTag("a");
224 xs << html::EndTag("div");
226 xs << html::EndTag("div");
231 void InsetFloatList::validate(LaTeXFeatures & features) const
233 features.useFloat(to_ascii(getParam("type")));