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 // this must be set before we enter InsetText::read()
173 InsetText::read(lex);
176 // Force default font, if so requested
177 // This avoids paragraphs in buffer language that would have a
178 // foreign language after a document language change, and it ensures
179 // that all new text in ERT and similar gets the "latex" language,
180 // since new text inherits the language from the last position of the
181 // existing text. As a side effect this makes us also robust against
182 // bugs in LyX that might lead to font changes in ERT in .lyx files.
183 resetParagraphsFont();
187 Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
190 theFontMetrics(getLayout().labelfont()).buttonText(
191 buttonLabel(bv), dim.wid, dim.asc, dim.des);
196 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
198 auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
200 FontInfo tmpfont = mi.base.font;
201 mi.base.font = getLayout().font();
202 mi.base.font.realize(tmpfont);
204 BufferView const & bv = *mi.base.bv;
206 switch (geometry(bv)) {
208 InsetText::metrics(mi, dim);
211 InsetText::metrics(mi, dim);
216 InsetText::metrics(mi, dim);
217 // consider width of the inset label
218 FontInfo font(getLayout().labelfont());
219 font.realize(sane_font);
225 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
232 dim = dimensionCollapsed(bv);
233 if (geometry(bv) == TopButton
234 || geometry(bv) == LeftButton) {
236 InsetText::metrics(mi, textdim);
237 openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
239 // Correct for button width.
240 dim.wid += textdim.wid;
241 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
242 dim.asc = textdim.asc;
244 dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
245 dim.wid = max(dim.wid, textdim.wid);
251 mi.base.font = tmpfont;
255 bool InsetCollapsable::setMouseHover(bool mouse_hover)
257 mouse_hover_ = mouse_hover;
262 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
264 BufferView const & bv = *pi.base.bv;
266 auto_open_[&bv] = bv.cursor().isInside(this);
268 FontInfo tmpfont = pi.base.font;
269 pi.base.font = getLayout().font();
270 pi.base.font.realize(tmpfont);
272 // Draw button first -- top, left or only
273 Dimension dimc = dimensionCollapsed(bv);
275 if (geometry(*pi.base.bv) == TopButton ||
276 geometry(*pi.base.bv) == LeftButton ||
277 geometry(*pi.base.bv) == ButtonOnly) {
278 button_dim.x1 = x + 0;
279 button_dim.x2 = x + dimc.width();
280 button_dim.y1 = y - dimc.asc;
281 button_dim.y2 = y + dimc.des;
283 FontInfo labelfont = getLayout().labelfont();
284 labelfont.setColor(labelColor());
285 pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
294 Dimension const textdim = InsetText::dimension(bv);
295 int const baseline = y;
297 switch (geometry(bv)) {
299 textx = x + dimc.width();
301 InsetText::draw(pi, textx, texty);
305 texty = baseline + dimc.des + textdim.asc;
306 InsetText::draw(pi, textx, texty);
313 InsetText::draw(pi, textx, texty);
319 const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
320 InsetText::draw(pi, textx, texty);
321 const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
323 int desc = textdim.descent();
324 if (geometry(bv) == Corners)
327 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
328 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
329 pi.pain.line(xx1, y + desc - 4,
333 pi.pain.line(xx1, y + desc,
337 // Make status_ value visible:
338 pi.pain.line(xx1, y + desc,
341 pi.pain.line(xx2 - 4, y + desc,
345 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
346 y + desc - 4, labelColor());
348 // the label below the text. Can be toggled.
349 if (geometry(bv) == SubLabel) {
350 FontInfo font(getLayout().labelfont());
351 font.realize(sane_font);
357 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
358 int const ww = max(textdim.wid, w);
359 pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
360 buttonLabel(bv), font, Color_none, Color_none);
364 // a visual cue when the cursor is inside the inset
365 Cursor const & cur = bv.cursor();
366 if (cur.isInside(this)) {
369 pi.pain.line(xx1, y + 4, xx1, y, labelColor());
370 pi.pain.line(xx1 + 4, y, xx1, y, labelColor());
371 pi.pain.line(xx2, y + 4, xx2, y,
373 pi.pain.line(xx2 - 4, y, xx2, y,
379 pi.base.font = tmpfont;
383 void InsetCollapsable::cursorPos(BufferView const & bv,
384 CursorSlice const & sl, bool boundary, int & x, int & y) const
386 if (geometry(bv) == ButtonOnly)
388 LASSERT(geometry(bv) != ButtonOnly, /**/);
390 InsetText::cursorPos(bv, sl, boundary, x, y);
391 Dimension const textdim = InsetText::dimension(bv);
393 switch (geometry(bv)) {
395 x += dimensionCollapsed(bv).wid;
398 y += dimensionCollapsed(bv).des + textdim.asc;
413 bool InsetCollapsable::editable() const
415 return geometry() != ButtonOnly;
419 bool InsetCollapsable::descendable() const
421 return geometry() != ButtonOnly;
425 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
427 return button_dim.contains(cmd.x, cmd.y);
431 docstring const InsetCollapsable::getNewLabel(docstring const & l) const
434 pos_type const max_length = 15;
435 pos_type const p_siz = paragraphs().begin()->size();
436 pos_type const n = min(max_length, p_siz);
439 for (; i < n && j < p_siz; ++j) {
440 if (paragraphs().begin()->isInset(j))
442 label += paragraphs().begin()->getChar(j);
445 if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
448 return label.empty() ? l : label;
452 void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
454 //lyxerr << "InsetCollapsable: edit left/right" << endl;
456 InsetText::edit(cur, front, entry_from);
460 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
462 //lyxerr << "InsetCollapsable: edit xy" << endl;
463 if (geometry(cur.bv()) == ButtonOnly
464 || (button_dim.contains(x, y)
465 && geometry(cur.bv()) != NoButton))
468 return InsetText::editXY(cur, x, y);
472 void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
474 //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
475 // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
477 switch (cmd.action) {
478 case LFUN_MOUSE_PRESS:
479 if (hitButton(cmd)) {
480 switch (cmd.button()) {
481 case mouse_button::button1:
482 case mouse_button::button3:
483 // Pass the command to the enclosing InsetText,
484 // so that the cursor gets set.
487 case mouse_button::none:
488 case mouse_button::button2:
489 case mouse_button::button4:
490 case mouse_button::button5:
495 } else if (geometry(cur.bv()) != ButtonOnly)
496 InsetText::doDispatch(cur, cmd);
501 case LFUN_MOUSE_MOTION:
502 case LFUN_MOUSE_DOUBLE:
503 case LFUN_MOUSE_TRIPLE:
506 else if (geometry(cur.bv()) != ButtonOnly)
507 InsetText::doDispatch(cur, cmd);
512 case LFUN_MOUSE_RELEASE:
513 if (!hitButton(cmd)) {
514 // The mouse click has to be within the inset!
515 if (geometry(cur.bv()) != ButtonOnly)
516 InsetText::doDispatch(cur, cmd);
521 if (cmd.button() != mouse_button::button1) {
526 // if we are selecting, we do not want to
530 // Left button is clicked, the user asks to
531 // toggle the inset visual state.
533 cur.updateFlags(Update::Force | Update::FitCursor);
534 if (geometry(cur.bv()) == ButtonOnly) {
535 setStatus(cur, Open);
539 setStatus(cur, Collapsed);
540 cur.bv().cursor() = cur;
543 case LFUN_INSET_TOGGLE:
544 if (cmd.argument() == "open")
545 setStatus(cur, Open);
546 else if (cmd.argument() == "close")
547 setStatus(cur, Collapsed);
548 else if (cmd.argument() == "toggle" || cmd.argument().empty())
549 if (status_ == Open) {
550 setStatus(cur, Collapsed);
551 if (geometry(cur.bv()) == ButtonOnly)
552 cur.top().forwardPos();
554 setStatus(cur, Open);
555 else // if assign or anything else
561 case LFUN_CLIPBOARD_PASTE:
562 case LFUN_SELECTION_PASTE:
563 case LFUN_PRIMARY_SELECTION_PASTE: {
564 InsetText::doDispatch(cur, cmd);
565 // Since we can only store plain text, we must reset all
567 // FIXME: Change only the pasted paragraphs
569 resetParagraphsFont();
573 case LFUN_TAB_INSERT: {
574 bool const multi_par_selection = cur.selection() &&
575 cur.selBegin().pit() != cur.selEnd().pit();
576 if (multi_par_selection) {
577 // If there is a multi-paragraph selection, a tab is inserted
578 // at the beginning of each paragraph.
579 cur.recordUndoSelection();
580 pit_type const pit_end = cur.selEnd().pit();
581 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
582 paragraphs()[pit].insertChar(0, '\t',
583 buffer().params().trackChanges);
584 // Update the selection pos to make sure the selection does not
585 // change as the inserted tab will increase the logical pos.
586 if (cur.anchor_.pit() == pit)
587 cur.anchor_.forwardPos();
588 if (cur.pit() == pit)
593 // Maybe we shouldn't allow tabs within a line, because they
594 // are not (yet) aligned as one might do expect.
595 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
601 case LFUN_TAB_DELETE:
602 if (cur.selection()) {
603 // If there is a selection, a tab (if present) is removed from
604 // the beginning of each paragraph.
605 cur.recordUndoSelection();
606 pit_type const pit_end = cur.selEnd().pit();
607 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
608 Paragraph & par = paragraphs()[pit];
609 if (par.getChar(0) == '\t') {
610 if (cur.pit() == pit)
612 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
613 cur.anchor_.backwardPos();
615 par.eraseChar(0, buffer().params().trackChanges);
617 // If no tab was present, try to remove up to four spaces.
618 for (int n_spaces = 0;
619 par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
620 if (cur.pit() == pit)
622 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
623 cur.anchor_.backwardPos();
625 par.eraseChar(0, buffer().params().trackChanges);
630 // If there is no selection, try to remove a tab or some spaces
631 // before the position of the cursor.
632 Paragraph & par = paragraphs()[cur.pit()];
633 pos_type const pos = cur.pos();
638 char_type const c = par.getChar(pos - 1);
642 par.eraseChar(cur.pos(), buffer().params().trackChanges);
644 for (int n_spaces = 0; cur.pos() > 0
645 && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
648 par.eraseChar(cur.pos(), buffer().params().trackChanges);
655 if (getLayout().isForceLtr()) {
656 // Force any new text to latex_language
657 // FIXME: This should only be necessary in constructor, but
658 // new paragraphs that are created by pressing enter at the
659 // start of an existing paragraph get the buffer language
660 // and not latex_language, so we take this brute force
662 cur.current_font.setLanguage(latex_language);
663 cur.real_current_font.setLanguage(latex_language);
665 InsetText::doDispatch(cur, cmd);
671 void InsetCollapsable::resetParagraphsFont()
673 Font font(inherit_font, buffer().params().language);
674 if (getLayout().isForceLtr())
675 font.setLanguage(latex_language);
676 if (getLayout().isPassThru()) {
677 ParagraphList::iterator par = paragraphs().begin();
678 ParagraphList::iterator const end = paragraphs().end();
680 par->resetFonts(font);
681 par->params().clear();
688 bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
689 FuncStatus & flag) const
691 switch (cmd.action) {
692 // FIXME At present, these are being enabled and disabled according to
693 // whether PASSTHRU has been set in the InsetLayout. This makes some
694 // sense, but there are other checks that should really be done. E.g.,
695 // one should not be able to inset IndexPrint inside an optional argument!!
696 case LFUN_ACCENT_ACUTE:
697 case LFUN_ACCENT_BREVE:
698 case LFUN_ACCENT_CARON:
699 case LFUN_ACCENT_CEDILLA:
700 case LFUN_ACCENT_CIRCLE:
701 case LFUN_ACCENT_CIRCUMFLEX:
702 case LFUN_ACCENT_DOT:
703 case LFUN_ACCENT_GRAVE:
704 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
705 case LFUN_ACCENT_MACRON:
706 case LFUN_ACCENT_OGONEK:
707 case LFUN_ACCENT_TIE:
708 case LFUN_ACCENT_TILDE:
709 case LFUN_ACCENT_UMLAUT:
710 case LFUN_ACCENT_UNDERBAR:
711 case LFUN_ACCENT_UNDERDOT:
713 case LFUN_BOX_INSERT:
714 case LFUN_BRANCH_INSERT:
715 case LFUN_CAPTION_INSERT:
716 case LFUN_DEPTH_DECREMENT:
717 case LFUN_DEPTH_INCREMENT:
718 case LFUN_ERT_INSERT:
719 case LFUN_FILE_INSERT:
720 case LFUN_FLEX_INSERT:
721 case LFUN_FLOAT_INSERT:
722 case LFUN_FLOAT_LIST_INSERT:
723 case LFUN_FLOAT_WIDE_INSERT:
725 case LFUN_FONT_BOLDSYMBOL:
726 case LFUN_FONT_TYPEWRITER:
727 case LFUN_FONT_DEFAULT:
730 case LFUN_FONT_ROMAN:
735 case LFUN_FONT_STATE:
736 case LFUN_FONT_UNDERLINE:
737 case LFUN_FONT_STRIKEOUT:
738 case LFUN_FONT_UULINE:
739 case LFUN_FONT_UWAVE:
740 case LFUN_FOOTNOTE_INSERT:
741 case LFUN_HYPERLINK_INSERT:
742 case LFUN_INDEX_INSERT:
743 case LFUN_INDEX_PRINT:
744 case LFUN_INSET_INSERT:
745 case LFUN_LABEL_GOTO:
746 case LFUN_LABEL_INSERT:
747 case LFUN_LAYOUT_TABULAR:
748 case LFUN_LINE_INSERT:
749 case LFUN_MARGINALNOTE_INSERT:
750 case LFUN_MATH_DISPLAY:
751 case LFUN_MATH_INSERT:
752 case LFUN_MATH_AMS_MATRIX:
753 case LFUN_MATH_MATRIX:
756 case LFUN_NEWLINE_INSERT:
757 case LFUN_NEWPAGE_INSERT:
759 case LFUN_NOMENCL_INSERT:
760 case LFUN_NOMENCL_PRINT:
761 case LFUN_NOTE_INSERT:
763 case LFUN_OPTIONAL_INSERT:
764 case LFUN_PHANTOM_INSERT:
765 case LFUN_REFERENCE_NEXT:
766 case LFUN_SERVER_GOTO_FILE_ROW:
767 case LFUN_SERVER_NOTIFY:
768 case LFUN_SERVER_SET_XY:
769 case LFUN_SPACE_INSERT:
770 case LFUN_SPECIALCHAR_INSERT:
771 case LFUN_TABULAR_INSERT:
772 case LFUN_TEXTSTYLE_APPLY:
773 case LFUN_TEXTSTYLE_UPDATE:
774 case LFUN_TOC_INSERT:
775 case LFUN_WRAP_INSERT:
776 if (getLayout().isPassThru()) {
777 flag.setEnabled(false);
780 return InsetText::getStatus(cur, cmd, flag);
782 case LFUN_INSET_TOGGLE:
783 if (cmd.argument() == "open")
784 flag.setEnabled(status_ != Open);
785 else if (cmd.argument() == "close")
786 flag.setEnabled(status_ == Open);
787 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
788 flag.setEnabled(true);
789 flag.setOnOff(status_ == Open);
791 flag.setEnabled(false);
795 flag.setEnabled(!getLayout().isForceLtr());
796 return InsetText::getStatus(cur, cmd, flag);
798 case LFUN_BREAK_PARAGRAPH:
799 flag.setEnabled(getLayout().isMultiPar());
802 case LFUN_TAB_INSERT:
803 case LFUN_TAB_DELETE:
804 if (getLayout().isPassThru()) {
805 flag.setEnabled(true);
808 return InsetText::getStatus(cur, cmd, flag);
811 return InsetText::getStatus(cur, cmd, flag);
816 void InsetCollapsable::setLabel(docstring const & l)
822 void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
826 if (status_ == Collapsed) {
827 cur.leaveInset(*this);
828 mouse_hover_ = false;
833 docstring InsetCollapsable::floatName(string const & type) const
835 BufferParams const & bp = buffer().params();
836 FloatList const & floats = bp.documentClass().floats();
837 FloatList::const_iterator it = floats[type];
839 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
843 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
845 InsetLayout::InsetDecoration const dec = getLayout().decoration();
846 return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
850 int InsetCollapsable::latex(odocstream & os,
851 OutputParams const & runparams) const
853 // This implements the standard way of handling the LaTeX output of
854 // a collapsable inset, either a command or an environment. Standard
855 // collapsable insets should not redefine this, non-standard ones may
857 if (!getLayout().latexname().empty()) {
858 if (getLayout().latextype() == InsetLayout::COMMAND) {
860 if (runparams.moving_arg)
862 os << '\\' << from_utf8(getLayout().latexname());
863 if (!getLayout().latexparam().empty())
864 os << from_utf8(getLayout().latexparam());
866 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
867 os << "%\n\\begin{" << from_utf8(getLayout().latexname()) << "}\n";
868 if (!getLayout().latexparam().empty())
869 os << from_utf8(getLayout().latexparam());
872 OutputParams rp = runparams;
873 if (getLayout().isPassThru())
875 if (getLayout().isNeedProtect())
876 rp.moving_arg = true;
877 int i = InsetText::latex(os, rp);
878 if (!getLayout().latexname().empty()) {
879 if (getLayout().latextype() == InsetLayout::COMMAND) {
881 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
882 os << "\n\\end{" << from_utf8(getLayout().latexname()) << "}\n";
890 // FIXME It seems as if it ought to be possible to do this more simply,
891 // maybe by calling InsetText::docbook() in the middle there.
892 int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
894 ParagraphList::const_iterator const beg = paragraphs().begin();
895 ParagraphList::const_iterator par = paragraphs().begin();
896 ParagraphList::const_iterator const end = paragraphs().end();
899 sgml::openTag(os, getLayout().latexname(),
900 par->getID(buffer(), runparams) + getLayout().latexparam());
902 for (; par != end; ++par) {
903 par->simpleDocBookOnePar(buffer(), os, runparams,
904 outerFont(distance(beg, par),
909 sgml::closeTag(os, getLayout().latexname());
915 docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
917 InsetLayout const & il = getLayout();
919 return InsetText::xhtml(os, runparams);
921 bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
922 if (!il.counter().empty()) {
923 BufferParams const & bp = buffer().masterBuffer()->params();
924 Counters & cntrs = bp.documentClass().counters();
925 cntrs.step(il.counter());
926 // FIXME: translate to paragraph language
927 if (!il.htmllabel().empty())
928 os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
930 bool innertag_opened = false;
931 if (!il.htmlinnertag().empty())
932 innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
933 docstring deferred = InsetText::xhtml(os, runparams);
935 html::closeTag(os, il.htmlinnertag());
937 html::closeTag(os, il.htmltag());
942 void InsetCollapsable::validate(LaTeXFeatures & features) const
944 features.useInsetLayout(getLayout());
945 InsetText::validate(features);
949 bool InsetCollapsable::undefined() const
951 docstring const & n = getLayout().name();
952 return n.empty() || n == DocumentClass::plainInsetLayout().name();
956 docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
959 if (decoration() == InsetLayout::CONGLOMERATE)
960 return from_ascii("context-conglomerate");
962 if (geometry(bv) == NoButton)
963 return from_ascii("context-collapsable");
965 Dimension dim = dimensionCollapsed(bv);
966 if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
967 return from_ascii("context-collapsable");
969 return InsetText::contextMenu(bv, x, y);
972 void InsetCollapsable::tocString(odocstream & os) const
974 if (!getLayout().isInToc())
976 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);