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"
19 #include "FloatList.h"
20 #include "funcrequest.h"
22 #include "LaTeXFeatures.h"
24 #include "metricsinfo.h"
27 #include "support/lstrings.h"
29 using namespace lyx::support;
35 InsetFloatList::InsetFloatList()
36 : InsetCommand(InsetCommandParams())
40 InsetFloatList::InsetFloatList(string const & type)
41 : InsetCommand(InsetCommandParams())
47 InsetFloatList::~InsetFloatList()
49 InsetCommandMailer mailer("toc", *this);
54 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
56 FloatList const & floats = buf.params().getLyXTextClass().floats();
57 FloatList::const_iterator it = floats[getCmdName()];
58 if (it != floats.end())
59 return _(it->second.listName());
61 return _("ERROR: Nonexistent float type!");
65 InsetOld::Code InsetFloatList::lyxCode() const
67 return InsetOld::FLOAT_LIST_CODE;
71 void InsetFloatList::write(Buffer const &, ostream & os) const
73 os << "FloatList " << getCmdName() << "\n";
77 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
79 FloatList const & floats = buf.params().getLyXTextClass().floats();
83 setCmdName(lex.getString());
84 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
85 if (!floats.typeExist(getCmdName()))
86 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
88 lex.printError("InsetFloatList: Parse error: `$$Token'");
91 token = lex.getString();
92 if (token == "\\end_inset")
95 if (token != "\\end_inset") {
96 lex.printError("Missing \\end_inset at this point. "
102 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
104 InsetCommand::metrics(mi, dim);
105 int center_indent = (mi.base.textwidth - dim.wid) / 2;
106 Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
109 dim.wid = mi.base.textwidth;
114 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
116 InsetCommand::draw(pi, x + button().box().x1, y);
120 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
122 switch (cmd.action) {
123 case LFUN_MOUSE_RELEASE:
124 if (button().box().contains(cmd.x, cmd.y))
125 InsetCommandMailer("toc", *this).showDialog(cmd.view());
128 case LFUN_INSET_DIALOG_SHOW:
129 InsetCommandMailer("toc", *this).showDialog(cmd.view());
133 return InsetCommand::localDispatch(cmd);
138 int InsetFloatList::latex(Buffer const & buf, ostream & os,
139 LatexRunParams const &) const
141 FloatList const & floats = buf.params().getLyXTextClass().floats();
142 FloatList::const_iterator cit = floats[getCmdName()];
144 if (cit != floats.end()) {
145 if (cit->second.builtin()) {
146 // Only two different types allowed here:
147 string const type = cit->second.type();
148 if (type == "table") {
149 os << "\\listoftables\n";
150 } else if (type == "figure") {
151 os << "\\listoffigures\n";
153 os << "%% unknown builtin float\n";
156 os << "\\listof{" << getCmdName() << "}{"
157 << cit->second.listName() << "}\n";
160 os << "%%\\listof{" << getCmdName() << "}{"
161 << bformat(_("List of %1$s"), cit->second.name())
168 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
170 os << getScreenLabel(buffer) << "\n\n";
172 lyx::toc::asciiTocList(getCmdName(), buffer, os);
179 void InsetFloatList::validate(LaTeXFeatures & features) const
181 features.useFloat(getCmdName());