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"
16 #include "insettext.h"
19 #include "BufferView.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
28 #include "metricsinfo.h"
29 #include "support/LOstream.h"
30 #include "support/lstrings.h"
38 void InsetNote::init()
45 InsetNote::InsetNote(BufferParams const & bp, string const & label)
46 : InsetCollapsable(bp)
54 InsetNote::InsetNote(InsetNote const & in)
55 : InsetCollapsable(in), params_(in.params_)
61 InsetNote::~InsetNote() // MV
63 InsetNoteMailer mailer("note", *this);
68 auto_ptr<InsetBase> InsetNote::clone() const
70 return auto_ptr<InsetBase>(new InsetNote(*this));
74 string const InsetNote::editMessage() const
76 return _("Opened Note Inset");
80 void InsetNote::write(Buffer const & buf, ostream & os) const
83 InsetCollapsable::write(buf, os);
87 void InsetNote::read(Buffer const & buf, LyXLex & lex)
89 InsetCollapsable::read(buf, lex);
94 void InsetNote::setButtonLabel()
96 LyXFont font(LyXFont::ALL_SANE);
100 if (params_.type == "Note") {
101 setLabel(_("LyX Note"));
102 font.setColor(LColor::note);
103 setBackgroundColor(LColor::notebg);
104 } else if (params_.type == "Comment") {
105 setLabel(_("Comment"));
106 font.setColor(LColor::comment);
107 setBackgroundColor(LColor::commentbg);
109 setLabel(_("Greyed Out"));
110 font.setColor(LColor::greyedout);
111 setBackgroundColor(LColor::greyedoutbg);
117 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
119 InsetCollapsable::metrics(mi, dim);
120 // Contrary to Greyedout, these cannot be construed as part of the
121 // running text: make them stand on their own
122 if (params_.type == "Note" || params_.type == "Comment")
124 dim.wid = mi.base.textwidth;
129 bool InsetNote::showInsetDialog(BufferView * bv) const
131 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
136 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
138 BufferView * bv = cmd.view();
140 switch (cmd.action) {
142 case LFUN_INSET_MODIFY: {
143 InsetNoteParams params;
144 InsetNoteMailer::string2params(cmd.argument, params);
145 params_.type = params.type;
147 bv->updateInset(this);
151 case LFUN_INSET_EDIT:
152 if (cmd.button() == mouse_button::button3)
154 return InsetCollapsable::localDispatch(cmd);
156 case LFUN_INSET_DIALOG_UPDATE:
157 InsetNoteMailer("note", *this).updateDialog(bv);
160 case LFUN_MOUSE_RELEASE:
161 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
162 InsetNoteMailer("note", *this).showDialog(bv);
168 return InsetCollapsable::localDispatch(cmd);
173 int InsetNote::latex(Buffer const & buf, ostream & os,
174 LatexRunParams const & runparams) const
176 string const pt = params_.type;
181 os << "%\n\\begin{comment}\n";
182 else if (pt == "Greyedout")
183 // we roll our own macro
184 os << "%\n\\begin{lyxgreyedout}\n";
187 i = inset.latex(buf, os, runparams);
189 if (pt == "Comment") {
190 os << "%\n\\end{comment}\n";
192 } else if (pt == "Greyedout") {
193 os << "%\n\\end{lyxgreyedout}\n";
200 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
202 string const pt = params_.type;
209 i = inset.linuxdoc(buf, os);
211 if (pt == "Comment") {
212 os << "\n</comment>\n";
219 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
221 string const pt = params_.type;
228 i = inset.docbook(buf, os, mixcont);
230 if (pt == "Comment") {
231 os << "\n</remark>\n";
238 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
241 string const pt = params_.type;
244 i = inset.ascii(buf, os, ll);
251 void InsetNote::validate(LaTeXFeatures & features) const
253 if (params_.type == "Comment")
254 features.require("verbatim");
255 if (params_.type == "Greyedout") {
256 features.require("color");
257 features.require("lyxgreyedout");
259 inset.validate(features);
264 InsetNoteMailer::InsetNoteMailer(string const & name,
266 : name_(name), inset_(inset)
271 string const InsetNoteMailer::inset2string(Buffer const &) const
273 return params2string(name_, inset_.params());
277 string const InsetNoteMailer::params2string(string const & name,
278 InsetNoteParams const & params)
283 return STRCONV(data.str());
287 void InsetNoteMailer::string2params(string const & in,
288 InsetNoteParams & params)
290 params = InsetNoteParams();
295 istringstream data(STRCONV(in));
302 void InsetNoteParams::write(ostream & os) const
308 void InsetNoteParams::read(LyXLex & lex)
312 string token = lex.getString();
317 type = lex.getString();