diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 4bc330b3ad..80bfbf4131 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -81,7 +81,7 @@ docstring InsetBranch::toolTip(BufferView const &, int, int) const } -void InsetBranch::setButtonLabel(BufferView const & bv) +docstring const InsetBranch::buttonLabel(BufferView const & bv) const { docstring s = _("Branch: ") + params_.branch; if (!params_.branch.empty()) { @@ -91,9 +91,9 @@ void InsetBranch::setButtonLabel(BufferView const & bv) s = _("Undef: ") + s; } if (decoration() == InsetLayout::CLASSIC) - setLabel(isOpen(bv) ? s : getNewLabel(s) ); + return isOpen(bv) ? s : getNewLabel(s); else - setLabel(params_.branch + ": " + getNewLabel(s)); + return params_.branch + ": " + getNewLabel(s); } diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 71591a127a..607d8cfba2 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -62,7 +62,7 @@ private: /// void read(Lexer & lex); /// - void setButtonLabel(BufferView const & bv); + docstring const buttonLabel(BufferView const & bv) const; /// ColorCode backgroundColor() const; /// diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 6c5a44bbef..4928eb073d 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -107,7 +107,7 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs) docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const { - Dimension dim = dimensionCollapsed(); + Dimension dim = dimensionCollapsed(bv); if (geometry(bv) == NoButton) return translateIfPossible(layout_->labelstring()); if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv)) @@ -187,12 +187,12 @@ void InsetCollapsable::read(Lexer & lex) } -Dimension InsetCollapsable::dimensionCollapsed() const +Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const { LASSERT(layout_, /**/); Dimension dim; theFontMetrics(layout_->labelfont()).buttonText( - labelstring_, dim.wid, dim.asc, dim.des); + buttonLabel(bv), dim.wid, dim.asc, dim.des); return dim; } @@ -207,7 +207,9 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const mi.base.font = layout_->font(); mi.base.font.realize(tmpfont); - switch (geometry(*mi.base.bv)) { + BufferView const & bv = *mi.base.bv; + + switch (geometry(bv)) { case NoButton: InsetText::metrics(mi, dim); break; @@ -226,16 +228,16 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const int w = 0; int a = 0; int d = 0; - theFontMetrics(font).rectText(labelstring_, w, a, d); + theFontMetrics(font).rectText(buttonLabel(bv), w, a, d); dim.des += a + d; break; } case TopButton: case LeftButton: case ButtonOnly: - dim = dimensionCollapsed(); - if (geometry(*mi.base.bv) == TopButton - || geometry(*mi.base.bv) == LeftButton) { + dim = dimensionCollapsed(bv); + if (geometry(bv) == TopButton + || geometry(bv) == LeftButton) { Dimension textdim; InsetText::metrics(mi, textdim); openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth; @@ -266,15 +268,16 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover) void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const { LASSERT(layout_, /**/); + BufferView const & bv = *pi.base.bv; - auto_open_[pi.base.bv] = pi.base.bv->cursor().isInside(this); + auto_open_[&bv] = bv.cursor().isInside(this); FontInfo tmpfont = pi.base.font; pi.base.font = layout_->font(); pi.base.font.realize(tmpfont); // Draw button first -- top, left or only - Dimension dimc = dimensionCollapsed(); + Dimension dimc = dimensionCollapsed(bv); if (geometry(*pi.base.bv) == TopButton || geometry(*pi.base.bv) == LeftButton || @@ -284,7 +287,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y1 = y - dimc.asc; button_dim.y2 = y + dimc.des; - pi.pain.buttonText(x, y, labelstring_, layout_->labelfont(), + pi.pain.buttonText(x, y, buttonLabel(bv), layout_->labelfont(), mouse_hover_); } else { button_dim.x1 = 0; @@ -293,10 +296,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y2 = 0; } - Dimension const textdim = InsetText::dimension(*pi.base.bv); + Dimension const textdim = InsetText::dimension(bv); int const baseline = y; int textx, texty; - switch (geometry(*pi.base.bv)) { + switch (geometry(bv)) { case LeftButton: textx = x + dimc.width(); texty = baseline; @@ -323,7 +326,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const const_cast(this)->setDrawFrame(true); int desc = textdim.descent(); - if (geometry(*pi.base.bv) == Corners) + if (geometry(bv) == Corners) desc -= 3; const int xx1 = x + TEXT_TO_INSET_OFFSET - 1; @@ -348,7 +351,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const y + desc - 4, layout_->labelfont().color()); // the label below the text. Can be toggled. - if (geometry(*pi.base.bv) == SubLabel) { + if (geometry(bv) == SubLabel) { FontInfo font(layout_->labelfont()); font.realize(sane_font); font.decSize(); @@ -356,15 +359,15 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const int w = 0; int a = 0; int d = 0; - theFontMetrics(font).rectText(labelstring_, w, a, d); + 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, - labelstring_, font, Color_none, Color_none); + buttonLabel(bv), font, Color_none, Color_none); desc += d; } // a visual cue when the cursor is inside the inset - Cursor & cur = pi.base.bv->cursor(); + Cursor const & cur = bv.cursor(); if (cur.isInside(this)) { y -= textdim.asc; y += 3; @@ -394,10 +397,10 @@ void InsetCollapsable::cursorPos(BufferView const & bv, switch (geometry(bv)) { case LeftButton: - x += dimensionCollapsed().wid; + x += dimensionCollapsed(bv).wid; break; case TopButton: { - y += dimensionCollapsed().des + textdim.asc; + y += dimensionCollapsed(bv).des + textdim.asc; break; } case NoButton: @@ -871,7 +874,7 @@ docstring InsetCollapsable::contextMenu(BufferView const & bv, int x, if (geometry(bv) == NoButton) return from_ascii("context-collapsable"); - Dimension dim = dimensionCollapsed(); + Dimension dim = dimensionCollapsed(bv); if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des) return from_ascii("context-collapsable"); diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 88055b4ba0..2308ae753f 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -69,8 +69,7 @@ public: /// return x,y of given position relative to the inset's baseline void cursorPos(BufferView const & bv, CursorSlice const & sl, - /// - bool boundary, int & x, int & y) const; + bool boundary, int & x, int & y) const; /// Returns true if (mouse) action is over the inset's button. /// Always returns false when the inset does not have a /// button. @@ -86,6 +85,9 @@ public: /// virtual void setButtonLabel() {} /// + virtual docstring const buttonLabel(BufferView const & bv) const + { return labelstring_; } + /// bool isOpen(BufferView const & bv) const { return geometry(bv) != ButtonOnly; } /// @@ -178,7 +180,7 @@ private: /// cache for the layout_. Make sure it is in sync with the document class! InsetLayout const * layout_; /// - Dimension dimensionCollapsed() const; + Dimension dimensionCollapsed(BufferView const & bv) const; /// /// should paragraphs be forced to use the empty layout? virtual bool forcePlainLayout(idx_type = 0) const diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index de911557c7..95cda7e7ca 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -162,12 +162,12 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd, } -void InsetERT::setButtonLabel(BufferView const & bv) +docstring const InsetERT::buttonLabel(BufferView const & bv) const { if (decoration() == InsetLayout::CLASSIC) - setLabel(isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"))); + return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")); else - setLabel(getNewLabel(_("ERT"))); + return getNewLabel(_("ERT")); } diff --git a/src/insets/InsetERT.h b/src/insets/InsetERT.h index 2df001b3e0..1015e2f8ce 100644 --- a/src/insets/InsetERT.h +++ b/src/insets/InsetERT.h @@ -69,7 +69,7 @@ private: /// Inset * clone() const { return new InsetERT(*this); } /// - void setButtonLabel(BufferView const & bv); + docstring const buttonLabel(BufferView const & bv) const; /// bool allowSpellCheck() const { return false; } }; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 035da731f2..15471f353f 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -397,13 +397,12 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd, } -void InsetListings::setButtonLabel(BufferView const & bv) +docstring const InsetListings::buttonLabel(BufferView const & bv) const { - // FIXME UNICODE if (decoration() == InsetLayout::CLASSIC) - setLabel(isOpen(bv) ? _("Listing") : getNewLabel(_("Listing"))); + return isOpen(bv) ? _("Listing") : getNewLabel(_("Listing")); else - setLabel(getNewLabel(_("Listing"))); + return getNewLabel(_("Listing")); } diff --git a/src/insets/InsetListings.h b/src/insets/InsetListings.h index 09d1ac7300..5396b7d0e1 100644 --- a/src/insets/InsetListings.h +++ b/src/insets/InsetListings.h @@ -73,7 +73,7 @@ private: /// Inset * clone() const { return new InsetListings(*this); } /// - void setButtonLabel(BufferView const & bv); + docstring const buttonLabel(BufferView const & bv) const; /// docstring getCaption(OutputParams const &) const;