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()
151 setLayout(buffer().params().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()
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 FontInfo labelfont = getLayout().labelfont();
310 labelfont.setColor(labelColor());
311 pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
320 Dimension const textdim = InsetText::dimension(bv);
321 int const baseline = y;
323 switch (geometry(bv)) {
325 textx = x + dimc.width();
327 InsetText::draw(pi, textx, texty);
331 texty = baseline + dimc.des + textdim.asc;
332 InsetText::draw(pi, textx, texty);
339 InsetText::draw(pi, textx, texty);
345 const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
346 InsetText::draw(pi, textx, texty);
347 const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
349 int desc = textdim.descent();
350 if (geometry(bv) == Corners)
353 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
354 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
355 pi.pain.line(xx1, y + desc - 4,
359 pi.pain.line(xx1, y + desc,
363 // Make status_ value visible:
364 pi.pain.line(xx1, y + desc,
367 pi.pain.line(xx2 - 4, y + desc,
371 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
372 y + desc - 4, labelColor());
374 // the label below the text. Can be toggled.
375 if (geometry(bv) == SubLabel) {
376 FontInfo font(getLayout().labelfont());
377 font.realize(sane_font);
383 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
384 int const ww = max(textdim.wid, w);
385 pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
386 buttonLabel(bv), font, Color_none, Color_none);
390 // a visual cue when the cursor is inside the inset
391 Cursor const & cur = bv.cursor();
392 if (cur.isInside(this)) {
395 pi.pain.line(xx1, y + 4, xx1, y, labelColor());
396 pi.pain.line(xx1 + 4, y, xx1, y, labelColor());
397 pi.pain.line(xx2, y + 4, xx2, y,
399 pi.pain.line(xx2 - 4, y, xx2, y,
405 pi.base.font = tmpfont;
409 void InsetCollapsable::cursorPos(BufferView const & bv,
410 CursorSlice const & sl, bool boundary, int & x, int & y) const
412 if (geometry(bv) == ButtonOnly)
414 LASSERT(geometry(bv) != ButtonOnly, /**/);
416 InsetText::cursorPos(bv, sl, boundary, x, y);
417 Dimension const textdim = InsetText::dimension(bv);
419 switch (geometry(bv)) {
421 x += dimensionCollapsed(bv).wid;
424 y += dimensionCollapsed(bv).des + textdim.asc;
439 bool InsetCollapsable::editable() const
441 return geometry() != ButtonOnly;
445 bool InsetCollapsable::descendable() const
447 return geometry() != ButtonOnly;
451 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
453 return button_dim.contains(cmd.x, cmd.y);
457 docstring const InsetCollapsable::getNewLabel(docstring const & l) const
460 pos_type const max_length = 15;
461 pos_type const p_siz = paragraphs().begin()->size();
462 pos_type const n = min(max_length, p_siz);
465 for (; i < n && j < p_siz; ++j) {
466 if (paragraphs().begin()->isInset(j))
468 label += paragraphs().begin()->getChar(j);
471 if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
474 return label.empty() ? l : label;
478 void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
480 //lyxerr << "InsetCollapsable: edit left/right" << endl;
482 InsetText::edit(cur, front, entry_from);
486 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
488 //lyxerr << "InsetCollapsable: edit xy" << endl;
489 if (geometry(cur.bv()) == ButtonOnly
490 || (button_dim.contains(x, y)
491 && geometry(cur.bv()) != NoButton))
494 return InsetText::editXY(cur, x, y);
498 void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
500 //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
501 // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
503 switch (cmd.action) {
504 case LFUN_MOUSE_PRESS:
505 if (hitButton(cmd)) {
506 switch (cmd.button()) {
507 case mouse_button::button1:
508 case mouse_button::button3:
509 // Pass the command to the enclosing InsetText,
510 // so that the cursor gets set.
513 case mouse_button::none:
514 case mouse_button::button2:
515 case mouse_button::button4:
516 case mouse_button::button5:
521 } else if (geometry(cur.bv()) != ButtonOnly)
522 InsetText::doDispatch(cur, cmd);
527 case LFUN_MOUSE_MOTION:
528 case LFUN_MOUSE_DOUBLE:
529 case LFUN_MOUSE_TRIPLE:
532 else if (geometry(cur.bv()) != ButtonOnly)
533 InsetText::doDispatch(cur, cmd);
538 case LFUN_MOUSE_RELEASE:
539 if (!hitButton(cmd)) {
540 // The mouse click has to be within the inset!
541 if (geometry(cur.bv()) != ButtonOnly)
542 InsetText::doDispatch(cur, cmd);
547 if (cmd.button() != mouse_button::button1) {
552 // if we are selecting, we do not want to
556 // Left button is clicked, the user asks to
557 // toggle the inset visual state.
559 cur.updateFlags(Update::Force | Update::FitCursor);
560 if (geometry(cur.bv()) == ButtonOnly) {
561 setStatus(cur, Open);
565 setStatus(cur, Collapsed);
566 cur.bv().cursor() = cur;
569 case LFUN_INSET_TOGGLE:
570 if (cmd.argument() == "open")
571 setStatus(cur, Open);
572 else if (cmd.argument() == "close")
573 setStatus(cur, Collapsed);
574 else if (cmd.argument() == "toggle" || cmd.argument().empty())
575 if (status_ == Open) {
576 setStatus(cur, Collapsed);
577 if (geometry(cur.bv()) == ButtonOnly)
578 cur.top().forwardPos();
580 setStatus(cur, Open);
581 else // if assign or anything else
587 case LFUN_CLIPBOARD_PASTE:
588 case LFUN_SELECTION_PASTE:
589 case LFUN_PRIMARY_SELECTION_PASTE: {
590 InsetText::doDispatch(cur, cmd);
591 // Since we can only store plain text, we must reset all
593 // FIXME: Change only the pasted paragraphs
595 resetParagraphsFont();
599 case LFUN_TAB_INSERT: {
600 bool const multi_par_selection = cur.selection() &&
601 cur.selBegin().pit() != cur.selEnd().pit();
602 if (multi_par_selection) {
603 // If there is a multi-paragraph selection, a tab is inserted
604 // at 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 paragraphs()[pit].insertChar(0, '\t',
609 buffer().params().trackChanges);
610 // Update the selection pos to make sure the selection does not
611 // change as the inserted tab will increase the logical pos.
612 if (cur.anchor_.pit() == pit)
613 cur.anchor_.forwardPos();
614 if (cur.pit() == pit)
619 // Maybe we shouldn't allow tabs within a line, because they
620 // are not (yet) aligned as one might do expect.
621 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
627 case LFUN_TAB_DELETE:
628 if (cur.selection()) {
629 // If there is a selection, a tab (if present) is removed from
630 // the beginning of each paragraph.
631 cur.recordUndoSelection();
632 pit_type const pit_end = cur.selEnd().pit();
633 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
634 Paragraph & par = paragraphs()[pit];
635 if (par.getChar(0) == '\t') {
636 if (cur.pit() == pit)
638 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
639 cur.anchor_.backwardPos();
641 par.eraseChar(0, buffer().params().trackChanges);
643 // If no tab was present, try to remove up to four spaces.
644 for (int n_spaces = 0;
645 par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
646 if (cur.pit() == pit)
648 if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
649 cur.anchor_.backwardPos();
651 par.eraseChar(0, buffer().params().trackChanges);
656 // If there is no selection, try to remove a tab or some spaces
657 // before the position of the cursor.
658 Paragraph & par = paragraphs()[cur.pit()];
659 pos_type const pos = cur.pos();
664 char_type const c = par.getChar(pos - 1);
668 par.eraseChar(cur.pos(), buffer().params().trackChanges);
670 for (int n_spaces = 0; cur.pos() > 0
671 && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
674 par.eraseChar(cur.pos(), buffer().params().trackChanges);
681 if (getLayout().isForceLtr()) {
682 // Force any new text to latex_language
683 // FIXME: This should only be necessary in constructor, but
684 // new paragraphs that are created by pressing enter at the
685 // start of an existing paragraph get the buffer language
686 // and not latex_language, so we take this brute force
688 cur.current_font.setLanguage(latex_language);
689 cur.real_current_font.setLanguage(latex_language);
691 InsetText::doDispatch(cur, cmd);
697 void InsetCollapsable::resetParagraphsFont()
699 Font font(inherit_font, buffer().params().language);
700 if (getLayout().isForceLtr())
701 font.setLanguage(latex_language);
702 if (getLayout().isPassThru()) {
703 ParagraphList::iterator par = paragraphs().begin();
704 ParagraphList::iterator const end = paragraphs().end();
706 par->resetFonts(font);
707 par->params().clear();
714 bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
715 FuncStatus & flag) const
717 switch (cmd.action) {
718 // FIXME At present, these are being enabled and disabled according to
719 // whether PASSTHRU has been set in the InsetLayout. This makes some
720 // sense, but there are other checks that should really be done. E.g.,
721 // one should not be able to inset IndexPrint inside an optional argument!!
722 case LFUN_ACCENT_ACUTE:
723 case LFUN_ACCENT_BREVE:
724 case LFUN_ACCENT_CARON:
725 case LFUN_ACCENT_CEDILLA:
726 case LFUN_ACCENT_CIRCLE:
727 case LFUN_ACCENT_CIRCUMFLEX:
728 case LFUN_ACCENT_DOT:
729 case LFUN_ACCENT_GRAVE:
730 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
731 case LFUN_ACCENT_MACRON:
732 case LFUN_ACCENT_OGONEK:
733 case LFUN_ACCENT_TIE:
734 case LFUN_ACCENT_TILDE:
735 case LFUN_ACCENT_UMLAUT:
736 case LFUN_ACCENT_UNDERBAR:
737 case LFUN_ACCENT_UNDERDOT:
739 case LFUN_BOX_INSERT:
740 case LFUN_BRANCH_INSERT:
741 case LFUN_CAPTION_INSERT:
742 case LFUN_DEPTH_DECREMENT:
743 case LFUN_DEPTH_INCREMENT:
744 case LFUN_ERT_INSERT:
745 case LFUN_FILE_INSERT:
746 case LFUN_FLEX_INSERT:
747 case LFUN_FLOAT_INSERT:
748 case LFUN_FLOAT_LIST_INSERT:
749 case LFUN_FLOAT_WIDE_INSERT:
751 case LFUN_FONT_BOLDSYMBOL:
752 case LFUN_FONT_TYPEWRITER:
753 case LFUN_FONT_DEFAULT:
756 case LFUN_FONT_ROMAN:
761 case LFUN_FONT_STATE:
762 case LFUN_FONT_UNDERLINE:
763 case LFUN_FONT_STRIKEOUT:
764 case LFUN_FONT_UULINE:
765 case LFUN_FONT_UWAVE:
766 case LFUN_FOOTNOTE_INSERT:
767 case LFUN_HYPERLINK_INSERT:
768 case LFUN_INDEX_INSERT:
769 case LFUN_INDEX_PRINT:
770 case LFUN_INSET_INSERT:
771 case LFUN_LABEL_GOTO:
772 case LFUN_LABEL_INSERT:
773 case LFUN_LAYOUT_TABULAR:
774 case LFUN_LINE_INSERT:
775 case LFUN_MARGINALNOTE_INSERT:
776 case LFUN_MATH_DISPLAY:
777 case LFUN_MATH_INSERT:
778 case LFUN_MATH_AMS_MATRIX:
779 case LFUN_MATH_MATRIX:
782 case LFUN_NEWLINE_INSERT:
783 case LFUN_NEWPAGE_INSERT:
785 case LFUN_NOMENCL_INSERT:
786 case LFUN_NOMENCL_PRINT:
787 case LFUN_NOTE_INSERT:
789 case LFUN_OPTIONAL_INSERT:
790 case LFUN_PHANTOM_INSERT:
791 case LFUN_REFERENCE_NEXT:
792 case LFUN_SERVER_GOTO_FILE_ROW:
793 case LFUN_SERVER_NOTIFY:
794 case LFUN_SERVER_SET_XY:
795 case LFUN_SPACE_INSERT:
796 case LFUN_SPECIALCHAR_INSERT:
797 case LFUN_TABULAR_INSERT:
798 case LFUN_TEXTSTYLE_APPLY:
799 case LFUN_TEXTSTYLE_UPDATE:
800 case LFUN_TOC_INSERT:
801 case LFUN_WRAP_INSERT:
802 if (getLayout().isPassThru()) {
803 flag.setEnabled(false);
806 return InsetText::getStatus(cur, cmd, flag);
808 case LFUN_INSET_TOGGLE:
809 if (cmd.argument() == "open")
810 flag.setEnabled(status_ != Open);
811 else if (cmd.argument() == "close")
812 flag.setEnabled(status_ == Open);
813 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
814 flag.setEnabled(true);
815 flag.setOnOff(status_ == Open);
817 flag.setEnabled(false);
821 flag.setEnabled(!getLayout().isForceLtr());
822 return InsetText::getStatus(cur, cmd, flag);
824 case LFUN_BREAK_PARAGRAPH:
825 flag.setEnabled(getLayout().isMultiPar());
828 case LFUN_TAB_INSERT:
829 case LFUN_TAB_DELETE:
830 if (getLayout().isPassThru()) {
831 flag.setEnabled(true);
834 return InsetText::getStatus(cur, cmd, flag);
837 return InsetText::getStatus(cur, cmd, flag);
842 void InsetCollapsable::setLabel(docstring const & l)
848 void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
852 if (status_ == Collapsed) {
853 cur.leaveInset(*this);
854 mouse_hover_ = false;
859 docstring InsetCollapsable::floatName(string const & type) const
861 BufferParams const & bp = buffer().params();
862 FloatList const & floats = bp.documentClass().floats();
863 FloatList::const_iterator it = floats[type];
865 return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
869 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
871 InsetLayout::InsetDecoration const dec = getLayout().decoration();
872 return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
876 int InsetCollapsable::latex(odocstream & os,
877 OutputParams const & runparams) const
879 // This implements the standard way of handling the LaTeX output of
880 // a collapsable inset, either a command or an environment. Standard
881 // collapsable insets should not redefine this, non-standard ones may
883 if (!getLayout().latexname().empty()) {
884 if (getLayout().latextype() == InsetLayout::COMMAND) {
886 if (runparams.moving_arg)
888 os << '\\' << from_utf8(getLayout().latexname());
889 if (!getLayout().latexparam().empty())
890 os << from_utf8(getLayout().latexparam());
892 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
893 os << "%\n\\begin{" << from_utf8(getLayout().latexname()) << "}\n";
894 if (!getLayout().latexparam().empty())
895 os << from_utf8(getLayout().latexparam());
898 OutputParams rp = runparams;
899 if (getLayout().isPassThru())
901 if (getLayout().isNeedProtect())
902 rp.moving_arg = true;
903 int i = InsetText::latex(os, rp);
904 if (!getLayout().latexname().empty()) {
905 if (getLayout().latextype() == InsetLayout::COMMAND) {
907 } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
908 os << "\n\\end{" << from_utf8(getLayout().latexname()) << "}\n";
916 // FIXME It seems as if it ought to be possible to do this more simply,
917 // maybe by calling InsetText::docbook() in the middle there.
918 int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
920 ParagraphList::const_iterator const beg = paragraphs().begin();
921 ParagraphList::const_iterator par = paragraphs().begin();
922 ParagraphList::const_iterator const end = paragraphs().end();
925 sgml::openTag(os, getLayout().latexname(),
926 par->getID(buffer(), runparams) + getLayout().latexparam());
928 for (; par != end; ++par) {
929 par->simpleDocBookOnePar(buffer(), os, runparams,
930 outerFont(distance(beg, par),
935 sgml::closeTag(os, getLayout().latexname());
941 docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
943 InsetLayout const & il = getLayout();
945 return InsetText::xhtml(os, runparams);
947 bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
948 if (!il.counter().empty()) {
949 BufferParams const & bp = buffer().masterBuffer()->params();
950 Counters & cntrs = bp.documentClass().counters();
951 cntrs.step(il.counter());
952 // FIXME: translate to paragraph language
953 if (!il.htmllabel().empty())
954 os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
956 bool innertag_opened = false;
957 if (!il.htmlinnertag().empty())
958 innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
959 docstring deferred = InsetText::xhtml(os, runparams);
961 html::closeTag(os, il.htmlinnertag());
963 html::closeTag(os, il.htmltag());
968 void InsetCollapsable::validate(LaTeXFeatures & features) const
970 features.useInsetLayout(getLayout());
971 InsetText::validate(features);
975 bool InsetCollapsable::undefined() const
977 docstring const & n = getLayout().name();
978 return n.empty() || n == DocumentClass::plainInsetLayout().name();
982 docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
985 if (decoration() == InsetLayout::CONGLOMERATE)
986 return from_ascii("context-conglomerate");
988 if (geometry(bv) == NoButton)
989 return from_ascii("context-collapsable");
991 Dimension dim = dimensionCollapsed(bv);
992 if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
993 return from_ascii("context-collapsable");
995 return InsetText::contextMenu(bv, x, y);
998 void InsetCollapsable::tocString(odocstream & os) const
1000 if (!getLayout().isInToc())
1002 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);