factor out the detection of clicking on the inset button as 'hitButton'.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7452 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2003-07-30 14:43:14 +00:00
parent 271412de78
commit c396168af0
4 changed files with 26 additions and 25 deletions

View File

@ -45,8 +45,7 @@ using std::max;
InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
: UpdatableInset(), collapsed_(collapsed), inset(bp), : UpdatableInset(), collapsed_(collapsed), inset(bp),
button_length(0), button_top_y(0), button_bottom_y(0), button_dim(0, 0, 0, 0), label("Label"),
label("Label"),
#if 0 #if 0
autocollapse(false), autocollapse(false),
#endif #endif
@ -63,8 +62,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in) InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
: UpdatableInset(in), collapsed_(in.collapsed_), : UpdatableInset(in), collapsed_(in.collapsed_),
framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset), framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
button_length(0), button_top_y(0), button_bottom_y(0), button_dim(0, 0, 0, 0), label(in.label),
label(in.label),
#if 0 #if 0
autocollapse(in.autocollapse), autocollapse(in.autocollapse),
#endif #endif
@ -159,9 +157,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
dimension_collapsed(dim_collapsed); dimension_collapsed(dim_collapsed);
int const aa = ascent(); int const aa = ascent();
button_length = dim_collapsed.width(); button_dim.x1 = 0;
button_top_y = -aa; button_dim.x2 = dim_collapsed.width();
button_bottom_y = -aa + dim_collapsed.height(); button_dim.y1 = -aa;
button_dim.y2 = -aa + dim_collapsed.height();
if (!isOpen()) { if (!isOpen()) {
draw_collapsed(pi, x, y); draw_collapsed(pi, x, y);
@ -241,8 +240,7 @@ void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
return; return;
} }
if ((cmd.button() != mouse_button::button3) && (cmd.x < button_length) && if (cmd.button() != mouse_button::button3 && hitButton(cmd))
(cmd.y >= button_top_y) && (cmd.y <= button_bottom_y))
{ {
if (collapsed_) { if (collapsed_) {
collapsed_ = false; collapsed_ = false;
@ -255,7 +253,7 @@ void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
bv->updateInset(this); bv->updateInset(this);
bv->buffer()->markDirty(); 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); ret = (inset.localDispatch(adjustCommand(cmd)) == DISPATCHED);
} }
if (cmd.button() == mouse_button::button3 && !ret) 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) InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
{ {
lyxerr << "InsetCollapsable::localDispatch: " lyxerr << "InsetCollapsable::localDispatch: "
@ -337,7 +341,7 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
FuncRequest cmd1 = cmd; FuncRequest cmd1 = cmd;
if (!bv->lockInset(this)) if (!bv->lockInset(this))
return DISPATCHED; return DISPATCHED;
if (cmd.y <= button_bottom_y) { if (cmd.y <= button_dim.y2) {
cmd1.y = 0; cmd1.y = 0;
} else { } else {
cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent()); cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent());
@ -348,12 +352,12 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
} }
case LFUN_MOUSE_PRESS: case LFUN_MOUSE_PRESS:
if (!collapsed_ && cmd.y > button_bottom_y) if (!collapsed_ && cmd.y > button_dim.y2)
inset.localDispatch(adjustCommand(cmd)); inset.localDispatch(adjustCommand(cmd));
return DISPATCHED; return DISPATCHED;
case LFUN_MOUSE_MOTION: case LFUN_MOUSE_MOTION:
if (!collapsed_ && cmd.y > button_bottom_y) if (!collapsed_ && cmd.y > button_dim.y2)
inset.localDispatch(adjustCommand(cmd)); inset.localDispatch(adjustCommand(cmd));
return DISPATCHED; return DISPATCHED;

View File

@ -19,6 +19,7 @@
#include "lyxfont.h" #include "lyxfont.h"
#include "funcrequest.h" // for adjustCommand #include "funcrequest.h" // for adjustCommand
#include "LColor.h" #include "LColor.h"
#include "box.h"
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
@ -51,6 +52,8 @@ public:
/// draw, either inlined (no button) or collapsed/open /// draw, either inlined (no button) or collapsed/open
void draw(PainterInfo & pi, int x, int y, bool inlined) const; void draw(PainterInfo & pi, int x, int y, bool inlined) const;
/// ///
bool hitButton(FuncRequest const &) const;
///
EDITABLE editable() const; EDITABLE editable() const;
/// ///
bool insertInset(BufferView *, InsetOld * inset); bool insertInset(BufferView *, InsetOld * inset);
@ -193,11 +196,7 @@ public:
mutable InsetText inset; mutable InsetText inset;
protected: protected:
/// ///
mutable int button_length; mutable Box button_dim;
///
mutable int button_top_y;
///
mutable int button_bottom_y;
/// ///
mutable int topx; mutable int topx;
mutable int topbaseline; mutable int topbaseline;

View File

@ -295,8 +295,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
return true; return true;
} }
if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) && if (status_ != Inlined && hitButton(cmd)) {
(cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
updateStatus(bv, true); updateStatus(bv, true);
} else { } else {
FuncRequest cmd1 = cmd; FuncRequest cmd1 = cmd;
@ -304,10 +303,10 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
cmd1.y = ascent() + cmd.y - inset.ascent(); cmd1.y = ascent() + cmd.y - inset.ascent();
// inlined is special - the text appears above // inlined is special - the text appears above
// button_bottom_y // button_dim.y2
if (status_ == Inlined) if (status_ == Inlined)
inset.localDispatch(cmd1); inset.localDispatch(cmd1);
else if (!collapsed_ && (cmd.y > button_bottom_y)) { else if (!collapsed_ && (cmd.y > button_dim.y2)) {
cmd1.y -= height_collapsed(); cmd1.y -= height_collapsed();
inset.localDispatch(cmd1); inset.localDispatch(cmd1);
} }

View File

@ -132,8 +132,7 @@ dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
InsetNoteMailer("note", *this).updateDialog(bv); InsetNoteMailer("note", *this).updateDialog(bv);
return DISPATCHED; return DISPATCHED;
case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && cmd.x < button_length if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
&& cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
InsetNoteMailer("note", *this).showDialog(bv); InsetNoteMailer("note", *this).showDialog(bv);
return DISPATCHED; return DISPATCHED;
} }