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"
26 #include "metricsinfo.h"
27 #include "paragraph.h"
29 #include "frontends/Alert.h"
30 #include "frontends/LyXView.h"
32 #include "support/std_sstream.h"
40 using std::istringstream;
42 using std::ostringstream;
50 LyXFont font(LyXFont::ALL_SANE);
53 font.setColor(LColor::latex);
60 InsetERT::InsetERT(BufferParams const & bp, CollapseStatus status)
61 : InsetCollapsable(bp, status)
67 InsetERT::InsetERT(InsetERT const & in)
68 : InsetCollapsable(in)
74 auto_ptr<InsetBase> InsetERT::clone() const
76 return auto_ptr<InsetBase>(new InsetERT(*this));
80 InsetERT::InsetERT(BufferParams const & bp,
81 Language const * l, string const & contents, CollapseStatus status)
82 : InsetCollapsable(bp, status)
84 LyXFont font(LyXFont::ALL_INHERIT, l);
85 string::const_iterator cit = contents.begin();
86 string::const_iterator end = contents.end();
88 for (; cit != end; ++cit)
89 paragraphs().begin()->insertChar(pos++, *cit, font);
91 // the init has to be after the initialization of the paragraph
92 // because of the label settings (draw_label for ert insets).
99 InsetERTMailer(*this).hideDialog();
103 void InsetERT::write(Buffer const & buf, ostream & os) const
106 InsetCollapsable::write(buf, os);
110 string const InsetERT::editMessage() const
112 return _("Opened ERT Inset");
116 int InsetERT::latex(Buffer const &, ostream & os,
117 OutputParams const &) const
119 ParagraphList::iterator par = paragraphs().begin();
120 ParagraphList::iterator end = paragraphs().end();
124 pos_type siz = par->size();
125 for (pos_type i = 0; i < siz; ++i) {
126 // ignore all struck out text
127 if (isDeletedText(*par, i))
130 if (par->isNewline(i)) {
134 os << par->getChar(i);
148 int InsetERT::plaintext(Buffer const &, ostream &,
149 OutputParams const & /*runparams*/) const
155 int InsetERT::linuxdoc(Buffer const &, ostream & os,
156 OutputParams const &) const
158 ParagraphList::iterator par = paragraphs().begin();
159 ParagraphList::iterator end = paragraphs().end();
163 pos_type siz = par->size();
164 for (pos_type i = 0; i < siz; ++i) {
165 if (par->isNewline(i)) {
169 os << par->getChar(i);
183 int InsetERT::docbook(Buffer const &, ostream & os,
184 OutputParams const &) const
186 ParagraphList::iterator par = paragraphs().begin();
187 ParagraphList::iterator end = paragraphs().end();
191 pos_type siz = par->size();
192 for (pos_type i = 0; i < siz; ++i) {
193 if (par->isNewline(i)) {
197 os << par->getChar(i);
211 void InsetERT::priv_dispatch(LCursor & cur, FuncRequest & cmd)
213 //lyxerr << "\nInsetERT::priv_dispatch (begin): cmd: " << cmd << endl;
214 switch (cmd.action) {
216 case LFUN_INSET_MODIFY: {
217 InsetCollapsable::CollapseStatus st;
218 InsetERTMailer::string2params(cmd.argument, st);
229 case LFUN_FREEFONT_APPLY:
230 case LFUN_FREEFONT_UPDATE:
237 case LFUN_FONT_STATE:
242 InsetCollapsable::priv_dispatch(cur, cmd);
248 void InsetERT::setButtonLabel()
250 setLabel(status() == Collapsed ? getNewLabel(_("ERT")) : _("ERT"));
254 bool InsetERT::insetAllowed(InsetOld::Code code) const
256 return code == InsetOld::NEWLINE_CODE;
260 void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
262 LyXFont tmpfont = mi.base.font;
263 getDrawFont(mi.base.font);
264 InsetCollapsable::metrics(mi, dim);
265 mi.base.font = tmpfont;
270 void InsetERT::draw(PainterInfo & pi, int x, int y) const
272 LyXFont tmpfont = pi.base.font;
273 getDrawFont(pi.base.font);
274 InsetCollapsable::draw(pi, x, y);
275 pi.base.font = tmpfont;
279 bool InsetERT::showInsetDialog(BufferView * bv) const
281 InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
286 void InsetERT::getDrawFont(LyXFont & font) const
288 font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
289 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
290 font.setColor(LColor::latex);
294 string const InsetERTMailer::name_("ert");
296 InsetERTMailer::InsetERTMailer(InsetERT & inset)
301 string const InsetERTMailer::inset2string(Buffer const &) const
303 return params2string(inset_.status());
307 void InsetERTMailer::string2params(string const & in,
308 InsetCollapsable::CollapseStatus & status)
310 status = InsetCollapsable::Collapsed;
314 istringstream data(in);
321 return print_mailer_error("InsetERTMailer", in, 1, name_);
326 status = static_cast<InsetCollapsable::CollapseStatus>(s);
331 InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
334 data << name_ << ' ' << status;