3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
15 #include "insetnote.h"
20 #include "BufferView.h"
23 #include "insets/insettext.h"
24 #include "support/LOstream.h"
25 #include "support/lstrings.h"
32 void InsetNote::init()
39 InsetNote::InsetNote(BufferParams const & bp, string const & label)
40 : InsetCollapsable(bp)
48 InsetNote::InsetNote(InsetNote const & in)
49 : InsetCollapsable(in), params_(in.params_)
55 InsetNote::~InsetNote() // MV
57 InsetNoteMailer mailer("note", *this);
62 auto_ptr<InsetBase> InsetNote::clone() const
64 return auto_ptr<InsetBase>(new InsetNote(*this));
68 string const InsetNote::editMessage() const
70 return _("Opened Note Inset");
74 void InsetNote::write(Buffer const * buf, ostream & os) const
77 InsetCollapsable::write(buf, os);
81 void InsetNote::read(Buffer const * buf, LyXLex & lex)
83 InsetCollapsable::read(buf, lex);
88 void InsetNote::setButtonLabel()
90 LyXFont font(LyXFont::ALL_SANE);
94 setLabel(params_.type);
95 if (params_.type == "Note" || params_.type == "Comment") {
96 font.setColor(LColor::note);
97 setBackgroundColor(LColor::notebg);
99 font.setColor(LColor::red);
100 setBackgroundColor(LColor::background);
106 bool InsetNote::showInsetDialog(BufferView * bv) const
108 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
113 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
115 BufferView * bv = cmd.view();
117 switch (cmd.action) {
118 case LFUN_INSET_MODIFY:
120 InsetNoteParams params;
121 InsetNoteMailer::string2params(cmd.argument, params);
122 params_.type = params.type;
124 bv->updateInset(this);
127 case LFUN_INSET_EDIT:
128 if (cmd.button() != mouse_button::button3)
129 return InsetCollapsable::localDispatch(cmd);
131 case LFUN_INSET_DIALOG_UPDATE:
132 InsetNoteMailer("note", *this).updateDialog(bv);
134 case LFUN_MOUSE_RELEASE:
135 if (cmd.button() == mouse_button::button3 && cmd.x < button_length
136 && cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
137 InsetNoteMailer("note", *this).showDialog(bv);
142 return InsetCollapsable::localDispatch(cmd);
147 int InsetNote::latex(Buffer const * buf, ostream & os,
148 LatexRunParams const & runparams) const
150 string const pt = params_.type;
154 os << "%\n\\begin{comment}\n"; // remember to validate
155 else if (pt == "Greyedout")
156 os << "%\n\\color[gray]{0.8}";
159 i = inset.latex(buf, os, runparams);
161 if (pt == "Comment") {
162 os << "%\n\\end{comment}\n";
164 } else if (pt == "Greyedout") {
165 os << "\\normalcolor%\n}";
172 int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
174 string const pt = params_.type;
181 i = inset.linuxdoc(buf, os);
183 if (pt == "Comment") {
184 os << "\n</comment>\n";
191 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
193 string const pt = params_.type;
200 i = inset.docbook(buf, os, mixcont);
202 if (pt == "Comment") {
203 os << "\n</remark>\n";
210 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
213 string const pt = params_.type;
216 i = inset.ascii(buf, os, ll);
223 void InsetNote::validate(LaTeXFeatures & features) const
225 if (params_.type == "Comment")
226 features.require("verbatim");
227 if (params_.type == "Greyedout")
228 features.require("color");
229 inset.validate(features);
234 InsetNoteMailer::InsetNoteMailer(string const & name,
236 : name_(name), inset_(inset)
241 string const InsetNoteMailer::inset2string(Buffer const &) const
243 return params2string(name_, inset_.params());
247 string const InsetNoteMailer::params2string(string const & name,
248 InsetNoteParams const & params)
253 return STRCONV(data.str());
257 void InsetNoteMailer::string2params(string const & in,
258 InsetNoteParams & params)
260 params = InsetNoteParams();
265 istringstream data(STRCONV(in));
272 void InsetNoteParams::write(ostream & os) const
278 void InsetNoteParams::read(LyXLex & lex)
282 string token = lex.getString();
287 type = lex.getString();