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"
18 #include "dispatchresult.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
23 #include "LaTeXFeatures.h"
25 #include "metricsinfo.h"
28 #include "support/lstrings.h"
30 using lyx::support::bformat;
37 InsetFloatList::InsetFloatList()
38 : InsetCommand(InsetCommandParams())
42 InsetFloatList::InsetFloatList(string const & type)
43 : InsetCommand(InsetCommandParams())
49 InsetFloatList::~InsetFloatList()
51 InsetCommandMailer mailer("toc", *this);
56 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
58 FloatList const & floats = buf.params().getLyXTextClass().floats();
59 FloatList::const_iterator it = floats[getCmdName()];
60 if (it != floats.end())
61 return _(it->second.listName());
63 return _("ERROR: Nonexistent float type!");
67 InsetOld::Code InsetFloatList::lyxCode() const
69 return InsetOld::FLOAT_LIST_CODE;
73 void InsetFloatList::write(Buffer const &, ostream & os) const
75 os << "FloatList " << getCmdName() << "\n";
79 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
81 FloatList const & floats = buf.params().getLyXTextClass().floats();
85 setCmdName(lex.getString());
86 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
87 if (!floats.typeExist(getCmdName()))
88 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
90 lex.printError("InsetFloatList: Parse error: `$$Token'");
93 token = lex.getString();
94 if (token == "\\end_inset")
97 if (token != "\\end_inset") {
98 lex.printError("Missing \\end_inset at this point. "
104 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
106 InsetCommand::metrics(mi, dim);
107 int center_indent = (mi.base.textwidth - dim.wid) / 2;
108 Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
111 dim.wid = mi.base.textwidth;
116 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
118 InsetCommand::draw(pi, x + button().box().x1, y);
123 InsetFloatList::priv_dispatch(FuncRequest const & cmd,
124 idx_type & idx, pos_type & pos)
126 switch (cmd.action) {
127 case LFUN_MOUSE_RELEASE:
128 if (button().box().contains(cmd.x, cmd.y))
129 InsetCommandMailer("toc", *this).showDialog(cmd.view());
130 return DispatchResult(true, true);
132 case LFUN_INSET_DIALOG_SHOW:
133 InsetCommandMailer("toc", *this).showDialog(cmd.view());
134 return DispatchResult(true, true);
137 return InsetCommand::priv_dispatch(cmd, idx, pos);
142 int InsetFloatList::latex(Buffer const & buf, ostream & os,
143 OutputParams const &) const
145 FloatList const & floats = buf.params().getLyXTextClass().floats();
146 FloatList::const_iterator cit = floats[getCmdName()];
148 if (cit != floats.end()) {
149 if (cit->second.builtin()) {
150 // Only two different types allowed here:
151 string const type = cit->second.type();
152 if (type == "table") {
153 os << "\\listoftables\n";
154 } else if (type == "figure") {
155 os << "\\listoffigures\n";
157 os << "%% unknown builtin float\n";
160 os << "\\listof{" << getCmdName() << "}{"
161 << cit->second.listName() << "}\n";
164 os << "%%\\listof{" << getCmdName() << "}{"
165 << bformat(_("List of %1$s"), cit->second.name())
172 int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
174 os << getScreenLabel(buffer) << "\n\n";
176 lyx::toc::asciiTocList(getCmdName(), buffer, os);
183 void InsetFloatList::validate(LaTeXFeatures & features) const
185 features.useFloat(getCmdName());