jdk/src/macosx/native/sun/awt/CDropTarget.m
changeset 16710 f041f82cdeac
parent 15985 b9e25a486549
child 20446 2452a42716c8
equal deleted inserted replaced
16709:ee3542d637fe 16710:f041f82cdeac
    79     if (control != nil) {
    79     if (control != nil) {
    80         JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
    80         JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
    81         fComponent = JNFNewGlobalRef(env, jcomponent);
    81         fComponent = JNFNewGlobalRef(env, jcomponent);
    82         fDropTarget = JNFNewGlobalRef(env, jdropTarget);
    82         fDropTarget = JNFNewGlobalRef(env, jdropTarget);
    83 
    83 
    84         AWTView *awtView = [((NSWindow *) control) contentView];
    84         fView = [((AWTView *) control) retain];
    85         fView = [awtView retain];
    85         [fView setDropTarget:self];
    86         [awtView setDropTarget:self];
       
    87 
    86 
    88 
    87 
    89     } else {
    88     } else {
    90         // This would be an error.
    89         // This would be an error.
    91         [self release];
    90         [self release];
   175 
   174 
   176 - (void)dealloc
   175 - (void)dealloc
   177 {
   176 {
   178     DLog2(@"[CDropTarget dealloc]: %@\n", self);
   177     DLog2(@"[CDropTarget dealloc]: %@\n", self);
   179 
   178 
       
   179     if(sCurrentDropTarget == self) {
       
   180         sCurrentDropTarget = nil;
       
   181     }
       
   182 
   180     [fView release];
   183     [fView release];
   181     fView = nil;
   184     fView = nil;
   182 
   185 
   183     [super dealloc];
   186     [super dealloc];
   184 }
   187 }
   488         jlongArray formats = sDraggingFormats;
   491         jlongArray formats = sDraggingFormats;
   489 
   492 
   490         JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
   493         JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
   491         if (sDraggingError == FALSE) {
   494         if (sDraggingError == FALSE) {
   492             // Double-casting self gets rid of 'different size' compiler warning:
   495             // 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)
   496             // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
       
   497             actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod,
       
   498                                        fComponent, (jint) javaLocation.x, (jint) javaLocation.y,
       
   499                                        dropAction, actions, formats, ptr_to_jlong(self));
   494         }
   500         }
   495 
   501 
   496         if (sDraggingError == FALSE) {
   502         if (sDraggingError == FALSE) {
   497             // Initialize drag operation:
   503             // Initialize drag operation:
   498             sDragOperation = NSDragOperationNone;
   504             sDragOperation = NSDragOperationNone;
   508                 [DnDUtilities mapJavaDragOperationToNS:dropAction] : NSDragOperationGeneric);
   514                 [DnDUtilities mapJavaDragOperationToNS:dropAction] : NSDragOperationGeneric);
   509 
   515 
   510             // Remember the dragOp for no-op'd update messages:
   516             // Remember the dragOp for no-op'd update messages:
   511             sUpdateOperation = dragOp;
   517             sUpdateOperation = dragOp;
   512         }
   518         }
   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     }
   519 
   520 
   520     // 9-11-02 Note: the native event thread would not handle an exception gracefully:
   521     // 9-11-02 Note: the native event thread would not handle an exception gracefully:
   521     //if (sDraggingError == TRUE)
   522     //if (sDraggingError == TRUE)
   522     //    [NSException raise:NSGenericException format:@"[CDropTarget draggingEntered] failed."];
   523     //    [NSException raise:NSGenericException format:@"[CDropTarget draggingEntered] failed."];
   606 
   607 
   607     if (sDraggingExited == FALSE && sDraggingError == FALSE) {
   608     if (sDraggingExited == FALSE && sDraggingError == FALSE) {
   608         JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
   609         JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
   609         if (sDraggingError == FALSE) {
   610         if (sDraggingError == FALSE) {
   610             DLog3(@"  - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y);
   611             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              // AWT_THREADING Safe (CToolkitThreadBlockedHandler) 
   612             // If we are in the same process as the sender, make the sender post the appropriate message
   613             JNFCallVoidMethod(env, fDropTargetContextPeer,
   613             if (sender) {
   614                               handleExitMessageMethod, fComponent, ptr_to_jlong(self));
   614                 [[CDragSource currentDragSource] postDragExit];
       
   615             }
       
   616         }
   615         }
   617 
   616 
   618         // 5-27-03 Note: [Radar 3270455]
   617         // 5-27-03 Note: [Radar 3270455]
   619         // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute
   618         // -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.
   619         // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs.