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 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
107 BufferView * bv = cmd.view();
109 switch (cmd.action) {
110 case LFUN_INSET_MODIFY:
112 InsetNoteParams params;
113 InsetNoteMailer::string2params(cmd.argument, params);
114 params_.type = params.type;
116 bv->updateInset(this);
119 case LFUN_INSET_EDIT:
120 if (cmd.button() != mouse_button::button3)
121 return InsetCollapsable::localDispatch(cmd);
123 case LFUN_INSET_DIALOG_UPDATE:
124 InsetNoteMailer("note", *this).updateDialog(bv);
126 case LFUN_MOUSE_RELEASE:
127 if (cmd.button() == mouse_button::button3 && cmd.x < button_length
128 && cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
129 InsetNoteMailer("note", *this).showDialog(bv);
134 return InsetCollapsable::localDispatch(cmd);
139 int InsetNote::latex(Buffer const * buf, ostream & os,
140 LatexRunParams const & runparams) const
142 string const pt = params_.type;
145 if (pt == "Comment") os << "%\n\\begin{comment}\n"; // remember to validate
146 if (pt == "Greyedout") os << "%\n\\textcolor[gray]{0.8}{";
148 i = inset.latex(buf, os, runparams);
150 if (pt == "Comment") {
151 os << "%\n\\end{comment}\n";
154 if (pt == "Greyedout") {
162 int InsetNote::linuxdoc(Buffer const *, std::ostream &) const
168 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
171 string const pt = params_.type;
172 // incomplete, untested - MV
174 i = inset.docbook(buf, os, mixcont);
179 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
182 string const pt = params_.type;
185 i = inset.ascii(buf, os, ll);
192 void InsetNote::validate(LaTeXFeatures & features) const
194 if (params_.type == "Comment")
195 features.require("verbatim");
196 if (params_.type == "Greyedout")
197 features.require("color");
198 inset.validate(features);
203 InsetNoteMailer::InsetNoteMailer(string const & name,
205 : name_(name), inset_(inset)
210 string const InsetNoteMailer::inset2string() const
212 return params2string(name_, inset_.params());
216 string const InsetNoteMailer::params2string(string const & name,
217 InsetNoteParams const & params)
222 return STRCONV(data.str());
226 void InsetNoteMailer::string2params(string const & in,
227 InsetNoteParams & params)
229 params = InsetNoteParams();
234 istringstream data(STRCONV(in));
241 void InsetNoteParams::write(ostream & os) const
247 void InsetNoteParams::read(LyXLex & lex)
251 string token = lex.getString();
256 type = lex.getString();