2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insettoc.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
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insettoc.h"
|
2003-09-04 01:18:42 +00:00
|
|
|
|
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "metricsinfo.h"
|
2002-07-21 15:51:07 +00:00
|
|
|
|
#include "toc.h"
|
2003-09-04 01:18:42 +00:00
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetTOC::InsetTOC(InsetCommandParams const & p)
|
|
|
|
|
: InsetCommand(p)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetTOC::~InsetTOC()
|
|
|
|
|
{
|
|
|
|
|
InsetCommandMailer mailer("toc", *this);
|
|
|
|
|
mailer.hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const InsetTOC::getScreenLabel(Buffer const &) const
|
2000-04-04 00:19:15 +00:00
|
|
|
|
{
|
2001-04-27 07:58:56 +00:00
|
|
|
|
string const cmdname(getCmdName());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-27 07:58:56 +00:00
|
|
|
|
if (cmdname == "tableofcontents")
|
2000-08-01 17:33:32 +00:00
|
|
|
|
return _("Table of Contents");
|
2001-05-04 10:36:36 +00:00
|
|
|
|
return _("Unknown toc list");
|
2000-08-01 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::Code InsetTOC::lyxCode() const
|
2000-08-01 17:33:32 +00:00
|
|
|
|
{
|
2001-04-04 20:40:16 +00:00
|
|
|
|
string const cmdname(getCmdName());
|
|
|
|
|
if (cmdname == "tableofcontents")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
return InsetOld::TOC_CODE;
|
|
|
|
|
return InsetOld::NO_CODE;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
void InsetTOC::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;
|
|
|
|
|
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
|
|
|
|
|
button().setBox(b);
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
dim.wid = mi.base.textwidth;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTOC::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-10-17 18:01:15 +00:00
|
|
|
|
dispatch_result
|
|
|
|
|
InsetTOC::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
|
idx_type & idx, pos_type & pos)
|
1999-09-27 18:44:28 +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:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return InsetCommand::priv_dispatch(cmd, idx, pos);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetTOC::ascii(Buffer const & buffer, ostream & os, int) const
|
2001-01-11 14:55:36 +00:00
|
|
|
|
{
|
2001-07-28 12:24:16 +00:00
|
|
|
|
os << getScreenLabel(buffer) << "\n\n";
|
2001-01-11 14:55:36 +00:00
|
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
|
lyx::toc::asciiTocList(lyx::toc::getType(getCmdName()), buffer, os);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2001-04-04 20:40:16 +00:00
|
|
|
|
os << "\n";
|
2001-01-11 14:55:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetTOC::linuxdoc(Buffer const &, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2001-04-27 07:58:56 +00:00
|
|
|
|
if (getCmdName() == "tableofcontents")
|
2000-08-01 17:33:32 +00:00
|
|
|
|
os << "<toc>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetTOC::docbook(Buffer const &, ostream & os, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2001-04-27 07:58:56 +00:00
|
|
|
|
if (getCmdName() == "tableofcontents")
|
2000-08-01 17:33:32 +00:00
|
|
|
|
os << "<toc></toc>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|