]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsible.cpp
Get rid of Qt resources
[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 int InsetCollapsible::topOffset(BufferView const * bv) const
161 {
162         switch (geometry(*bv)) {
163         case Corners:
164         case SubLabel:
165                 return 0;
166         default:
167                 return InsetText::topOffset(bv);
168         }
169 }
170
171 int InsetCollapsible::bottomOffset(BufferView const * bv) const
172 {
173         switch (geometry(*bv)) {
174         case Corners:
175         case SubLabel:
176                 return InsetText::bottomOffset(bv) / 4;
177         default:
178                 return InsetText::bottomOffset(bv);
179         }
180 }
181
182
183 Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const
184 {
185         Dimension dim;
186         FontInfo labelfont(getLabelfont());
187         labelfont.realize(sane_font);
188         theFontMetrics(labelfont).buttonText(
189                 buttonLabel(bv), Inset::textOffset(&bv), dim.wid, dim.asc, dim.des);
190         return dim;
191 }
192
193
194 void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
195 {
196         view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
197
198         FontInfo tmpfont = mi.base.font;
199         mi.base.font = getFont();
200         mi.base.font.realize(tmpfont);
201
202         BufferView const & bv = *mi.base.bv;
203
204         switch (geometry(bv)) {
205         case NoButton:
206                 InsetText::metrics(mi, dim);
207                 break;
208         case Corners:
209                 InsetText::metrics(mi, dim);
210                 break;
211         case SubLabel: {
212                 InsetText::metrics(mi, dim);
213                 // consider width of the inset label
214                 FontInfo font(getLabelfont());
215                 font.realize(sane_font);
216                 font.decSize();
217                 font.decSize();
218                 int w = 0;
219                 int a = 0;
220                 int d = 0;
221                 theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
222                 dim.des += a + d;
223                 break;
224                 }
225         case TopButton:
226         case LeftButton:
227         case ButtonOnly:
228                 if (hasFixedWidth()){
229                         int const mindim = view_[&bv].button_dim_.x2 - view_[&bv].button_dim_.x1;
230                         if (mi.base.textwidth < mindim)
231                                 mi.base.textwidth = mindim;
232                 }
233                 dim = dimensionCollapsed(bv);
234                 if (geometry(bv) == TopButton || geometry(bv) == LeftButton) {
235                         Dimension textdim;
236                         InsetText::metrics(mi, textdim);
237                         view_[&bv].openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
238                         if (view_[&bv].openinlined_) {
239                                 // Correct for button width.
240                                 dim.wid += textdim.wid;
241                                 dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
242                                 dim.asc = textdim.asc;
243                         } else {
244                                 dim.des += textdim.height() + topOffset(mi.base.bv);
245                                 dim.wid = max(dim.wid, textdim.wid);
246                         }
247                 }
248                 break;
249         }
250
251         mi.base.font = tmpfont;
252 }
253
254
255 bool InsetCollapsible::setMouseHover(BufferView const * bv, bool mouse_hover)
256         const
257 {
258         view_[bv].mouse_hover_ = mouse_hover;
259         return true;
260 }
261
262
263 void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
264 {
265         BufferView const & bv = *pi.base.bv;
266
267         view_[&bv].auto_open_ = bv.cursor().isInside(this);
268
269         Changer dummy = pi.base.font.change(getFont(), true);
270
271         // Draw button first -- top, left or only
272         Dimension dimc = dimensionCollapsed(bv);
273
274         if (geometry(bv) == TopButton ||
275             geometry(bv) == LeftButton ||
276             geometry(bv) == ButtonOnly) {
277                 view_[&bv].button_dim_.x1 = x + 0;
278                 view_[&bv].button_dim_.x2 = x + dimc.width();
279                 view_[&bv].button_dim_.y1 = y - dimc.asc;
280                 view_[&bv].button_dim_.y2 = y + dimc.des;
281
282                 FontInfo labelfont = getLabelfont();
283                 labelfont.setColor(labelColor());
284                 labelfont.realize(pi.base.font);
285                 pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
286                                    view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
287                                    Color_buttonframe, Inset::textOffset(pi.base.bv));
288                 // Draw the change tracking cue on the label, unless RowPainter already
289                 // takes care of it.
290                 if (canPaintChange(bv))
291                         pi.change.paintCue(pi, x, y, x + dimc.width(), labelfont);
292         } else {
293                 view_[&bv].button_dim_.x1 = 0;
294                 view_[&bv].button_dim_.y1 = 0;
295                 view_[&bv].button_dim_.x2 = 0;
296                 view_[&bv].button_dim_.y2 = 0;
297         }
298
299         Dimension const textdim = dimensionHelper(bv);
300         int const baseline = y;
301         int textx, texty;
302         Geometry g = geometry(bv);
303         switch (g) {
304         case LeftButton:
305         case TopButton: {
306                 if (g == LeftButton) {
307                         textx = x + dimc.width();
308                         texty = baseline;
309                 } else {
310                         textx = x;
311                         texty = baseline + dimc.des + textdim.asc;
312                 }
313                 // Do not draw the cue for INSERTED -- it is already in the button and
314                 // that's enough.
315                 Changer cdummy = (pi.change.type == Change::INSERTED)
316                         ? make_change(pi.change, Change())
317                         : Changer();
318                 InsetText::draw(pi, textx, texty);
319                 break;
320         }
321         case ButtonOnly:
322                 break;
323         case NoButton:
324                 textx = x;
325                 texty = baseline;
326                 InsetText::draw(pi, textx, texty);
327                 break;
328         case SubLabel:
329         case Corners:
330                 textx = x;
331                 texty = baseline;
332                 // We will take care of the frame and the change tracking cue
333                 // ourselves, below.
334                 {
335                         Changer cdummy = make_change(pi.change, Change());
336                         const_cast<InsetCollapsible *>(this)->setDrawFrame(false);
337                         InsetText::draw(pi, textx, texty);
338                         const_cast<InsetCollapsible *>(this)->setDrawFrame(true);
339                 }
340
341                 int desc = textdim.descent();
342
343                 // Colour the frame according to the change type. (Like for tables.)
344                 Color colour = pi.change.changed() ? pi.change.color()
345                                                     : Color_foreground;
346                 const int xx1 = x + leftOffset(pi.base.bv) - 1;
347                 const int xx2 = x + textdim.wid - rightOffset(pi.base.bv) + 1;
348                 pi.pain.line(xx1, y + desc - 4,
349                              xx1, y + desc, colour);
350                 if (status_ == Open)
351                         pi.pain.line(xx1, y + desc,
352                                      xx2, y + desc, colour);
353                 else {
354                         // Make status_ value visible:
355                         pi.pain.line(xx1, y + desc,
356                                      xx1 + 4, y + desc, colour);
357                         pi.pain.line(xx2 - 4, y + desc,
358                                      xx2, y + desc, colour);
359                 }
360                 pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
361                              y + desc - 4, colour);
362
363                 // the label below the text. Can be toggled.
364                 if (g == SubLabel) {
365                         FontInfo font(getLabelfont());
366                         if (pi.change.changed())
367                                 font.setPaintColor(colour);
368                         font.realize(sane_font);
369                         font.decSize();
370                         font.decSize();
371                         int w = 0;
372                         int a = 0;
373                         int d = 0;
374                         Color const col = pi.full_repaint ? Color_none : pi.backgroundColor();
375                         theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
376                         int const ww = max(textdim.wid, w);
377                         pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
378                                          buttonLabel(bv), font, col, Color_none);
379                 }
380
381                 int const y1 = y - textdim.asc + 3;
382                 // a visual cue when the cursor is inside the inset
383                 Cursor const & cur = bv.cursor();
384                 if (cur.isInside(this)) {
385                         pi.pain.line(xx1, y1 + 4, xx1, y1, colour);
386                         pi.pain.line(xx1 + 4, y1, xx1, y1, colour);
387                         pi.pain.line(xx2, y1 + 4, xx2, y1, colour);
388                         pi.pain.line(xx2 - 4, y1, xx2, y1, colour);
389                 }
390                 // Strike through the inset if deleted and not already handled by
391                 // RowPainter.
392                 if (pi.change.deleted() && canPaintChange(bv))
393                         pi.change.paintCue(pi, xx1, y1, xx2, y + desc);
394                 break;
395         }
396 }
397
398
399 void InsetCollapsible::cursorPos(BufferView const & bv,
400                 CursorSlice const & sl, bool boundary, int & x, int & y) const
401 {
402         if (geometry(bv) == ButtonOnly)
403                 status_ = Open;
404
405         InsetText::cursorPos(bv, sl, boundary, x, y);
406         Dimension const textdim = dimensionHelper(bv);
407
408         switch (geometry(bv)) {
409         case LeftButton:
410                 x += dimensionCollapsed(bv).wid;
411                 break;
412         case TopButton: {
413                 y += dimensionCollapsed(bv).des + textdim.asc;
414                 break;
415         }
416         case NoButton:
417         case SubLabel:
418         case Corners:
419                 // Do nothing
420                 break;
421         case ButtonOnly:
422                 // Cannot get here
423                 break;
424         }
425 }
426
427
428 bool InsetCollapsible::editable() const
429 {
430         if (tempfile_)
431                 return false;
432         
433         switch (decoration()) {
434         case InsetLayout::CLASSIC:
435         case InsetLayout::MINIMALISTIC:
436                 return status_ == Open;
437         default:
438                 return true;
439         }
440 }
441
442
443 bool InsetCollapsible::descendable(BufferView const & bv) const
444 {
445         if (tempfile_)
446                 return false;
447
448         return geometry(bv) != ButtonOnly;
449 }
450
451
452 bool InsetCollapsible::clickable(BufferView const & bv, int x, int y) const
453 {
454         return view_[&bv].button_dim_.contains(x, y);
455 }
456
457
458 docstring const InsetCollapsible::getNewLabel(docstring const & l) const
459 {
460         odocstringstream label;
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);
464         pos_type i = 0;
465         pos_type j = 0;
466         for (; i < n && j < p_siz; ++j) {
467                 if (paragraphs().begin()->isDeleted(j))
468                         continue;
469                 if (paragraphs().begin()->isInset(j)) {
470                         if (!paragraphs().begin()->getInset(j)->isChar())
471                                 continue;
472                         paragraphs().begin()->getInset(j)->toString(label);
473                 } else
474                         label.put(paragraphs().begin()->getChar(j));
475                 ++i;
476         }
477         if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
478                 label << "...";
479         }
480         return label.str().empty() ? l : label.str();
481 }
482
483
484 void InsetCollapsible::edit(Cursor & cur, bool front, EntryDirection entry_from)
485 {
486         //lyxerr << "InsetCollapsible: edit left/right" << endl;
487         cur.push(*this);
488         InsetText::edit(cur, front, entry_from);
489 }
490
491
492 Inset * InsetCollapsible::editXY(Cursor & cur, int x, int y)
493 {
494         //lyxerr << "InsetCollapsible: edit xy" << endl;
495         if (geometry(cur.bv()) == ButtonOnly
496                 || !descendable(cur.bv())
497             || (view_[&cur.bv()].button_dim_.contains(x, y)
498                 && geometry(cur.bv()) != NoButton))
499                 return this;
500         cur.push(*this);
501         return InsetText::editXY(cur, x, y);
502 }
503
504
505 void InsetCollapsible::doDispatch(Cursor & cur, FuncRequest & cmd)
506 {
507         //lyxerr << "InsetCollapsible::doDispatch (begin): cmd: " << cmd
508         //      << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
509
510         bool const hitButton = clickable(cur.bv(), cmd.x(), cmd.y());
511
512         switch (cmd.action()) {
513         case LFUN_MOUSE_PRESS:
514                 if (hitButton) {
515                         switch (cmd.button()) {
516                         case mouse_button::button1:
517                         case mouse_button::button3:
518                                 // Pass the command to the enclosing InsetText,
519                                 // so that the cursor gets set.
520                                 cur.undispatched();
521                                 break;
522                         case mouse_button::none:
523                         case mouse_button::button2:
524                         case mouse_button::button4:
525                         case mouse_button::button5:
526                                 // Nothing to do.
527                                 cur.noScreenUpdate();
528                                 break;
529                         }
530                 } else if (geometry(cur.bv()) != ButtonOnly)
531                         InsetText::doDispatch(cur, cmd);
532                 else
533                         cur.undispatched();
534                 break;
535
536         case LFUN_MOUSE_DOUBLE:
537         case LFUN_MOUSE_TRIPLE:
538                 if (hitButton)
539                         cur.noScreenUpdate();
540                 else if (geometry(cur.bv()) != ButtonOnly)
541                         InsetText::doDispatch(cur, cmd);
542                 else
543                         cur.undispatched();
544                 break;
545
546         case LFUN_MOUSE_RELEASE:
547                 if (!hitButton) {
548                         // The mouse click has to be within the inset!
549                         if (geometry(cur.bv()) != ButtonOnly)
550                                 InsetText::doDispatch(cur, cmd);
551                         else
552                                 cur.undispatched();
553                         break;
554                 }
555                 if (cmd.button() != mouse_button::button1) {
556                         // Nothing to do.
557                         cur.noScreenUpdate();
558                         break;
559                 }
560                 // if we are selecting, we do not want to
561                 // toggle the inset.
562                 if (cur.selection())
563                         break;
564                 // Left button is clicked, the user asks to
565                 // toggle the inset visual state.
566                 cur.dispatched();
567                 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
568                 if (geometry(cur.bv()) == ButtonOnly) {
569                         setStatus(cur, Open);
570                         edit(cur, true);
571                 }
572                 else
573                         setStatus(cur, Collapsed);
574                 cur.bv().cursor() = cur;
575                 break;
576
577         case LFUN_INSET_TOGGLE:
578                 if (cmd.argument() == "open")
579                         setStatus(cur, Open);
580                 else if (cmd.argument() == "close")
581                         setStatus(cur, Collapsed);
582                 else if (cmd.argument() == "toggle" || cmd.argument().empty())
583                         if (status_ == Open)
584                                 setStatus(cur, Collapsed);
585                         else
586                                 setStatus(cur, Open);
587                 else // if assign or anything else
588                         cur.undispatched();
589                 cur.dispatched();
590                 break;
591
592         case LFUN_INSET_EDIT: {
593                 cur.push(*this);
594                 text().selectAll(cur);
595                 string const format =
596                         cur.buffer()->params().documentClass().outputFormat();
597                 string const ext = theFormats().extension(format);
598                 tempfile_.reset(new support::TempFile("ert_editXXXXXX." + ext));
599                 support::FileName const tempfilename = tempfile_->name();
600                 string const name = tempfilename.toFilesystemEncoding();
601                 ofdocstream os(name.c_str());
602                 os << cur.selectionAsString(false);
603                 os.close();
604                 // Since we lock the inset while the external file is edited,
605                 // we need to move the cursor outside and clear any selection inside
606                 cur.clearSelection();
607                 cur.pop();
608                 cur.leaveInset(*this);
609                 theFormats().edit(buffer(), tempfilename, format);
610                 break;
611         }
612         case LFUN_INSET_END_EDIT: {
613                 support::FileName const tempfilename = tempfile_->name();
614                 docstring const s = tempfilename.fileContents("UTF-8");
615                 cur.recordUndoInset(this);
616                 cur.push(*this);
617                 text().selectAll(cur);
618                 cap::replaceSelection(cur);
619                 cur.text()->insertStringAsLines(cur, s, cur.current_font);
620                 // FIXME (gb) it crashes without this
621                 cur.fixIfBroken();
622                 tempfile_.reset();
623                 cur.pop();
624                 break;
625         }
626
627         default:
628                 InsetText::doDispatch(cur, cmd);
629                 break;
630         }
631 }
632
633
634 bool InsetCollapsible::getStatus(Cursor & cur, FuncRequest const & cmd,
635                 FuncStatus & flag) const
636 {
637         switch (cmd.action()) {
638         case LFUN_INSET_TOGGLE:
639                 if (cmd.argument() == "open")
640                         flag.setEnabled(status_ != Open);
641                 else if (cmd.argument() == "close")
642                         flag.setEnabled(status_ == Open);
643                 else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
644                         flag.setEnabled(true);
645                         flag.setOnOff(status_ == Open);
646                 } else
647                         flag.setEnabled(false);
648                 return true;
649
650         case LFUN_INSET_EDIT:
651                 flag.setEnabled(getLayout().editExternally() && tempfile_ == 0);
652                 return true;
653
654         case LFUN_INSET_END_EDIT:
655                 flag.setEnabled(getLayout().editExternally() && tempfile_ != 0);
656                 return true;
657
658         default:
659                 return InsetText::getStatus(cur, cmd, flag);
660         }
661 }
662
663
664 void InsetCollapsible::setLabel(docstring const & l)
665 {
666         labelstring_ = l;
667 }
668
669
670 docstring InsetCollapsible::getLabel() const
671 {
672         InsetLayout const & il = getLayout();
673         return labelstring_.empty() ?
674                 translateIfPossible(il.labelstring()) : labelstring_;
675 }
676
677
678 docstring const InsetCollapsible::buttonLabel(BufferView const & bv) const
679 {
680         // indicate changed content in label (#8645)
681         // ✎ U+270E LOWER RIGHT PENCIL
682         docstring const indicator = (isChanged() && geometry(bv) == ButtonOnly)
683                 ? docstring(1, 0x270E) : docstring();
684         InsetLayout const & il = getLayout();
685         docstring const label = getLabel();
686         if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
687                 return indicator + label;
688         return indicator + getNewLabel(label);
689 }
690
691
692 void InsetCollapsible::setStatus(Cursor & cur, CollapseStatus status)
693 {
694         status_ = status;
695         setButtonLabel();
696         if (status_ == Collapsed)
697                 cur.leaveInset(*this);
698 }
699
700
701 InsetLayout::InsetDecoration InsetCollapsible::decoration() const
702 {
703         InsetLayout::InsetDecoration const dec = getLayout().decoration();
704         return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
705 }
706
707
708 string InsetCollapsible::contextMenu(BufferView const & bv, int x,
709         int y) const
710 {
711         string context_menu = contextMenuName();
712         string const it_context_menu = InsetText::contextMenuName();
713         if (decoration() == InsetLayout::CONGLOMERATE)
714                 return context_menu + ";" + it_context_menu;
715
716         string const ic_context_menu = InsetCollapsible::contextMenuName();
717         if (ic_context_menu != context_menu)
718                 context_menu += ";" + ic_context_menu;
719
720         if (geometry(bv) == NoButton)
721                 return context_menu + ";" + it_context_menu;
722
723         Dimension dim = dimensionCollapsed(bv);
724         if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
725                 return context_menu;
726
727         return it_context_menu;
728 }
729
730
731 string InsetCollapsible::contextMenuName() const
732 {
733         if (decoration() == InsetLayout::CONGLOMERATE)
734                 return "context-conglomerate";
735         else
736                 return "context-collapsible";
737 }
738
739
740 bool InsetCollapsible::canPaintChange(BufferView const & bv) const
741 {
742         // return false to let RowPainter draw the change tracking cue consistently
743         // with the surrounding text, when the inset is inline: for buttons, for
744         // non-allowMultiPar insets.
745         switch (geometry(bv)) {
746         case Corners:
747         case SubLabel:
748                 return allowMultiPar();
749         case ButtonOnly:
750                 return false;
751         default:
752                 break;
753         }
754         return true;
755 }
756
757
758 void InsetCollapsible::addToToc(DocIterator const & cpit, bool output_active,
759                                 UpdateType utype, TocBackend & backend) const
760 {
761         bool doing_output = output_active && producesOutput();
762         InsetLayout const & layout = getLayout();
763         if (!layout.addToToc())
764                 return InsetText::addToToc(cpit, doing_output, utype, backend);
765
766         TocBuilder & b = backend.builder(layout.tocType());
767         // Cursor inside the inset
768         DocIterator pit = cpit;
769         pit.push_back(CursorSlice(const_cast<InsetCollapsible &>(*this)));
770         docstring const label = getLabel();
771         b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active);
772         // Proceed with the rest of the inset.
773         InsetText::addToToc(cpit, doing_output, utype, backend);
774         if (layout.isTocCaption()) {
775                 docstring str;
776                 text().forOutliner(str, TOC_ENTRY_LENGTH);
777                 b.argumentItem(str);
778         }
779         b.pop();
780 }
781
782
783
784 } // namespace lyx