First steps at getting drag & drop to work properly. Simple drag & drop (draging Tracker items) should work now. Not sure about the negotiated version (with mimetype exchange). Fixed left behind drag bitmaps. Some cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2006-04-10 21:22:05 +00:00
parent a4237b2a8e
commit 39cdae74a7
7 changed files with 67 additions and 50 deletions
+9
View File
@@ -136,6 +136,15 @@ class BMessage::Private {
return fMessage->fHeader->target == B_PREFERRED_TOKEN; return fMessage->fHeader->target == B_PREFERRED_TOKEN;
} }
void
SetWasDropped(bool wasDropped)
{
if (wasDropped)
fMessage->fHeader->flags |= MESSAGE_FLAG_WAS_DROPPED;
else
fMessage->fHeader->flags &= ~MESSAGE_FLAG_WAS_DROPPED;
}
status_t status_t
Clear() Clear()
{ {
+8 -6
View File
@@ -1266,12 +1266,13 @@ BView::DragMessage(BMessage *message, BRect dragRect, BHandler *replyTo)
message->AddInt32("buttons", buttons); message->AddInt32("buttons", buttons);
} }
BMessage::Private(message).SetReply(BMessenger(replyTo, replyTo->Looper())); BMessage::Private privateMessage(message);
privateMessage.SetReply(BMessenger(replyTo, replyTo->Looper()));
int32 bufferSize = message->FlattenedSize(); int32 bufferSize = privateMessage.NativeFlattenedSize();
char* buffer = new (nothrow) char[bufferSize]; char* buffer = new (nothrow) char[bufferSize];
if (buffer) { if (buffer) {
message->Flatten(buffer, bufferSize); privateMessage.NativeFlatten(buffer, bufferSize);
fOwner->fLink->StartMessage(AS_LAYER_DRAG_RECT); fOwner->fLink->StartMessage(AS_LAYER_DRAG_RECT);
fOwner->fLink->Attach<BRect>(dragRect); fOwner->fLink->Attach<BRect>(dragRect);
@@ -1323,12 +1324,13 @@ BView::DragMessage(BMessage *message, BBitmap *image,
message->AddInt32("buttons", buttons); message->AddInt32("buttons", buttons);
} }
BMessage::Private(message).SetReply(BMessenger(replyTo, replyTo->Looper())); BMessage::Private privateMessage(message);
privateMessage.SetReply(BMessenger(replyTo, replyTo->Looper()));
int32 bufferSize = message->FlattenedSize(); int32 bufferSize = privateMessage.NativeFlattenedSize();
char* buffer = new (nothrow) char[bufferSize]; char* buffer = new (nothrow) char[bufferSize];
if (buffer) { if (buffer) {
message->Flatten(buffer, bufferSize); privateMessage.NativeFlatten(buffer, bufferSize);
fOwner->fLink->StartMessage(AS_LAYER_DRAG_IMAGE); fOwner->fLink->StartMessage(AS_LAYER_DRAG_IMAGE);
fOwner->fLink->Attach<int32>(image->_ServerToken()); fOwner->fLink->Attach<int32>(image->_ServerToken());
+18 -15
View File
@@ -897,42 +897,46 @@ FrameMoved(origin);
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
{ {
if (BView *view = dynamic_cast<BView *>(target)) {
BPoint where; BPoint where;
msg->FindPoint("be:view_where", &where); msg->FindPoint("be:view_where", &where);
if (BView *view = dynamic_cast<BView *>(target))
view->MouseDown(where); view->MouseDown(where);
else } else
target->MessageReceived(msg); target->MessageReceived(msg);
break; break;
} }
case B_MOUSE_UP: case B_MOUSE_UP:
{ {
if (BView *view = dynamic_cast<BView *>(target)) {
BPoint where; BPoint where;
msg->FindPoint("be:view_where", &where); msg->FindPoint("be:view_where", &where);
if (BView *view = dynamic_cast<BView *>(target))
view->MouseUp(where); view->MouseUp(where);
else } else
target->MessageReceived(msg); target->MessageReceived(msg);
break; break;
} }
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
{ {
if (BView *view = dynamic_cast<BView *>(target)) {
BPoint where; BPoint where;
uint32 buttons; uint32 buttons;
uint32 transit; uint32 transit;
msg->FindPoint("be:view_where", &where); msg->FindPoint("be:view_where", &where);
msg->FindInt32("buttons", (int32*)&buttons); msg->FindInt32("buttons", (int32*)&buttons);
msg->FindInt32("be:transit", (int32*)&transit); msg->FindInt32("be:transit", (int32*)&transit);
// bigtime_t when;
// if (msg->FindInt64("when", (int64*)&when) < B_OK) #if 0
// printf("BWindow B_MOUSE_MOVED no when\n"); bigtime_t when;
// else if (system_time() - when > 5000) { if (msg->FindInt64("when", (int64*)&when) < B_OK)
// printf("BWindow B_MOUSE_MOVED lagging behind\n"); printf("BWindow B_MOUSE_MOVED no when\n");
// } else if (system_time() - when > 5000)
printf("BWindow B_MOUSE_MOVED lagging behind\n");
#endif
BMessage* dragMessage = NULL; BMessage* dragMessage = NULL;
if (msg->HasMessage("be:drag_message")) { if (msg->HasMessage("be:drag_message")) {
dragMessage = new BMessage(); dragMessage = new BMessage();
@@ -942,12 +946,11 @@ FrameMoved(origin);
} }
} }
if (BView *view = dynamic_cast<BView *>(target))
view->MouseMoved(where, transit, dragMessage); view->MouseMoved(where, transit, dragMessage);
else delete dragMessage;
} else
target->MessageReceived(msg); target->MessageReceived(msg);
delete dragMessage;
break; break;
} }
+5 -4
View File
@@ -15,6 +15,7 @@
#include "InputManager.h" #include "InputManager.h"
#include "ServerBitmap.h" #include "ServerBitmap.h"
#include <MessagePrivate.h>
#include <TokenSpace.h> #include <TokenSpace.h>
#include <Autolock.h> #include <Autolock.h>
@@ -524,10 +525,9 @@ EventDispatcher::SetDragMessage(BMessage& message,
fHWInterface->SetDragBitmap(bitmap, offsetFromCursor); fHWInterface->SetDragBitmap(bitmap, offsetFromCursor);
BAutolock _(this);
fDragMessage = message; fDragMessage = message;
fDraggingMessage = true; fDraggingMessage = true;
fDragOffset = offsetFromCursor;
} }
@@ -630,12 +630,13 @@ EventDispatcher::_DeliverDragMessage()
ETRACE(("EventDispatcher::_DeliverDragMessage()\n")); ETRACE(("EventDispatcher::_DeliverDragMessage()\n"));
if (fDraggingMessage && fPreviousMouseTarget != NULL) { if (fDraggingMessage && fPreviousMouseTarget != NULL) {
BMessage::Private(fDragMessage).SetWasDropped(true);
fDragMessage.RemoveName("_original_what"); fDragMessage.RemoveName("_original_what");
fDragMessage.AddInt32("_original_what", fDragMessage.what); fDragMessage.AddInt32("_original_what", fDragMessage.what);
fDragMessage.AddPoint("_drop_point_", fLastCursorPosition);
fDragMessage.AddPoint("_drop_offset_", fDragOffset);
fDragMessage.what = _MESSAGE_DROPPED_; fDragMessage.what = _MESSAGE_DROPPED_;
// fDragMessage.AddBool("dropped", true);
//printf(" sending message to previous mouse target\n");
_SendMessage(fPreviousMouseTarget->Messenger(), _SendMessage(fPreviousMouseTarget->Messenger(),
&fDragMessage, 100.0); &fDragMessage, 100.0);
} }
+1
View File
@@ -139,6 +139,7 @@ class EventDispatcher : public BLocker {
BMessage fDragMessage; BMessage fDragMessage;
bool fDraggingMessage; bool fDraggingMessage;
BPoint fDragOffset;
ServerBitmap* fDragBitmap; ServerBitmap* fDragBitmap;
// NOTE: unfortunately, the EventDispatcher // NOTE: unfortunately, the EventDispatcher
// has to know what a ServerBitmap is... // has to know what a ServerBitmap is...
+1 -2
View File
@@ -1782,8 +1782,7 @@ ServerWindow::_DispatchViewMessage(int32 code,
if (link.Read(buffer, bufferSize) == B_OK if (link.Read(buffer, bufferSize) == B_OK
&& dragMessage.Unflatten(buffer) == B_OK) { && dragMessage.Unflatten(buffer) == B_OK) {
fDesktop->EventDispatcher().SetDragMessage(dragMessage, fDesktop->EventDispatcher().SetDragMessage(dragMessage,
NULL, // should be dragRect NULL /* should be dragRect */, offset);
offset);
} }
delete[] buffer; delete[] buffer;
} }
+3 -1
View File
@@ -637,7 +637,7 @@ HWInterface::_AdoptDragBitmap(const ServerBitmap* bitmap, const BPoint& offset)
} }
_RestoreCursorArea(); _RestoreCursorArea();
Invalidate(_CursorFrame()); BRect cursorFrame = _CursorFrame();
if (fCursorAndDragBitmap && fCursorAndDragBitmap != fCursor) { if (fCursorAndDragBitmap && fCursorAndDragBitmap != fCursor) {
delete fCursorAndDragBitmap; delete fCursorAndDragBitmap;
@@ -764,6 +764,8 @@ HWInterface::_AdoptDragBitmap(const ServerBitmap* bitmap, const BPoint& offset)
fCursorAndDragBitmap = fCursor; fCursorAndDragBitmap = fCursor;
} }
Invalidate(cursorFrame);
// NOTE: the EventDispatcher does the reference counting stuff for us // NOTE: the EventDispatcher does the reference counting stuff for us
// TODO: You can not simply call Release() on a ServerBitmap like you // TODO: You can not simply call Release() on a ServerBitmap like you
// can for a ServerCursor... it could be changed, but there are linking // can for a ServerCursor... it could be changed, but there are linking