+
+
+bool InsetERT::checkInsertChar(LyXFont & /* font */)
+{
+#ifdef SET_HARD_FONT
+ LyXFont f(LyXFont::ALL_INHERIT, latex_language);
+ font = f;
+ font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+ font.setColor(LColor::latex);
+#endif
+ return true;
+}
+
+
+int InsetERT::ascent(BufferView * bv, LyXFont const & font) const
+{
+ if (!inlined())
+ return InsetCollapsable::ascent(bv, font);
+
+ return inset.ascent(bv, font);
+}
+
+
+int InsetERT::descent(BufferView * bv, LyXFont const & font) const
+{
+ if (!inlined())
+ return InsetCollapsable::descent(bv, font);
+
+ return inset.descent(bv, font);
+}
+
+
+int InsetERT::width(BufferView * bv, LyXFont const & font) const
+{
+ if (!inlined())
+ return InsetCollapsable::width(bv, font);
+
+ return inset.width(bv, font);
+}
+
+
+void InsetERT::draw(BufferView * bv, LyXFont const & f,
+ int baseline, float & x) const
+{
+ InsetCollapsable::draw(bv, f, baseline, x, inlined());
+}
+
+
+void InsetERT::set_latex_font(BufferView * /* bv */)
+{
+#ifdef SET_HARD_FONT
+ LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+
+ font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+ font.setColor(LColor::latex);
+
+ inset.getLyXText(bv)->setFont(bv, font, false);
+#endif
+}
+
+
+// attention this function can be called with bv == 0
+void InsetERT::status(BufferView * bv, ERTStatus const st) const
+{
+ if (st != status_) {
+ status_ = st;
+ switch (st) {
+ case Inlined:
+ if (bv)
+ inset.setUpdateStatus(bv, InsetText::INIT);
+ break;
+ case Open:
+ collapsed_ = false;
+ setButtonLabel();
+ break;
+ case Collapsed:
+ collapsed_ = true;
+ setButtonLabel();
+ if (bv)
+ bv->unlockInset(const_cast<InsetERT *>(this));
+ break;
+ }
+ if (bv) {
+ bv->updateInset(const_cast<InsetERT *>(this));
+ bv->buffer()->markDirty();
+ }
+ }
+}
+
+
+bool InsetERT::showInsetDialog(BufferView * bv) const
+{
+ InsetERTMailer mailer(const_cast<InsetERT &>(*this));
+ mailer.showDialog(bv);
+ return true;
+}
+
+
+void InsetERT::open(BufferView * bv)
+{
+ if (!collapsed_)
+ return;
+ status(bv, Open);
+}
+
+
+void InsetERT::close(BufferView * bv) const
+{
+ if (status_ == Collapsed || status_ == Inlined)
+ return;
+
+ status(bv, Collapsed);
+}
+
+
+WordLangTuple const
+InsetERT::selectNextWordToSpellcheck(BufferView * bv, float &) const
+{
+ bv->unlockInset(const_cast<InsetERT *>(this));
+ return WordLangTuple();
+}
+
+
+void InsetERT::getDrawFont(LyXFont & font) const
+{
+ LyXFont f(LyXFont::ALL_INHERIT, latex_language);
+ font = f;
+ font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+ font.setColor(LColor::latex);
+}
+
+
+int InsetERT::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
+{
+ int w = InsetCollapsable::getMaxWidth(bv, in);
+ if (status_ != Inlined || w < 0)
+ return w;
+ LyXText * text = inset.getLyXText(bv);
+ int rw = text->rows().begin()->width();
+ if (!rw)
+ rw = w;
+ rw += 40;
+ if (text->rows().size() == 1 && rw < w)
+ return -1;
+ return w;
+}
+
+
+void InsetERT::update(BufferView * bv, bool reinit)
+{
+ if (inset.need_update & InsetText::INIT ||
+ inset.need_update & InsetText::FULL) {
+ setButtonLabel();
+ }
+
+ InsetCollapsable::update(bv, reinit);
+}
+
+
+string const InsetERTMailer::name_("ert");
+
+InsetERTMailer::InsetERTMailer(InsetERT & inset)
+ : inset_(inset)
+{}
+
+
+string const InsetERTMailer::inset2string() const
+{
+ return params2string(inset_.status());
+}
+
+
+void InsetERTMailer::string2params(string const & in,
+ InsetERT::ERTStatus & status)
+{
+ status = InsetERT::Collapsed;
+
+ string name;
+ string body = split(in, name, ' ');
+
+ if (body.empty())
+ return;
+
+ status = static_cast<InsetERT::ERTStatus>(strToInt(body));
+}
+
+
+string const
+InsetERTMailer::params2string(InsetERT::ERTStatus status)
+{
+ return name_ + ' ' + tostr(status);
+}