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 setLayout(&buf.params().documentClass());
113 setAutoBreakRows(true);
115 setFrameColor(Color_collapsableframe);
119 InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
121 status_(rhs.status_),
122 layout_(rhs.layout_),
123 labelstring_(rhs.labelstring_),
124 button_dim(rhs.button_dim),
125 openinlined_(rhs.openinlined_),
126 auto_open_(rhs.auto_open_),
127 // the sole purpose of this copy constructor
133 docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
135 Dimension dim = dimensionCollapsed(bv);
136 if (geometry(bv) == NoButton)
137 return translateIfPossible(getLayout().labelstring());
138 if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
141 OutputParams rp(&buffer().params().encoding());
142 odocstringstream ods;
143 InsetText::plaintext(ods, rp);
144 docstring const content_tip = ods.str();
145 return support::wrapParas(content_tip, 4);
149 void InsetCollapsable::setLayout(BufferParams const & bp)
151 setLayout(bp.documentClassPtr());
155 void InsetCollapsable::setLayout(DocumentClass const * const dc)
158 layout_ = &(dc->insetLayout(name()));
159 labelstring_ = translateIfPossible(getLayout().labelstring());
161 layout_ = &DocumentClass::plainInsetLayout();
162 labelstring_ = _("UNDEFINED");
169 void InsetCollapsable::write(ostream & os) const
181 text().write(buffer(), os);
185 void InsetCollapsable::read(Lexer & lex)
187 lex.setContext("InsetCollapsable::read");
190 lex >> "status" >> tmp_token;
191 if (tmp_token == "open")
194 // this must be set before we enter InsetText::read()
195 setLayout(buffer().params());
196 InsetText::read(lex);
197 // set button label again as the inset contents was not read yet at
201 // Force default font, if so requested
202 // This avoids paragraphs in buffer language that would have a
203 // foreign language after a document language change, and it ensures
204 // that all new text in ERT and similar gets the "latex" language,
205 // since new text inherits the language from the last position of the
206 // existing text. As a side effect this makes us also robust against
207 // bugs in LyX that might lead to font changes in ERT in .lyx files.
208 resetParagraphsFont();
212 Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
214 LASSERT(layout_, /**/);
216 theFontMetrics(getLayout().labelfont()).buttonText(
217 buttonLabel(bv), dim.wid, dim.asc, dim.des);
222 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
224 auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
226 FontInfo tmpfont = mi.base.font;
227 mi.base.font = getLayout().font();
228 mi.base.font.realize(tmpfont);
230 BufferView const & bv = *mi.base.bv;
232 switch (geometry(bv)) {
234 InsetText::metrics(mi, dim);
237 InsetText::metrics(mi, dim);
242 InsetText::metrics(mi, dim);
243 // consider width of the inset label
244 FontInfo font(getLayout().labelfont());
245 font.realize(sane_font);
251 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
258 dim = dimensionCollapsed(bv);
259 if (geometry(bv) == TopButton
260 || geometry(bv) == LeftButton) {
262 InsetText::metrics(mi, textdim);
263 openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
265 // Correct for button width.
266 dim.wid += textdim.wid;
267 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
268 dim.asc = textdim.asc;
270 dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
271 dim.wid = max(dim.wid, textdim.wid);
277 mi.base.font = tmpfont;
281 bool InsetCollapsable::setMouseHover(bool mouse_hover)
283 mouse_hover_ = mouse_hover;
288 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
290 BufferView const & bv = *pi.base.bv;
292 auto_open_[&bv] = bv.cursor().isInside(this);
294 FontInfo tmpfont = pi.base.font;
295 pi.base.font = getLayout().font();
296 pi.base.font.realize(tmpfont);
298 // Draw button first -- top, left or only
299 Dimension dimc = dimensionCollapsed(bv);
301 if (geometry(*pi.base.bv) == TopButton ||
302 geometry(*pi.base.bv) == LeftButton ||
303 geometry(*pi.base.bv) == ButtonOnly) {
304 button_dim.x1 = x + 0;
305 button_dim.x2 = x + dimc.width();
306 button_dim.y1 = y - dimc.asc;
307 button_dim.y2 = y + dimc.des;
309 pi.pain.buttonText(x, y, buttonLabel(bv), getLayout().labelfont(),
318 Dimension const textdim = InsetText::dimension(bv);
319 int const baseline = y;
321 switch (geometry(bv)) {
323 textx = x + dimc.width();
325 InsetText::draw(pi, textx, texty);
329 texty = baseline + dimc.des + textdim.asc;
330 InsetText::draw(pi, textx, texty);
337 InsetText::draw(pi, textx, texty);
343 const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
344 InsetText::draw(pi, textx, texty);
345 const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
347 int desc = textdim.descent();
348 if (geometry(bv) == Corners)
351 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
352 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
353 pi.pain.line(xx1, y + desc - 4,
355 getLayout().labelfont().color());
357 pi.pain.line(xx1, y + desc,
359 getLayout().labelfont().color());
361 // Make status_ value visible:
362 pi.pain.line(xx1, y + desc,
364 getLayout().labelfont().color());
365 pi.pain.line(xx2 - 4, y + desc,
367 getLayout().labelfont().color());
369 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
370 y + desc - 4, getLayout().labelfont().color());
372 // the label below the text. Can be toggled.
373 if (geometry(bv) == SubLabel) {
374 FontInfo font(getLayout().labelfont());
375 font.realize(sane_font);
381 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
382 int const ww = max(textdim.wid, w);
383 pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
384 buttonLabel(bv), font, Color_none, Color_none);
388 // a visual cue when the cursor is inside the inset
389 Cursor const & cur = bv.cursor();
390 if (cur.isInside(this)) {
393 pi.pain.line(xx1, y + 4, xx1, y, getLayout().labelfont().color());
394 pi.pain.line(xx1 + 4, y, xx1, y, getLayout().labelfont().color());
395 pi.pain.line(xx2, y + 4, xx2, y,
396 getLayout().labelfont().color());
397 pi.pain.line(xx2 - 4, y, xx2, y,
398 getLayout().labelfont().color());
403 pi.base.font = tmpfont;
407 void InsetCollapsable::cursorPos(BufferView const & bv,
408 CursorSlice const & sl, bool boundary, int & x, int & y) const
410 if (geometry(bv) == ButtonOnly)
412 LASSERT(geometry(bv) != ButtonOnly, /**/);
414 InsetText::cursorPos(bv, sl, boundary, x, y);
415 Dimension const textdim = InsetText::dimension(bv);
417 switch (geometry(bv)) {
419 x += dimensionCollapsed(bv).wid;
422 y += dimensionCollapsed(bv).des + textdim.asc;
437 bool InsetCollapsable::editable() const
439 return geometry() != ButtonOnly;
443 bool InsetCollapsable::descendable() const
445 return geometry() != ButtonOnly;
449 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
451 return button_dim.contains(cmd.x, cmd.y);
455 docstring const InsetCollapsable::getNewLabel(docstring const & l) const
458 pos_type const max_length = 15;
459 pos_type const p_siz = paragraphs().begin()->size();
460 pos_type const n = min(max_length, p_siz);
463 for (; i < n && j < p_siz; ++j) {
464 if (paragraphs().begin()->isInset(j))
466 label += paragraphs().begin()->getChar(j);
469 if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
472 return label.empty() ? l : label;
476 void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
478 //lyxerr << "InsetCollapsable: edit left/right" << endl;
480 InsetText::edit(cur, front, entry_from);
484 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
486 //lyxerr << "InsetCollapsable: edit xy" << endl;
487 if (geometry(cur.bv()) == ButtonOnly
488 || (button_dim.contains(x, y)
489 && geometry(cur.bv()) != NoButton))
492 return InsetText::editXY(cur, x, y);
496 void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
498 //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
499 // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
501 switch (cmd.action) {
502 case LFUN_MOUSE_PRESS:
503 if (hitButton(cmd)) {
504 switch (cmd.button()) {
505 case mouse_button::button1:
506 case mouse_button::button3:
507 // Pass the command to the enclosing InsetText,
508 // so that the cursor gets set.
511 case mouse_button::none:
512 case mouse_button::button2:
513 case mouse_button::button4:
514 case mouse_button::button5:
519 } else if (geometry(cur.bv()) != ButtonOnly)
520 InsetText::doDispatch(cur, cmd);
525 case LFUN_MOUSE_MOTION:
526 case LFUN_MOUSE_DOUBLE:
527 case LFUN_MOUSE_TRIPLE:
530 else if (geometry(cur.bv()) != ButtonOnly)
531 InsetText::doDispatch(cur, cmd);
536 case LFUN_MOUSE_RELEASE:
537 if (!hitButton(cmd)) {
538 // The mouse click has to be within the inset!
539 if (geometry(cur.bv()) != ButtonOnly)
540 InsetText::doDispatch(cur, cmd);
545 if (cmd.button() != mouse_button::button1) {
550 // if we are selecting, we do not want to
554 // Left button is clicked, the user asks to
555 // toggle the inset visual state.
557 cur.updateFlags(Update::Force | Update::FitCursor);
558 if (geometry(cur.bv()) == ButtonOnly) {
559 setStatus(cur, Open);
563 setStatus(cur, Collapsed);
564 cur.bv().cursor() = cur;
567 case LFUN_INSET_TOGGLE:
568 if (cmd.argument() == "open")
569 setStatus(cur, Open);
570 else if (cmd.argument() == "close")
571 setStatus(cur, Collapsed);
572 else if (cmd.argument() == "toggle" || cmd.argument().empty())
573 if (status_ == Open) {
574 setStatus(cur, Collapsed);
575 if (geometry(cur.bv()) == ButtonOnly)
576 cur.top().forwardPos();
578 setStatus(cur, Open);
579 else // if assign or anything else
585 case LFUN_CLIPBOARD_PASTE:
586 case LFUN_SELECTION_PASTE:
587 case LFUN_PRIMARY_SELECTION_PASTE: {
588 InsetText::doDispatch(cur, cmd);
589 // Since we can only store plain text, we must reset all
591 // FIXME: Change only the pasted paragraphs
593 resetParagraphsFont();
597 case LFUN_TAB_INSERT: {
598 bool const multi_par_selection = cur.selection() &&
599 cur.selBegin().pit() != cur.selEnd().pit();
600 if (multi_par_selection) {
601 // If there is a multi-paragraph selection, a tab is inserted
602 // at the beginning of each paragraph.
603 cur.recordUndoSelection();
604 pit_type const pit_end = cur.selEnd().pit();
605 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
606 paragraphs()[pit].insertChar(0, '\t',
607 buffer().params().trackChanges);
608 // Update the selection pos to make sure the selection does not
609 // change as the inserted tab will increase the logical pos.
610 if (cur.anchor_.pit() == pit)
611 cur.anchor_.forwardPos();
612 if (cur.pit() == pit)
617 // Maybe we shouldn't allow tabs within a line, because they
618 // are not (yet) aligned as one might do expect.
619 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
625 case LFUN_TAB_DELETE:
626 if (cur.selection()) {
627 // If there is a selection, a tab (if present) is removed from
628 // the beginning of each paragraph.
629 cur.recordUndoSelection();
630 pit_type const pit_end = cur.selEnd().pit();
631 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
632 Paragraph & par = paragraphs()[pit];
633 if (par.getChar(0) == '\t') {
634 if (cur.pit() == pit)
636 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
637 cur.anchor_.backwardPos();
639 par.eraseChar(0, buffer().params().trackChanges);
641 // If no tab was present, try to remove up to four spaces.
642 for (int n_spaces = 0;
643 par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
644 if (cur.pit() == pit)
646 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
647 cur.anchor_.backwardPos();
649 par.eraseChar(0, buffer().params().trackChanges);
654 // If there is no selection, try to remove a tab or some spaces
655 // before the position of the cursor.
656 Paragraph & par = paragraphs()[cur.pit()];
657 pos_type const pos = cur.pos();
662 char_type const c = par.getChar(pos - 1);
666 par.eraseChar(cur.pos(), buffer().params().trackChanges);
668 for (int n_spaces = 0; cur.pos() > 0
669 && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
672 par.eraseChar(cur.pos(), buffer().params().trackChanges);
679 if (getLayout().isForceLtr()) {
680 // Force any new text to latex_language
681 // FIXME: This should only be necessary in constructor, but
682 // new paragraphs that are created by pressing enter at the
683 // start of an existing paragraph get the buffer language
684 // and not latex_language, so we take this brute force
686 cur.current_font.setLanguage(latex_language);
687 cur.real_current_font.setLanguage(latex_language);
689 InsetText::doDispatch(cur, cmd);
695 bool InsetCollapsable::allowMultiPar() const
697 return getLayout().isMultiPar();
701 void InsetCollapsable::resetParagraphsFont()
703 Font font(inherit_font, buffer().params().language);
704 if (getLayout().isForceLtr())
705 font.setLanguage(latex_language);
706 if (getLayout().isPassThru()) {
707 ParagraphList::iterator par = paragraphs().begin();
708 ParagraphList::iterator const end = paragraphs().end();
710 par->resetFonts(font);
711 par->params().clear();
718 bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
719 FuncStatus & flag) const
721 switch (cmd.action) {
722 // FIXME At present, these are being enabled and disabled according to
723 // whether PASSTHRU has been set in the InsetLayout. This makes some
724 // sense, but there are other checks that should really be done. E.g.,
725 // one should not be able to inset IndexPrint inside an optional argument!!
726 case LFUN_ACCENT_ACUTE:
727 case LFUN_ACCENT_BREVE:
728 case LFUN_ACCENT_CARON:
729 case LFUN_ACCENT_CEDILLA:
730 case LFUN_ACCENT_CIRCLE:
731 case LFUN_ACCENT_CIRCUMFLEX:
732 case LFUN_ACCENT_DOT:
733 case LFUN_ACCENT_GRAVE:
734 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
735 case LFUN_ACCENT_MACRON:
736 case LFUN_ACCENT_OGONEK:
737 case LFUN_ACCENT_TIE:
738 case LFUN_ACCENT_TILDE:
739 case LFUN_ACCENT_UMLAUT:
740 case LFUN_ACCENT_UNDERBAR:
741 case LFUN_ACCENT_UNDERDOT:
743 case LFUN_BOX_INSERT:
744 case LFUN_BRANCH_INSERT:
745 case LFUN_CAPTION_INSERT:
746 case LFUN_DEPTH_DECREMENT:
747 case LFUN_DEPTH_INCREMENT:
748 case LFUN_ERT_INSERT:
749 case LFUN_FILE_INSERT:
750 case LFUN_FLEX_INSERT:
751 case LFUN_FLOAT_INSERT:
752 case LFUN_FLOAT_LIST_INSERT:
753 case LFUN_FLOAT_WIDE_INSERT:
755 case LFUN_FONT_BOLDSYMBOL:
756 case LFUN_FONT_TYPEWRITER:
757 case LFUN_FONT_DEFAULT:
760 case LFUN_FONT_ROMAN:
765 case LFUN_FONT_STATE:
766 case LFUN_FONT_UNDERLINE:
767 case LFUN_FONT_STRIKEOUT:
768 case LFUN_FONT_UULINE:
769 case LFUN_FONT_UWAVE:
770 case LFUN_FOOTNOTE_INSERT:
771 case LFUN_HYPERLINK_INSERT:
772 case LFUN_INDEX_INSERT:
773 case LFUN_INDEX_PRINT:
774 case LFUN_INSET_INSERT:
775 case LFUN_LABEL_GOTO:
776 case LFUN_LABEL_INSERT:
777 case LFUN_LAYOUT_TABULAR:
778 case LFUN_LINE_INSERT:
779 case LFUN_MARGINALNOTE_INSERT:
780 case LFUN_MATH_DISPLAY:
781 case LFUN_MATH_INSERT:
782 case LFUN_MATH_AMS_MATRIX:
783 case LFUN_MATH_MATRIX:
786 case LFUN_NEWLINE_INSERT:
787 case LFUN_NEWPAGE_INSERT:
789 case LFUN_NOMENCL_INSERT:
790 case LFUN_NOMENCL_PRINT:
791 case LFUN_NOTE_INSERT:
793 case LFUN_OPTIONAL_INSERT:
794 case LFUN_PHANTOM_INSERT:
795 case LFUN_REFERENCE_NEXT:
796 case LFUN_SERVER_GOTO_FILE_ROW:
797 case LFUN_SERVER_NOTIFY:
798 case LFUN_SERVER_SET_XY:
799 case LFUN_SPACE_INSERT:
800 case LFUN_SPECIALCHAR_INSERT:
801 case LFUN_TABULAR_INSERT:
802 case LFUN_TEXTSTYLE_APPLY:
803 case LFUN_TEXTSTYLE_UPDATE:
804 case LFUN_TOC_INSERT:
805 case LFUN_WRAP_INSERT:
806 if (getLayout().isPassThru()) {
807 flag.setEnabled(false);
810 return InsetText::getStatus(cur, cmd, flag);
812 case LFUN_INSET_TOGGLE:
813 if (cmd.argument() == "open")
814 flag.setEnabled(status_ != Open);
815 else if (cmd.argument() == "close")
816 flag.setEnabled(status_ == Open);
817 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
818 flag.setEnabled(true);
819 flag.setOnOff(status_ == Open);
821 flag.setEnabled(false);
825 flag.setEnabled(!getLayout().isForceLtr());
826 return InsetText::getStatus(cur, cmd, flag);
828 case LFUN_BREAK_PARAGRAPH:
829 flag.setEnabled(getLayout().isMultiPar());
832 case LFUN_TAB_INSERT:
833 case LFUN_TAB_DELETE:
834 if (getLayout().isPassThru()) {
835 flag.setEnabled(true);
838 return InsetText::getStatus(cur, cmd, flag);
841 return InsetText::getStatus(cur, cmd, flag);
846 void InsetCollapsable::setLabel(docstring const & l)
852 void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
856 if (status_ == Collapsed) {
857 cur.leaveInset(*this);
858 mouse_hover_ = false;
863 docstring InsetCollapsable::floatName(
864 string const & type, BufferParams const & bp) const
866 FloatList const & floats = bp.documentClass().floats();
867 FloatList::const_iterator it = floats[type];
869 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
873 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
875 InsetLayout::InsetDecoration const dec = getLayout().decoration();
877 case InsetLayout::CLASSIC:
878 case InsetLayout::MINIMALISTIC:
879 case InsetLayout::CONGLOMERATE:
881 case InsetLayout::DEFAULT:
884 if (lyxCode() == FLEX_CODE)
885 return InsetLayout::CONGLOMERATE;
886 return InsetLayout::CLASSIC;
890 int InsetCollapsable::latex(odocstream & os,
891 OutputParams const & runparams) const
893 // This implements the standard way of handling the LaTeX output of
894 // a collapsable inset, either a command or an environment. Standard
895 // collapsable insets should not redefine this, non-standard ones may
897 if (!getLayout().latexname().empty()) {
898 if (getLayout().latextype() == InsetLayout::COMMAND) {
900 if (runparams.moving_arg)
902 os << '\\' << from_utf8(getLayout().latexname());
903 if (!getLayout().latexparam().empty())
904 os << from_utf8(getLayout().latexparam());
906 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
907 os << "%\n\\begin{" << from_utf8(getLayout().latexname()) << "}\n";
908 if (!getLayout().latexparam().empty())
909 os << from_utf8(getLayout().latexparam());
912 OutputParams rp = runparams;
913 if (getLayout().isPassThru())
915 if (getLayout().isNeedProtect())
916 rp.moving_arg = true;
917 int i = InsetText::latex(os, rp);
918 if (!getLayout().latexname().empty()) {
919 if (getLayout().latextype() == InsetLayout::COMMAND) {
921 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
922 os << "\n\\end{" << from_utf8(getLayout().latexname()) << "}\n";
930 // FIXME It seems as if it ought to be possible to do this more simply,
931 // maybe by calling InsetText::docbook() in the middle there.
932 int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
934 ParagraphList::const_iterator const beg = paragraphs().begin();
935 ParagraphList::const_iterator par = paragraphs().begin();
936 ParagraphList::const_iterator const end = paragraphs().end();
939 sgml::openTag(os, getLayout().latexname(),
940 par->getID(buffer(), runparams) + getLayout().latexparam());
942 for (; par != end; ++par) {
943 par->simpleDocBookOnePar(buffer(), os, runparams,
944 outerFont(distance(beg, par),
949 sgml::closeTag(os, getLayout().latexname());
955 docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
957 InsetLayout const & il = getLayout();
959 return InsetText::xhtml(os, runparams);
961 bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
962 if (!il.counter().empty()) {
963 BufferParams const & bp = buffer().masterBuffer()->params();
964 Counters & cntrs = bp.documentClass().counters();
965 cntrs.step(il.counter());
966 // FIXME: translate to paragraph language
967 if (!il.htmllabel().empty())
968 os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
970 bool innertag_opened = false;
971 if (!il.htmlinnertag().empty())
972 innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
973 docstring deferred = InsetText::xhtml(os, runparams);
975 html::closeTag(os, il.htmlinnertag());
977 html::closeTag(os, il.htmltag());
982 void InsetCollapsable::validate(LaTeXFeatures & features) const
984 features.useInsetLayout(getLayout());
985 InsetText::validate(features);
989 bool InsetCollapsable::undefined() const
991 docstring const & n = getLayout().name();
992 return n.empty() || n == DocumentClass::plainInsetLayout().name();
996 docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
999 if (decoration() == InsetLayout::CONGLOMERATE)
1000 return from_ascii("context-conglomerate");
1002 if (geometry(bv) == NoButton)
1003 return from_ascii("context-collapsable");
1005 Dimension dim = dimensionCollapsed(bv);
1006 if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
1007 return from_ascii("context-collapsable");
1009 return InsetText::contextMenu(bv, x, y);
1012 void InsetCollapsable::tocString(odocstream & os) const
1014 if (!getLayout().isInToc())
1016 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);