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
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
2001-07-20 09:57:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
#include "Lsstream.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
|
|
|
|
#include "insetnote.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxfont.h"
|
2001-11-26 18:03:23 +00:00
|
|
|
#include "language.h"
|
2001-07-23 09:11:14 +00:00
|
|
|
#include "buffer.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
#include "BufferView.h"
|
2003-07-08 14:19:25 +00:00
|
|
|
#include "lyxlex.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
#include "support/LOstream.h"
|
2001-07-24 10:13:19 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using std::ostream;
|
2003-07-25 17:11:25 +00:00
|
|
|
using std::auto_ptr;
|
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();
|
2003-07-08 14:19:25 +00:00
|
|
|
setLabel(label);
|
2001-07-23 09:11:14 +00:00
|
|
|
}
|
|
|
|
|
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-07-08 14:19:25 +00:00
|
|
|
InsetNote::~InsetNote() // MV
|
|
|
|
{
|
|
|
|
InsetNoteMailer mailer("note", *this);
|
|
|
|
mailer.hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-11 11:52:05 +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
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::read(Buffer const * buf, LyXLex & lex)
|
|
|
|
{
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
setButtonLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::setButtonLabel()
|
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
|
|
|
|
setLabel(params_.type);
|
|
|
|
if (params_.type == "Note" || params_.type == "Comment") {
|
|
|
|
font.setColor(LColor::note);
|
|
|
|
setBackgroundColor(LColor::notebg);
|
|
|
|
} else {
|
|
|
|
font.setColor(LColor::red);
|
|
|
|
setBackgroundColor(LColor::background);
|
|
|
|
}
|
|
|
|
setLabelFont(font);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
|
|
|
|
{
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
{
|
|
|
|
InsetNoteParams params;
|
|
|
|
InsetNoteMailer::string2params(cmd.argument, params);
|
|
|
|
params_.type = params.type;
|
|
|
|
setButtonLabel();
|
|
|
|
bv->updateInset(this);
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
case LFUN_INSET_EDIT:
|
2003-07-25 17:11:25 +00:00
|
|
|
if (cmd.button() != mouse_button::button3)
|
2003-07-08 14:19:25 +00:00
|
|
|
return InsetCollapsable::localDispatch(cmd);
|
|
|
|
return UNDISPATCHED;
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
InsetNoteMailer("note", *this).updateDialog(bv);
|
|
|
|
return DISPATCHED;
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2003-07-25 17:11:25 +00:00
|
|
|
if (cmd.button() == mouse_button::button3 && cmd.x < button_length
|
2003-07-08 14:19:25 +00:00
|
|
|
&& cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
|
|
|
|
InsetNoteMailer("note", *this).showDialog(bv);
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
// fallthrough:
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::localDispatch(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetNote::latex(Buffer const * buf, ostream & os,
|
|
|
|
LatexRunParams const & runparams) const
|
|
|
|
{
|
|
|
|
string const pt = params_.type;
|
|
|
|
|
|
|
|
int i = 0;
|
2003-07-21 08:08:04 +00:00
|
|
|
if (pt == "Comment")
|
|
|
|
os << "%\n\\begin{comment}\n"; // remember to validate
|
|
|
|
else if (pt == "Greyedout")
|
|
|
|
os << "%\n\\textcolor[gray]{0.8}{";
|
|
|
|
|
|
|
|
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-07-25 17:11:25 +00:00
|
|
|
i += 3;
|
|
|
|
} else if (pt == "Greyedout") {
|
2003-07-21 08:08:04 +00:00
|
|
|
os << "\\normalcolor%\n}";
|
2003-07-08 14:19:25 +00:00
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-27 13:02:26 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
if (params_.type == "Greyedout")
|
|
|
|
features.require("color");
|
|
|
|
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);
|
|
|
|
return STRCONV(data.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteMailer::string2params(string const & in,
|
|
|
|
InsetNoteParams & params)
|
|
|
|
{
|
|
|
|
params = InsetNoteParams();
|
|
|
|
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(STRCONV(in));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|