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);
133 InsetNote::priv_dispatch(FuncRequest const & cmd,
134 idx_type & idx, pos_type & pos)
136 BufferView * bv = cmd.view();
138 switch (cmd.action) {
140 case LFUN_INSET_MODIFY: {
141 InsetNoteMailer::string2params(cmd.argument, params_);
143 bv->updateInset(this);
147 case LFUN_INSET_EDIT:
148 if (cmd.button() == mouse_button::button3)
150 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
152 case LFUN_INSET_DIALOG_UPDATE:
153 InsetNoteMailer("note", *this).updateDialog(bv);
156 case LFUN_MOUSE_RELEASE:
157 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
158 InsetNoteMailer("note", *this).showDialog(bv);
164 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
169 int InsetNote::latex(Buffer const & buf, ostream & os,
170 LatexRunParams const & runparams) const
172 string const pt = params_.type;
177 os << "%\n\\begin{comment}\n";
178 else if (pt == "Greyedout")
179 // we roll our own macro
180 os << "%\n\\begin{lyxgreyedout}\n";
183 i = inset.latex(buf, os, runparams);
185 if (pt == "Comment") {
186 os << "%\n\\end{comment}\n";
188 } else if (pt == "Greyedout") {
189 os << "%\n\\end{lyxgreyedout}\n";
196 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
198 string const pt = params_.type;
205 i = inset.linuxdoc(buf, os);
207 if (pt == "Comment") {
208 os << "\n</comment>\n";
215 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
217 string const pt = params_.type;
224 i = inset.docbook(buf, os, mixcont);
226 if (pt == "Comment") {
227 os << "\n</remark>\n";
234 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
237 string const pt = params_.type;
240 i = inset.ascii(buf, os, ll);
247 void InsetNote::validate(LaTeXFeatures & features) const
249 if (params_.type == "Comment")
250 features.require("verbatim");
251 if (params_.type == "Greyedout") {
252 features.require("color");
253 features.require("lyxgreyedout");
255 inset.validate(features);
260 InsetNoteMailer::InsetNoteMailer(string const & name,
262 : name_(name), inset_(inset)
267 string const InsetNoteMailer::inset2string(Buffer const &) const
269 return params2string(name_, inset_.params());
273 string const InsetNoteMailer::params2string(string const & name,
274 InsetNoteParams const & params)
283 void InsetNoteMailer::string2params(string const & in,
284 InsetNoteParams & params)
286 params = InsetNoteParams();
291 istringstream data(in);
298 void InsetNoteParams::write(ostream & os) const
304 void InsetNoteParams::read(LyXLex & lex)
308 string token = lex.getString();
313 type = lex.getString();