namespace lyx {
InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
- : InsetText(buf, ltype), status_(Open), openinlined_(false)
+ : InsetText(buf, ltype), status_(Open)
{
setDrawFrame(true);
setFrameColor(Color_collapsableframe);
// The sole purpose of this copy constructor is to make sure
-// that the mouse_hover_ map is not copied and remains empty.
+// that the view_ map is not copied and remains empty.
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
: InsetText(rhs),
status_(rhs.status_),
- labelstring_(rhs.labelstring_),
- button_dim(rhs.button_dim),
- openinlined_(rhs.openinlined_)
+ labelstring_(rhs.labelstring_)
{}
InsetCollapsable::~InsetCollapsable()
{
- map<BufferView const *, bool>::iterator it = mouse_hover_.begin();
- map<BufferView const *, bool>::iterator end = mouse_hover_.end();
+ map<BufferView const *, View>::iterator it = view_.begin();
+ map<BufferView const *, View>::iterator end = view_.end();
for (; it != end; ++it)
- if (it->second)
+ if (it->second.mouse_hover_)
it->first->clearLastInset(this);
}
{
if (decoration() == InsetLayout::CONGLOMERATE)
return status_;
- return auto_open_[&bv] ? Open : status_;
+ return view_[&bv].auto_open_ ? Open : status_;
}
switch (decoration()) {
case InsetLayout::CLASSIC:
if (status(bv) == Open)
- return openinlined_ ? LeftButton : TopButton;
+ return view_[&bv].openinlined_ ? LeftButton : TopButton;
return ButtonOnly;
case InsetLayout::MINIMALISTIC:
}
-InsetCollapsable::Geometry InsetCollapsable::geometry() const
-{
- switch (decoration()) {
- case InsetLayout::CLASSIC:
- if (status_ == Open)
- return openinlined_ ? LeftButton : TopButton;
- return ButtonOnly;
-
- case InsetLayout::MINIMALISTIC:
- return status_ == Open ? NoButton : ButtonOnly ;
-
- case InsetLayout::CONGLOMERATE:
- return status_ == Open ? SubLabel : Corners ;
-
- case InsetLayout::DEFAULT:
- break; // this shouldn't happen
- }
-
- // dummy return value to shut down a warning,
- // this is dead code.
- return NoButton;
-}
-
-
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
Dimension const dim = dimensionCollapsed(bv);
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
- auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
+ view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
mi.base.font = getFont();
case LeftButton:
case ButtonOnly:
if (hasFixedWidth()){
- int const mindim = button_dim.x2 - button_dim.x1;
+ int const mindim = view_[&bv].button_dim_.x2 - view_[&bv].button_dim_.x1;
if (mi.base.textwidth < mindim)
mi.base.textwidth = mindim;
}
dim = dimensionCollapsed(bv);
- if (geometry(bv) == TopButton
- || geometry(bv) == LeftButton) {
+ if (geometry(bv) == TopButton || geometry(bv) == LeftButton) {
Dimension textdim;
InsetText::metrics(mi, textdim);
- openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
- if (openinlined_) {
+ view_[&bv].openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
+ if (view_[&bv].openinlined_) {
// Correct for button width.
dim.wid += textdim.wid;
dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
bool InsetCollapsable::setMouseHover(BufferView const * bv, bool mouse_hover)
const
{
- mouse_hover_[bv] = mouse_hover;
+ view_[bv].mouse_hover_ = mouse_hover;
return true;
}
{
BufferView const & bv = *pi.base.bv;
- auto_open_[&bv] = bv.cursor().isInside(this);
+ view_[&bv].auto_open_ = bv.cursor().isInside(this);
FontInfo tmpfont = pi.base.font;
pi.base.font = getFont();
if (geometry(bv) == TopButton ||
geometry(bv) == LeftButton ||
geometry(bv) == ButtonOnly) {
- button_dim.x1 = x + 0;
- button_dim.x2 = x + dimc.width();
- button_dim.y1 = y - dimc.asc;
- button_dim.y2 = y + dimc.des;
+ view_[&bv].button_dim_.x1 = x + 0;
+ view_[&bv].button_dim_.x2 = x + dimc.width();
+ view_[&bv].button_dim_.y1 = y - dimc.asc;
+ view_[&bv].button_dim_.y2 = y + dimc.des;
FontInfo labelfont = getLabelfont();
labelfont.setColor(labelColor());
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
- mouse_hover_[&bv]);
+ view_[&bv].mouse_hover_);
} else {
- button_dim.x1 = 0;
- button_dim.y1 = 0;
- button_dim.x2 = 0;
- button_dim.y2 = 0;
+ view_[&bv].button_dim_.x1 = 0;
+ view_[&bv].button_dim_.y1 = 0;
+ view_[&bv].button_dim_.x2 = 0;
+ view_[&bv].button_dim_.y2 = 0;
}
Dimension const textdim = InsetText::dimension(bv);
const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
- pi.pain.line(xx1, y + desc - 4,
- xx1, y + desc,
+ pi.pain.line(xx1, y + desc - 4,
+ xx1, y + desc,
Color_foreground);
if (status_ == Open)
- pi.pain.line(xx1, y + desc,
+ pi.pain.line(xx1, y + desc,
xx2, y + desc,
Color_foreground);
else {
xx2, y + desc,
Color_foreground);
}
- pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
+ pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
y + desc - 4, Color_foreground);
// the label below the text. Can be toggled.
bool InsetCollapsable::editable() const
{
- return geometry() != ButtonOnly;
+ switch (decoration()) {
+ case InsetLayout::CLASSIC:
+ case InsetLayout::MINIMALISTIC:
+ return status_ == Open;
+ default:
+ return true;
+ }
}
}
-bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
-{
- return button_dim.contains(cmd.x(), cmd.y());
-}
-
-
-bool InsetCollapsable::clickable(int x, int y) const
+bool InsetCollapsable::clickable(BufferView const & bv, int x, int y) const
{
- FuncRequest cmd(LFUN_NOACTION, x, y, mouse_button::none);
- return hitButton(cmd);
+ return view_[&bv].button_dim_.contains(x, y);
}
{
//lyxerr << "InsetCollapsable: edit xy" << endl;
if (geometry(cur.bv()) == ButtonOnly
- || (button_dim.contains(x, y)
- && geometry(cur.bv()) != NoButton))
+ || (view_[&cur.bv()].button_dim_.contains(x, y)
+ && geometry(cur.bv()) != NoButton))
return this;
cur.push(*this);
return InsetText::editXY(cur, x, y);
//lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
+ bool const hitButton = clickable(cur.bv(), cmd.x(), cmd.y());
+
switch (cmd.action()) {
case LFUN_MOUSE_PRESS:
- if (hitButton(cmd)) {
+ if (hitButton) {
switch (cmd.button()) {
case mouse_button::button1:
case mouse_button::button3:
case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
- if (hitButton(cmd))
+ if (hitButton)
cur.noScreenUpdate();
else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
break;
case LFUN_MOUSE_RELEASE:
- if (!hitButton(cmd)) {
+ if (!hitButton) {
// The mouse click has to be within the inset!
if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
- cur.undispatched();
+ cur.undispatched();
break;
}
if (cmd.button() != mouse_button::button1) {
docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const
{
InsetLayout const & il = getLayout();
- docstring const label = labelstring_.empty() ?
+ docstring const label = labelstring_.empty() ?
translateIfPossible(il.labelstring()) : labelstring_;
if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
return label;