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(layout_->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(layout_->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(layout_->labelfont()).buttonText(
217 buttonLabel(bv), dim.wid, dim.asc, dim.des);
222 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
224 LASSERT(layout_, /**/);
226 auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
228 FontInfo tmpfont = mi.base.font;
229 mi.base.font = layout_->font();
230 mi.base.font.realize(tmpfont);
232 BufferView const & bv = *mi.base.bv;
234 switch (geometry(bv)) {
236 InsetText::metrics(mi, dim);
239 InsetText::metrics(mi, dim);
244 InsetText::metrics(mi, dim);
245 // consider width of the inset label
246 FontInfo font(layout_->labelfont());
247 font.realize(sane_font);
253 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
260 dim = dimensionCollapsed(bv);
261 if (geometry(bv) == TopButton
262 || geometry(bv) == LeftButton) {
264 InsetText::metrics(mi, textdim);
265 openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
267 // Correct for button width.
268 dim.wid += textdim.wid;
269 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
270 dim.asc = textdim.asc;
272 dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
273 dim.wid = max(dim.wid, textdim.wid);
279 mi.base.font = tmpfont;
283 bool InsetCollapsable::setMouseHover(bool mouse_hover)
285 mouse_hover_ = mouse_hover;
290 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
292 LASSERT(layout_, /**/);
293 BufferView const & bv = *pi.base.bv;
295 auto_open_[&bv] = bv.cursor().isInside(this);
297 FontInfo tmpfont = pi.base.font;
298 pi.base.font = layout_->font();
299 pi.base.font.realize(tmpfont);
301 // Draw button first -- top, left or only
302 Dimension dimc = dimensionCollapsed(bv);
304 if (geometry(*pi.base.bv) == TopButton ||
305 geometry(*pi.base.bv) == LeftButton ||
306 geometry(*pi.base.bv) == ButtonOnly) {
307 button_dim.x1 = x + 0;
308 button_dim.x2 = x + dimc.width();
309 button_dim.y1 = y - dimc.asc;
310 button_dim.y2 = y + dimc.des;
312 pi.pain.buttonText(x, y, buttonLabel(bv), layout_->labelfont(),
321 Dimension const textdim = InsetText::dimension(bv);
322 int const baseline = y;
324 switch (geometry(bv)) {
326 textx = x + dimc.width();
328 InsetText::draw(pi, textx, texty);
332 texty = baseline + dimc.des + textdim.asc;
333 InsetText::draw(pi, textx, texty);
340 InsetText::draw(pi, textx, texty);
346 const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
347 InsetText::draw(pi, textx, texty);
348 const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
350 int desc = textdim.descent();
351 if (geometry(bv) == Corners)
354 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
355 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
356 pi.pain.line(xx1, y + desc - 4,
358 layout_->labelfont().color());
360 pi.pain.line(xx1, y + desc,
362 layout_->labelfont().color());
364 // Make status_ value visible:
365 pi.pain.line(xx1, y + desc,
367 layout_->labelfont().color());
368 pi.pain.line(xx2 - 4, y + desc,
370 layout_->labelfont().color());
372 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
373 y + desc - 4, layout_->labelfont().color());
375 // the label below the text. Can be toggled.
376 if (geometry(bv) == SubLabel) {
377 FontInfo font(layout_->labelfont());
378 font.realize(sane_font);
384 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
385 int const ww = max(textdim.wid, w);
386 pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
387 buttonLabel(bv), font, Color_none, Color_none);
391 // a visual cue when the cursor is inside the inset
392 Cursor const & cur = bv.cursor();
393 if (cur.isInside(this)) {
396 pi.pain.line(xx1, y + 4, xx1, y, layout_->labelfont().color());
397 pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont().color());
398 pi.pain.line(xx2, y + 4, xx2, y,
399 layout_->labelfont().color());
400 pi.pain.line(xx2 - 4, y, xx2, y,
401 layout_->labelfont().color());
406 pi.base.font = tmpfont;
410 void InsetCollapsable::cursorPos(BufferView const & bv,
411 CursorSlice const & sl, bool boundary, int & x, int & y) const
413 if (geometry(bv) == ButtonOnly)
415 LASSERT(geometry(bv) != ButtonOnly, /**/);
417 InsetText::cursorPos(bv, sl, boundary, x, y);
418 Dimension const textdim = InsetText::dimension(bv);
420 switch (geometry(bv)) {
422 x += dimensionCollapsed(bv).wid;
425 y += dimensionCollapsed(bv).des + textdim.asc;
440 bool InsetCollapsable::editable() const
442 return geometry() != ButtonOnly;
446 bool InsetCollapsable::descendable() const
448 return geometry() != ButtonOnly;
452 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
454 return button_dim.contains(cmd.x, cmd.y);
458 docstring const InsetCollapsable::getNewLabel(docstring const & l) const
461 pos_type const max_length = 15;
462 pos_type const p_siz = paragraphs().begin()->size();
463 pos_type const n = min(max_length, p_siz);
466 for (; i < n && j < p_siz; ++j) {
467 if (paragraphs().begin()->isInset(j))
469 label += paragraphs().begin()->getChar(j);
472 if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
475 return label.empty() ? l : label;
479 void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
481 //lyxerr << "InsetCollapsable: edit left/right" << endl;
483 InsetText::edit(cur, front, entry_from);
487 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
489 //lyxerr << "InsetCollapsable: edit xy" << endl;
490 if (geometry(cur.bv()) == ButtonOnly
491 || (button_dim.contains(x, y)
492 && geometry(cur.bv()) != NoButton))
495 return InsetText::editXY(cur, x, y);
499 void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
501 //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
502 // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
504 switch (cmd.action) {
505 case LFUN_MOUSE_PRESS:
506 if (hitButton(cmd)) {
507 switch (cmd.button()) {
508 case mouse_button::button1:
509 case mouse_button::button3:
510 // Pass the command to the enclosing InsetText,
511 // so that the cursor gets set.
514 case mouse_button::none:
515 case mouse_button::button2:
516 case mouse_button::button4:
517 case mouse_button::button5:
522 } else if (geometry(cur.bv()) != ButtonOnly)
523 InsetText::doDispatch(cur, cmd);
528 case LFUN_MOUSE_MOTION:
529 case LFUN_MOUSE_DOUBLE:
530 case LFUN_MOUSE_TRIPLE:
533 else if (geometry(cur.bv()) != ButtonOnly)
534 InsetText::doDispatch(cur, cmd);
539 case LFUN_MOUSE_RELEASE:
540 if (!hitButton(cmd)) {
541 // The mouse click has to be within the inset!
542 if (geometry(cur.bv()) != ButtonOnly)
543 InsetText::doDispatch(cur, cmd);
548 if (cmd.button() != mouse_button::button1) {
553 // if we are selecting, we do not want to
557 // Left button is clicked, the user asks to
558 // toggle the inset visual state.
560 cur.updateFlags(Update::Force | Update::FitCursor);
561 if (geometry(cur.bv()) == ButtonOnly) {
562 setStatus(cur, Open);
566 setStatus(cur, Collapsed);
567 cur.bv().cursor() = cur;
570 case LFUN_INSET_TOGGLE:
571 if (cmd.argument() == "open")
572 setStatus(cur, Open);
573 else if (cmd.argument() == "close")
574 setStatus(cur, Collapsed);
575 else if (cmd.argument() == "toggle" || cmd.argument().empty())
576 if (status_ == Open) {
577 setStatus(cur, Collapsed);
578 if (geometry(cur.bv()) == ButtonOnly)
579 cur.top().forwardPos();
581 setStatus(cur, Open);
582 else // if assign or anything else
588 case LFUN_CLIPBOARD_PASTE:
589 case LFUN_SELECTION_PASTE:
590 case LFUN_PRIMARY_SELECTION_PASTE: {
591 InsetText::doDispatch(cur, cmd);
592 // Since we can only store plain text, we must reset all
594 // FIXME: Change only the pasted paragraphs
596 resetParagraphsFont();
600 case LFUN_TAB_INSERT: {
601 bool const multi_par_selection = cur.selection() &&
602 cur.selBegin().pit() != cur.selEnd().pit();
603 if (multi_par_selection) {
604 // If there is a multi-paragraph selection, a tab is inserted
605 // at the beginning of each paragraph.
606 cur.recordUndoSelection();
607 pit_type const pit_end = cur.selEnd().pit();
608 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
609 paragraphs()[pit].insertChar(0, '\t',
610 buffer().params().trackChanges);
611 // Update the selection pos to make sure the selection does not
612 // change as the inserted tab will increase the logical pos.
613 if (cur.anchor_.pit() == pit)
614 cur.anchor_.forwardPos();
615 if (cur.pit() == pit)
620 // Maybe we shouldn't allow tabs within a line, because they
621 // are not (yet) aligned as one might do expect.
622 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
628 case LFUN_TAB_DELETE:
629 if (cur.selection()) {
630 // If there is a selection, a tab (if present) is removed from
631 // the beginning of each paragraph.
632 cur.recordUndoSelection();
633 pit_type const pit_end = cur.selEnd().pit();
634 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
635 Paragraph & par = paragraphs()[pit];
636 if (par.getChar(0) == '\t') {
637 if (cur.pit() == pit)
639 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
640 cur.anchor_.backwardPos();
642 par.eraseChar(0, buffer().params().trackChanges);
644 // If no tab was present, try to remove up to four spaces.
645 for (int n_spaces = 0;
646 par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
647 if (cur.pit() == pit)
649 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
650 cur.anchor_.backwardPos();
652 par.eraseChar(0, buffer().params().trackChanges);
657 // If there is no selection, try to remove a tab or some spaces
658 // before the position of the cursor.
659 Paragraph & par = paragraphs()[cur.pit()];
660 pos_type const pos = cur.pos();
665 char_type const c = par.getChar(pos - 1);
669 par.eraseChar(cur.pos(), buffer().params().trackChanges);
671 for (int n_spaces = 0; cur.pos() > 0
672 && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
675 par.eraseChar(cur.pos(), buffer().params().trackChanges);
682 if (layout_ && layout_->isForceLtr()) {
683 // Force any new text to latex_language
684 // FIXME: This should only be necessary in constructor, but
685 // new paragraphs that are created by pressing enter at the
686 // start of an existing paragraph get the buffer language
687 // and not latex_language, so we take this brute force
689 cur.current_font.setLanguage(latex_language);
690 cur.real_current_font.setLanguage(latex_language);
692 InsetText::doDispatch(cur, cmd);
698 bool InsetCollapsable::allowMultiPar() const
700 return layout_->isMultiPar();
704 void InsetCollapsable::resetParagraphsFont()
706 Font font(inherit_font, buffer().params().language);
707 if (layout_->isForceLtr())
708 font.setLanguage(latex_language);
709 if (layout_->isPassThru()) {
710 ParagraphList::iterator par = paragraphs().begin();
711 ParagraphList::iterator const end = paragraphs().end();
713 par->resetFonts(font);
714 par->params().clear();
721 bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
722 FuncStatus & flag) const
724 switch (cmd.action) {
725 // FIXME At present, these are being enabled and disabled according to
726 // whether PASSTHRU has been set in the InsetLayout. This makes some
727 // sense, but there are other checks that should really be done. E.g.,
728 // one should not be able to inset IndexPrint inside an optional argument!!
729 case LFUN_ACCENT_ACUTE:
730 case LFUN_ACCENT_BREVE:
731 case LFUN_ACCENT_CARON:
732 case LFUN_ACCENT_CEDILLA:
733 case LFUN_ACCENT_CIRCLE:
734 case LFUN_ACCENT_CIRCUMFLEX:
735 case LFUN_ACCENT_DOT:
736 case LFUN_ACCENT_GRAVE:
737 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
738 case LFUN_ACCENT_MACRON:
739 case LFUN_ACCENT_OGONEK:
740 case LFUN_ACCENT_TIE:
741 case LFUN_ACCENT_TILDE:
742 case LFUN_ACCENT_UMLAUT:
743 case LFUN_ACCENT_UNDERBAR:
744 case LFUN_ACCENT_UNDERDOT:
746 case LFUN_BOX_INSERT:
747 case LFUN_BRANCH_INSERT:
748 case LFUN_CAPTION_INSERT:
749 case LFUN_DEPTH_DECREMENT:
750 case LFUN_DEPTH_INCREMENT:
751 case LFUN_ERT_INSERT:
752 case LFUN_FILE_INSERT:
753 case LFUN_FLEX_INSERT:
754 case LFUN_FLOAT_INSERT:
755 case LFUN_FLOAT_LIST_INSERT:
756 case LFUN_FLOAT_WIDE_INSERT:
758 case LFUN_FONT_BOLDSYMBOL:
759 case LFUN_FONT_TYPEWRITER:
760 case LFUN_FONT_DEFAULT:
763 case LFUN_FONT_ROMAN:
768 case LFUN_FONT_STATE:
769 case LFUN_FONT_UNDERLINE:
770 case LFUN_FONT_STRIKEOUT:
771 case LFUN_FONT_UULINE:
772 case LFUN_FONT_UWAVE:
773 case LFUN_FOOTNOTE_INSERT:
774 case LFUN_HYPERLINK_INSERT:
775 case LFUN_INDEX_INSERT:
776 case LFUN_INDEX_PRINT:
777 case LFUN_INSET_INSERT:
778 case LFUN_LABEL_GOTO:
779 case LFUN_LABEL_INSERT:
780 case LFUN_LAYOUT_TABULAR:
781 case LFUN_LINE_INSERT:
782 case LFUN_MARGINALNOTE_INSERT:
783 case LFUN_MATH_DISPLAY:
784 case LFUN_MATH_INSERT:
785 case LFUN_MATH_MATRIX:
788 case LFUN_NEWLINE_INSERT:
789 case LFUN_NEWPAGE_INSERT:
791 case LFUN_NOMENCL_INSERT:
792 case LFUN_NOMENCL_PRINT:
793 case LFUN_NOTE_INSERT:
795 case LFUN_OPTIONAL_INSERT:
796 case LFUN_PHANTOM_INSERT:
797 case LFUN_REFERENCE_NEXT:
798 case LFUN_SERVER_GOTO_FILE_ROW:
799 case LFUN_SERVER_NOTIFY:
800 case LFUN_SERVER_SET_XY:
801 case LFUN_SPACE_INSERT:
802 case LFUN_SPECIALCHAR_INSERT:
803 case LFUN_TABULAR_INSERT:
804 case LFUN_TEXTSTYLE_APPLY:
805 case LFUN_TEXTSTYLE_UPDATE:
806 case LFUN_TOC_INSERT:
807 case LFUN_WRAP_INSERT:
808 if (layout_->isPassThru()) {
809 flag.setEnabled(false);
812 return InsetText::getStatus(cur, cmd, flag);
814 case LFUN_INSET_TOGGLE:
815 if (cmd.argument() == "open")
816 flag.setEnabled(status_ != Open);
817 else if (cmd.argument() == "close")
818 flag.setEnabled(status_ == Open);
819 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
820 flag.setEnabled(true);
821 flag.setOnOff(status_ == Open);
823 flag.setEnabled(false);
827 flag.setEnabled(!layout_->isForceLtr());
828 return InsetText::getStatus(cur, cmd, flag);
830 case LFUN_BREAK_PARAGRAPH:
831 flag.setEnabled(layout_->isMultiPar());
834 case LFUN_TAB_INSERT:
835 case LFUN_TAB_DELETE:
836 if (layout_->isPassThru()) {
837 flag.setEnabled(true);
840 return InsetText::getStatus(cur, cmd, flag);
843 return InsetText::getStatus(cur, cmd, flag);
848 void InsetCollapsable::setLabel(docstring const & l)
854 void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
858 if (status_ == Collapsed) {
859 cur.leaveInset(*this);
860 mouse_hover_ = false;
865 docstring InsetCollapsable::floatName(
866 string const & type, BufferParams const & bp) const
868 FloatList const & floats = bp.documentClass().floats();
869 FloatList::const_iterator it = floats[type];
871 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
875 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
878 return InsetLayout::CLASSIC;
879 InsetLayout::InsetDecoration const dec = layout_->decoration();
881 case InsetLayout::CLASSIC:
882 case InsetLayout::MINIMALISTIC:
883 case InsetLayout::CONGLOMERATE:
885 case InsetLayout::DEFAULT:
888 if (lyxCode() == FLEX_CODE)
889 return InsetLayout::CONGLOMERATE;
890 return InsetLayout::CLASSIC;
894 int InsetCollapsable::latex(odocstream & os,
895 OutputParams const & runparams) const
897 // FIXME: What should we do layout_ is 0?
903 // This implements the standard way of handling the LaTeX output of
904 // a collapsable inset, either a command or an environment. Standard
905 // collapsable insets should not redefine this, non-standard ones may
907 if (!layout_->latexname().empty()) {
908 if (layout_->latextype() == InsetLayout::COMMAND) {
910 if (runparams.moving_arg)
912 os << '\\' << from_utf8(layout_->latexname());
913 if (!layout_->latexparam().empty())
914 os << from_utf8(layout_->latexparam());
916 } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
917 os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n";
918 if (!layout_->latexparam().empty())
919 os << from_utf8(layout_->latexparam());
922 OutputParams rp = runparams;
923 if (layout_->isPassThru())
925 if (layout_->isNeedProtect())
926 rp.moving_arg = true;
927 int i = InsetText::latex(os, rp);
928 if (!layout_->latexname().empty()) {
929 if (layout_->latextype() == InsetLayout::COMMAND) {
931 } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
932 os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n";
940 // FIXME It seems as if it ought to be possible to do this more simply,
941 // maybe by calling InsetText::docbook() in the middle there.
942 int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
944 ParagraphList::const_iterator const beg = paragraphs().begin();
945 ParagraphList::const_iterator par = paragraphs().begin();
946 ParagraphList::const_iterator const end = paragraphs().end();
949 sgml::openTag(os, getLayout().latexname(),
950 par->getID(buffer(), runparams) + getLayout().latexparam());
952 for (; par != end; ++par) {
953 par->simpleDocBookOnePar(buffer(), os, runparams,
954 outerFont(distance(beg, par),
959 sgml::closeTag(os, getLayout().latexname());
965 docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
967 InsetLayout const & il = getLayout();
969 return InsetText::xhtml(os, runparams);
971 bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
972 if (!il.counter().empty()) {
973 // FIXME Master buffer?
974 Counters & cntrs = buffer().params().documentClass().counters();
975 cntrs.step(il.counter());
976 if (!il.htmllabel().empty())
977 os << cntrs.counterLabel(translateIfPossible(from_ascii(il.htmllabel())));
979 bool innertag_opened = false;
980 if (!il.htmlinnertag().empty())
981 innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
982 docstring deferred = InsetText::xhtml(os, runparams);
984 html::closeTag(os, il.htmlinnertag());
986 html::closeTag(os, il.htmltag());
991 void InsetCollapsable::validate(LaTeXFeatures & features) const
993 features.useInsetLayout(getLayout());
994 InsetText::validate(features);
998 bool InsetCollapsable::undefined() const
1000 docstring const & n = getLayout().name();
1001 return n.empty() || n == DocumentClass::plainInsetLayout().name();
1005 docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
1008 if (decoration() == InsetLayout::CONGLOMERATE)
1009 return from_ascii("context-conglomerate");
1011 if (geometry(bv) == NoButton)
1012 return from_ascii("context-collapsable");
1014 Dimension dim = dimensionCollapsed(bv);
1015 if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
1016 return from_ascii("context-collapsable");
1018 return InsetText::contextMenu(bv, x, y);
1021 void InsetCollapsable::tocString(odocstream & os) const
1023 if (!getLayout().isInToc())
1025 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);