+
+void InsetCollapsable::insetUnlock(BufferView * bv)
+{
+#if 0
+ if (autocollapse) {
+ if (change_label_with_text) {
+ draw_label = get_new_label();
+ } else {
+ draw_label = label;
+ }
+ collapsed_ = true;
+ }
+#endif
+ inset.insetUnlock(bv);
+ if (scroll())
+ scroll(bv, 0.0F);
+ bv->updateInset(this, false);
+}
+
+
+void InsetCollapsable::insetButtonPress(BufferView * bv,
+ int x, int y, int button)
+{
+ if (!collapsed_ && (y > button_bottom_y)) {
+ LyXFont font(LyXFont::ALL_SANE);
+ int yy = ascent(bv, font) + y -
+ (ascent_collapsed() +
+ descent_collapsed() +
+ inset.ascent(bv, font));
+ inset.insetButtonPress(bv, x, yy, button);
+ }
+}
+
+
+bool InsetCollapsable::insetButtonRelease(BufferView * bv,
+ int x, int y, int button)
+{
+ bool ret = false;
+ if ((button != 3) && (x >= 0) && (x < button_length) &&
+ (y >= button_top_y) && (y <= button_bottom_y))
+ {
+ if (collapsed_) {
+ collapsed_ = false;
+// should not be called on inset open!
+// inset.insetButtonRelease(bv, 0, 0, button);
+ inset.setUpdateStatus(bv, InsetText::FULL);
+ bv->updateInset(this, false);
+ } else {
+ collapsed_ = true;
+ bv->unlockInset(this);
+ bv->updateInset(this, false);
+ }
+ } else if (!collapsed_ && (y > button_bottom_y)) {
+ LyXFont font(LyXFont::ALL_SANE);
+ int yy = ascent(bv, font) + y -
+ (ascent_collapsed() +
+ descent_collapsed() +
+ inset.ascent(bv, font));
+ ret = inset.insetButtonRelease(bv, x, yy, button);
+ }
+ if ((button == 3) && !ret) {
+ return showInsetDialog(bv);
+ }
+ return false;
+}
+
+
+void InsetCollapsable::insetMotionNotify(BufferView * bv,
+ int x, int y, int state)
+{
+ if (y > button_bottom_y) {
+ LyXFont font(LyXFont::ALL_SANE);
+ int yy = ascent(bv, font) + y -
+ (ascent_collapsed() +
+ descent_collapsed() +
+ inset.ascent(bv, font));
+ inset.insetMotionNotify(bv, x, yy, state);
+ }
+}
+
+
+void InsetCollapsable::insetKeyPress(XKeyEvent * xke)
+{
+ inset.insetKeyPress(xke);
+}
+
+
+int InsetCollapsable::latex(Buffer const * buf, ostream & os,
+ bool fragile, bool free_spc) const
+{
+ return inset.latex(buf, os, fragile, free_spc);
+}
+
+
+int InsetCollapsable::ascii(Buffer const * buf, ostream & os, int ll) const
+{
+ return inset.ascii(buf, os, ll);
+}
+
+
+int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const
+{
+ return inset.linuxdoc(buf, os);
+}
+
+
+int InsetCollapsable::docbook(Buffer const * buf, ostream & os) const
+{
+ return inset.docbook(buf, os);
+}
+
+#if 0
+int InsetCollapsable::getMaxWidth(BufferView * bv,
+ UpdatableInset const * in) const
+{
+#if 0
+ int const w = UpdatableInset::getMaxWidth(bv, in);
+
+ if (w < 0) {
+ // What does a negative max width signify? (Lgb)
+ // Use the max width of the draw-area (Jug)
+ return w;
+ }
+ // should be at least 30 pixels !!!
+ return max(30, w - width_collapsed());
+#else
+ return UpdatableInset::getMaxWidth(bv, in);
+#endif
+}
+#endif
+
+
+void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
+ bool reinit)
+{
+ if (in_update) {
+ if (reinit && owner()) {
+ owner()->update(bv, font, true);
+ }
+ return;
+ }
+ in_update = true;
+ inset.update(bv, font, reinit);
+ if (reinit && owner()) {
+ owner()->update(bv, font, true);
+ }
+ in_update = false;
+}
+
+
+UpdatableInset::RESULT
+InsetCollapsable::localDispatch(BufferView * bv, kb_action action,
+ string const & arg)
+{
+ UpdatableInset::RESULT result = inset.localDispatch(bv, action, arg);
+ if (result >= FINISHED)
+ bv->unlockInset(this);
+ first_after_edit = false;
+ return result;
+}
+
+
+bool InsetCollapsable::lockInsetInInset(BufferView * bv, UpdatableInset * in)
+{
+ if (&inset == in)
+ return true;
+ return inset.lockInsetInInset(bv, in);
+}
+
+
+bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in,
+ bool lr)
+{
+ if (&inset == in) {
+ bv->unlockInset(this);
+ return true;
+ }
+ return inset.unlockInsetInInset(bv, in, lr);
+}
+
+
+bool InsetCollapsable::updateInsetInInset(BufferView * bv, Inset *in)
+{
+ if (in == this)
+ return true;
+ return inset.updateInsetInInset(bv, in);
+}
+
+
+unsigned int InsetCollapsable::insetInInsetY()
+{
+ return inset.insetInInsetY() - (top_baseline - inset.y());
+}
+
+
+void InsetCollapsable::validate(LaTeXFeatures & features) const
+{
+ inset.validate(features);
+}
+
+
+void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const
+{
+ inset.getCursorPos(bv, x , y);
+}
+
+
+void InsetCollapsable::toggleInsetCursor(BufferView * bv)
+{
+ inset.toggleInsetCursor(bv);
+}
+
+
+void InsetCollapsable::showInsetCursor(BufferView * bv, bool show)
+{
+ inset.showInsetCursor(bv, show);
+}
+
+
+void InsetCollapsable::hideInsetCursor(BufferView * bv)
+{
+ inset.hideInsetCursor(bv);
+}
+
+
+UpdatableInset * InsetCollapsable::getLockingInset() const
+{
+ UpdatableInset * in = inset.getLockingInset();
+ if (const_cast<InsetText *>(&inset) == in)
+ return const_cast<InsetCollapsable *>(this);
+ return in;
+}
+
+
+UpdatableInset * InsetCollapsable::getFirstLockingInsetOfType(Inset::Code c)
+{
+ if (c == lyxCode())
+ return this;
+ return inset.getFirstLockingInsetOfType(c);
+}
+
+
+void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font,
+ bool toggleall, bool selectall)
+{
+ inset.setFont(bv, font, toggleall, selectall);
+}
+
+
+bool InsetCollapsable::doClearArea() const
+{
+ return inset.doClearArea();
+}
+
+
+LyXText * InsetCollapsable::getLyXText(BufferView const * bv,
+ bool const recursive) const
+{
+ return inset.getLyXText(bv, recursive);
+}
+
+
+void InsetCollapsable::deleteLyXText(BufferView * bv, bool recursive) const
+{
+ inset.deleteLyXText(bv, recursive);
+}
+
+
+void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const
+{
+ inset.resizeLyXText(bv, force);
+ LyXFont font(LyXFont::ALL_SANE);
+ oldWidth = width(bv, font);
+}
+
+
+vector<string> const InsetCollapsable::getLabelList() const
+{
+ return inset.getLabelList();
+}
+
+
+bool InsetCollapsable::nodraw() const
+{
+ return inset.nodraw();
+}
+
+
+int InsetCollapsable::scroll(bool recursive) const
+{
+ int sx = UpdatableInset::scroll(false);
+
+ if (recursive)
+ sx += inset.scroll(recursive);
+
+ return sx;
+}
+
+
+Paragraph * InsetCollapsable::getParFromID(int id) const
+{
+ lyxerr[Debug::INFO] << "Looking for paragraph " << id << endl;
+ return inset.getParFromID(id);
+}
+
+
+Paragraph * InsetCollapsable::firstParagraph() const
+{
+ return inset.firstParagraph();
+}
+
+
+Paragraph * InsetCollapsable::getFirstParagraph(int i) const
+{
+ return inset.getFirstParagraph(i);
+}
+
+
+LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
+{
+ return inset.cursor(bv);
+}
+
+
+Inset * InsetCollapsable::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetCollapsable *>(this);
+ return inset.getInsetFromID(id_arg);
+}
+
+
+void InsetCollapsable::open(BufferView * bv)
+{
+ if (!collapsed_) return;
+
+ collapsed_ = false;
+ bv->updateInset(this, false);
+}
+
+
+void InsetCollapsable::close(BufferView * bv) const