Synchronizing insets asserts with two views open

This finishes the change of http://www.lyx.org/trac/changeset/28587.

Replace the setButtonLabels functions that need a BufferView by buttonLabel functions. These functions modify the label at drawing time. 

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28610 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-02-25 22:35:41 +00:00
parent d31e25e159
commit 7eb04d61d9
8 changed files with 41 additions and 37 deletions

View File

@ -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);
}

View File

@ -62,7 +62,7 @@ private:
///
void read(Lexer & lex);
///
void setButtonLabel(BufferView const & bv);
docstring const buttonLabel(BufferView const & bv) const;
///
ColorCode backgroundColor() const;
///

View File

@ -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<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;
@ -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");

View File

@ -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

View File

@ -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"));
}

View File

@ -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; }
};

View File

@ -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"));
}

View File

@ -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;