src/macosx/native/sun/awt/CDropTarget.m

Print this page




 473     if (sDraggingError == FALSE) {
 474         sDraggingExited = FALSE;
 475         sDraggingLocation = [sender draggingLocation];
 476         NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
 477         DLog5(@"+ dragEnter: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y);
 478 
 479                 ////////// BEGIN Calculate the current drag actions //////////
 480                 jint actions = java_awt_dnd_DnDConstants_ACTION_NONE;
 481         jint dropAction = actions;
 482 
 483                 [self calculateCurrentSourceActions:&actions dropAction:&dropAction];
 484 
 485                 sJavaDropOperation = dropAction;
 486                 ////////// END Calculate the current drag actions //////////
 487 
 488         jlongArray formats = sDraggingFormats;
 489 
 490         JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
 491         if (sDraggingError == FALSE) {
 492             // Double-casting self gets rid of 'different size' compiler warning:
 493             actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)


 494         }
 495 
 496         if (sDraggingError == FALSE) {
 497             // Initialize drag operation:
 498             sDragOperation = NSDragOperationNone;
 499 
 500             // Map Java actions back to NSDragOperation.
 501             // 1-6-03 Note: if the entry point of this CDropTarget isn't covered by a droppable component
 502             // (as can be the case with lightweight children) we must not return NSDragOperationNone
 503             // since that would prevent dropping into any of the contained drop targets.
 504             // Unfortunately there is no easy way to test this so we just test actions and override them
 505             // with GENERIC if necessary. Proper drag operations will be returned by draggingUpdated: which is
 506             // called right away, taking care of setting the right cursor and snap-back action.
 507             dragOp = ((actions != java_awt_dnd_DnDConstants_ACTION_NONE) ?
 508                 [DnDUtilities mapJavaDragOperationToNS:dropAction] : NSDragOperationGeneric);
 509 
 510             // Remember the dragOp for no-op'd update messages:
 511             sUpdateOperation = dragOp;
 512         }
 513 
 514         // If we are in the same process as the sender, make the sender post the appropriate message
 515         if (sender) {
 516             [[CDragSource currentDragSource] postDragEnter];
 517         }
 518     }
 519 
 520     // 9-11-02 Note: the native event thread would not handle an exception gracefully:
 521     //if (sDraggingError == TRUE)
 522     //    [NSException raise:NSGenericException format:@"[CDropTarget draggingEntered] failed."];
 523 
 524     DLog2(@"[CDropTarget draggingEntered]: returning %lu\n", (unsigned long) dragOp);
 525 
 526     return dragOp;
 527 }
 528 
 529 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
 530 {
 531     //DLog2(@"[CDropTarget draggingUpdated]: %@\n", self);
 532 
 533     sCurrentDropTarget = self;
 534 
 535     // Set the initial drag operation return value:
 536     NSDragOperation dragOp = (sDraggingError == FALSE ? sUpdateOperation : NSDragOperationNone);
 537 


 591         }
 592     }
 593 
 594     DLog2(@"[CDropTarget draggingUpdated]: returning %lu\n", (unsigned long) dragOp);
 595 
 596     return dragOp;
 597 }
 598 
 599 - (void)draggingExited:(id<NSDraggingInfo>)sender
 600 {
 601     DLog2(@"[CDropTarget draggingExited]: %@\n", self);
 602 
 603     sCurrentDropTarget = nil;
 604 
 605     JNIEnv* env = [ThreadUtilities getJNIEnv];
 606 
 607     if (sDraggingExited == FALSE && sDraggingError == FALSE) {
 608         JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
 609         if (sDraggingError == FALSE) {
 610             DLog3(@"  - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y);
 611             JNFCallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
 612             // If we are in the same process as the sender, make the sender post the appropriate message
 613             if (sender) {
 614                 [[CDragSource currentDragSource] postDragExit];
 615             }
 616         }
 617 
 618         // 5-27-03 Note: [Radar 3270455]
 619         // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute
 620         // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs.
 621         sDraggingExited = TRUE;
 622     }
 623 
 624     DLog(@"[CDropTarget draggingExited]: returning.\n");
 625 }
 626 
 627 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
 628 {
 629     DLog2(@"[CDropTarget prepareForDragOperation]: %@\n", self);
 630     DLog2(@"[CDropTarget prepareForDragOperation]: returning %@\n", (sDraggingError ? @"NO" : @"YES"));
 631 
 632     return sDraggingError ? NO : YES;
 633 }
 634 
 635 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender




 473     if (sDraggingError == FALSE) {
 474         sDraggingExited = FALSE;
 475         sDraggingLocation = [sender draggingLocation];
 476         NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
 477         DLog5(@"+ dragEnter: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y);
 478 
 479                 ////////// BEGIN Calculate the current drag actions //////////
 480                 jint actions = java_awt_dnd_DnDConstants_ACTION_NONE;
 481         jint dropAction = actions;
 482 
 483                 [self calculateCurrentSourceActions:&actions dropAction:&dropAction];
 484 
 485                 sJavaDropOperation = dropAction;
 486                 ////////// END Calculate the current drag actions //////////
 487 
 488         jlongArray formats = sDraggingFormats;
 489 
 490         JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
 491         if (sDraggingError == FALSE) {
 492             // Double-casting self gets rid of 'different size' compiler warning:
 493             actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod,
 494                                        fComponent, (jint) javaLocation.x, (jint) javaLocation.y,
 495                                        dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
 496         }
 497 
 498         if (sDraggingError == FALSE) {
 499             // Initialize drag operation:
 500             sDragOperation = NSDragOperationNone;
 501 
 502             // Map Java actions back to NSDragOperation.
 503             // 1-6-03 Note: if the entry point of this CDropTarget isn't covered by a droppable component
 504             // (as can be the case with lightweight children) we must not return NSDragOperationNone
 505             // since that would prevent dropping into any of the contained drop targets.
 506             // Unfortunately there is no easy way to test this so we just test actions and override them
 507             // with GENERIC if necessary. Proper drag operations will be returned by draggingUpdated: which is
 508             // called right away, taking care of setting the right cursor and snap-back action.
 509             dragOp = ((actions != java_awt_dnd_DnDConstants_ACTION_NONE) ?
 510                 [DnDUtilities mapJavaDragOperationToNS:dropAction] : NSDragOperationGeneric);
 511 
 512             // Remember the dragOp for no-op'd update messages:
 513             sUpdateOperation = dragOp;
 514         }





 515     }
 516 
 517     // 9-11-02 Note: the native event thread would not handle an exception gracefully:
 518     //if (sDraggingError == TRUE)
 519     //    [NSException raise:NSGenericException format:@"[CDropTarget draggingEntered] failed."];
 520 
 521     DLog2(@"[CDropTarget draggingEntered]: returning %lu\n", (unsigned long) dragOp);
 522 
 523     return dragOp;
 524 }
 525 
 526 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
 527 {
 528     //DLog2(@"[CDropTarget draggingUpdated]: %@\n", self);
 529 
 530     sCurrentDropTarget = self;
 531 
 532     // Set the initial drag operation return value:
 533     NSDragOperation dragOp = (sDraggingError == FALSE ? sUpdateOperation : NSDragOperationNone);
 534 


 588         }
 589     }
 590 
 591     DLog2(@"[CDropTarget draggingUpdated]: returning %lu\n", (unsigned long) dragOp);
 592 
 593     return dragOp;
 594 }
 595 
 596 - (void)draggingExited:(id<NSDraggingInfo>)sender
 597 {
 598     DLog2(@"[CDropTarget draggingExited]: %@\n", self);
 599 
 600     sCurrentDropTarget = nil;
 601 
 602     JNIEnv* env = [ThreadUtilities getJNIEnv];
 603 
 604     if (sDraggingExited == FALSE && sDraggingError == FALSE) {
 605         JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
 606         if (sDraggingError == FALSE) {
 607             DLog3(@"  - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y);
 608              // AWT_THREADING Safe (CToolkitThreadBlockedHandler) 
 609             JNFCallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self));



 610         }
 611 
 612         // 5-27-03 Note: [Radar 3270455]
 613         // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute
 614         // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs.
 615         sDraggingExited = TRUE;
 616     }
 617 
 618     DLog(@"[CDropTarget draggingExited]: returning.\n");
 619 }
 620 
 621 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
 622 {
 623     DLog2(@"[CDropTarget prepareForDragOperation]: %@\n", self);
 624     DLog2(@"[CDropTarget prepareForDragOperation]: returning %@\n", (sDraggingError ? @"NO" : @"YES"));
 625 
 626     return sDraggingError ? NO : YES;
 627 }
 628 
 629 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender