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