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
17 #include "insetnote.h"
22 #include "BufferView.h"
25 #include "insets/insettext.h"
26 #include "support/LOstream.h"
27 #include "support/lstrings.h"
34 void InsetNote::init()
41 InsetNote::InsetNote(BufferParams const & bp, string const & label)
42 : InsetCollapsable(bp)
50 InsetNote::InsetNote(InsetNote const & in)
51 : InsetCollapsable(in), params_(in.params_)
57 InsetNote::~InsetNote() // MV
59 InsetNoteMailer mailer("note", *this);
64 auto_ptr<InsetBase> InsetNote::clone() const
66 return auto_ptr<InsetBase>(new InsetNote(*this));
70 string const InsetNote::editMessage() const
72 return _("Opened Note Inset");
76 void InsetNote::write(Buffer const * buf, ostream & os) const
79 InsetCollapsable::write(buf, os);
83 void InsetNote::read(Buffer const * buf, LyXLex & lex)
85 InsetCollapsable::read(buf, lex);
90 void InsetNote::setButtonLabel()
92 LyXFont font(LyXFont::ALL_SANE);
96 if (params_.type == "Note") {
97 setLabel(_("LyX Note"));
98 font.setColor(LColor::note);
99 setBackgroundColor(LColor::notebg);
100 } else if (params_.type == "Comment") {
101 setLabel(_("Comment"));
102 font.setColor(LColor::comment);
103 setBackgroundColor(LColor::commentbg);
105 setLabel(_("Greyed Out"));
106 font.setColor(LColor::greyedout);
107 setBackgroundColor(LColor::greyedoutbg);
113 bool InsetNote::showInsetDialog(BufferView * bv) const
115 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
120 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
122 BufferView * bv = cmd.view();
124 switch (cmd.action) {
126 case LFUN_INSET_MODIFY: {
127 InsetNoteParams params;
128 InsetNoteMailer::string2params(cmd.argument, params);
129 params_.type = params.type;
135 case LFUN_INSET_EDIT:
136 if (cmd.button() == mouse_button::button3)
138 return InsetCollapsable::localDispatch(cmd);
140 case LFUN_INSET_DIALOG_UPDATE:
141 InsetNoteMailer("note", *this).updateDialog(bv);
144 case LFUN_MOUSE_RELEASE:
145 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
146 InsetNoteMailer("note", *this).showDialog(bv);
152 return InsetCollapsable::localDispatch(cmd);
157 int InsetNote::latex(Buffer const * buf, ostream & os,
158 LatexRunParams const & runparams) const
160 string const pt = params_.type;
165 os << "%\n\\begin{comment}\n";
166 else if (pt == "Greyedout")
167 // we roll our own macro
168 os << "%\n\\begin{lyxgreyedout}\n";
171 i = inset.latex(buf, os, runparams);
173 if (pt == "Comment") {
174 os << "%\n\\end{comment}\n";
176 } else if (pt == "Greyedout") {
177 os << "%\n\\end{lyxgreyedout}\n";
184 int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
186 string const pt = params_.type;
193 i = inset.linuxdoc(buf, os);
195 if (pt == "Comment") {
196 os << "\n</comment>\n";
203 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
205 string const pt = params_.type;
212 i = inset.docbook(buf, os, mixcont);
214 if (pt == "Comment") {
215 os << "\n</remark>\n";
222 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
225 string const pt = params_.type;
228 i = inset.ascii(buf, os, ll);
235 void InsetNote::validate(LaTeXFeatures & features) const
237 if (params_.type == "Comment")
238 features.require("verbatim");
239 if (params_.type == "Greyedout") {
240 features.require("color");
241 features.require("lyxgreyedout");
243 inset.validate(features);
248 InsetNoteMailer::InsetNoteMailer(string const & name,
250 : name_(name), inset_(inset)
255 string const InsetNoteMailer::inset2string(Buffer const &) const
257 return params2string(name_, inset_.params());
261 string const InsetNoteMailer::params2string(string const & name,
262 InsetNoteParams const & params)
267 return STRCONV(data.str());
271 void InsetNoteMailer::string2params(string const & in,
272 InsetNoteParams & params)
274 params = InsetNoteParams();
279 istringstream data(STRCONV(in));
286 void InsetNoteParams::write(ostream & os) const
292 void InsetNoteParams::read(LyXLex & lex)
296 string token = lex.getString();
301 type = lex.getString();