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)
: 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
@ -159,9 +157,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
dimension_collapsed(dim_collapsed);
int const aa = ascent();
button_length = dim_collapsed.width();
button_top_y = -aa;
button_bottom_y = -aa + dim_collapsed.height();
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;

View File

@ -19,6 +19,7 @@
#include "lyxfont.h"
#include "funcrequest.h" // for adjustCommand
#include "LColor.h"
#include "box.h"
#include <boost/weak_ptr.hpp>
@ -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;

View File

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

View File

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