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 "dispatchresult.h"
19 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
24 #include "metricsinfo.h"
25 #include "paragraph.h"
27 #include "support/std_sstream.h"
32 using std::istringstream;
34 using std::ostringstream;
37 void InsetNote::init()
44 InsetNote::InsetNote(BufferParams const & bp, string const & label)
45 : InsetCollapsable(bp)
52 InsetNote::InsetNote(InsetNote const & in)
53 : InsetCollapsable(in), params_(in.params_)
59 InsetNote::~InsetNote()
61 InsetNoteMailer("note", *this).hideDialog();
65 auto_ptr<InsetBase> InsetNote::clone() const
67 return auto_ptr<InsetBase>(new InsetNote(*this));
71 string const InsetNote::editMessage() const
73 return _("Opened Note Inset");
77 void InsetNote::write(Buffer const & buf, ostream & os) const
80 InsetCollapsable::write(buf, os);
84 void InsetNote::read(Buffer const & buf, LyXLex & lex)
86 InsetCollapsable::read(buf, lex);
91 void InsetNote::setButtonLabel()
93 LyXFont font(LyXFont::ALL_SANE);
97 if (params_.type == "Note") {
98 setLabel(_("LyX Note"));
99 font.setColor(LColor::note);
100 setBackgroundColor(LColor::notebg);
101 } else if (params_.type == "Comment") {
102 setLabel(_("Comment"));
103 font.setColor(LColor::comment);
104 setBackgroundColor(LColor::commentbg);
106 setLabel(_("Greyed Out"));
107 font.setColor(LColor::greyedout);
108 setBackgroundColor(LColor::greyedoutbg);
114 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
116 InsetCollapsable::metrics(mi, dim);
117 // Contrary to Greyedout, these cannot be construed as part of the
118 // running text: make them stand on their own
119 if (params_.type == "Note" || params_.type == "Comment")
121 dim.wid = mi.base.textwidth;
126 bool InsetNote::showInsetDialog(BufferView * bv) const
128 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
134 InsetNote::priv_dispatch(FuncRequest const & cmd,
135 idx_type & idx, pos_type & pos)
137 BufferView * bv = cmd.view();
139 switch (cmd.action) {
141 case LFUN_INSET_MODIFY: {
142 InsetNoteMailer::string2params(cmd.argument, params_);
144 bv->updateInset(this);
145 return DispatchResult(true, true);
148 case LFUN_INSET_DIALOG_UPDATE:
149 InsetNoteMailer("note", *this).updateDialog(bv);
150 return DispatchResult(true, true);
152 case LFUN_MOUSE_RELEASE:
153 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
154 InsetNoteMailer("note", *this).showDialog(bv);
155 return DispatchResult(true, true);
160 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
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,
193 LatexRunParams const & runparams) const
195 string const pt = params_.type;
202 i = inset.linuxdoc(buf, os, runparams);
204 if (pt == "Comment") {
205 os << "\n</comment>\n";
212 int InsetNote::docbook(Buffer const & buf, std::ostream & os,
213 LatexRunParams const & runparams) const
215 string const pt = params_.type;
222 i = inset.docbook(buf, os, runparams);
224 if (pt == "Comment") {
225 os << "\n</remark>\n";
232 int InsetNote::ascii(Buffer const & buf, std::ostream & os,
233 LatexRunParams const & runparams) const
236 string const pt = params_.type;
239 i = inset.ascii(buf, os, runparams);
246 void InsetNote::validate(LaTeXFeatures & features) const
248 if (params_.type == "Comment")
249 features.require("verbatim");
250 if (params_.type == "Greyedout") {
251 features.require("color");
252 features.require("lyxgreyedout");
254 inset.validate(features);
259 InsetNoteMailer::InsetNoteMailer(string const & name,
261 : name_(name), inset_(inset)
266 string const InsetNoteMailer::inset2string(Buffer const &) const
268 return params2string(name_, inset_.params());
272 string const InsetNoteMailer::params2string(string const & name,
273 InsetNoteParams const & params)
282 void InsetNoteMailer::string2params(string const & in,
283 InsetNoteParams & params)
285 params = InsetNoteParams();
290 istringstream data(in);
297 void InsetNoteParams::write(ostream & os) const
303 void InsetNoteParams::read(LyXLex & lex)
307 string token = lex.getString();
312 type = lex.getString();