+
+
+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, bool cleared) const
+{
+ Painter & pain = bv->painter();
+
+ button_length = width_collapsed();
+ button_top_y = -ascent(bv, f);
+ button_bottom_y = -ascent(bv, f) + ascent_collapsed() +
+ descent_collapsed();
+
+ if (!isOpen()) {
+ draw_collapsed(pain, baseline, x);
+ x += TEXT_TO_INSET_OFFSET;
+ return;
+ }
+
+ float old_x = x;
+
+ if (!owner())
+ x += static_cast<float>(scroll());
+
+ if (!cleared && (inset.need_update == InsetText::FULL ||
+ inset.need_update == InsetText::INIT ||
+ top_x != int(x) ||
+ top_baseline != baseline))
+ {
+ // we don't need anymore to clear here we just have to tell
+ // the underlying LyXText that it should do the RowClear!
+ inset.setUpdateStatus(bv, InsetText::FULL);
+ bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
+ return;
+ }
+
+ top_x = int(x);
+ topx_set = true;
+ top_baseline = baseline;
+
+ int const bl = baseline - ascent(bv, f) + ascent_collapsed();
+
+ if (inlined()) {
+ inset.draw(bv, f, baseline, x, cleared);
+ } else {
+ draw_collapsed(pain, bl, old_x);
+ inset.draw(bv, f,
+ bl + descent_collapsed() + inset.ascent(bv, f),
+ x, cleared);
+ }
+ need_update = NONE;
+}
+
+
+void InsetERT::set_latex_font(BufferView * bv)
+{
+#ifndef INHERIT_LANG
+ LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+#else
+ LyXFont font(LyXFont::ALL_INHERIT);
+#endif
+
+ font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+ font.setColor(LColor::latex);
+ inset.getLyXText(bv)->setFont(bv, font, false);
+}
+
+
+void InsetERT::status(BufferView * bv, ERTStatus const st) const
+{
+ if (st != status_) {
+ status_ = st;
+ switch (st) {
+ case Inlined:
+ inset.setAutoBreakRows(false);
+ break;
+ case Open:
+ inset.setAutoBreakRows(true);
+ collapsed_ = false;
+ need_update = FULL;
+ setButtonLabel();
+ break;
+ case Collapsed:
+ inset.setAutoBreakRows(true);
+ collapsed_ = true;
+ need_update = FULL;
+ setButtonLabel();
+ if (bv)
+ bv->unlockInset(const_cast<InsetERT *>(this));
+ break;
+ }
+ if (bv)
+ bv->updateInset(const_cast<InsetERT *>(this), false);
+ }
+}
+
+
+bool InsetERT::showInsetDialog(BufferView * bv) const
+{
+ bv->owner()->getDialogs()->showERT(const_cast<InsetERT *>(this));
+ return true;
+}
+
+
+void InsetERT::open(BufferView * bv)
+{
+ if (!collapsed_)
+ return;
+ status(bv, Open);
+}
+
+
+void InsetERT::close(BufferView * bv) const
+{
+ if (collapsed_)
+ return;
+ status(bv, Collapsed);
+}
+
+
+string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,float &) const
+{
+ bv->unlockInset(const_cast<InsetERT *>(this));
+ return string();
+}