Mouse hover property should be dependent on the specific bufferview. If there are 2 views showing the same buffer, an Inset can be shown as hovered in only one view.

This is also in preparation of a decent fix for bug #3900.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34347 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-04-30 14:47:46 +00:00
parent 0833a4a94c
commit 4c611e5745
9 changed files with 33 additions and 32 deletions

View File

@ -1902,13 +1902,13 @@ void BufferView::updateHoveredInset() const
bool need_redraw = false;
if (d->last_inset_)
// Remove the hint on the last hovered inset (if any).
need_redraw |= d->last_inset_->setMouseHover(false);
need_redraw |= d->last_inset_->setMouseHover(this, false);
// const_cast because of setMouseHover().
Inset * inset = const_cast<Inset *>(covering_inset);
if (inset)
// Highlight the newly hovered inset (if any).
need_redraw |= inset->setMouseHover(true);
need_redraw |= inset->setMouseHover(this, true);
d->last_inset_ = inset;

View File

@ -495,7 +495,7 @@ void Inset::metricsMarkers2(Dimension & dim, int framesize) const
void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
{
ColorCode pen_color = mouseHovered() || editing(pi.base.bv)?
ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)?
Color_mathframe : Color_mathcorners;
Dimension const dim = dimension(*pi.base.bv);
@ -512,7 +512,7 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
{
ColorCode pen_color = mouseHovered() || editing(pi.base.bv)?
ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)?
Color_mathframe : Color_mathcorners;
drawMarkers(pi, x, y);

View File

@ -284,15 +284,15 @@ public:
/// \c cur is the new cursor, some slice points to this. Use the update flags to cause a redraw.
virtual bool notifyCursorEnters(Cursor & /*cur*/)
{ return false; }
/// is called when the mouse enter or leave this inset
/// return true if this inset needs repaint
virtual bool setMouseHover(bool) { return false; }
/// is called when the mouse enters or leaves this inset
/// return true if this inset needs a repaint
virtual bool setMouseHover(BufferView const * bv, bool) { return false; }
/// return true if this inset is hovered (under mouse)
/// This is by now only used by mathed to draw corners
/// (Inset::drawMarkers() and Inset::drawMarkers2()).
/// Other insets do not have to redefine this function to
/// return the correct status of mouseHovered.
virtual bool mouseHovered() const { return false; }
virtual bool mouseHovered(BufferView const * bv) const { return false; }
/// request "external features"
virtual void validate(LaTeXFeatures &) const {}

View File

@ -42,8 +42,7 @@ using namespace std;
namespace lyx {
InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
: InsetText(buf, ltype), status_(Open),
openinlined_(false), mouse_hover_(false)
: InsetText(buf, ltype), status_(Open), openinlined_(false)
{
setAutoBreakRows(true);
setDrawFrame(true);
@ -59,7 +58,7 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
openinlined_(rhs.openinlined_),
auto_open_(rhs.auto_open_),
// the sole purpose of this copy constructor
mouse_hover_(false)
mouse_hover_()
{
}
@ -230,9 +229,9 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
}
bool InsetCollapsable::setMouseHover(bool mouse_hover)
bool InsetCollapsable::setMouseHover(BufferView const * bv, bool mouse_hover)
{
mouse_hover_ = mouse_hover;
mouse_hover_[bv] = mouse_hover;
return true;
}
@ -261,7 +260,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
FontInfo labelfont = getLayout().labelfont();
labelfont.setColor(labelColor());
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
mouse_hover_);
mouse_hover_[&bv]);
} else {
button_dim.x1 = 0;
button_dim.y1 = 0;
@ -586,7 +585,7 @@ void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
setButtonLabel();
if (status_ == Collapsed) {
cur.leaveInset(*this);
mouse_hover_ = false;
mouse_hover_.clear();
}
}

View File

@ -125,7 +125,7 @@ public:
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
bool setMouseHover(bool mouse_hover);
bool setMouseHover(BufferView const * bv, bool mouse_hover);
///
ColorCode backgroundColor(PainterInfo const &) const
{ return getLayout().bgcolor(); }
@ -163,7 +163,7 @@ private:
/// dependent on the bufferview, compare with MathMacro::editing_.
mutable std::map<BufferView const *, bool> auto_open_;
/// changes color when mouse enters/leaves this inset
bool mouse_hover_;
mutable std::map<BufferView const *, bool> mouse_hover_;
};
} // namespace lyx

View File

@ -73,16 +73,16 @@ void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
}
bool InsetCommand::setMouseHover(bool mouse_hover)
bool InsetCommand::setMouseHover(BufferView const * bv, bool mouse_hover)
{
mouse_hover_ = mouse_hover;
mouse_hover_[bv] = mouse_hover;
return true;
}
void InsetCommand::draw(PainterInfo & pi, int x, int y) const
{
button_.setRenderState(mouse_hover_);
button_.setRenderState(mouse_hover_[pi.base.bv]);
button_.draw(pi, x, y);
}

View File

@ -99,7 +99,7 @@ private:
///
RenderButton & button() const { return button_; }
///
bool setMouseHover(bool mouse_hover);
bool setMouseHover(BufferView const * bv, bool mouse_hover);
/// Return parameter information for command cmdName.
/// Not implemented here. Must be implemented in derived class.
static ParamInfo const & findInfo(std::string const & cmdName);
@ -120,7 +120,7 @@ private:
///
std::string mailer_name_;
/// changes color when mouse enters/leaves this inset
bool mouse_hover_;
mutable std::map<BufferView const *, bool> mouse_hover_;
///
mutable RenderButton button_;
};

View File

@ -80,15 +80,14 @@ using cap::selClearOrDel;
InsetMathNest::InsetMathNest(Buffer * buf, idx_type nargs)
: InsetMath(buf), cells_(nargs), lock_(false), mouse_hover_(false)
: InsetMath(buf), cells_(nargs), lock_(false)
{
setBuffer(*buf);
}
InsetMathNest::InsetMathNest(InsetMathNest const & inset)
: InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_),
mouse_hover_(false)
: InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_)
{}
@ -96,7 +95,7 @@ InsetMathNest & InsetMathNest::operator=(InsetMathNest const & inset)
{
cells_ = inset.cells_;
lock_ = inset.lock_;
mouse_hover_ = false;
mouse_hover_.clear();
InsetMath::operator=(inset);
return *this;
}
@ -395,9 +394,9 @@ int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
}
bool InsetMathNest::setMouseHover(bool mouse_hover)
bool InsetMathNest::setMouseHover(BufferView const * bv, bool mouse_hover)
{
mouse_hover_ = mouse_hover;
mouse_hover_[bv] = mouse_hover;
return true;
}

View File

@ -17,6 +17,8 @@
// FIXME: remove
#include "support/docstring.h"
#include <map>
namespace lyx {
/** Abstract base class for all math objects that contain nested items.
@ -111,9 +113,10 @@ public:
///
int latex(odocstream & os, OutputParams const & runparams) const;
///
bool setMouseHover(bool mouse_hover);
bool setMouseHover(BufferView const * bv, bool mouse_hover);
///
bool mouseHovered() const { return mouse_hover_; }
bool mouseHovered(BufferView const * bv) const
{ return mouse_hover_[bv]; }
///
bool completionSupported(Cursor const &) const;
@ -194,8 +197,8 @@ protected:
/// if the inset is locked, it can't be entered with the cursor
bool lock_;
///
bool mouse_hover_;
};
mutable std::map<BufferView const *, bool> mouse_hover_;
};