2 * \file insetfloatlist.C
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"
19 #include "FloatList.h"
20 #include "funcrequest.h"
22 #include "LaTeXFeatures.h"
24 #include "metricsinfo.h"
27 #include "support/lstrings.h"
29 using lyx::support::bformat;
36 InsetFloatList::InsetFloatList()
37 : InsetCommand(InsetCommandParams())
41 InsetFloatList::InsetFloatList(string const & type)
42 : InsetCommand(InsetCommandParams())
48 InsetFloatList::~InsetFloatList()
50 InsetCommandMailer mailer("toc", *this);
55 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
57 FloatList const & floats = buf.params().getLyXTextClass().floats();
58 FloatList::const_iterator it = floats[getCmdName()];
59 if (it != floats.end())
60 return _(it->second.listName());
62 return _("ERROR: Nonexistent float type!");
66 InsetOld::Code InsetFloatList::lyxCode() const
68 return InsetOld::FLOAT_LIST_CODE;
72 void InsetFloatList::write(Buffer const &, ostream & os) const
74 os << "FloatList " << getCmdName() << "\n";
78 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
80 FloatList const & floats = buf.params().getLyXTextClass().floats();
84 setCmdName(lex.getString());
85 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
86 if (!floats.typeExist(getCmdName()))
87 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
89 lex.printError("InsetFloatList: Parse error: `$$Token'");
92 token = lex.getString();
93 if (token == "\\end_inset")
96 if (token != "\\end_inset") {
97 lex.printError("Missing \\end_inset at this point. "
103 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
105 InsetCommand::metrics(mi, dim);
106 int center_indent = (mi.base.textwidth - dim.wid) / 2;
107 Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
110 dim.wid = mi.base.textwidth;
115 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
117 InsetCommand::draw(pi, x + button().box().x1, y);
121 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
123 switch (cmd.action) {
124 case LFUN_MOUSE_RELEASE:
125 if (button().box().contains(cmd.x, cmd.y))
126 InsetCommandMailer("toc", *this).showDialog(cmd.view());
129 case LFUN_INSET_DIALOG_SHOW:
130 InsetCommandMailer("toc", *this).showDialog(cmd.view());
134 return InsetCommand::localDispatch(cmd);
139 int InsetFloatList::latex(Buffer const & buf, ostream & os,
140 LatexRunParams const &) const
142 FloatList const & floats = buf.params().getLyXTextClass().floats();
143 FloatList::const_iterator cit = floats[getCmdName()];
145 if (cit != floats.end()) {
146 if (cit->second.builtin()) {
147 // Only two different types allowed here:
148 string const type = cit->second.type();
149 if (type == "table") {
150 os << "\\listoftables\n";
151 } else if (type == "figure") {
152 os << "\\listoffigures\n";
154 os << "%% unknown builtin float\n";
157 os << "\\listof{" << getCmdName() << "}{"
158 << cit->second.listName() << "}\n";
161 os << "%%\\listof{" << getCmdName() << "}{"
162 << bformat(_("List of %1$s"), cit->second.name())
169 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
171 os << getScreenLabel(buffer) << "\n\n";
173 lyx::toc::asciiTocList(getCmdName(), buffer, os);
180 void InsetFloatList::validate(LaTeXFeatures & features) const
182 features.useFloat(getCmdName());