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"
31 void InsetNote::init()
38 InsetNote::InsetNote(BufferParams const & bp, string const & label)
39 : InsetCollapsable(bp)
47 InsetNote::InsetNote(InsetNote const & in)
48 : InsetCollapsable(in), params_(in.params_)
54 InsetNote::~InsetNote() // MV
56 InsetNoteMailer mailer("note", *this);
61 InsetBase * InsetNote::clone() const
63 return new InsetNote(*this);
67 string const InsetNote::editMessage() const
69 return _("Opened Note Inset");
73 void InsetNote::write(Buffer const * buf, ostream & os) const
76 InsetCollapsable::write(buf, os);
80 void InsetNote::read(Buffer const * buf, LyXLex & lex)
82 InsetCollapsable::read(buf, lex);
87 void InsetNote::setButtonLabel()
89 LyXFont font(LyXFont::ALL_SANE);
93 setLabel(params_.type);
94 if (params_.type == "Note" || params_.type == "Comment") {
95 font.setColor(LColor::note);
96 setBackgroundColor(LColor::notebg);
98 font.setColor(LColor::red);
99 setBackgroundColor(LColor::background);
105 bool InsetNote::showInsetDialog(BufferView * bv) const
107 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
112 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
114 BufferView * bv = cmd.view();
116 switch (cmd.action) {
117 case LFUN_INSET_MODIFY:
119 InsetNoteParams params;
120 InsetNoteMailer::string2params(cmd.argument, params);
121 params_.type = params.type;
123 bv->updateInset(this);
126 case LFUN_INSET_EDIT:
127 if (cmd.button() != mouse_button::button3)
128 return InsetCollapsable::localDispatch(cmd);
130 case LFUN_INSET_DIALOG_UPDATE:
131 InsetNoteMailer("note", *this).updateDialog(bv);
133 case LFUN_MOUSE_RELEASE:
134 if (cmd.button() == mouse_button::button3 && cmd.x < button_length
135 && cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
136 InsetNoteMailer("note", *this).showDialog(bv);
141 return InsetCollapsable::localDispatch(cmd);
146 int InsetNote::latex(Buffer const * buf, ostream & os,
147 LatexRunParams const & runparams) const
149 string const pt = params_.type;
153 os << "%\n\\begin{comment}\n"; // remember to validate
154 else if (pt == "Greyedout")
155 os << "%\n\\textcolor[gray]{0.8}{";
158 i = inset.latex(buf, os, runparams);
160 if (pt == "Comment") {
161 os << "%\n\\end{comment}\n";
163 } else if (pt == "Greyedout") {
164 os << "\\normalcolor%\n}";
171 int InsetNote::linuxdoc(Buffer const *, std::ostream &) const
177 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
180 string const pt = params_.type;
181 // incomplete, untested - MV
183 i = inset.docbook(buf, os, mixcont);
188 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
191 string const pt = params_.type;
194 i = inset.ascii(buf, os, ll);
201 void InsetNote::validate(LaTeXFeatures & features) const
203 if (params_.type == "Comment")
204 features.require("verbatim");
205 if (params_.type == "Greyedout")
206 features.require("color");
207 inset.validate(features);
212 InsetNoteMailer::InsetNoteMailer(string const & name,
214 : name_(name), inset_(inset)
219 string const InsetNoteMailer::inset2string() const
221 return params2string(name_, inset_.params());
225 string const InsetNoteMailer::params2string(string const & name,
226 InsetNoteParams const & params)
231 return STRCONV(data.str());
235 void InsetNoteMailer::string2params(string const & in,
236 InsetNoteParams & params)
238 params = InsetNoteParams();
243 istringstream data(STRCONV(in));
250 void InsetNoteParams::write(ostream & os) const
256 void InsetNoteParams::read(LyXLex & lex)
260 string token = lex.getString();
265 type = lex.getString();