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))
}
-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;
}
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;
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;
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 ||
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;
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;
const_cast<InsetCollapsable *>(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;
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();
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;
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:
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");
/// 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.
///
virtual void setButtonLabel() {}
///
+ virtual docstring const buttonLabel(BufferView const & bv) const
+ { return labelstring_; }
+ ///
bool isOpen(BufferView const & bv) const
{ return geometry(bv) != ButtonOnly; }
///
/// 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