X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCollapsable.cpp;h=fa9f01056ab685e00ae67280e2faafa1541dec5f;hb=239b9919ffe28338d789e6dc9122228f77ab77a7;hp=520d902dcbbc492530fae22d629610049435887a;hpb=f151b932c248f7d78e54c085cd942d0aa9e4c475;p=lyx.git diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 520d902dcb..fa9f01056a 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -24,6 +24,7 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "TocBackend.h" #include "frontends/FontMetrics.h" #include "frontends/Painter.h" @@ -244,6 +245,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const FontInfo labelfont = getLabelfont(); labelfont.setColor(labelColor()); + labelfont.realize(pi.base.font); pi.pain.buttonText(x, y, buttonLabel(bv), labelfont, view_[&bv].mouse_hover_); // Draw the change tracking cue on the label, unless RowPainter already @@ -257,7 +259,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const view_[&bv].button_dim_.y2 = 0; } - Dimension const textdim = InsetText::dimension(bv); + Dimension const textdim = dimensionHelper(bv); int const baseline = y; int textx, texty; Geometry g = geometry(bv); @@ -273,8 +275,9 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const } // Do not draw the cue for INSERTED -- it is already in the button and // that's enough. - Changer dummy = make_change(pi.change_, Change(), - pi.change_.type == Change::INSERTED); + Changer dummy = (pi.change_.type == Change::INSERTED) + ? make_change(pi.change_, Change()) + : Changer(); InsetText::draw(pi, textx, texty); break; } @@ -332,10 +335,11 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const int w = 0; int a = 0; int d = 0; + Color const col = pi.full_repaint ? Color_none : pi.backgroundColor(this); theFontMetrics(font).rectText(buttonLabel(bv), w, a, d); int const ww = max(textdim.wid, w); pi.pain.rectText(x + (ww - w) / 2, y + desc + a, - buttonLabel(bv), font, Color_none, Color_none); + buttonLabel(bv), font, col, Color_none); } int const y1 = y - textdim.asc + 3; @@ -363,7 +367,7 @@ void InsetCollapsable::cursorPos(BufferView const & bv, status_ = Open; InsetText::cursorPos(bv, sl, boundary, x, y); - Dimension const textdim = InsetText::dimension(bv); + Dimension const textdim = dimensionHelper(bv); switch (geometry(bv)) { case LeftButton: @@ -573,11 +577,18 @@ void InsetCollapsable::setLabel(docstring const & l) } -docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const +docstring InsetCollapsable::getLabel() const { InsetLayout const & il = getLayout(); - docstring const label = labelstring_.empty() ? + return labelstring_.empty() ? translateIfPossible(il.labelstring()) : labelstring_; +} + + +docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const +{ + InsetLayout const & il = getLayout(); + docstring const label = getLabel(); if (!il.contentaslabel() || geometry(bv) != ButtonOnly) return label; return getNewLabel(label); @@ -650,4 +661,30 @@ bool InsetCollapsable::canPaintChange(BufferView const & bv) const } +void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active, + UpdateType utype) const +{ + bool doing_output = output_active && producesOutput(); + InsetLayout const & layout = getLayout(); + if (layout.addToToc()) { + TocBuilder & b = buffer().tocBackend().builder(layout.tocType()); + // Cursor inside the inset + DocIterator pit = cpit; + pit.push_back(CursorSlice(const_cast(*this))); + docstring const label = getLabel(); + b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active); + // Proceed with the rest of the inset. + InsetText::addToToc(cpit, doing_output, utype); + if (layout.isTocCaption()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH); + b.argumentItem(str); + } + b.pop(); + } else + InsetText::addToToc(cpit, doing_output, utype); +} + + + } // namespace lyx