]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsible.cpp
Indicate change of content in label of collapsed collapsible
[lyx.git] / src / insets / InsetCollapsible.cpp
1 /**
2  * \file InsetCollapsible.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetCollapsible.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "CutAndPaste.h"
21 #include "Cursor.h"
22 #include "Dimension.h"
23 #include "Format.h"
24 #include "FuncRequest.h"
25 #include "FuncStatus.h"
26 #include "InsetLayout.h"
27 #include "Lexer.h"
28 #include "MetricsInfo.h"
29 #include "OutputParams.h"
30 #include "TextClass.h"
31 #include "TocBackend.h"
32
33 #include "frontends/FontMetrics.h"
34 #include "frontends/Painter.h"
35
36 #include "support/debug.h"
37 #include "support/docstream.h"
38 #include "support/gettext.h"
39 #include "support/lassert.h"
40 #include "support/lstrings.h"
41 #include "support/RefChanger.h"
42 #include "support/TempFile.h"
43
44 using namespace std;
45
46
47 namespace lyx {
48
49 InsetCollapsible::InsetCollapsible(Buffer * buf, InsetText::UsePlain ltype)
50         : InsetText(buf, ltype), status_(Open)
51 {
52         setDrawFrame(true);
53         setFrameColor(Color_collapsibleframe);
54 }
55
56
57 // The sole purpose of this copy constructor is to make sure
58 // that the view_ map is not copied and remains empty.
59 InsetCollapsible::InsetCollapsible(InsetCollapsible const & rhs)
60         : InsetText(rhs),
61           status_(rhs.status_),
62           labelstring_(rhs.labelstring_)
63 {
64         tempfile_.reset();
65 }
66
67
68 InsetCollapsible & InsetCollapsible::operator=(InsetCollapsible const & that)
69 {
70         if (&that == this)
71                 return *this;
72         *this = InsetCollapsible(that);
73         return *this;
74 }
75
76
77 InsetCollapsible::~InsetCollapsible()
78 {
79         map<BufferView const *, View>::iterator it = view_.begin();
80         map<BufferView const *, View>::iterator end = view_.end();
81         for (; it != end; ++it)
82                 if (it->second.mouse_hover_)
83                         it->first->clearLastInset(this);
84 }
85
86
87 InsetCollapsible::CollapseStatus InsetCollapsible::status(BufferView const & bv) const
88 {
89         if (decoration() == InsetLayout::CONGLOMERATE)
90                 return status_;
91         return view_[&bv].auto_open_ ? Open : status_;
92 }
93
94
95 InsetCollapsible::Geometry InsetCollapsible::geometry(BufferView const & bv) const
96 {
97         switch (decoration()) {
98         case InsetLayout::CLASSIC:
99                 if (status(bv) == Open)
100                         return view_[&bv].openinlined_ ? LeftButton : TopButton;
101                 return ButtonOnly;
102
103         case InsetLayout::MINIMALISTIC:
104                 return status(bv) == Open ? NoButton : ButtonOnly ;
105
106         case InsetLayout::CONGLOMERATE:
107                 return status(bv) == Open ? SubLabel : Corners ;
108
109         case InsetLayout::DEFAULT:
110                 break; // this shouldn't happen
111         }
112
113         // dummy return value to shut down a warning,
114         // this is dead code.
115         return NoButton;
116 }
117
118
119 docstring InsetCollapsible::toolTip(BufferView const & bv, int x, int y) const
120 {
121         Dimension const dim = dimensionCollapsed(bv);
122         if (geometry(bv) == NoButton)
123                 return translateIfPossible(getLayout().labelstring());
124         if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
125                 return docstring();
126
127         return toolTipText();
128 }
129
130
131 void InsetCollapsible::write(ostream & os) const
132 {
133         os << "status ";
134         switch (status_) {
135         case Open:
136                 os << "open";
137                 break;
138         case Collapsed:
139                 os << "collapsed";
140                 break;
141         }
142         os << "\n";
143         text().write(os);
144 }
145
146
147 void InsetCollapsible::read(Lexer & lex)
148 {
149         lex.setContext("InsetCollapsible::read");
150         string tmp_token;
151         status_ = Collapsed;
152         lex >> "status" >> tmp_token;
153         if (tmp_token == "open")
154                 status_ = Open;
155
156         InsetText::read(lex);
157         setButtonLabel();
158 }
159
160
161 Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const
162 {
163         Dimension dim;
164         FontInfo labelfont(getLabelfont());
165         labelfont.realize(sane_font);
166         theFontMetrics(labelfont).buttonText(
167                 buttonLabel(bv), TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
168         return dim;
169 }
170
171
172 void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
173 {
174         view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
175
176         FontInfo tmpfont = mi.base.font;
177         mi.base.font = getFont();
178         mi.base.font.realize(tmpfont);
179
180         BufferView const & bv = *mi.base.bv;
181
182         switch (geometry(bv)) {
183         case NoButton:
184                 InsetText::metrics(mi, dim);
185                 break;
186         case Corners:
187                 InsetText::metrics(mi, dim);
188                 dim.des -= 3;
189                 dim.asc -= 1;
190                 break;
191         case SubLabel: {
192                 InsetText::metrics(mi, dim);
193                 // consider width of the inset label
194                 FontInfo font(getLabelfont());
195                 font.realize(sane_font);
196                 font.decSize();
197                 font.decSize();
198                 int w = 0;
199                 int a = 0;
200                 int d = 0;
201                 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
202                 dim.des += a + d;
203                 break;
204                 }
205         case TopButton:
206         case LeftButton:
207         case ButtonOnly:
208                 if (hasFixedWidth()){
209                         int const mindim = view_[&bv].button_dim_.x2 - view_[&bv].button_dim_.x1;
210                         if (mi.base.textwidth < mindim)
211                                 mi.base.textwidth = mindim;
212                 }
213                 dim = dimensionCollapsed(bv);
214                 if (geometry(bv) == TopButton || geometry(bv) == LeftButton) {
215                         Dimension textdim;
216                         InsetText::metrics(mi, textdim);
217                         view_[&bv].openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
218                         if (view_[&bv].openinlined_) {
219                                 // Correct for button width.
220                                 dim.wid += textdim.wid;
221                                 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
222                                 dim.asc = textdim.asc;
223                         } else {
224                                 dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
225                                 dim.wid = max(dim.wid, textdim.wid);
226                         }
227                 }
228                 break;
229         }
230
231         mi.base.font = tmpfont;
232 }
233
234
235 bool InsetCollapsible::setMouseHover(BufferView const * bv, bool mouse_hover)
236         const
237 {
238         view_[bv].mouse_hover_ = mouse_hover;
239         return true;
240 }
241
242
243 void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
244 {
245         BufferView const & bv = *pi.base.bv;
246
247         view_[&bv].auto_open_ = bv.cursor().isInside(this);
248
249         Changer dummy = pi.base.font.change(getFont(), true);
250
251         // Draw button first -- top, left or only
252         Dimension dimc = dimensionCollapsed(bv);
253
254         if (geometry(bv) == TopButton ||
255             geometry(bv) == LeftButton ||
256             geometry(bv) == ButtonOnly) {
257                 view_[&bv].button_dim_.x1 = x + 0;
258                 view_[&bv].button_dim_.x2 = x + dimc.width();
259                 view_[&bv].button_dim_.y1 = y - dimc.asc;
260                 view_[&bv].button_dim_.y2 = y + dimc.des;
261
262                 FontInfo labelfont = getLabelfont();
263                 labelfont.setColor(labelColor());
264                 labelfont.realize(pi.base.font);
265                 pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
266                                    view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
267                                    Color_buttonframe, TEXT_TO_INSET_OFFSET);
268                 // Draw the change tracking cue on the label, unless RowPainter already
269                 // takes care of it.
270                 if (canPaintChange(bv))
271                         pi.change_.paintCue(pi, x, y, x + dimc.width(), labelfont);
272         } else {
273                 view_[&bv].button_dim_.x1 = 0;
274                 view_[&bv].button_dim_.y1 = 0;
275                 view_[&bv].button_dim_.x2 = 0;
276                 view_[&bv].button_dim_.y2 = 0;
277         }
278
279         Dimension const textdim = dimensionHelper(bv);
280         int const baseline = y;
281         int textx, texty;
282         Geometry g = geometry(bv);
283         switch (g) {
284         case LeftButton:
285         case TopButton: {
286                 if (g == LeftButton) {
287                         textx = x + dimc.width();
288                         texty = baseline;
289                 } else {
290                         textx = x;
291                         texty = baseline + dimc.des + textdim.asc;
292                 }
293                 // Do not draw the cue for INSERTED -- it is already in the button and
294                 // that's enough.
295                 Changer cdummy = (pi.change_.type == Change::INSERTED)
296                         ? make_change(pi.change_, Change())
297                         : Changer();
298                 InsetText::draw(pi, textx, texty);
299                 break;
300         }
301         case ButtonOnly:
302                 break;
303         case NoButton:
304                 textx = x;
305                 texty = baseline;
306                 InsetText::draw(pi, textx, texty);
307                 break;
308         case SubLabel:
309         case Corners:
310                 textx = x;
311                 texty = baseline;
312                 // We will take care of the frame and the change tracking cue
313                 // ourselves, below.
314                 {
315                         Changer cdummy = make_change(pi.change_, Change());
316                         const_cast<InsetCollapsible *>(this)->setDrawFrame(false);
317                         InsetText::draw(pi, textx, texty);
318                         const_cast<InsetCollapsible *>(this)->setDrawFrame(true);
319                 }
320
321                 int desc = textdim.descent();
322                 if (g == Corners)
323                         desc -= 3;
324
325                 // Colour the frame according to the change type. (Like for tables.)
326                 Color colour = pi.change_.changed() ? pi.change_.color()
327                                                     : Color_foreground;
328                 const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
329                 const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
330                 pi.pain.line(xx1, y + desc - 4,
331                              xx1, y + desc, colour);
332                 if (status_ == Open)
333                         pi.pain.line(xx1, y + desc,
334                                      xx2, y + desc, colour);
335                 else {
336                         // Make status_ value visible:
337                         pi.pain.line(xx1, y + desc,
338                                      xx1 + 4, y + desc, colour);
339                         pi.pain.line(xx2 - 4, y + desc,
340                                      xx2, y + desc, colour);
341                 }
342                 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
343                              y + desc - 4, colour);
344
345                 // the label below the text. Can be toggled.
346                 if (g == SubLabel) {
347                         FontInfo font(getLabelfont());
348                         if (pi.change_.changed())
349                                 font.setPaintColor(colour);
350                         font.realize(sane_font);
351                         font.decSize();
352                         font.decSize();
353                         int w = 0;
354                         int a = 0;
355                         int d = 0;
356                         Color const col = pi.full_repaint ? Color_none : pi.backgroundColor(this);
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, col, Color_none);
361                 }
362
363                 int const y1 = y - textdim.asc + 3;
364                 // a visual cue when the cursor is inside the inset
365                 Cursor const & cur = bv.cursor();
366                 if (cur.isInside(this)) {
367                         pi.pain.line(xx1, y1 + 4, xx1, y1, colour);
368                         pi.pain.line(xx1 + 4, y1, xx1, y1, colour);
369                         pi.pain.line(xx2, y1 + 4, xx2, y1, colour);
370                         pi.pain.line(xx2 - 4, y1, xx2, y1, colour);
371                 }
372                 // Strike through the inset if deleted and not already handled by
373                 // RowPainter.
374                 if (pi.change_.deleted() && canPaintChange(bv))
375                         pi.change_.paintCue(pi, xx1, y1, xx2, y + desc);
376                 break;
377         }
378 }
379
380
381 void InsetCollapsible::cursorPos(BufferView const & bv,
382                 CursorSlice const & sl, bool boundary, int & x, int & y) const
383 {
384         if (geometry(bv) == ButtonOnly)
385                 status_ = Open;
386
387         InsetText::cursorPos(bv, sl, boundary, x, y);
388         Dimension const textdim = dimensionHelper(bv);
389
390         switch (geometry(bv)) {
391         case LeftButton:
392                 x += dimensionCollapsed(bv).wid;
393                 break;
394         case TopButton: {
395                 y += dimensionCollapsed(bv).des + textdim.asc;
396                 break;
397         }
398         case NoButton:
399         case SubLabel:
400         case Corners:
401                 // Do nothing
402                 break;
403         case ButtonOnly:
404                 // Cannot get here
405                 break;
406         }
407 }
408
409
410 bool InsetCollapsible::editable() const
411 {
412         if (tempfile_)
413                 return false;
414         
415         switch (decoration()) {
416         case InsetLayout::CLASSIC:
417         case InsetLayout::MINIMALISTIC:
418                 return status_ == Open;
419         default:
420                 return true;
421         }
422 }
423
424
425 bool InsetCollapsible::descendable(BufferView const & bv) const
426 {
427         if (tempfile_)
428                 return false;
429
430         return geometry(bv) != ButtonOnly;
431 }
432
433
434 bool InsetCollapsible::clickable(BufferView const & bv, int x, int y) const
435 {
436         return view_[&bv].button_dim_.contains(x, y);
437 }
438
439
440 docstring const InsetCollapsible::getNewLabel(docstring const & l) const
441 {
442         odocstringstream label;
443         pos_type const max_length = 15;
444         pos_type const p_siz = paragraphs().begin()->size();
445         pos_type const n = min(max_length, p_siz);
446         pos_type i = 0;
447         pos_type j = 0;
448         bool changed_content = false;
449         for (; i < n && j < p_siz; ++j) {
450                 if (paragraphs().begin()->isChanged(j)) {
451                         changed_content = true;
452                         if (paragraphs().begin()->isDeleted(j))
453                                 continue;
454                 }
455                 if (paragraphs().begin()->isInset(j)) {
456                         if (!paragraphs().begin()->getInset(j)->isChar())
457                                 continue;
458                         paragraphs().begin()->getInset(j)->toString(label);
459                 } else
460                         label.put(paragraphs().begin()->getChar(j));
461                 ++i;
462         }
463         if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
464                 label << "...";
465         }
466         docstring lbl;
467         // indicate changed content in label (#8645)
468         if (changed_content)
469                 lbl = char_type(0x270E);// ✎ U+270E LOWER RIGHT PENCIL
470         lbl += label.str();
471         return lbl.empty() ? l : lbl;
472 }
473
474
475 void InsetCollapsible::edit(Cursor & cur, bool front, EntryDirection entry_from)
476 {
477         //lyxerr << "InsetCollapsible: edit left/right" << endl;
478         cur.push(*this);
479         InsetText::edit(cur, front, entry_from);
480 }
481
482
483 Inset * InsetCollapsible::editXY(Cursor & cur, int x, int y)
484 {
485         //lyxerr << "InsetCollapsible: edit xy" << endl;
486         if (geometry(cur.bv()) == ButtonOnly
487                 || !descendable(cur.bv())
488             || (view_[&cur.bv()].button_dim_.contains(x, y)
489                 && geometry(cur.bv()) != NoButton))
490                 return this;
491         cur.push(*this);
492         return InsetText::editXY(cur, x, y);
493 }
494
495
496 void InsetCollapsible::doDispatch(Cursor & cur, FuncRequest & cmd)
497 {
498         //lyxerr << "InsetCollapsible::doDispatch (begin): cmd: " << cmd
499         //      << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
500
501         bool const hitButton = clickable(cur.bv(), cmd.x(), cmd.y());
502
503         switch (cmd.action()) {
504         case LFUN_MOUSE_PRESS:
505                 if (hitButton) {
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.
511                                 cur.undispatched();
512                                 break;
513                         case mouse_button::none:
514                         case mouse_button::button2:
515                         case mouse_button::button4:
516                         case mouse_button::button5:
517                                 // Nothing to do.
518                                 cur.noScreenUpdate();
519                                 break;
520                         }
521                 } else if (geometry(cur.bv()) != ButtonOnly)
522                         InsetText::doDispatch(cur, cmd);
523                 else
524                         cur.undispatched();
525                 break;
526
527         case LFUN_MOUSE_DOUBLE:
528         case LFUN_MOUSE_TRIPLE:
529                 if (hitButton)
530                         cur.noScreenUpdate();
531                 else if (geometry(cur.bv()) != ButtonOnly)
532                         InsetText::doDispatch(cur, cmd);
533                 else
534                         cur.undispatched();
535                 break;
536
537         case LFUN_MOUSE_RELEASE:
538                 if (!hitButton) {
539                         // The mouse click has to be within the inset!
540                         if (geometry(cur.bv()) != ButtonOnly)
541                                 InsetText::doDispatch(cur, cmd);
542                         else
543                                 cur.undispatched();
544                         break;
545                 }
546                 if (cmd.button() != mouse_button::button1) {
547                         // Nothing to do.
548                         cur.noScreenUpdate();
549                         break;
550                 }
551                 // if we are selecting, we do not want to
552                 // toggle the inset.
553                 if (cur.selection())
554                         break;
555                 // Left button is clicked, the user asks to
556                 // toggle the inset visual state.
557                 cur.dispatched();
558                 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
559                 if (geometry(cur.bv()) == ButtonOnly) {
560                         setStatus(cur, Open);
561                         edit(cur, true);
562                 }
563                 else
564                         setStatus(cur, Collapsed);
565                 cur.bv().cursor() = cur;
566                 break;
567
568         case LFUN_INSET_TOGGLE:
569                 if (cmd.argument() == "open")
570                         setStatus(cur, Open);
571                 else if (cmd.argument() == "close")
572                         setStatus(cur, Collapsed);
573                 else if (cmd.argument() == "toggle" || cmd.argument().empty())
574                         if (status_ == Open)
575                                 setStatus(cur, Collapsed);
576                         else
577                                 setStatus(cur, Open);
578                 else // if assign or anything else
579                         cur.undispatched();
580                 cur.dispatched();
581                 break;
582
583         case LFUN_INSET_EDIT: {
584                 cur.push(*this);
585                 text().selectAll(cur);
586                 string const format =
587                         cur.buffer()->params().documentClass().outputFormat();
588                 string const ext = theFormats().extension(format);
589                 tempfile_.reset(new support::TempFile("ert_editXXXXXX." + ext));
590                 support::FileName const tempfilename = tempfile_->name();
591                 string const name = tempfilename.toFilesystemEncoding();
592                 ofdocstream os(name.c_str());
593                 os << cur.selectionAsString(false);
594                 os.close();
595                 // Since we lock the inset while the external file is edited,
596                 // we need to move the cursor outside and clear any selection inside
597                 cur.clearSelection();
598                 cur.pop();
599                 cur.leaveInset(*this);
600                 theFormats().edit(buffer(), tempfilename, format);
601                 break;
602         }
603         case LFUN_INSET_END_EDIT: {
604                 support::FileName const tempfilename = tempfile_->name();
605                 docstring const s = tempfilename.fileContents("UTF-8");
606                 cur.recordUndoInset(this);
607                 cur.push(*this);
608                 text().selectAll(cur);
609                 cap::replaceSelection(cur);
610                 cur.text()->insertStringAsLines(cur, s, cur.current_font);
611                 // FIXME (gb) it crashes without this
612                 cur.fixIfBroken();
613                 tempfile_.reset();
614                 cur.pop();
615                 break;
616         }
617
618         default:
619                 InsetText::doDispatch(cur, cmd);
620                 break;
621         }
622 }
623
624
625 bool InsetCollapsible::getStatus(Cursor & cur, FuncRequest const & cmd,
626                 FuncStatus & flag) const
627 {
628         switch (cmd.action()) {
629         case LFUN_INSET_TOGGLE:
630                 if (cmd.argument() == "open")
631                         flag.setEnabled(status_ != Open);
632                 else if (cmd.argument() == "close")
633                         flag.setEnabled(status_ == Open);
634                 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
635                         flag.setEnabled(true);
636                         flag.setOnOff(status_ == Open);
637                 } else
638                         flag.setEnabled(false);
639                 return true;
640
641         case LFUN_INSET_EDIT:
642                 flag.setEnabled(getLayout().editExternally() && tempfile_ == 0);
643                 return true;
644
645         case LFUN_INSET_END_EDIT:
646                 flag.setEnabled(getLayout().editExternally() && tempfile_ != 0);
647                 return true;
648
649         default:
650                 return InsetText::getStatus(cur, cmd, flag);
651         }
652 }
653
654
655 void InsetCollapsible::setLabel(docstring const & l)
656 {
657         labelstring_ = l;
658 }
659
660
661 docstring InsetCollapsible::getLabel() const
662 {
663         InsetLayout const & il = getLayout();
664         return labelstring_.empty() ?
665                 translateIfPossible(il.labelstring()) : labelstring_;
666 }
667
668
669 docstring const InsetCollapsible::buttonLabel(BufferView const & bv) const
670 {
671         InsetLayout const & il = getLayout();
672         docstring const label = getLabel();
673         if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
674                 return label;
675         return getNewLabel(label);
676 }
677
678
679 void InsetCollapsible::setStatus(Cursor & cur, CollapseStatus status)
680 {
681         status_ = status;
682         setButtonLabel();
683         if (status_ == Collapsed)
684                 cur.leaveInset(*this);
685 }
686
687
688 InsetLayout::InsetDecoration InsetCollapsible::decoration() const
689 {
690         InsetLayout::InsetDecoration const dec = getLayout().decoration();
691         return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
692 }
693
694
695 string InsetCollapsible::contextMenu(BufferView const & bv, int x,
696         int y) const
697 {
698         string context_menu = contextMenuName();
699         string const it_context_menu = InsetText::contextMenuName();
700         if (decoration() == InsetLayout::CONGLOMERATE)
701                 return context_menu + ";" + it_context_menu;
702
703         string const ic_context_menu = InsetCollapsible::contextMenuName();
704         if (ic_context_menu != context_menu)
705                 context_menu += ";" + ic_context_menu;
706
707         if (geometry(bv) == NoButton)
708                 return context_menu + ";" + it_context_menu;
709
710         Dimension dim = dimensionCollapsed(bv);
711         if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
712                 return context_menu;
713
714         return it_context_menu;
715 }
716
717
718 string InsetCollapsible::contextMenuName() const
719 {
720         if (decoration() == InsetLayout::CONGLOMERATE)
721                 return "context-conglomerate";
722         else
723                 return "context-collapsible";
724 }
725
726
727 bool InsetCollapsible::canPaintChange(BufferView const & bv) const
728 {
729         // return false to let RowPainter draw the change tracking cue consistently
730         // with the surrounding text, when the inset is inline: for buttons, for
731         // non-allowMultiPar insets.
732         switch (geometry(bv)) {
733         case Corners:
734         case SubLabel:
735                 return allowMultiPar();
736         case ButtonOnly:
737                 return false;
738         default:
739                 break;
740         }
741         return true;
742 }
743
744
745 void InsetCollapsible::addToToc(DocIterator const & cpit, bool output_active,
746                                 UpdateType utype, TocBackend & backend) const
747 {
748         bool doing_output = output_active && producesOutput();
749         InsetLayout const & layout = getLayout();
750         if (!layout.addToToc())
751                 return InsetText::addToToc(cpit, doing_output, utype, backend);
752
753         TocBuilder & b = backend.builder(layout.tocType());
754         // Cursor inside the inset
755         DocIterator pit = cpit;
756         pit.push_back(CursorSlice(const_cast<InsetCollapsible &>(*this)));
757         docstring const label = getLabel();
758         b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active);
759         // Proceed with the rest of the inset.
760         InsetText::addToToc(cpit, doing_output, utype, backend);
761         if (layout.isTocCaption()) {
762                 docstring str;
763                 text().forOutliner(str, TOC_ENTRY_LENGTH);
764                 b.argumentItem(str);
765         }
766         b.pop();
767 }
768
769
770
771 } // namespace lyx