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"
23 #include "metricsinfo.h"
24 #include "paragraph.h"
26 #include "support/std_sstream.h"
29 using std::istringstream;
31 using std::ostringstream;
34 void InsetNote::init()
41 InsetNote::InsetNote(BufferParams const & bp, string const & label)
42 : InsetCollapsable(bp)
49 InsetNote::InsetNote(InsetNote const & in)
50 : InsetCollapsable(in), params_(in.params_)
56 InsetNote::~InsetNote()
58 InsetNoteMailer mailer("note", *this);
63 auto_ptr<InsetBase> InsetNote::clone() const
65 return auto_ptr<InsetBase>(new InsetNote(*this));
69 string const InsetNote::editMessage() const
71 return _("Opened Note Inset");
75 void InsetNote::write(Buffer const & buf, ostream & os) const
78 InsetCollapsable::write(buf, os);
82 void InsetNote::read(Buffer const & buf, LyXLex & lex)
84 InsetCollapsable::read(buf, lex);
89 void InsetNote::setButtonLabel()
91 LyXFont font(LyXFont::ALL_SANE);
95 if (params_.type == "Note") {
96 setLabel(_("LyX Note"));
97 font.setColor(LColor::note);
98 setBackgroundColor(LColor::notebg);
99 } else if (params_.type == "Comment") {
100 setLabel(_("Comment"));
101 font.setColor(LColor::comment);
102 setBackgroundColor(LColor::commentbg);
104 setLabel(_("Greyed Out"));
105 font.setColor(LColor::greyedout);
106 setBackgroundColor(LColor::greyedoutbg);
112 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
114 InsetCollapsable::metrics(mi, dim);
115 // Contrary to Greyedout, these cannot be construed as part of the
116 // running text: make them stand on their own
117 if (params_.type == "Note" || params_.type == "Comment")
119 dim.wid = mi.base.textwidth;
124 bool InsetNote::showInsetDialog(BufferView * bv) const
126 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
131 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
133 BufferView * bv = cmd.view();
135 switch (cmd.action) {
137 case LFUN_INSET_MODIFY: {
138 InsetNoteMailer::string2params(cmd.argument, params_);
140 bv->updateInset(this);
144 case LFUN_INSET_EDIT:
145 if (cmd.button() == mouse_button::button3)
147 return InsetCollapsable::localDispatch(cmd);
149 case LFUN_INSET_DIALOG_UPDATE:
150 InsetNoteMailer("note", *this).updateDialog(bv);
153 case LFUN_MOUSE_RELEASE:
154 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
155 InsetNoteMailer("note", *this).showDialog(bv);
161 return InsetCollapsable::localDispatch(cmd);
166 int InsetNote::latex(Buffer const & buf, ostream & os,
167 LatexRunParams const & runparams) const
169 string const pt = params_.type;
174 os << "%\n\\begin{comment}\n";
175 else if (pt == "Greyedout")
176 // we roll our own macro
177 os << "%\n\\begin{lyxgreyedout}\n";
180 i = inset.latex(buf, os, runparams);
182 if (pt == "Comment") {
183 os << "%\n\\end{comment}\n";
185 } else if (pt == "Greyedout") {
186 os << "%\n\\end{lyxgreyedout}\n";
193 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
195 string const pt = params_.type;
202 i = inset.linuxdoc(buf, os);
204 if (pt == "Comment") {
205 os << "\n</comment>\n";
212 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
214 string const pt = params_.type;
221 i = inset.docbook(buf, os, mixcont);
223 if (pt == "Comment") {
224 os << "\n</remark>\n";
231 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
234 string const pt = params_.type;
237 i = inset.ascii(buf, os, ll);
244 void InsetNote::validate(LaTeXFeatures & features) const
246 if (params_.type == "Comment")
247 features.require("verbatim");
248 if (params_.type == "Greyedout") {
249 features.require("color");
250 features.require("lyxgreyedout");
252 inset.validate(features);
257 InsetNoteMailer::InsetNoteMailer(string const & name,
259 : name_(name), inset_(inset)
264 string const InsetNoteMailer::inset2string(Buffer const &) const
266 return params2string(name_, inset_.params());
270 string const InsetNoteMailer::params2string(string const & name,
271 InsetNoteParams const & params)
280 void InsetNoteMailer::string2params(string const & in,
281 InsetNoteParams & params)
283 params = InsetNoteParams();
288 istringstream data(in);
295 void InsetNoteParams::write(ostream & os) const
301 void InsetNoteParams::read(LyXLex & lex)
305 string token = lex.getString();
310 type = lex.getString();