* Fix regression spotted by Humdinger. Emulate right click dragging like it

used to work before, i.e right mouse button dragging works and the context
menu shows on mouse up if not dragged. I guess that at some point we'll rethink
all the mouse gestures we support and maybe simplify a bit, like dropping
long click support (as an emulated right button), and possibly
separating some features via user settings if needed.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41929 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexandre Deckner
2011-06-05 01:55:52 +00:00
parent 58e371f5a5
commit f2068166ad
2 changed files with 47 additions and 41 deletions
@@ -6,7 +6,7 @@
/*! /*!
\class LongAndDragTrackingFilter \class LongAndDragTrackingFilter
\brief A simple long mouse down and drag detection filter \brief A simple long mouse down and drag detection filter
* *
* A simple mouse filter that detects long clicks and pointer drags. * A simple mouse filter that detects long clicks and pointer drags.
* A long click message is sent when the mouse button is kept down * A long click message is sent when the mouse button is kept down
* for a duration longer than a given threshold while the pointer stays * for a duration longer than a given threshold while the pointer stays
@@ -18,8 +18,8 @@
* the moment of the click. The drag message is ready to use with the * the moment of the click. The drag message is ready to use with the
* be/haiku drag and drop API cf. comment in code. * be/haiku drag and drop API cf. comment in code.
* *
* Note: for simplicity and current needs (Tracker), only the left mouse * Current limitation: A long mouse down or a drag can be detected for
* button is tracked. * any mouse button, but any released button cancels the tracking.
* *
*/ */
@@ -77,8 +77,7 @@ LongAndDragTrackingFilter::Filter(BMessage* message, BHandler** target)
message->FindInt32("buttons", (int32*)&fClickButtons); message->FindInt32("buttons", (int32*)&fClickButtons);
if ((fClickButtons & B_PRIMARY_MOUSE_BUTTON) if (fClickButtons != 0) {
== B_PRIMARY_MOUSE_BUTTON) {
BView* targetView = dynamic_cast<BView*>(*target); BView* targetView = dynamic_cast<BView*>(*target);
if (targetView != NULL) if (targetView != NULL)
@@ -97,14 +96,15 @@ LongAndDragTrackingFilter::Filter(BMessage* message, BHandler** target)
case B_MOUSE_UP: case B_MOUSE_UP:
_StopTracking(); _StopTracking();
message->AddInt32("last_buttons", (int32)fClickButtons);
return B_DISPATCH_MESSAGE; return B_DISPATCH_MESSAGE;
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
{ {
if (fMessageRunner != NULL) { if (fMessageRunner != NULL) {
BPoint where; BPoint where;
message->FindPoint("be:view_where", &where); message->FindPoint("be:view_where", &where);
BPoint delta(fClickPoint - where); BPoint delta(fClickPoint - where);
float squaredDelta = (delta.x * delta.x) + (delta.y * delta.y); float squaredDelta = (delta.x * delta.x) + (delta.y * delta.y);
@@ -114,7 +114,7 @@ LongAndDragTrackingFilter::Filter(BMessage* message, BHandler** target)
// name it "be:view_where" since BView::DragMessage // name it "be:view_where" since BView::DragMessage
// positions the dragging frame/bitmap by retrieving // positions the dragging frame/bitmap by retrieving
// the current message and reading that field // the current message and reading that field
dragMessage.AddInt32("buttons", fClickButtons); dragMessage.AddInt32("buttons", (int32)fClickButtons);
BMessenger messenger(*target); BMessenger messenger(*target);
messenger.SendMessage(&dragMessage); messenger.SendMessage(&dragMessage);
+39 -33
View File
@@ -2159,17 +2159,17 @@ BPoseView::MessageReceived(BMessage *message)
case kMiniIconMode: case kMiniIconMode:
SetViewMode(message->what); SetViewMode(message->what);
break; break;
case kMsgMouseDragged: case kMsgMouseDragged:
MouseDragged(message); MouseDragged(message);
break; break;
case kMsgMouseLongDown: case kMsgMouseLongDown:
MouseLongDown(message); MouseLongDown(message);
break; break;
case B_MOUSE_IDLE: case B_MOUSE_IDLE:
MouseIdle(message); MouseIdle(message);
break; break;
case B_SELECT_ALL: case B_SELECT_ALL:
@@ -6707,7 +6707,7 @@ BPoseView::MouseMoved(BPoint mouseLoc, uint32 moveCode, const BMessage *message)
{ {
if (fSelectionRectInfo.isDragging) if (fSelectionRectInfo.isDragging)
_UpdateSelectionRect(mouseLoc); _UpdateSelectionRect(mouseLoc);
if (!fDropEnabled || !message) if (!fDropEnabled || !message)
return; return;
@@ -6737,7 +6737,7 @@ BPoseView::MouseMoved(BPoint mouseLoc, uint32 moveCode, const BMessage *message)
fDropTarget = NULL; fDropTarget = NULL;
} }
break; break;
} }
} }
@@ -6745,7 +6745,9 @@ void
BPoseView::MouseDragged(const BMessage *message) BPoseView::MouseDragged(const BMessage *message)
{ {
BPoint where; BPoint where;
if (message->FindPoint("be:view_where", &where) != B_OK) uint32 buttons = 0;
if (message->FindPoint("be:view_where", &where) != B_OK
|| message->FindInt32("buttons", (int32*)&buttons) != B_OK)
return; return;
bool extendSelection = (modifiers() & B_COMMAND_KEY) && fMultipleSelection; bool extendSelection = (modifiers() & B_COMMAND_KEY) && fMultipleSelection;
@@ -6754,8 +6756,8 @@ BPoseView::MouseDragged(const BMessage *message)
BPose* pose = FindPose(where, &index); BPose* pose = FindPose(where, &index);
if (pose != NULL) if (pose != NULL)
DragSelectedPoses(pose, where); DragSelectedPoses(pose, where);
else else if (buttons == B_PRIMARY_MOUSE_BUTTON)
_BeginSelectionRect(where, extendSelection); _BeginSelectionRect(where, extendSelection);
} }
@@ -6780,7 +6782,7 @@ BPoseView::MouseIdle(const BMessage *message)
if (buttons == 0 || window == NULL) if (buttons == 0 || window == NULL)
return; return;
if (fDropTarget != NULL) { if (fDropTarget != NULL) {
window->DragStart(message); window->DragStart(message);
FrameForPose(fDropTarget, true, &fStartFrame); FrameForPose(fDropTarget, true, &fStartFrame);
@@ -6808,35 +6810,13 @@ BPoseView::MouseDown(BPoint where)
MakeFocus(); MakeFocus();
// "right" mouse button handling for context-sensitive menus
uint32 buttons = (uint32)window->CurrentMessage()->FindInt32("buttons"); uint32 buttons = (uint32)window->CurrentMessage()->FindInt32("buttons");
uint32 modifs = modifiers(); uint32 modifs = modifiers();
bool showContext = true;
if ((buttons & B_SECONDARY_MOUSE_BUTTON) == 0)
showContext = (modifs & B_CONTROL_KEY) != 0;
if (showContext) {
int32 index;
BPose *pose = FindPose(where, &index);
if (!pose) {
ShowContextMenu(where);
return;
}
if (!pose->IsSelected()) {
ClearSelection();
pose->Select(true);
fSelectionList->AddItem(pose);
DrawPose(pose, index, false);
}
ShowContextMenu(where);
}
bool extendSelection = (modifs & B_COMMAND_KEY) && fMultipleSelection; bool extendSelection = (modifs & B_COMMAND_KEY) && fMultipleSelection;
CommitActivePose(); CommitActivePose();
// see if mouse down occurred within a pose
int32 index; int32 index;
BPose *pose = FindPose(where, &index); BPose *pose = FindPose(where, &index);
if (pose) { if (pose) {
@@ -6853,10 +6833,16 @@ BPoseView::MouseDown(BPoint where)
window->Activate(); window->Activate();
window->UpdateIfNeeded(); window->UpdateIfNeeded();
// only clear selection if we are not extending it // only clear selection if we are not extending it
if (!extendSelection || !fSelectionRectEnabled || !fMultipleSelection) if (!extendSelection || !fSelectionRectEnabled || !fMultipleSelection)
ClearSelection(); ClearSelection();
// show desktop context menu
if (buttons == B_SECONDARY_MOUSE_BUTTON
|| (modifs & B_CONTROL_KEY) != 0) {
ShowContextMenu(where);
}
} }
if (fSelectionChangedHook) if (fSelectionChangedHook)
@@ -6874,6 +6860,26 @@ BPoseView::MouseUp(BPoint where)
BPose* pose = FindPose(where, &index); BPose* pose = FindPose(where, &index);
if (pose != NULL && fAllowPoseEditing) if (pose != NULL && fAllowPoseEditing)
pose->MouseUp(BPoint(0, index * fListElemHeight), this, where, index); pose->MouseUp(BPoint(0, index * fListElemHeight), this, where, index);
uint32 lastButtons = Window()->CurrentMessage()->FindInt32("last_buttons");
// this handy field has been added by the tracking filter.
// we need lastButtons for right button mouse-up tracking,
// because there's currently no way to know wich buttons were
// released in BView::MouseUp (unlike BView::KeyUp)
// Showing the pose context menu is done on mouse up (or long click)
// to make right button dragging possible
if (pose != NULL && pose == fLastClickedPose
&& (lastButtons == B_SECONDARY_MOUSE_BUTTON
|| (modifiers() & B_CONTROL_KEY) != 0)) {
if (!pose->IsSelected()) {
ClearSelection();
pose->Select(true);
fSelectionList->AddItem(pose);
DrawPose(pose, index, false);
}
ShowContextMenu(where);
}
} }