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.
17 #include "insetnote.h"
18 #include "metricsinfo.h"
23 #include "BufferView.h"
26 #include "insets/insettext.h"
27 #include "support/LOstream.h"
28 #include "support/lstrings.h"
35 void InsetNote::init()
42 InsetNote::InsetNote(BufferParams const & bp, string const & label)
43 : InsetCollapsable(bp)
51 InsetNote::InsetNote(InsetNote const & in)
52 : InsetCollapsable(in), params_(in.params_)
58 InsetNote::~InsetNote() // MV
60 InsetNoteMailer mailer("note", *this);
65 auto_ptr<InsetBase> InsetNote::clone() const
67 return auto_ptr<InsetBase>(new InsetNote(*this));
71 string const InsetNote::editMessage() const
73 return _("Opened Note Inset");
77 void InsetNote::write(Buffer const & buf, ostream & os) const
80 InsetCollapsable::write(buf, os);
84 void InsetNote::read(Buffer const & buf, LyXLex & lex)
86 InsetCollapsable::read(buf, lex);
91 void InsetNote::setButtonLabel()
93 LyXFont font(LyXFont::ALL_SANE);
97 if (params_.type == "Note") {
98 setLabel(_("LyX Note"));
99 font.setColor(LColor::note);
100 setBackgroundColor(LColor::notebg);
101 } else if (params_.type == "Comment") {
102 setLabel(_("Comment"));
103 font.setColor(LColor::comment);
104 setBackgroundColor(LColor::commentbg);
106 setLabel(_("Greyed Out"));
107 font.setColor(LColor::greyedout);
108 setBackgroundColor(LColor::greyedoutbg);
114 void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
116 InsetCollapsable::metrics(mi, dim);
117 // Contrary to Greyedout, these cannot be construed as part of the
118 // running text: make them stand on their own
119 if (params_.type == "Note" || params_.type == "Comment")
121 dim.wid = mi.base.textwidth;
126 bool InsetNote::showInsetDialog(BufferView * bv) const
128 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
133 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
135 BufferView * bv = cmd.view();
137 switch (cmd.action) {
139 case LFUN_INSET_MODIFY: {
140 InsetNoteParams params;
141 InsetNoteMailer::string2params(cmd.argument, params);
142 params_.type = params.type;
144 bv->updateInset(this);
148 case LFUN_INSET_EDIT:
149 if (cmd.button() == mouse_button::button3)
151 return InsetCollapsable::localDispatch(cmd);
153 case LFUN_INSET_DIALOG_UPDATE:
154 InsetNoteMailer("note", *this).updateDialog(bv);
157 case LFUN_MOUSE_RELEASE:
158 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
159 InsetNoteMailer("note", *this).showDialog(bv);
165 return InsetCollapsable::localDispatch(cmd);
170 int InsetNote::latex(Buffer const & buf, ostream & os,
171 LatexRunParams const & runparams) const
173 string const pt = params_.type;
178 os << "%\n\\begin{comment}\n";
179 else if (pt == "Greyedout")
180 // we roll our own macro
181 os << "%\n\\begin{lyxgreyedout}\n";
184 i = inset.latex(buf, os, runparams);
186 if (pt == "Comment") {
187 os << "%\n\\end{comment}\n";
189 } else if (pt == "Greyedout") {
190 os << "%\n\\end{lyxgreyedout}\n";
197 int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
199 string const pt = params_.type;
206 i = inset.linuxdoc(buf, os);
208 if (pt == "Comment") {
209 os << "\n</comment>\n";
216 int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
218 string const pt = params_.type;
225 i = inset.docbook(buf, os, mixcont);
227 if (pt == "Comment") {
228 os << "\n</remark>\n";
235 int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
238 string const pt = params_.type;
241 i = inset.ascii(buf, os, ll);
248 void InsetNote::validate(LaTeXFeatures & features) const
250 if (params_.type == "Comment")
251 features.require("verbatim");
252 if (params_.type == "Greyedout") {
253 features.require("color");
254 features.require("lyxgreyedout");
256 inset.validate(features);
261 InsetNoteMailer::InsetNoteMailer(string const & name,
263 : name_(name), inset_(inset)
268 string const InsetNoteMailer::inset2string(Buffer const &) const
270 return params2string(name_, inset_.params());
274 string const InsetNoteMailer::params2string(string const & name,
275 InsetNoteParams const & params)
280 return STRCONV(data.str());
284 void InsetNoteMailer::string2params(string const & in,
285 InsetNoteParams & params)
287 params = InsetNoteParams();
292 istringstream data(STRCONV(in));
299 void InsetNoteParams::write(ostream & os) const
305 void InsetNoteParams::read(LyXLex & lex)
309 string token = lex.getString();
314 type = lex.getString();