* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
+ * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include "Lsstream.h"
-
#include "insetnote.h"
-#include "gettext.h"
-#include "lyxfont.h"
-#include "language.h"
-#include "buffer.h"
+
#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "LaTeXFeatures.h"
+#include "LColor.h"
#include "lyxlex.h"
-#include "lyxtext.h"
-#include "insets/insettext.h"
-#include "support/LOstream.h"
-#include "support/lstrings.h"
-#include "debug.h"
+#include "metricsinfo.h"
+#include "paragraph.h"
+
+#include "support/std_sstream.h"
+
+using std::string;
+using std::auto_ptr;
+using std::istringstream;
using std::ostream;
+using std::ostringstream;
void InsetNote::init()
{
params_.type = label;
init();
- setLabel(label);
}
}
-InsetNote::~InsetNote() // MV
+InsetNote::~InsetNote()
{
InsetNoteMailer mailer("note", *this);
mailer.hideDialog();
}
-InsetBase * InsetNote::clone() const
+auto_ptr<InsetBase> InsetNote::clone() const
{
- return new InsetNote(*this);
+ return auto_ptr<InsetBase>(new InsetNote(*this));
}
}
-void InsetNote::write(Buffer const * buf, ostream & os) const
+void InsetNote::write(Buffer const & buf, ostream & os) const
{
params_.write(os);
InsetCollapsable::write(buf, os);
}
-void InsetNote::read(Buffer const * buf, LyXLex & lex)
+void InsetNote::read(Buffer const & buf, LyXLex & lex)
{
InsetCollapsable::read(buf, lex);
setButtonLabel();
font.decSize();
font.decSize();
- setLabel(params_.type);
- if (params_.type == "Note" || params_.type == "Comment") {
+ if (params_.type == "Note") {
+ setLabel(_("LyX Note"));
font.setColor(LColor::note);
setBackgroundColor(LColor::notebg);
+ } else if (params_.type == "Comment") {
+ setLabel(_("Comment"));
+ font.setColor(LColor::comment);
+ setBackgroundColor(LColor::commentbg);
} else {
- font.setColor(LColor::red);
- setBackgroundColor(LColor::background);
+ setLabel(_("Greyed Out"));
+ font.setColor(LColor::greyedout);
+ setBackgroundColor(LColor::greyedoutbg);
}
setLabelFont(font);
}
+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")
+ if (isOpen())
+ dim.wid = mi.base.textwidth;
+ dim_ = dim;
+}
+
+
bool InsetNote::showInsetDialog(BufferView * bv) const
{
InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
BufferView * bv = cmd.view();
switch (cmd.action) {
- case LFUN_INSET_MODIFY:
- {
- InsetNoteParams params;
- InsetNoteMailer::string2params(cmd.argument, params);
- params_.type = params.type;
+
+ case LFUN_INSET_MODIFY: {
+ InsetNoteMailer::string2params(cmd.argument, params_);
setButtonLabel();
bv->updateInset(this);
return DISPATCHED;
- }
+ }
+
case LFUN_INSET_EDIT:
- if (cmd.button() != mouse_button::button3)
- return InsetCollapsable::localDispatch(cmd);
- return UNDISPATCHED;
+ if (cmd.button() == mouse_button::button3)
+ return UNDISPATCHED;
+ return InsetCollapsable::localDispatch(cmd);
+
case LFUN_INSET_DIALOG_UPDATE:
InsetNoteMailer("note", *this).updateDialog(bv);
return DISPATCHED;
+
case LFUN_MOUSE_RELEASE:
- if (cmd.button() == mouse_button::button3 && cmd.x < button_length
- && cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
InsetNoteMailer("note", *this).showDialog(bv);
return DISPATCHED;
}
// fallthrough:
+
default:
return InsetCollapsable::localDispatch(cmd);
}
}
-int InsetNote::latex(Buffer const * buf, ostream & os,
+int InsetNote::latex(Buffer const & buf, ostream & os,
LatexRunParams const & runparams) const
{
string const pt = params_.type;
int i = 0;
- if (pt == "Comment") os << "%\n\\begin{comment}\n"; // remember to validate
- if (pt == "Greyedout") os << "%\n\\textcolor[gray]{0.8}{";
- if (pt != "Note") {
+ if (pt == "Comment")
+ // verbatim
+ os << "%\n\\begin{comment}\n";
+ else if (pt == "Greyedout")
+ // we roll our own macro
+ os << "%\n\\begin{lyxgreyedout}\n";
+
+ if (pt != "Note")
i = inset.latex(buf, os, runparams);
- }
+
if (pt == "Comment") {
os << "%\n\\end{comment}\n";
- i += 3;
- }
- if (pt == "Greyedout") {
- os << "%\n}";
- i += 2;
+ i += 4;
+ } else if (pt == "Greyedout") {
+ os << "%\n\\end{lyxgreyedout}\n";
+ i += 4;
}
return i;
}
-int InsetNote::linuxdoc(Buffer const *, std::ostream &) const
-{
- return 0;
+int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
+{
+ 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;
}
-int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
+int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
{
- int i = 0;
string const pt = params_.type;
- // incomplete, untested - MV
- if (pt != "Note")
+
+ int i = 0;
+ if (pt == "Comment")
+ os << "<remark>\n";
+
+ if (pt != "Note")
i = inset.docbook(buf, os, mixcont);
- return i;
+
+ if (pt == "Comment") {
+ os << "\n</remark>\n";
+ i += 3;
+ }
+ return i;
}
-int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
+int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
{
int i = 0;
string const pt = params_.type;
void InsetNote::validate(LaTeXFeatures & features) const
{
- if (params_.type == "Comment")
+ if (params_.type == "Comment")
features.require("verbatim");
- if (params_.type == "Greyedout")
+ if (params_.type == "Greyedout") {
features.require("color");
+ features.require("lyxgreyedout");
+ }
inset.validate(features);
}
}
-string const InsetNoteMailer::inset2string() const
+string const InsetNoteMailer::inset2string(Buffer const &) const
{
return params2string(name_, inset_.params());
}
ostringstream data;
data << name << ' ';
params.write(data);
- return STRCONV(data.str());
+ return data.str();
}
if (in.empty())
return;
- istringstream data(STRCONV(in));
+ istringstream data(in);
LyXLex lex(0,0);
lex.setStream(data);
params.read(lex);
type = lex.getString();
}
}
-