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"
18 #include "FloatList.h"
19 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
23 #include "metricsinfo.h"
26 #include "support/lstrings.h"
28 using namespace lyx::support;
34 InsetFloatList::InsetFloatList()
35 : InsetCommand(InsetCommandParams())
39 InsetFloatList::InsetFloatList(string const & type)
40 : InsetCommand(InsetCommandParams())
46 InsetFloatList::~InsetFloatList()
48 InsetCommandMailer mailer("toc", *this);
53 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
55 FloatList const & floats = buf.params().getLyXTextClass().floats();
56 FloatList::const_iterator it = floats[getCmdName()];
57 if (it != floats.end())
58 return _(it->second.listName());
60 return _("ERROR: Nonexistent float type!");
64 InsetOld::Code InsetFloatList::lyxCode() const
66 return InsetOld::FLOAT_LIST_CODE;
70 void InsetFloatList::write(Buffer const &, ostream & os) const
72 os << "FloatList " << getCmdName() << "\n";
76 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
78 FloatList const & floats = buf.params().getLyXTextClass().floats();
82 setCmdName(lex.getString());
83 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
84 if (!floats.typeExist(getCmdName()))
85 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
87 lex.printError("InsetFloatList: Parse error: `$$Token'");
90 token = lex.getString();
91 if (token == "\\end_inset")
94 if (token != "\\end_inset") {
95 lex.printError("Missing \\end_inset at this point. "
101 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
103 InsetCommand::metrics(mi, dim);
104 int center_indent = (mi.base.textwidth - dim.wid) / 2;
105 Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
108 dim.wid = mi.base.textwidth;
113 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
115 InsetCommand::draw(pi, x + button().box().x1, y);
119 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
121 switch (cmd.action) {
122 case LFUN_MOUSE_RELEASE:
123 if (button().box().contains(cmd.x, cmd.y))
124 InsetCommandMailer("toc", *this).showDialog(cmd.view());
127 case LFUN_INSET_DIALOG_SHOW:
128 InsetCommandMailer("toc", *this).showDialog(cmd.view());
132 return InsetCommand::localDispatch(cmd);
137 int InsetFloatList::latex(Buffer const & buf, ostream & os,
138 LatexRunParams const &) const
140 FloatList const & floats = buf.params().getLyXTextClass().floats();
141 FloatList::const_iterator cit = floats[getCmdName()];
143 if (cit != floats.end()) {
144 if (cit->second.builtin()) {
145 // Only two different types allowed here:
146 string const type = cit->second.type();
147 if (type == "table") {
148 os << "\\listoftables\n";
149 } else if (type == "figure") {
150 os << "\\listoffigures\n";
152 os << "%% unknown builtin float\n";
155 os << "\\listof{" << getCmdName() << "}{"
156 << cit->second.listName() << "}\n";
159 os << "%%\\listof{" << getCmdName() << "}{"
160 << bformat(_("List of %1$s"), cit->second.name())
167 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
169 os << getScreenLabel(buffer) << "\n\n";
171 lyx::toc::asciiTocList(getCmdName(), buffer, os);
178 void InsetFloatList::validate(LaTeXFeatures & features) const
180 features.useFloat(getCmdName());