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"
17 #include "BufferView.h"
18 #include "funcrequest.h"
20 #include "LaTeXFeatures.h"
22 #include "metricsinfo.h"
30 void InsetNote::init()
37 InsetNote::InsetNote(BufferParams const & bp, string const & label)
38 : InsetCollapsable(bp)
46 InsetNote::InsetNote(InsetNote const & in)
47 : InsetCollapsable(in), params_(in.params_)
53 InsetNote::~InsetNote() // MV
55 InsetNoteMailer mailer("note", *this);
60 auto_ptr<InsetBase> InsetNote::clone() const
62 return auto_ptr<InsetBase>(new InsetNote(*this));
66 string const InsetNote::editMessage() const
68 return _("Opened Note Inset");
72 void InsetNote::write(Buffer const & buf, ostream & os) const
75 InsetCollapsable::write(buf, os);
79 void InsetNote::read(Buffer const & buf, LyXLex & lex)
81 InsetCollapsable::read(buf, lex);
86 void InsetNote::setButtonLabel()
88 LyXFont font(LyXFont::ALL_SANE);
92 if (params_.type == "Note") {
93 setLabel(_("LyX Note"));
94 font.setColor(LColor::note);
95 setBackgroundColor(LColor::notebg);
96 } else if (params_.type == "Comment") {
97 setLabel(_("Comment"));
98 font.setColor(LColor::comment);
99 setBackgroundColor(LColor::commentbg);
101 setLabel(_("Greyed Out"));
102 font.setColor(LColor::greyedout);
103 setBackgroundColor(LColor::greyedoutbg);
109 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
111 InsetCollapsable::metrics(mi, dim);
112 // Contrary to Greyedout, these cannot be construed as part of the
113 // running text: make them stand on their own
114 if (params_.type == "Note" || params_.type == "Comment")
116 dim.wid = mi.base.textwidth;
121 bool InsetNote::showInsetDialog(BufferView * bv) const
123 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
128 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
130 BufferView * bv = cmd.view();
132 switch (cmd.action) {
134 case LFUN_INSET_MODIFY: {
135 InsetNoteParams params;
136 InsetNoteMailer::string2params(cmd.argument, params);
137 params_.type = params.type;
139 bv->updateInset(this);
143 case LFUN_INSET_EDIT:
144 if (cmd.button() == mouse_button::button3)
146 return InsetCollapsable::localDispatch(cmd);
148 case LFUN_INSET_DIALOG_UPDATE:
149 InsetNoteMailer("note", *this).updateDialog(bv);
152 case LFUN_MOUSE_RELEASE:
153 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
154 InsetNoteMailer("note", *this).showDialog(bv);
160 return InsetCollapsable::localDispatch(cmd);
165 int InsetNote::latex(Buffer const & buf, ostream & os,
166 LatexRunParams const & runparams) const
168 string const pt = params_.type;
173 os << "%\n\\begin{comment}\n";
174 else if (pt == "Greyedout")
175 // we roll our own macro
176 os << "%\n\\begin{lyxgreyedout}\n";
179 i = inset.latex(buf, os, runparams);
181 if (pt == "Comment") {
182 os << "%\n\\end{comment}\n";
184 } else if (pt == "Greyedout") {
185 os << "%\n\\end{lyxgreyedout}\n";
192 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
194 string const pt = params_.type;
201 i = inset.linuxdoc(buf, os);
203 if (pt == "Comment") {
204 os << "\n</comment>\n";
211 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
213 string const pt = params_.type;
220 i = inset.docbook(buf, os, mixcont);
222 if (pt == "Comment") {
223 os << "\n</remark>\n";
230 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
233 string const pt = params_.type;
236 i = inset.ascii(buf, os, ll);
243 void InsetNote::validate(LaTeXFeatures & features) const
245 if (params_.type == "Comment")
246 features.require("verbatim");
247 if (params_.type == "Greyedout") {
248 features.require("color");
249 features.require("lyxgreyedout");
251 inset.validate(features);
256 InsetNoteMailer::InsetNoteMailer(string const & name,
258 : name_(name), inset_(inset)
263 string const InsetNoteMailer::inset2string(Buffer const &) const
265 return params2string(name_, inset_.params());
269 string const InsetNoteMailer::params2string(string const & name,
270 InsetNoteParams const & params)
275 return STRCONV(data.str());
279 void InsetNoteMailer::string2params(string const & in,
280 InsetNoteParams & params)
282 params = InsetNoteParams();
287 istringstream data(STRCONV(in));
294 void InsetNoteParams::write(ostream & os) const
300 void InsetNoteParams::read(LyXLex & lex)
304 string token = lex.getString();
309 type = lex.getString();