+ Paragraph * par = inset.paragraph();
+ int lines = 0;
+ while (par) {
+ pos_type siz = par->size();
+ for (pos_type i = 0; i < siz; ++i) {
+ // ignore all struck out text
+ if (isDeletedText(*par, i))
+ continue;
+
+ if (par->isNewline(i)) {
+ os << '\n';
+ ++lines;
+ } else {
+ os << par->getChar(i);
+ }
+ }
+ par = par->next();
+ if (par) {
+ os << "\n\n";
+ lines += 2;
+ }
+ }
+
+ return lines;
+}
+
+
+int InsetERT::ascii(Buffer const *, ostream &, int /*linelen*/) const
+{
+ return 0;
+}
+
+
+int InsetERT::linuxdoc(Buffer const *, ostream & os) const
+{
+ Paragraph * par = inset.paragraph();
+ int lines = 0;
+ while (par) {
+ pos_type siz = par->size();
+ for (pos_type i = 0; i < siz; ++i) {
+ if (par->isNewline(i)) {
+ os << '\n';
+ ++lines;
+ } else {
+ os << par->getChar(i);
+ }
+ }
+ par = par->next();
+ if (par) {
+ os << "\n";
+ lines ++;
+ }
+ }
+
+ return lines;
+}
+
+
+int InsetERT::docbook(Buffer const *, ostream & os, bool) const
+{
+ Paragraph * par = inset.paragraph();
+ int lines = 0;
+ while (par) {
+ pos_type siz = par->size();
+ for (pos_type i = 0; i < siz; ++i) {
+ if (par->isNewline(i)) {
+ os << '\n';
+ ++lines;
+ } else {
+ os << par->getChar(i);
+ }
+ }
+ par = par->next();
+ if (par) {
+ os << "\n";
+ lines ++;
+ }
+ }
+
+ return lines;
+}
+
+
+Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
+{
+ Inset::RESULT result = UNDISPATCHED;
+ BufferView * bv = cmd.view();
+
+ if (inset.paragraph()->empty()) {
+ set_latex_font(bv);
+ }
+
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetERT::ERTStatus status_;
+ InsetERTMailer::string2params(cmd.argument, status_);
+
+ status(bv, status_);
+
+ /* FIXME: I refuse to believe we have to live
+ * with ugliness like this ! Note that this
+ * rebreak *is* needed. Consider a change from
+ * Open (needfullrow) to Inlined (only the space
+ * taken by the text).
+ */
+ LyXText * t = inset.getLyXText(cmd.view());
+ t->need_break_row = t->rows().begin();
+ t->fullRebreak();
+ t->setCursorIntern(t->cursor.par(), t->cursor.pos());
+ inset.update(cmd.view(), true);
+ bv->updateInset(this);
+ result = DISPATCHED;
+ }
+ break;
+
+ case LFUN_MOUSE_PRESS:
+ lfunMousePress(cmd);
+ result = DISPATCHED;
+ break;
+
+ case LFUN_MOUSE_MOTION:
+ lfunMouseMotion(cmd);
+ result = DISPATCHED;
+ break;
+
+ case LFUN_MOUSE_RELEASE:
+ lfunMouseRelease(cmd);
+ result = DISPATCHED;
+ break;
+
+ case LFUN_LAYOUT:
+ bv->owner()->setLayout(inset.paragraph()->layout()->name());
+ result = DISPATCHED_NOUPDATE;
+ break;
+
+ default:
+ result = InsetCollapsable::localDispatch(cmd);
+ }
+
+ switch (cmd.action) {
+ case LFUN_BREAKPARAGRAPH:
+ case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
+ case LFUN_BACKSPACE:
+ case LFUN_BACKSPACE_SKIP:
+ case LFUN_DELETE:
+ case LFUN_DELETE_SKIP:
+ case LFUN_DELETE_LINE_FORWARD:
+ case LFUN_CUT:
+ set_latex_font(bv);
+ break;
+
+ default:
+ break;
+ }
+ return result;
+}
+
+
+string const InsetERT::get_new_label() const
+{
+ string la;
+ pos_type const max_length = 15;
+ pos_type const p_siz = inset.paragraph()->size();
+ pos_type const n = min(max_length, p_siz);
+ pos_type i = 0;
+ pos_type j = 0;
+ for(; i < n && j < p_siz; ++j) {
+ if (inset.paragraph()->isInset(j))
+ continue;
+ la += inset.paragraph()->getChar(j);
+ ++i;
+ }
+ if (inset.paragraph()->next() || (i > 0 && j < p_siz)) {
+ la += "...";
+ }
+ if (la.empty()) {
+ la = _("ERT");
+ }
+ return la;
+}
+
+
+void InsetERT::setButtonLabel() const
+{
+ if (status_ == Collapsed) {
+ setLabel(get_new_label());
+ } else {
+ setLabel(_("ERT"));
+ }
+}
+
+
+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);