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"
31 using std::istringstream;
33 using std::ostringstream;
36 void InsetNote::init()
43 InsetNote::InsetNote(BufferParams const & bp, string const & label)
44 : InsetCollapsable(bp)
51 InsetNote::InsetNote(InsetNote const & in)
52 : InsetCollapsable(in), params_(in.params_)
58 InsetNote::~InsetNote()
60 InsetNoteMailer("note", *this).hideDialog();
64 auto_ptr<InsetBase> InsetNote::clone() const
66 return auto_ptr<InsetBase>(new InsetNote(*this));
70 string const InsetNote::editMessage() const
72 return _("Opened Note Inset");
76 void InsetNote::write(Buffer const & buf, ostream & os) const
79 InsetCollapsable::write(buf, os);
83 void InsetNote::read(Buffer const & buf, LyXLex & lex)
85 InsetCollapsable::read(buf, lex);
90 void InsetNote::setButtonLabel()
92 LyXFont font(LyXFont::ALL_SANE);
96 if (params_.type == "Note") {
97 setLabel(_("LyX Note"));
98 font.setColor(LColor::note);
99 setBackgroundColor(LColor::notebg);
100 } else if (params_.type == "Comment") {
101 setLabel(_("Comment"));
102 font.setColor(LColor::comment);
103 setBackgroundColor(LColor::commentbg);
105 setLabel(_("Greyed Out"));
106 font.setColor(LColor::greyedout);
107 setBackgroundColor(LColor::greyedoutbg);
113 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
115 InsetCollapsable::metrics(mi, dim);
116 // Contrary to Greyedout, these cannot be construed as part of the
117 // running text: make them stand on their own
118 if (params_.type == "Note" || params_.type == "Comment")
120 dim.wid = mi.base.textwidth;
125 bool InsetNote::showInsetDialog(BufferView * bv) const
127 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
132 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
134 BufferView * bv = cmd.view();
136 switch (cmd.action) {
138 case LFUN_INSET_MODIFY: {
139 InsetNoteMailer::string2params(cmd.argument, params_);
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)
281 void InsetNoteMailer::string2params(string const & in,
282 InsetNoteParams & params)
284 params = InsetNoteParams();
289 istringstream data(in);
296 void InsetNoteParams::write(ostream & os) const
302 void InsetNoteParams::read(LyXLex & lex)
306 string token = lex.getString();
311 type = lex.getString();