3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "insetnote.h"
17 #include "BufferView.h"
18 #include "dispatchresult.h"
19 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
24 #include "metricsinfo.h"
25 #include "paragraph.h"
27 #include "support/std_sstream.h"
32 using std::istringstream;
34 using std::ostringstream;
37 void InsetNote::init()
44 InsetNote::InsetNote(BufferParams const & bp, string const & label)
45 : InsetCollapsable(bp)
52 InsetNote::InsetNote(InsetNote const & in)
53 : InsetCollapsable(in), params_(in.params_)
59 InsetNote::~InsetNote()
61 InsetNoteMailer("note", *this).hideDialog();
65 auto_ptr<InsetBase> InsetNote::clone() const
67 return auto_ptr<InsetBase>(new InsetNote(*this));
71 string const InsetNote::editMessage() const
73 return _("Opened Note Inset");
77 void InsetNote::write(Buffer const & buf, ostream & os) const
80 InsetCollapsable::write(buf, os);
84 void InsetNote::read(Buffer const & buf, LyXLex & lex)
86 InsetCollapsable::read(buf, lex);
91 void InsetNote::setButtonLabel()
93 LyXFont font(LyXFont::ALL_SANE);
97 if (params_.type == "Note") {
98 setLabel(_("LyX Note"));
99 font.setColor(LColor::note);
100 setBackgroundColor(LColor::notebg);
101 } else if (params_.type == "Comment") {
102 setLabel(_("Comment"));
103 font.setColor(LColor::comment);
104 setBackgroundColor(LColor::commentbg);
106 setLabel(_("Greyed Out"));
107 font.setColor(LColor::greyedout);
108 setBackgroundColor(LColor::greyedoutbg);
114 bool InsetNote::showInsetDialog(BufferView * bv) const
116 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
122 InsetNote::priv_dispatch(FuncRequest const & cmd,
123 idx_type & idx, pos_type & pos)
125 BufferView * bv = cmd.view();
127 switch (cmd.action) {
129 case LFUN_INSET_MODIFY: {
130 InsetNoteMailer::string2params(cmd.argument, params_);
133 return DispatchResult(true, true);
136 case LFUN_INSET_DIALOG_UPDATE:
137 InsetNoteMailer("note", *this).updateDialog(bv);
138 return DispatchResult(true, true);
140 case LFUN_MOUSE_RELEASE:
141 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
142 InsetNoteMailer("note", *this).showDialog(bv);
143 return DispatchResult(true, true);
148 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
153 int InsetNote::latex(Buffer const & buf, ostream & os,
154 OutputParams const & runparams) const
156 string const pt = params_.type;
161 os << "%\n\\begin{comment}\n";
162 else if (pt == "Greyedout")
163 // we roll our own macro
164 os << "%\n\\begin{lyxgreyedout}\n";
167 i = inset.latex(buf, os, runparams);
169 if (pt == "Comment") {
170 os << "%\n\\end{comment}\n";
172 } else if (pt == "Greyedout") {
173 os << "%\n\\end{lyxgreyedout}\n";
180 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os,
181 OutputParams const & runparams) const
183 string const pt = params_.type;
190 i = inset.linuxdoc(buf, os, runparams);
192 if (pt == "Comment") {
193 os << "\n</comment>\n";
200 int InsetNote::docbook(Buffer const & buf, std::ostream & os,
201 OutputParams const & runparams) const
203 string const pt = params_.type;
210 i = inset.docbook(buf, os, runparams);
212 if (pt == "Comment") {
213 os << "\n</remark>\n";
220 int InsetNote::plaintext(Buffer const & buf, std::ostream & os,
221 OutputParams const & runparams) const
224 string const pt = params_.type;
227 i = inset.plaintext(buf, os, runparams);
234 void InsetNote::validate(LaTeXFeatures & features) const
236 if (params_.type == "Comment")
237 features.require("verbatim");
238 if (params_.type == "Greyedout") {
239 features.require("color");
240 features.require("lyxgreyedout");
242 inset.validate(features);
247 InsetNoteMailer::InsetNoteMailer(string const & name,
249 : name_(name), inset_(inset)
254 string const InsetNoteMailer::inset2string(Buffer const &) const
256 return params2string(name_, inset_.params());
260 string const InsetNoteMailer::params2string(string const & name,
261 InsetNoteParams const & params)
270 void InsetNoteMailer::string2params(string const & in,
271 InsetNoteParams & params)
273 params = InsetNoteParams();
278 istringstream data(in);
285 void InsetNoteParams::write(ostream & os) const
291 void InsetNoteParams::read(LyXLex & lex)
295 string token = lex.getString();
300 type = lex.getString();