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("toc", *this).hideDialog();
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);
122 InsetFloatList::priv_dispatch(FuncRequest const & cmd,
123 idx_type & idx, pos_type & pos)
125 switch (cmd.action) {
126 case LFUN_MOUSE_RELEASE:
127 if (button().box().contains(cmd.x, cmd.y))
128 InsetCommandMailer("toc", *this).showDialog(cmd.view());
129 return DispatchResult(true, true);
131 case LFUN_INSET_DIALOG_SHOW:
132 InsetCommandMailer("toc", *this).showDialog(cmd.view());
133 return DispatchResult(true, true);
136 return InsetCommand::priv_dispatch(cmd, idx, pos);
141 int InsetFloatList::latex(Buffer const & buf, ostream & os,
142 OutputParams const &) const
144 FloatList const & floats = buf.params().getLyXTextClass().floats();
145 FloatList::const_iterator cit = floats[getCmdName()];
147 if (cit != floats.end()) {
148 if (cit->second.builtin()) {
149 // Only two different types allowed here:
150 string const type = cit->second.type();
151 if (type == "table") {
152 os << "\\listoftables\n";
153 } else if (type == "figure") {
154 os << "\\listoffigures\n";
156 os << "%% unknown builtin float\n";
159 os << "\\listof{" << getCmdName() << "}{"
160 << cit->second.listName() << "}\n";
163 os << "%%\\listof{" << getCmdName() << "}{"
164 << bformat(_("List of %1$s"), cit->second.name())
171 int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
173 os << getScreenLabel(buffer) << "\n\n";
175 lyx::toc::asciiTocList(getCmdName(), buffer, os);
182 void InsetFloatList::validate(LaTeXFeatures & features) const
184 features.useFloat(getCmdName());