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"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-12-10 17:28:14 +00:00
|
|
|
|
#include "debug.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-12-10 17:28:14 +00:00
|
|
|
|
#include "support/lyxalgo.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2003-12-10 17:28:14 +00:00
|
|
|
|
#include "support/translator.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
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
typedef Translator<std::string, InsetNoteParams::Type> NoteTranslator;
|
|
|
|
|
|
|
|
|
|
NoteTranslator const init_notetranslator() {
|
|
|
|
|
NoteTranslator translator("Note", InsetNoteParams::Note);
|
|
|
|
|
translator.addPair("Comment", InsetNoteParams::Comment);
|
|
|
|
|
translator.addPair("Greyedout", InsetNoteParams::Greyedout);
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NoteTranslator const init_notetranslator_loc() {
|
|
|
|
|
NoteTranslator translator(_("Note"), InsetNoteParams::Note);
|
|
|
|
|
translator.addPair(_("Comment"), InsetNoteParams::Comment);
|
|
|
|
|
translator.addPair(_("Greyed out"), InsetNoteParams::Greyedout);
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NoteTranslator const & notetranslator() {
|
|
|
|
|
static NoteTranslator translator = init_notetranslator();
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NoteTranslator const & notetranslator_loc() {
|
|
|
|
|
static NoteTranslator translator = init_notetranslator_loc();
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetNoteParams::InsetNoteParams()
|
|
|
|
|
: type(Note)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteParams::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
string const label = notetranslator().find(type);
|
|
|
|
|
os << "Note " << label << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteParams::read(LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
string label;
|
|
|
|
|
lex >> label;
|
|
|
|
|
if (lex)
|
|
|
|
|
type = notetranslator().find(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-12-10 17:28:14 +00:00
|
|
|
|
params_.type = notetranslator().find(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-12-10 14:49:51 +00:00
|
|
|
|
InsetNoteMailer(*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
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
params_.read(lex);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
setButtonLabel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::setButtonLabel()
|
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
string const label = notetranslator_loc().find(params_.type);
|
|
|
|
|
setLabel(label);
|
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
switch (params_.type) {
|
|
|
|
|
case InsetNoteParams::Note:
|
2003-07-08 14:19:25 +00:00
|
|
|
|
font.setColor(LColor::note);
|
|
|
|
|
setBackgroundColor(LColor::notebg);
|
2003-12-10 17:28:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case InsetNoteParams::Comment:
|
2003-07-30 21:47:18 +00:00
|
|
|
|
font.setColor(LColor::comment);
|
|
|
|
|
setBackgroundColor(LColor::commentbg);
|
2003-12-10 17:28:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case InsetNoteParams::Greyedout:
|
2003-07-30 21:47:18 +00:00
|
|
|
|
font.setColor(LColor::greyedout);
|
|
|
|
|
setBackgroundColor(LColor::greyedoutbg);
|
2003-12-10 17:28:14 +00:00
|
|
|
|
break;
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
}
|
2003-07-15 23:52:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetNote::showInsetDialog(BufferView * bv) const
|
|
|
|
|
{
|
2003-12-10 14:49:51 +00:00
|
|
|
|
InsetNoteMailer(const_cast<InsetNote &>(*this)).showDialog(bv);
|
2003-07-15 23:52:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void InsetNote::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +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();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.bv().update();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetNoteMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd))
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetNoteMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
else
|
|
|
|
|
InsetCollapsable::priv_dispatch(cur, cmd);
|
|
|
|
|
break;
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
default:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
InsetCollapsable::priv_dispatch(cur, cmd);
|
|
|
|
|
break;
|
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-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
string type;
|
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
|
type = "comment";
|
|
|
|
|
else if (params_.type == InsetNoteParams::Greyedout)
|
|
|
|
|
type = "lyxgreyedout";
|
|
|
|
|
|
|
|
|
|
ostringstream ss;
|
|
|
|
|
ss << "%\n\\begin{" << type << "}\n";
|
|
|
|
|
inset.latex(buf, ss, runparams);
|
|
|
|
|
ss << "%\n\\end{" << type << "}\n";
|
|
|
|
|
|
|
|
|
|
string const str = ss.str();
|
|
|
|
|
os << str;
|
|
|
|
|
// Return how many newlines we issued.
|
|
|
|
|
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-07-25 17:11:25 +00:00
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
|
return 0;
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
ostringstream ss;
|
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
|
ss << "<comment>\n";
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
inset.linuxdoc(buf, ss, runparams);
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
|
ss << "\n</comment>\n";
|
|
|
|
|
|
|
|
|
|
string const str = ss.str();
|
|
|
|
|
os << str;
|
|
|
|
|
// Return how many newlines we issued.
|
|
|
|
|
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetNote::docbook(Buffer const & buf, std::ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
|
return 0;
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
ostringstream ss;
|
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
|
ss << "<remark>\n";
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
inset.docbook(buf, ss, runparams);
|
2003-07-27 13:02:26 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
|
ss << "\n</remark>\n";
|
|
|
|
|
|
|
|
|
|
string const str = ss.str();
|
|
|
|
|
os << str;
|
|
|
|
|
// Return how many newlines we issued.
|
|
|
|
|
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetNote::plaintext(Buffer const & buf, std::ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
ostringstream ss;
|
|
|
|
|
ss << "[";
|
|
|
|
|
inset.plaintext(buf, ss, runparams);
|
|
|
|
|
ss << "]";
|
|
|
|
|
|
|
|
|
|
string const str = ss.str();
|
|
|
|
|
os << str;
|
|
|
|
|
// Return how many newlines we issued.
|
|
|
|
|
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNote::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
features.require("verbatim");
|
2003-12-10 17:28:14 +00:00
|
|
|
|
if (params_.type == InsetNoteParams::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-10 14:49:51 +00:00
|
|
|
|
string const InsetNoteMailer:: name_("note");
|
|
|
|
|
|
|
|
|
|
InsetNoteMailer::InsetNoteMailer(InsetNote & inset)
|
|
|
|
|
: inset_(inset)
|
|
|
|
|
{}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetNoteMailer::inset2string(Buffer const &) const
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
2003-12-10 14:49:51 +00:00
|
|
|
|
return params2string(inset_.params());
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-10 14:49:51 +00:00
|
|
|
|
string const InsetNoteMailer::params2string(InsetNoteParams const & params)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2003-12-10 14:49:51 +00:00
|
|
|
|
data << name_ << ' ';
|
2003-07-08 14:19:25 +00:00
|
|
|
|
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,
|
2003-12-10 14:49:51 +00:00
|
|
|
|
InsetNoteParams & params)
|
2003-07-08 14:19:25 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetNoteMailer", in, 1, name_);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
|
// by LyXText::readInset
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string id;
|
|
|
|
|
lex >> id;
|
|
|
|
|
if (!lex || id != "Note")
|
|
|
|
|
return print_mailer_error("InsetBoxMailer", in, 2, "Note");
|
2003-12-10 17:28:14 +00:00
|
|
|
|
|
|
|
|
|
params.read(lex);
|
2003-07-08 14:19:25 +00:00
|
|
|
|
}
|