2 * \file InsetCollapsable.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
15 #include "InsetCollapsable.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
21 #include "Dimension.h"
22 #include "DispatchResult.h"
23 #include "FloatList.h"
24 #include "FuncRequest.h"
25 #include "FuncStatus.h"
26 #include "InsetLayout.h"
27 #include "InsetList.h"
29 #include "LaTeXFeatures.h"
31 #include "MetricsInfo.h"
32 #include "output_xhtml.h"
33 #include "paragraph_funcs.h"
34 #include "ParagraphParameters.h"
36 #include "TextClass.h"
38 #include "frontends/FontMetrics.h"
39 #include "frontends/Painter.h"
41 #include "support/debug.h"
42 #include "support/docstream.h"
43 #include "support/gettext.h"
44 #include "support/lassert.h"
45 #include "support/lstrings.h"
52 InsetCollapsable::CollapseStatus InsetCollapsable::status(BufferView const & bv) const
54 if (decoration() == InsetLayout::CONGLOMERATE)
56 return auto_open_[&bv] ? Open : status_;
60 InsetCollapsable::Geometry InsetCollapsable::geometry(BufferView const & bv) const
62 switch (decoration()) {
63 case InsetLayout::CLASSIC:
64 if (status(bv) == Open)
65 return openinlined_ ? LeftButton : TopButton;
68 case InsetLayout::MINIMALISTIC:
69 return status(bv) == Open ? NoButton : ButtonOnly ;
71 case InsetLayout::CONGLOMERATE:
72 return status(bv) == Open ? SubLabel : Corners ;
74 case InsetLayout::DEFAULT:
75 break; // this shouldn't happen
78 // dummy return value to shut down a warning,
84 InsetCollapsable::Geometry InsetCollapsable::geometry() const
86 switch (decoration()) {
87 case InsetLayout::CLASSIC:
89 return openinlined_ ? LeftButton : TopButton;
92 case InsetLayout::MINIMALISTIC:
93 return status_ == Open ? NoButton : ButtonOnly ;
95 case InsetLayout::CONGLOMERATE:
96 return status_ == Open ? SubLabel : Corners ;
98 case InsetLayout::DEFAULT:
99 break; // this shouldn't happen
102 // dummy return value to shut down a warning,
103 // this is dead code.
108 InsetCollapsable::InsetCollapsable(Buffer const & buf, InsetText::UsePlain ltype)
109 : InsetText(buf, ltype), status_(Inset::Open),
110 openinlined_(false), mouse_hover_(false)
112 setAutoBreakRows(true);
114 setFrameColor(Color_collapsableframe);
118 InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
120 status_(rhs.status_),
121 labelstring_(rhs.labelstring_),
122 button_dim(rhs.button_dim),
123 openinlined_(rhs.openinlined_),
124 auto_open_(rhs.auto_open_),
125 // the sole purpose of this copy constructor
131 docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
133 Dimension dim = dimensionCollapsed(bv);
134 if (geometry(bv) == NoButton)
135 return translateIfPossible(getLayout().labelstring());
136 if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
139 OutputParams rp(&buffer().params().encoding());
140 odocstringstream ods;
141 InsetText::plaintext(ods, rp);
142 docstring const content_tip = ods.str();
143 return support::wrapParas(content_tip, 4);
147 void InsetCollapsable::write(ostream & os) const
159 text().write(buffer(), os);
163 void InsetCollapsable::read(Lexer & lex)
165 lex.setContext("InsetCollapsable::read");
168 lex >> "status" >> tmp_token;
169 if (tmp_token == "open")
172 InsetText::read(lex);
177 Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
180 theFontMetrics(getLayout().labelfont()).buttonText(
181 buttonLabel(bv), dim.wid, dim.asc, dim.des);
186 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
188 auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
190 FontInfo tmpfont = mi.base.font;
191 mi.base.font = getLayout().font();
192 mi.base.font.realize(tmpfont);
194 BufferView const & bv = *mi.base.bv;
196 switch (geometry(bv)) {
198 InsetText::metrics(mi, dim);
201 InsetText::metrics(mi, dim);
206 InsetText::metrics(mi, dim);
207 // consider width of the inset label
208 FontInfo font(getLayout().labelfont());
209 font.realize(sane_font);
215 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
222 dim = dimensionCollapsed(bv);
223 if (geometry(bv) == TopButton
224 || geometry(bv) == LeftButton) {
226 InsetText::metrics(mi, textdim);
227 openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
229 // Correct for button width.
230 dim.wid += textdim.wid;
231 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
232 dim.asc = textdim.asc;
234 dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
235 dim.wid = max(dim.wid, textdim.wid);
241 mi.base.font = tmpfont;
245 bool InsetCollapsable::setMouseHover(bool mouse_hover)
247 mouse_hover_ = mouse_hover;
252 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
254 BufferView const & bv = *pi.base.bv;
256 auto_open_[&bv] = bv.cursor().isInside(this);
258 FontInfo tmpfont = pi.base.font;
259 pi.base.font = getLayout().font();
260 pi.base.font.realize(tmpfont);
262 // Draw button first -- top, left or only
263 Dimension dimc = dimensionCollapsed(bv);
265 if (geometry(*pi.base.bv) == TopButton ||
266 geometry(*pi.base.bv) == LeftButton ||
267 geometry(*pi.base.bv) == ButtonOnly) {
268 button_dim.x1 = x + 0;
269 button_dim.x2 = x + dimc.width();
270 button_dim.y1 = y - dimc.asc;
271 button_dim.y2 = y + dimc.des;
273 FontInfo labelfont = getLayout().labelfont();
274 labelfont.setColor(labelColor());
275 pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
284 Dimension const textdim = InsetText::dimension(bv);
285 int const baseline = y;
287 switch (geometry(bv)) {
289 textx = x + dimc.width();
291 InsetText::draw(pi, textx, texty);
295 texty = baseline + dimc.des + textdim.asc;
296 InsetText::draw(pi, textx, texty);
303 InsetText::draw(pi, textx, texty);
309 const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
310 InsetText::draw(pi, textx, texty);
311 const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
313 int desc = textdim.descent();
314 if (geometry(bv) == Corners)
317 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
318 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
319 pi.pain.line(xx1, y + desc - 4,
323 pi.pain.line(xx1, y + desc,
327 // Make status_ value visible:
328 pi.pain.line(xx1, y + desc,
331 pi.pain.line(xx2 - 4, y + desc,
335 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
336 y + desc - 4, labelColor());
338 // the label below the text. Can be toggled.
339 if (geometry(bv) == SubLabel) {
340 FontInfo font(getLayout().labelfont());
341 font.realize(sane_font);
347 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
348 int const ww = max(textdim.wid, w);
349 pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
350 buttonLabel(bv), font, Color_none, Color_none);
354 // a visual cue when the cursor is inside the inset
355 Cursor const & cur = bv.cursor();
356 if (cur.isInside(this)) {
359 pi.pain.line(xx1, y + 4, xx1, y, labelColor());
360 pi.pain.line(xx1 + 4, y, xx1, y, labelColor());
361 pi.pain.line(xx2, y + 4, xx2, y,
363 pi.pain.line(xx2 - 4, y, xx2, y,
369 pi.base.font = tmpfont;
373 void InsetCollapsable::cursorPos(BufferView const & bv,
374 CursorSlice const & sl, bool boundary, int & x, int & y) const
376 if (geometry(bv) == ButtonOnly)
378 LASSERT(geometry(bv) != ButtonOnly, /**/);
380 InsetText::cursorPos(bv, sl, boundary, x, y);
381 Dimension const textdim = InsetText::dimension(bv);
383 switch (geometry(bv)) {
385 x += dimensionCollapsed(bv).wid;
388 y += dimensionCollapsed(bv).des + textdim.asc;
403 bool InsetCollapsable::editable() const
405 return geometry() != ButtonOnly;
409 bool InsetCollapsable::descendable() const
411 return geometry() != ButtonOnly;
415 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
417 return button_dim.contains(cmd.x, cmd.y);
421 docstring const InsetCollapsable::getNewLabel(docstring const & l) const
424 pos_type const max_length = 15;
425 pos_type const p_siz = paragraphs().begin()->size();
426 pos_type const n = min(max_length, p_siz);
429 for (; i < n && j < p_siz; ++j) {
430 if (paragraphs().begin()->isInset(j))
432 label += paragraphs().begin()->getChar(j);
435 if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
438 return label.empty() ? l : label;
442 void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
444 //lyxerr << "InsetCollapsable: edit left/right" << endl;
446 InsetText::edit(cur, front, entry_from);
450 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
452 //lyxerr << "InsetCollapsable: edit xy" << endl;
453 if (geometry(cur.bv()) == ButtonOnly
454 || (button_dim.contains(x, y)
455 && geometry(cur.bv()) != NoButton))
458 return InsetText::editXY(cur, x, y);
462 void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
464 //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
465 // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
467 switch (cmd.action) {
468 case LFUN_MOUSE_PRESS:
469 if (hitButton(cmd)) {
470 switch (cmd.button()) {
471 case mouse_button::button1:
472 case mouse_button::button3:
473 // Pass the command to the enclosing InsetText,
474 // so that the cursor gets set.
477 case mouse_button::none:
478 case mouse_button::button2:
479 case mouse_button::button4:
480 case mouse_button::button5:
485 } else if (geometry(cur.bv()) != ButtonOnly)
486 InsetText::doDispatch(cur, cmd);
491 case LFUN_MOUSE_MOTION:
492 case LFUN_MOUSE_DOUBLE:
493 case LFUN_MOUSE_TRIPLE:
496 else if (geometry(cur.bv()) != ButtonOnly)
497 InsetText::doDispatch(cur, cmd);
502 case LFUN_MOUSE_RELEASE:
503 if (!hitButton(cmd)) {
504 // The mouse click has to be within the inset!
505 if (geometry(cur.bv()) != ButtonOnly)
506 InsetText::doDispatch(cur, cmd);
511 if (cmd.button() != mouse_button::button1) {
516 // if we are selecting, we do not want to
520 // Left button is clicked, the user asks to
521 // toggle the inset visual state.
523 cur.updateFlags(Update::Force | Update::FitCursor);
524 if (geometry(cur.bv()) == ButtonOnly) {
525 setStatus(cur, Open);
529 setStatus(cur, Collapsed);
530 cur.bv().cursor() = cur;
533 case LFUN_INSET_TOGGLE:
534 if (cmd.argument() == "open")
535 setStatus(cur, Open);
536 else if (cmd.argument() == "close")
537 setStatus(cur, Collapsed);
538 else if (cmd.argument() == "toggle" || cmd.argument().empty())
539 if (status_ == Open) {
540 setStatus(cur, Collapsed);
541 if (geometry(cur.bv()) == ButtonOnly)
542 cur.top().forwardPos();
544 setStatus(cur, Open);
545 else // if assign or anything else
550 case LFUN_TAB_INSERT: {
551 bool const multi_par_selection = cur.selection() &&
552 cur.selBegin().pit() != cur.selEnd().pit();
553 if (multi_par_selection) {
554 // If there is a multi-paragraph selection, a tab is inserted
555 // at the beginning of each paragraph.
556 cur.recordUndoSelection();
557 pit_type const pit_end = cur.selEnd().pit();
558 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
559 paragraphs()[pit].insertChar(0, '\t',
560 buffer().params().trackChanges);
561 // Update the selection pos to make sure the selection does not
562 // change as the inserted tab will increase the logical pos.
563 if (cur.anchor_.pit() == pit)
564 cur.anchor_.forwardPos();
565 if (cur.pit() == pit)
570 // Maybe we shouldn't allow tabs within a line, because they
571 // are not (yet) aligned as one might do expect.
572 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
578 case LFUN_TAB_DELETE:
579 if (cur.selection()) {
580 // If there is a selection, a tab (if present) is removed from
581 // the beginning of each paragraph.
582 cur.recordUndoSelection();
583 pit_type const pit_end = cur.selEnd().pit();
584 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
585 Paragraph & par = paragraphs()[pit];
586 if (par.getChar(0) == '\t') {
587 if (cur.pit() == pit)
589 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
590 cur.anchor_.backwardPos();
592 par.eraseChar(0, buffer().params().trackChanges);
594 // If no tab was present, try to remove up to four spaces.
595 for (int n_spaces = 0;
596 par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
597 if (cur.pit() == pit)
599 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
600 cur.anchor_.backwardPos();
602 par.eraseChar(0, buffer().params().trackChanges);
607 // If there is no selection, try to remove a tab or some spaces
608 // before the position of the cursor.
609 Paragraph & par = paragraphs()[cur.pit()];
610 pos_type const pos = cur.pos();
615 char_type const c = par.getChar(pos - 1);
619 par.eraseChar(cur.pos(), buffer().params().trackChanges);
621 for (int n_spaces = 0; cur.pos() > 0
622 && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
625 par.eraseChar(cur.pos(), buffer().params().trackChanges);
632 if (getLayout().isForceLtr()) {
633 // Force any new text to latex_language
634 // FIXME: This should only be necessary in constructor, but
635 // new paragraphs that are created by pressing enter at the
636 // start of an existing paragraph get the buffer language
637 // and not latex_language, so we take this brute force
639 cur.current_font.setLanguage(latex_language);
640 cur.real_current_font.setLanguage(latex_language);
642 InsetText::doDispatch(cur, cmd);
648 bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
649 FuncStatus & flag) const
651 switch (cmd.action) {
652 // FIXME At present, these are being enabled and disabled according to
653 // whether PASSTHRU has been set in the InsetLayout. This makes some
654 // sense, but there are other checks that should really be done. E.g.,
655 // one should not be able to inset IndexPrint inside an optional argument!!
656 case LFUN_ACCENT_ACUTE:
657 case LFUN_ACCENT_BREVE:
658 case LFUN_ACCENT_CARON:
659 case LFUN_ACCENT_CEDILLA:
660 case LFUN_ACCENT_CIRCLE:
661 case LFUN_ACCENT_CIRCUMFLEX:
662 case LFUN_ACCENT_DOT:
663 case LFUN_ACCENT_GRAVE:
664 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
665 case LFUN_ACCENT_MACRON:
666 case LFUN_ACCENT_OGONEK:
667 case LFUN_ACCENT_TIE:
668 case LFUN_ACCENT_TILDE:
669 case LFUN_ACCENT_UMLAUT:
670 case LFUN_ACCENT_UNDERBAR:
671 case LFUN_ACCENT_UNDERDOT:
673 case LFUN_BOX_INSERT:
674 case LFUN_BRANCH_INSERT:
675 case LFUN_CAPTION_INSERT:
676 case LFUN_DEPTH_DECREMENT:
677 case LFUN_DEPTH_INCREMENT:
678 case LFUN_ERT_INSERT:
679 case LFUN_FILE_INSERT:
680 case LFUN_FLEX_INSERT:
681 case LFUN_FLOAT_INSERT:
682 case LFUN_FLOAT_LIST_INSERT:
683 case LFUN_FLOAT_WIDE_INSERT:
685 case LFUN_FONT_BOLDSYMBOL:
686 case LFUN_FONT_TYPEWRITER:
687 case LFUN_FONT_DEFAULT:
690 case LFUN_FONT_ROMAN:
695 case LFUN_FONT_STATE:
696 case LFUN_FONT_UNDERLINE:
697 case LFUN_FONT_STRIKEOUT:
698 case LFUN_FONT_UULINE:
699 case LFUN_FONT_UWAVE:
700 case LFUN_FOOTNOTE_INSERT:
701 case LFUN_HYPERLINK_INSERT:
702 case LFUN_INDEX_INSERT:
703 case LFUN_INDEX_PRINT:
704 case LFUN_INSET_INSERT:
705 case LFUN_LABEL_GOTO:
706 case LFUN_LABEL_INSERT:
707 case LFUN_LAYOUT_TABULAR:
708 case LFUN_LINE_INSERT:
709 case LFUN_MARGINALNOTE_INSERT:
710 case LFUN_MATH_DISPLAY:
711 case LFUN_MATH_INSERT:
712 case LFUN_MATH_AMS_MATRIX:
713 case LFUN_MATH_MATRIX:
716 case LFUN_NEWLINE_INSERT:
717 case LFUN_NEWPAGE_INSERT:
719 case LFUN_NOMENCL_INSERT:
720 case LFUN_NOMENCL_PRINT:
721 case LFUN_NOTE_INSERT:
723 case LFUN_OPTIONAL_INSERT:
724 case LFUN_PHANTOM_INSERT:
725 case LFUN_REFERENCE_NEXT:
726 case LFUN_SERVER_GOTO_FILE_ROW:
727 case LFUN_SERVER_NOTIFY:
728 case LFUN_SERVER_SET_XY:
729 case LFUN_SPACE_INSERT:
730 case LFUN_SPECIALCHAR_INSERT:
731 case LFUN_TABULAR_INSERT:
732 case LFUN_TEXTSTYLE_APPLY:
733 case LFUN_TEXTSTYLE_UPDATE:
734 case LFUN_TOC_INSERT:
735 case LFUN_WRAP_INSERT:
736 if (getLayout().isPassThru()) {
737 flag.setEnabled(false);
740 return InsetText::getStatus(cur, cmd, flag);
742 case LFUN_INSET_TOGGLE:
743 if (cmd.argument() == "open")
744 flag.setEnabled(status_ != Open);
745 else if (cmd.argument() == "close")
746 flag.setEnabled(status_ == Open);
747 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
748 flag.setEnabled(true);
749 flag.setOnOff(status_ == Open);
751 flag.setEnabled(false);
755 flag.setEnabled(!getLayout().isForceLtr());
756 return InsetText::getStatus(cur, cmd, flag);
758 case LFUN_BREAK_PARAGRAPH:
759 flag.setEnabled(getLayout().isMultiPar());
762 case LFUN_TAB_INSERT:
763 case LFUN_TAB_DELETE:
764 if (getLayout().isPassThru()) {
765 flag.setEnabled(true);
768 return InsetText::getStatus(cur, cmd, flag);
771 return InsetText::getStatus(cur, cmd, flag);
776 void InsetCollapsable::setLabel(docstring const & l)
782 void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
786 if (status_ == Collapsed) {
787 cur.leaveInset(*this);
788 mouse_hover_ = false;
793 docstring InsetCollapsable::floatName(string const & type) const
795 BufferParams const & bp = buffer().params();
796 FloatList const & floats = bp.documentClass().floats();
797 FloatList::const_iterator it = floats[type];
799 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
803 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
805 InsetLayout::InsetDecoration const dec = getLayout().decoration();
806 return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
810 int InsetCollapsable::latex(odocstream & os,
811 OutputParams const & runparams) const
813 // This implements the standard way of handling the LaTeX output of
814 // a collapsable inset, either a command or an environment. Standard
815 // collapsable insets should not redefine this, non-standard ones may
817 if (!getLayout().latexname().empty()) {
818 if (getLayout().latextype() == InsetLayout::COMMAND) {
820 if (runparams.moving_arg)
822 os << '\\' << from_utf8(getLayout().latexname());
823 if (!getLayout().latexparam().empty())
824 os << from_utf8(getLayout().latexparam());
826 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
827 os << "%\n\\begin{" << from_utf8(getLayout().latexname()) << "}\n";
828 if (!getLayout().latexparam().empty())
829 os << from_utf8(getLayout().latexparam());
832 OutputParams rp = runparams;
833 if (getLayout().isPassThru())
835 if (getLayout().isNeedProtect())
836 rp.moving_arg = true;
837 int i = InsetText::latex(os, rp);
838 if (!getLayout().latexname().empty()) {
839 if (getLayout().latextype() == InsetLayout::COMMAND) {
841 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
842 os << "\n\\end{" << from_utf8(getLayout().latexname()) << "}\n";
850 // FIXME It seems as if it ought to be possible to do this more simply,
851 // maybe by calling InsetText::docbook() in the middle there.
852 int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
854 ParagraphList::const_iterator const beg = paragraphs().begin();
855 ParagraphList::const_iterator par = paragraphs().begin();
856 ParagraphList::const_iterator const end = paragraphs().end();
859 sgml::openTag(os, getLayout().latexname(),
860 par->getID(buffer(), runparams) + getLayout().latexparam());
862 for (; par != end; ++par) {
863 par->simpleDocBookOnePar(buffer(), os, runparams,
864 outerFont(distance(beg, par),
869 sgml::closeTag(os, getLayout().latexname());
875 docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
877 InsetLayout const & il = getLayout();
879 return InsetText::xhtml(os, runparams);
881 bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
882 if (!il.counter().empty()) {
883 BufferParams const & bp = buffer().masterBuffer()->params();
884 Counters & cntrs = bp.documentClass().counters();
885 cntrs.step(il.counter());
886 // FIXME: translate to paragraph language
887 if (!il.htmllabel().empty())
888 os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
890 bool innertag_opened = false;
891 if (!il.htmlinnertag().empty())
892 innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
893 docstring deferred = InsetText::xhtml(os, runparams);
895 html::closeTag(os, il.htmlinnertag());
897 html::closeTag(os, il.htmltag());
902 void InsetCollapsable::validate(LaTeXFeatures & features) const
904 features.useInsetLayout(getLayout());
905 InsetText::validate(features);
909 bool InsetCollapsable::undefined() const
911 docstring const & n = getLayout().name();
912 return n.empty() || n == DocumentClass::plainInsetLayout().name();
916 docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
919 if (decoration() == InsetLayout::CONGLOMERATE)
920 return from_ascii("context-conglomerate");
922 if (geometry(bv) == NoButton)
923 return from_ascii("context-collapsable");
925 Dimension dim = dimensionCollapsed(bv);
926 if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
927 return from_ascii("context-collapsable");
929 return InsetText::contextMenu(bv, x, y);
932 void InsetCollapsable::tocString(odocstream & os) const
934 if (!getLayout().isInToc())
936 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);