2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetnote.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Angus Leeming
|
2003-08-01 15:36:47 +00:00
|
|
|
|
* \author Martin Vermeer
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-07-20 09:57:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetnote.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
|
2001-07-20 09:57:23 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2003-07-08 14:19:25 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2001-07-20 09:57:23 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
void InsetNote::init()
|
2001-07-20 09:57:23 +00:00
|
|
|
|
{
|
|
|
|
|
setInsetName("Note");
|
2003-07-08 14:19:25 +00:00
|
|
|
|
setButtonLabel();
|
2001-07-20 09:57:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 10:13:19 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
InsetNote::InsetNote(BufferParams const & bp, string const & label)
|
2002-03-03 20:25:07 +00:00
|
|
|
|
: InsetCollapsable(bp)
|
2001-07-23 09:11:14 +00:00
|
|
|
|
{
|
2003-07-08 14:19:25 +00:00
|
|
|
|
params_.type = label;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 10:13:19 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetNote::InsetNote(InsetNote const & in)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-22 07:39:46 +00:00
|
|
|
|
InsetNote::~InsetNote()
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
2003-10-15 08:49:44 +00:00
|
|
|
|
InsetNoteMailer("note", *this).hideDialog();
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetNote::clone() const
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetNote(*this));
|
2001-07-27 12:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const InsetNote::editMessage() const
|
2001-07-20 09:57:23 +00:00
|
|
|
|
{
|
|
|
|
|
return _("Opened Note Inset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetNote::write(Buffer const & buf, ostream & os) const
|
2001-07-20 09:57:23 +00:00
|
|
|
|
{
|
2003-07-08 14:19:25 +00:00
|
|
|
|
params_.write(os);
|
2001-07-20 09:57:23 +00:00
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetNote::read(Buffer const & buf, LyXLex & lex)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
setButtonLabel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::setButtonLabel()
|
|
|
|
|
{
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
|
2003-07-30 21:47:18 +00:00
|
|
|
|
if (params_.type == "Note") {
|
|
|
|
|
setLabel(_("LyX Note"));
|
2003-07-08 14:19:25 +00:00
|
|
|
|
font.setColor(LColor::note);
|
|
|
|
|
setBackgroundColor(LColor::notebg);
|
2003-07-30 21:47:18 +00:00
|
|
|
|
} else if (params_.type == "Comment") {
|
|
|
|
|
setLabel(_("Comment"));
|
|
|
|
|
font.setColor(LColor::comment);
|
|
|
|
|
setBackgroundColor(LColor::commentbg);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
} else {
|
2003-07-30 21:47:18 +00:00
|
|
|
|
setLabel(_("Greyed Out"));
|
|
|
|
|
font.setColor(LColor::greyedout);
|
|
|
|
|
setBackgroundColor(LColor::greyedoutbg);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
}
|
2003-07-15 23:52:05 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
InsetCollapsable::metrics(mi, dim);
|
|
|
|
|
// Contrary to Greyedout, these cannot be construed as part of the
|
|
|
|
|
// running text: make them stand on their own
|
|
|
|
|
if (params_.type == "Note" || params_.type == "Comment")
|
2003-09-16 15:39:33 +00:00
|
|
|
|
if (isOpen())
|
2003-08-26 10:33:59 +00:00
|
|
|
|
dim.wid = mi.base.textwidth;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-15 23:52:05 +00:00
|
|
|
|
bool InsetNote::showInsetDialog(BufferView * bv) const
|
|
|
|
|
{
|
|
|
|
|
InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2003-10-17 18:01:15 +00:00
|
|
|
|
InsetNote::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
|
idx_type & idx, pos_type & pos)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-09-22 07:39:46 +00:00
|
|
|
|
InsetNoteMailer::string2params(cmd.argument, params_);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
setButtonLabel();
|
2003-08-27 13:51:18 +00:00
|
|
|
|
bv->updateInset(this);
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2003-08-05 08:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
case LFUN_INSET_EDIT:
|
2003-08-05 08:07:07 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button3)
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(UNDISPATCHED);
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
InsetNoteMailer("note", *this).updateDialog(bv);
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2003-07-30 14:43:14 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
|
2003-07-08 14:19:25 +00:00
|
|
|
|
InsetNoteMailer("note", *this).showDialog(bv);
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
// fallthrough:
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetNote::latex(Buffer const & buf, ostream & os,
|
2003-07-08 14:19:25 +00:00
|
|
|
|
LatexRunParams const & runparams) const
|
|
|
|
|
{
|
|
|
|
|
string const pt = params_.type;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
2003-07-21 08:08:04 +00:00
|
|
|
|
if (pt == "Comment")
|
2003-07-29 12:20:04 +00:00
|
|
|
|
// verbatim
|
|
|
|
|
os << "%\n\\begin{comment}\n";
|
2003-07-21 08:08:04 +00:00
|
|
|
|
else if (pt == "Greyedout")
|
2003-07-29 12:20:04 +00:00
|
|
|
|
// we roll our own macro
|
|
|
|
|
os << "%\n\\begin{lyxgreyedout}\n";
|
2003-07-21 08:08:04 +00:00
|
|
|
|
|
|
|
|
|
if (pt != "Note")
|
2003-07-08 14:19:25 +00:00
|
|
|
|
i = inset.latex(buf, os, runparams);
|
2003-07-21 08:08:04 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
if (pt == "Comment") {
|
|
|
|
|
os << "%\n\\end{comment}\n";
|
2003-08-26 10:33:59 +00:00
|
|
|
|
i += 4;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
} else if (pt == "Greyedout") {
|
2003-07-29 12:20:04 +00:00
|
|
|
|
os << "%\n\\end{lyxgreyedout}\n";
|
2003-08-26 10:33:59 +00:00
|
|
|
|
i += 4;
|
2003-09-09 18:27:24 +00:00
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
|
2003-07-25 17:11:25 +00:00
|
|
|
|
{
|
2003-07-27 13:02:26 +00:00
|
|
|
|
string const pt = params_.type;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
if (pt == "Comment")
|
|
|
|
|
os << "<comment>\n";
|
|
|
|
|
|
|
|
|
|
if (pt != "Note")
|
|
|
|
|
i = inset.linuxdoc(buf, os);
|
|
|
|
|
|
|
|
|
|
if (pt == "Comment") {
|
|
|
|
|
os << "\n</comment>\n";
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
string const pt = params_.type;
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
if (pt == "Comment")
|
|
|
|
|
os << "<remark>\n";
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
if (pt != "Note")
|
2003-07-08 14:19:25 +00:00
|
|
|
|
i = inset.docbook(buf, os, mixcont);
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
|
|
|
|
if (pt == "Comment") {
|
|
|
|
|
os << "\n</remark>\n";
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return i;
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
string const pt = params_.type;
|
|
|
|
|
if (pt != "Note") {
|
|
|
|
|
os << "[";
|
|
|
|
|
i = inset.ascii(buf, os, ll);
|
|
|
|
|
os << "]";
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
if (params_.type == "Comment")
|
2003-07-08 14:19:25 +00:00
|
|
|
|
features.require("verbatim");
|
2003-07-29 12:20:04 +00:00
|
|
|
|
if (params_.type == "Greyedout") {
|
2003-07-08 14:19:25 +00:00
|
|
|
|
features.require("color");
|
2003-07-29 12:20:04 +00:00
|
|
|
|
features.require("lyxgreyedout");
|
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
inset.validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetNoteMailer::InsetNoteMailer(string const & name,
|
|
|
|
|
InsetNote & inset)
|
|
|
|
|
: name_(name), inset_(inset)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetNoteMailer::inset2string(Buffer const &) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
return params2string(name_, inset_.params());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetNoteMailer::params2string(string const & name,
|
|
|
|
|
InsetNoteParams const & params)
|
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
|
|
|
|
data << name << ' ';
|
|
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteMailer::string2params(string const & in,
|
|
|
|
|
InsetNoteParams & params)
|
|
|
|
|
{
|
|
|
|
|
params = InsetNoteParams();
|
|
|
|
|
|
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
|
|
|
|
params.read(lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteParams::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << type << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteParams::read(LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
type = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
}
|