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 *, string const & contents, CollapseStatus status)
83 : InsetCollapsable(bp, status)
85 //LyXFont font(LyXFont::ALL_INHERIT, lang);
88 string::const_iterator cit = contents.begin();
89 string::const_iterator end = contents.end();
91 for (; cit != end; ++cit)
92 paragraphs().begin()->insertChar(pos++, *cit, font);
94 // the init has to be after the initialization of the paragraph
95 // because of the label settings (draw_label for ert insets).
100 InsetERT::~InsetERT()
102 InsetERTMailer(*this).hideDialog();
106 void InsetERT::write(Buffer const & buf, ostream & os) const
109 InsetCollapsable::write(buf, os);
113 string const InsetERT::editMessage() const
115 return _("Opened ERT Inset");
119 int InsetERT::latex(Buffer const &, ostream & os,
120 OutputParams const &) const
122 ParagraphList::const_iterator par = paragraphs().begin();
123 ParagraphList::const_iterator end = paragraphs().end();
127 pos_type siz = par->size();
128 for (pos_type i = 0; i < siz; ++i) {
129 // ignore all struck out text
130 if (isDeletedText(*par, i))
133 if (par->isNewline(i)) {
137 os << par->getChar(i);
151 int InsetERT::plaintext(Buffer const &, ostream &,
152 OutputParams const & /*runparams*/) const
158 int InsetERT::linuxdoc(Buffer const &, ostream & os,
159 OutputParams const &) const
161 ParagraphList::const_iterator par = paragraphs().begin();
162 ParagraphList::const_iterator end = paragraphs().end();
166 pos_type siz = par->size();
167 for (pos_type i = 0; i < siz; ++i) {
168 if (par->isNewline(i)) {
172 os << par->getChar(i);
186 int InsetERT::docbook(Buffer const &, ostream & os,
187 OutputParams const &) const
189 ParagraphList::const_iterator par = paragraphs().begin();
190 ParagraphList::const_iterator end = paragraphs().end();
194 pos_type siz = par->size();
195 for (pos_type i = 0; i < siz; ++i) {
196 if (par->isNewline(i)) {
200 os << par->getChar(i);
214 void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd)
216 //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
217 switch (cmd.action) {
219 case LFUN_INSET_MODIFY: {
220 InsetCollapsable::CollapseStatus st;
221 InsetERTMailer::string2params(cmd.argument, st);
227 InsetCollapsable::doDispatch(cur, cmd);
233 bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd,
234 FuncStatus & status) const
236 switch (cmd.action) {
243 case LFUN_FREEFONT_APPLY:
244 case LFUN_FREEFONT_UPDATE:
251 case LFUN_FONT_STATE:
253 status.enabled(false);
257 return InsetCollapsable::getStatus(cur, cmd, status);
262 void InsetERT::setButtonLabel()
264 setLabel(status() == Collapsed ? getNewLabel(_("ERT")) : _("ERT"));
268 bool InsetERT::insetAllowed(InsetBase::Code code) const
270 return code == InsetBase::NEWLINE_CODE;
274 void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
276 LyXFont tmpfont = mi.base.font;
277 getDrawFont(mi.base.font);
278 InsetCollapsable::metrics(mi, dim);
279 mi.base.font = tmpfont;
284 void InsetERT::draw(PainterInfo & pi, int x, int y) const
286 LyXFont tmpfont = pi.base.font;
287 getDrawFont(pi.base.font);
288 InsetCollapsable::draw(pi, x, y);
289 pi.base.font = tmpfont;
293 bool InsetERT::showInsetDialog(BufferView * bv) const
295 InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
300 void InsetERT::getDrawFont(LyXFont & font) const
302 font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
303 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
304 font.setColor(LColor::latex);
308 string const InsetERTMailer::name_("ert");
310 InsetERTMailer::InsetERTMailer(InsetERT & inset)
315 string const InsetERTMailer::inset2string(Buffer const &) const
317 return params2string(inset_.status());
321 void InsetERTMailer::string2params(string const & in,
322 InsetCollapsable::CollapseStatus & status)
324 status = InsetCollapsable::Collapsed;
328 istringstream data(in);
335 return print_mailer_error("InsetERTMailer", in, 1, name_);
340 status = static_cast<InsetCollapsable::CollapseStatus>(s);
345 InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
348 data << name_ << ' ' << status;