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 "BufferView.h"
19 #include "FloatList.h"
20 #include "funcrequest.h"
22 #include "LaTeXFeatures.h"
24 #include "metricsinfo.h"
28 #include "support/lstrings.h"
30 using namespace lyx::support;
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 center_indent_ = (mi.base.textwidth - dim.wid) / 2;
107 dim.wid = mi.base.textwidth;
112 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
114 InsetCommand::draw(pi, x + center_indent_, y);
118 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
120 switch (cmd.action) {
121 case LFUN_INSET_EDIT:
122 InsetCommandMailer("toc", *this).showDialog(cmd.view());
125 return InsetCommand::localDispatch(cmd);
130 int InsetFloatList::latex(Buffer const & buf, ostream & os,
131 LatexRunParams const &) const
133 FloatList const & floats = buf.params.getLyXTextClass().floats();
134 FloatList::const_iterator cit = floats[getCmdName()];
136 if (cit != floats.end()) {
137 if (cit->second.builtin()) {
138 // Only two different types allowed here:
139 string const type = cit->second.type();
140 if (type == "table") {
141 os << "\\listoftables\n";
142 } else if (type == "figure") {
143 os << "\\listoffigures\n";
145 os << "%% unknown builtin float\n";
148 os << "\\listof{" << getCmdName() << "}{"
149 << cit->second.listName() << "}\n";
152 os << "%%\\listof{" << getCmdName() << "}{"
153 << bformat(_("List of %1$s"), cit->second.name())
160 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
162 os << getScreenLabel(buffer) << "\n\n";
164 lyx::toc::asciiTocList(getCmdName(), buffer, os);
171 void InsetFloatList::validate(LaTeXFeatures & features) const
173 features.useFloat(getCmdName());