diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 050e11fe6d..2a328f3c46 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -45,8 +45,7 @@ using std::max; InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) : UpdatableInset(), collapsed_(collapsed), inset(bp), - button_length(0), button_top_y(0), button_bottom_y(0), - label("Label"), + button_dim(0, 0, 0, 0), label("Label"), #if 0 autocollapse(false), #endif @@ -63,8 +62,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) InsetCollapsable::InsetCollapsable(InsetCollapsable const & in) : UpdatableInset(in), collapsed_(in.collapsed_), framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset), - button_length(0), button_top_y(0), button_bottom_y(0), - label(in.label), + button_dim(0, 0, 0, 0), label(in.label), #if 0 autocollapse(in.autocollapse), #endif @@ -158,10 +156,11 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const Dimension dim_collapsed; dimension_collapsed(dim_collapsed); - int const aa = ascent(); - button_length = dim_collapsed.width(); - button_top_y = -aa; - button_bottom_y = -aa + dim_collapsed.height(); + int const aa = ascent(); + button_dim.x1 = 0; + button_dim.x2 = dim_collapsed.width(); + button_dim.y1 = -aa; + button_dim.y2 = -aa + dim_collapsed.height(); if (!isOpen()) { draw_collapsed(pi, x, y); @@ -241,8 +240,7 @@ void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) return; } - if ((cmd.button() != mouse_button::button3) && (cmd.x < button_length) && - (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) + if (cmd.button() != mouse_button::button3 && hitButton(cmd)) { if (collapsed_) { collapsed_ = false; @@ -255,7 +253,7 @@ void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) bv->updateInset(this); bv->buffer()->markDirty(); } - } else if (!collapsed_ && (cmd.y > button_bottom_y)) { + } else if (!collapsed_ && (cmd.y > button_dim.y2)) { ret = (inset.localDispatch(adjustCommand(cmd)) == DISPATCHED); } if (cmd.button() == mouse_button::button3 && !ret) @@ -288,6 +286,12 @@ int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) co } +bool InsetCollapsable::hitButton(FuncRequest const & cmd) const +{ + return button_dim.contained(cmd.x, cmd.y); +} + + InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd) { lyxerr << "InsetCollapsable::localDispatch: " @@ -337,7 +341,7 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd) FuncRequest cmd1 = cmd; if (!bv->lockInset(this)) return DISPATCHED; - if (cmd.y <= button_bottom_y) { + if (cmd.y <= button_dim.y2) { cmd1.y = 0; } else { cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent()); @@ -348,12 +352,12 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd) } case LFUN_MOUSE_PRESS: - if (!collapsed_ && cmd.y > button_bottom_y) + if (!collapsed_ && cmd.y > button_dim.y2) inset.localDispatch(adjustCommand(cmd)); return DISPATCHED; case LFUN_MOUSE_MOTION: - if (!collapsed_ && cmd.y > button_bottom_y) + if (!collapsed_ && cmd.y > button_dim.y2) inset.localDispatch(adjustCommand(cmd)); return DISPATCHED; diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index d12af3c925..30ad137784 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -19,6 +19,7 @@ #include "lyxfont.h" #include "funcrequest.h" // for adjustCommand #include "LColor.h" +#include "box.h" #include @@ -51,6 +52,8 @@ public: /// draw, either inlined (no button) or collapsed/open void draw(PainterInfo & pi, int x, int y, bool inlined) const; /// + bool hitButton(FuncRequest const &) const; + /// EDITABLE editable() const; /// bool insertInset(BufferView *, InsetOld * inset); @@ -193,11 +196,7 @@ public: mutable InsetText inset; protected: /// - mutable int button_length; - /// - mutable int button_top_y; - /// - mutable int button_bottom_y; + mutable Box button_dim; /// mutable int topx; mutable int topbaseline; diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 86aa7b7bef..f153d61e4c 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -295,8 +295,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd) return true; } - if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) && - (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) { + if (status_ != Inlined && hitButton(cmd)) { updateStatus(bv, true); } else { FuncRequest cmd1 = cmd; @@ -304,10 +303,10 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd) cmd1.y = ascent() + cmd.y - inset.ascent(); // inlined is special - the text appears above - // button_bottom_y + // button_dim.y2 if (status_ == Inlined) inset.localDispatch(cmd1); - else if (!collapsed_ && (cmd.y > button_bottom_y)) { + else if (!collapsed_ && (cmd.y > button_dim.y2)) { cmd1.y -= height_collapsed(); inset.localDispatch(cmd1); } diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index adc7c99629..92a79b09f7 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -132,8 +132,7 @@ dispatch_result InsetNote::localDispatch(FuncRequest const & cmd) InsetNoteMailer("note", *this).updateDialog(bv); return DISPATCHED; case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3 && cmd.x < button_length - && cmd.y >= button_top_y && cmd.y <= button_bottom_y) { + if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { InsetNoteMailer("note", *this).showDialog(bv); return DISPATCHED; }