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"
24 #include "support/std_sstream.h"
27 using std::istringstream;
29 using std::ostringstream;
32 void InsetNote::init()
39 InsetNote::InsetNote(BufferParams const & bp, string const & label)
40 : InsetCollapsable(bp)
48 InsetNote::InsetNote(InsetNote const & in)
49 : InsetCollapsable(in), params_(in.params_)
55 InsetNote::~InsetNote() // MV
57 InsetNoteMailer mailer("note", *this);
62 auto_ptr<InsetBase> InsetNote::clone() const
64 return auto_ptr<InsetBase>(new InsetNote(*this));
68 string const InsetNote::editMessage() const
70 return _("Opened Note Inset");
74 void InsetNote::write(Buffer const & buf, ostream & os) const
77 InsetCollapsable::write(buf, os);
81 void InsetNote::read(Buffer const & buf, LyXLex & lex)
83 InsetCollapsable::read(buf, lex);
88 void InsetNote::setButtonLabel()
90 LyXFont font(LyXFont::ALL_SANE);
94 if (params_.type == "Note") {
95 setLabel(_("LyX Note"));
96 font.setColor(LColor::note);
97 setBackgroundColor(LColor::notebg);
98 } else if (params_.type == "Comment") {
99 setLabel(_("Comment"));
100 font.setColor(LColor::comment);
101 setBackgroundColor(LColor::commentbg);
103 setLabel(_("Greyed Out"));
104 font.setColor(LColor::greyedout);
105 setBackgroundColor(LColor::greyedoutbg);
111 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
113 InsetCollapsable::metrics(mi, dim);
114 // Contrary to Greyedout, these cannot be construed as part of the
115 // running text: make them stand on their own
116 if (params_.type == "Note" || params_.type == "Comment")
118 dim.wid = mi.base.textwidth;
123 bool InsetNote::showInsetDialog(BufferView * bv) const
125 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
130 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
132 BufferView * bv = cmd.view();
134 switch (cmd.action) {
136 case LFUN_INSET_MODIFY: {
137 InsetNoteParams params;
138 InsetNoteMailer::string2params(cmd.argument, params);
139 params_.type = params.type;
141 bv->updateInset(this);
145 case LFUN_INSET_EDIT:
146 if (cmd.button() == mouse_button::button3)
148 return InsetCollapsable::localDispatch(cmd);
150 case LFUN_INSET_DIALOG_UPDATE:
151 InsetNoteMailer("note", *this).updateDialog(bv);
154 case LFUN_MOUSE_RELEASE:
155 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
156 InsetNoteMailer("note", *this).showDialog(bv);
162 return InsetCollapsable::localDispatch(cmd);
167 int InsetNote::latex(Buffer const & buf, ostream & os,
168 LatexRunParams const & runparams) const
170 string const pt = params_.type;
175 os << "%\n\\begin{comment}\n";
176 else if (pt == "Greyedout")
177 // we roll our own macro
178 os << "%\n\\begin{lyxgreyedout}\n";
181 i = inset.latex(buf, os, runparams);
183 if (pt == "Comment") {
184 os << "%\n\\end{comment}\n";
186 } else if (pt == "Greyedout") {
187 os << "%\n\\end{lyxgreyedout}\n";
194 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
196 string const pt = params_.type;
203 i = inset.linuxdoc(buf, os);
205 if (pt == "Comment") {
206 os << "\n</comment>\n";
213 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
215 string const pt = params_.type;
222 i = inset.docbook(buf, os, mixcont);
224 if (pt == "Comment") {
225 os << "\n</remark>\n";
232 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
235 string const pt = params_.type;
238 i = inset.ascii(buf, os, ll);
245 void InsetNote::validate(LaTeXFeatures & features) const
247 if (params_.type == "Comment")
248 features.require("verbatim");
249 if (params_.type == "Greyedout") {
250 features.require("color");
251 features.require("lyxgreyedout");
253 inset.validate(features);
258 InsetNoteMailer::InsetNoteMailer(string const & name,
260 : name_(name), inset_(inset)
265 string const InsetNoteMailer::inset2string(Buffer const &) const
267 return params2string(name_, inset_.params());
271 string const InsetNoteMailer::params2string(string const & name,
272 InsetNoteParams const & params)
277 return STRCONV(data.str());
281 void InsetNoteMailer::string2params(string const & in,
282 InsetNoteParams & params)
284 params = InsetNoteParams();
289 istringstream data(STRCONV(in));
296 void InsetNoteParams::write(ostream & os) const
302 void InsetNoteParams::read(LyXLex & lex)
306 string token = lex.getString();
311 type = lex.getString();