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"
14 #include "FloatList.h"
15 #include "metricsinfo.h"
16 #include "LaTeXFeatures.h"
18 #include "BufferView.h"
19 #include "funcrequest.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 center_indent_ = (mi.base.textwidth - dim.wid) / 2;
105 dim.wid = mi.base.textwidth;
110 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
112 InsetCommand::draw(pi, x + center_indent_, y);
116 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
118 switch (cmd.action) {
119 case LFUN_INSET_EDIT:
120 InsetCommandMailer("toc", *this).showDialog(cmd.view());
123 return InsetCommand::localDispatch(cmd);
128 int InsetFloatList::latex(Buffer const * buf, ostream & os,
129 LatexRunParams const &) const
131 FloatList const & floats = buf->params.getLyXTextClass().floats();
132 FloatList::const_iterator cit = floats[getCmdName()];
134 if (cit != floats.end()) {
135 if (cit->second.builtin()) {
136 // Only two different types allowed here:
137 string const type = cit->second.type();
138 if (type == "table") {
139 os << "\\listoftables\n";
140 } else if (type == "figure") {
141 os << "\\listoffigures\n";
143 os << "%% unknown builtin float\n";
146 os << "\\listof{" << getCmdName() << "}{"
147 << cit->second.listName() << "}\n";
150 os << "%%\\listof{" << getCmdName() << "}{"
151 << bformat(_("List of %1$s"), cit->second.name())
158 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
160 os << getScreenLabel(buffer) << "\n\n";
162 lyx::toc::asciiTocList(getCmdName(), buffer, os);
169 void InsetFloatList::validate(LaTeXFeatures & features) const
171 features.useFloat(getCmdName());