3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
17 #include "bufferparams.h"
18 #include "BufferView.h"
20 #include "dispatchresult.h"
21 #include "funcrequest.h"
22 #include "FuncStatus.h"
27 #include "metricsinfo.h"
28 #include "paragraph.h"
30 #include "frontends/Alert.h"
31 #include "frontends/LyXView.h"
41 using std::istringstream;
43 using std::ostringstream;
51 LyXFont font(LyXFont::ALL_SANE);
54 font.setColor(LColor::latex);
61 InsetERT::InsetERT(BufferParams const & bp, CollapseStatus status)
62 : InsetCollapsable(bp, status)
68 InsetERT::InsetERT(InsetERT const & in)
69 : InsetCollapsable(in)
75 auto_ptr<InsetBase> InsetERT::doClone() const
77 return auto_ptr<InsetBase>(new InsetERT(*this));
81 InsetERT::InsetERT(BufferParams const & bp,
82 Language const * l, string const & contents, CollapseStatus status)
83 : InsetCollapsable(bp, status)
85 LyXFont font(LyXFont::ALL_INHERIT, l);
86 string::const_iterator cit = contents.begin();
87 string::const_iterator end = contents.end();
89 for (; cit != end; ++cit)
90 paragraphs().begin()->insertChar(pos++, *cit, font);
92 // the init has to be after the initialization of the paragraph
93 // because of the label settings (draw_label for ert insets).
100 InsetERTMailer(*this).hideDialog();
104 void InsetERT::write(Buffer const & buf, ostream & os) const
107 InsetCollapsable::write(buf, os);
111 string const InsetERT::editMessage() const
113 return _("Opened ERT Inset");
117 int InsetERT::latex(Buffer const &, ostream & os,
118 OutputParams const &) const
120 ParagraphList::const_iterator par = paragraphs().begin();
121 ParagraphList::const_iterator end = paragraphs().end();
125 pos_type siz = par->size();
126 for (pos_type i = 0; i < siz; ++i) {
127 // ignore all struck out text
128 if (isDeletedText(*par, i))
131 if (par->isNewline(i)) {
135 os << par->getChar(i);
149 int InsetERT::plaintext(Buffer const &, ostream &,
150 OutputParams const & /*runparams*/) const
156 int InsetERT::linuxdoc(Buffer const &, ostream & os,
157 OutputParams const &) const
159 ParagraphList::const_iterator par = paragraphs().begin();
160 ParagraphList::const_iterator end = paragraphs().end();
164 pos_type siz = par->size();
165 for (pos_type i = 0; i < siz; ++i) {
166 if (par->isNewline(i)) {
170 os << par->getChar(i);
184 int InsetERT::docbook(Buffer const &, ostream & os,
185 OutputParams const &) const
187 ParagraphList::const_iterator par = paragraphs().begin();
188 ParagraphList::const_iterator end = paragraphs().end();
192 pos_type siz = par->size();
193 for (pos_type i = 0; i < siz; ++i) {
194 if (par->isNewline(i)) {
198 os << par->getChar(i);
212 void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd)
214 //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
215 switch (cmd.action) {
217 case LFUN_INSET_MODIFY: {
218 InsetCollapsable::CollapseStatus st;
219 InsetERTMailer::string2params(cmd.argument, st);
225 InsetCollapsable::doDispatch(cur, cmd);
231 bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd,
232 FuncStatus & status) const
234 switch (cmd.action) {
241 case LFUN_FREEFONT_APPLY:
242 case LFUN_FREEFONT_UPDATE:
249 case LFUN_FONT_STATE:
251 status.enabled(false);
255 return InsetCollapsable::getStatus(cur, cmd, status);
260 void InsetERT::setButtonLabel()
262 setLabel(status() == Collapsed ? getNewLabel(_("P-ERT")) : _("P-ERT"));
266 bool InsetERT::insetAllowed(InsetBase::Code code) const
268 return code == InsetBase::NEWLINE_CODE;
272 void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
274 LyXFont tmpfont = mi.base.font;
275 getDrawFont(mi.base.font);
276 InsetCollapsable::metrics(mi, dim);
277 mi.base.font = tmpfont;
282 void InsetERT::draw(PainterInfo & pi, int x, int y) const
284 LyXFont tmpfont = pi.base.font;
285 getDrawFont(pi.base.font);
286 InsetCollapsable::draw(pi, x, y);
287 pi.base.font = tmpfont;
291 bool InsetERT::showInsetDialog(BufferView * bv) const
293 InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
298 void InsetERT::getDrawFont(LyXFont & font) const
300 font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
301 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
302 font.setColor(LColor::latex);
306 string const InsetERTMailer::name_("ert");
308 InsetERTMailer::InsetERTMailer(InsetERT & inset)
313 string const InsetERTMailer::inset2string(Buffer const &) const
315 return params2string(inset_.status());
319 void InsetERTMailer::string2params(string const & in,
320 InsetCollapsable::CollapseStatus & status)
322 status = InsetCollapsable::Collapsed;
326 istringstream data(in);
333 return print_mailer_error("InsetERTMailer", in, 1, name_);
338 status = static_cast<InsetCollapsable::CollapseStatus>(s);
343 InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
346 data << name_ << ' ' << status;