2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetfloatlist.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include <config.h>
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
|
|
#include "insetfloatlist.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "Floating.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
#include "FloatList.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2002-04-04 14:39:55 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2002-07-21 15:51:07 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2002-07-21 15:51:07 +00:00
|
|
|
|
#include "toc.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
2001-05-04 13:17:01 +00:00
|
|
|
|
using std::endl;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
|
InsetFloatList::InsetFloatList()
|
|
|
|
|
: InsetCommand(InsetCommandParams())
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{}
|
2001-11-27 10:56:14 +00:00
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
|
InsetFloatList::InsetFloatList(string const & type)
|
|
|
|
|
: InsetCommand(InsetCommandParams())
|
|
|
|
|
{
|
|
|
|
|
setCmdName(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetFloatList::~InsetFloatList()
|
|
|
|
|
{
|
|
|
|
|
InsetCommandMailer mailer("toc", *this);
|
|
|
|
|
mailer.hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const InsetFloatList::getScreenLabel(Buffer const & buf) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
FloatList const & floats = buf.params().getLyXTextClass().floats();
|
2002-08-27 15:51:19 +00:00
|
|
|
|
FloatList::const_iterator it = floats[getCmdName()];
|
|
|
|
|
if (it != floats.end())
|
2002-04-28 14:00:48 +00:00
|
|
|
|
return _(it->second.listName());
|
|
|
|
|
else
|
|
|
|
|
return _("ERROR: Nonexistent float type!");
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::Code InsetFloatList::lyxCode() const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
|
return InsetOld::FLOAT_LIST_CODE;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloatList::write(Buffer const &, ostream & os) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2001-11-27 10:56:14 +00:00
|
|
|
|
os << "FloatList " << getCmdName() << "\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
FloatList const & floats = buf.params().getLyXTextClass().floats();
|
2001-05-04 10:36:36 +00:00
|
|
|
|
string token;
|
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.eatLine()) {
|
2001-11-27 10:56:14 +00:00
|
|
|
|
setCmdName(lex.getString());
|
2002-04-28 14:00:48 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
|
2002-08-27 15:51:19 +00:00
|
|
|
|
if (!floats.typeExist(getCmdName()))
|
2002-04-28 14:00:48 +00:00
|
|
|
|
lex.printError("InsetFloatList: Unknown float type: `$$Token'");
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else
|
|
|
|
|
lex.printError("InsetFloatList: Parse error: `$$Token'");
|
2001-08-06 19:13:25 +00:00
|
|
|
|
while (lex.isOK()) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
token = lex.getString();
|
2001-05-04 10:36:36 +00:00
|
|
|
|
if (token == "\\end_inset")
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
|
"Read: `$$Token'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
InsetCommand::metrics(mi, dim);
|
2003-09-04 14:02:05 +00:00
|
|
|
|
int center_indent = (mi.base.textwidth - dim.wid) / 2;
|
2003-09-09 18:27:24 +00:00
|
|
|
|
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
|
2003-09-04 14:02:05 +00:00
|
|
|
|
button().setBox(b);
|
2003-09-09 18:27:24 +00:00
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
dim.wid = mi.base.textwidth;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
2003-09-04 14:02:05 +00:00
|
|
|
|
InsetCommand::draw(pi, x + button().box().x1, y);
|
2003-08-26 10:33:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-09-04 14:02:05 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
if (button().box().contains(cmd.x, cmd.y))
|
|
|
|
|
InsetCommandMailer("toc", *this).showDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_SHOW:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
InsetCommandMailer("toc", *this).showDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
2003-09-04 14:02:05 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
default:
|
|
|
|
|
return InsetCommand::localDispatch(cmd);
|
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetFloatList::latex(Buffer const & buf, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
|
LatexRunParams const &) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
FloatList const & floats = buf.params().getLyXTextClass().floats();
|
2002-08-27 15:51:19 +00:00
|
|
|
|
FloatList::const_iterator cit = floats[getCmdName()];
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
if (cit != floats.end()) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
if (cit->second.builtin()) {
|
|
|
|
|
// Only two different types allowed here:
|
|
|
|
|
string const type = cit->second.type();
|
|
|
|
|
if (type == "table") {
|
|
|
|
|
os << "\\listoftables\n";
|
|
|
|
|
} else if (type == "figure") {
|
|
|
|
|
os << "\\listoffigures\n";
|
|
|
|
|
} else {
|
|
|
|
|
os << "%% unknown builtin float\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2001-11-27 10:56:14 +00:00
|
|
|
|
os << "\\listof{" << getCmdName() << "}{"
|
2002-04-04 14:39:55 +00:00
|
|
|
|
<< cit->second.listName() << "}\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2003-05-13 09:48:57 +00:00
|
|
|
|
os << "%%\\listof{" << getCmdName() << "}{"
|
|
|
|
|
<< bformat(_("List of %1$s"), cit->second.name())
|
2002-11-24 15:20:31 +00:00
|
|
|
|
<< "}\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2001-07-28 12:24:16 +00:00
|
|
|
|
os << getScreenLabel(buffer) << "\n\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
|
lyx::toc::asciiTocList(getCmdName(), buffer, os);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
|
|
os << "\n";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-04-04 14:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloatList::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.useFloat(getCmdName());
|
|
|
|
|
}
|