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"
27 #include "metricsinfo.h"
28 #include "support/LOstream.h"
29 #include "support/lstrings.h"
37 void InsetNote::init()
44 InsetNote::InsetNote(BufferParams const & bp, string const & label)
45 : InsetCollapsable(bp)
53 InsetNote::InsetNote(InsetNote const & in)
54 : InsetCollapsable(in), params_(in.params_)
60 InsetNote::~InsetNote() // MV
62 InsetNoteMailer mailer("note", *this);
67 auto_ptr<InsetBase> InsetNote::clone() const
69 return auto_ptr<InsetBase>(new InsetNote(*this));
73 string const InsetNote::editMessage() const
75 return _("Opened Note Inset");
79 void InsetNote::write(Buffer const & buf, ostream & os) const
82 InsetCollapsable::write(buf, os);
86 void InsetNote::read(Buffer const & buf, LyXLex & lex)
88 InsetCollapsable::read(buf, lex);
93 void InsetNote::setButtonLabel()
95 LyXFont font(LyXFont::ALL_SANE);
99 if (params_.type == "Note") {
100 setLabel(_("LyX Note"));
101 font.setColor(LColor::note);
102 setBackgroundColor(LColor::notebg);
103 } else if (params_.type == "Comment") {
104 setLabel(_("Comment"));
105 font.setColor(LColor::comment);
106 setBackgroundColor(LColor::commentbg);
108 setLabel(_("Greyed Out"));
109 font.setColor(LColor::greyedout);
110 setBackgroundColor(LColor::greyedoutbg);
116 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
118 InsetCollapsable::metrics(mi, dim);
119 // Contrary to Greyedout, these cannot be construed as part of the
120 // running text: make them stand on their own
121 if (params_.type == "Note" || params_.type == "Comment")
123 dim.wid = mi.base.textwidth;
128 bool InsetNote::showInsetDialog(BufferView * bv) const
130 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
135 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
137 BufferView * bv = cmd.view();
139 switch (cmd.action) {
141 case LFUN_INSET_MODIFY: {
142 InsetNoteParams params;
143 InsetNoteMailer::string2params(cmd.argument, params);
144 params_.type = params.type;
146 bv->updateInset(this);
150 case LFUN_INSET_EDIT:
151 if (cmd.button() == mouse_button::button3)
153 return InsetCollapsable::localDispatch(cmd);
155 case LFUN_INSET_DIALOG_UPDATE:
156 InsetNoteMailer("note", *this).updateDialog(bv);
159 case LFUN_MOUSE_RELEASE:
160 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
161 InsetNoteMailer("note", *this).showDialog(bv);
167 return InsetCollapsable::localDispatch(cmd);
172 int InsetNote::latex(Buffer const & buf, ostream & os,
173 LatexRunParams const & runparams) const
175 string const pt = params_.type;
180 os << "%\n\\begin{comment}\n";
181 else if (pt == "Greyedout")
182 // we roll our own macro
183 os << "%\n\\begin{lyxgreyedout}\n";
186 i = inset.latex(buf, os, runparams);
188 if (pt == "Comment") {
189 os << "%\n\\end{comment}\n";
191 } else if (pt == "Greyedout") {
192 os << "%\n\\end{lyxgreyedout}\n";
199 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
201 string const pt = params_.type;
208 i = inset.linuxdoc(buf, os);
210 if (pt == "Comment") {
211 os << "\n</comment>\n";
218 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
220 string const pt = params_.type;
227 i = inset.docbook(buf, os, mixcont);
229 if (pt == "Comment") {
230 os << "\n</remark>\n";
237 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
240 string const pt = params_.type;
243 i = inset.ascii(buf, os, ll);
250 void InsetNote::validate(LaTeXFeatures & features) const
252 if (params_.type == "Comment")
253 features.require("verbatim");
254 if (params_.type == "Greyedout") {
255 features.require("color");
256 features.require("lyxgreyedout");
258 inset.validate(features);
263 InsetNoteMailer::InsetNoteMailer(string const & name,
265 : name_(name), inset_(inset)
270 string const InsetNoteMailer::inset2string(Buffer const &) const
272 return params2string(name_, inset_.params());
276 string const InsetNoteMailer::params2string(string const & name,
277 InsetNoteParams const & params)
282 return STRCONV(data.str());
286 void InsetNoteMailer::string2params(string const & in,
287 InsetNoteParams & params)
289 params = InsetNoteParams();
294 istringstream data(STRCONV(in));
301 void InsetNoteParams::write(ostream & os) const
307 void InsetNoteParams::read(LyXLex & lex)
311 string token = lex.getString();
316 type = lex.getString();