4632N/A#import <Cocoa/Cocoa.h>
4632N/A// When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized.
4632N/A// We must stop posting MouseEvent.MOUSE_DRAGGED events for the duration of the drag or all hell will break
4632N/A+ (void)javaDraggingBegin;
4632N/A+ (void)javaDraggingEnd;
4632N/A+ (void)javaDraggingBegin
4632N/A+ (void)javaDraggingEnd
4632N/A return sCurrentDragSource;
4632N/A- (id)init:(jobject)jdragsourcecontextpeer component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control
4632N/A dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount
5037N/A dragImage:(jobject)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety
4632N/A sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap
5037N/A if (jnsdragimage) {
4632N/A// * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
4632N/A JNF_STATIC_MEMBER_CACHE(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;");
4632N/A// * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
4632N/A JNF_MEMBER_CACHE(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B");
4632N/A data = JNFCallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE);
4632N/A// Encodes a byte array of zero-terminated filenames into an NSArray of NSStrings representing them.
4632N/A // This is to be able to drop transferables containing only a serialized object flavor, e.g.:
4632N/A // "JAVA_DATAFLAVOR:application/x-java-serialized-object; class=java.awt.Label".
4632N/A hasNSTypeData = true;
4632N/A // When TransferHandler is used with Swing components it puts only a type like this on the pasteboard:
4632N/A // "JAVA_DATAFLAVOR:application/x-java-jvm-local-objectref; class=java.lang.String"
4632N/A // Since our drop targets aren't trained for arbitrary data types yet we need to fake an empty string
4632N/A // KCH - 3550405 If the drag is between Swing components, formatsLength == 0, so expand the check.
4632N/A // Also, use a custom format rather than NSString, since that will prevent random views from accepting the drag
4632N/A // If I provide the filenames _right now_, NSFilenamesPboardType is properly converted to CoreDrag flavors
4632N/A// This is an NSPasteboard callback. In declareTypesToPasteboard:withEnv:, we only declared the types
4632N/A// Note that if the transfer is handled entirely from Swing (as in a local-vm drag), this method may never be called.
4632N/A- (void)validateDragImage
4632N/A hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:32];
6099N/A NSPoint eventLocation = [fView convertPoint:NSMakePoint(fDragPos.x, fDragPos.y) toView:nil];
4632N/A // Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000):
4632N/A mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseDownButtons:fModifiers];
4632N/A mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseUpButtons:fModifiers];
4632N/A modifierFlags:modifiers timestamp:timeStamp windowNumber:windowNumber context:graphicsContext
4632N/A DLog5(@" - drag image: %f, %f (%f x %f)", fDragImageOffset.x, fDragImageOffset.y, [dragImage size].width, [dragImage size].height);
4632N/A DLog3(@" - event point (window) %f, %f", [dragEvent locationInWindow].x, [dragEvent locationInWindow].y);
4632N/A // Set up the fDragMouseModifier, so we can |= it later (since CoreDrag doesn't tell us mouse states during a drag)
4632N/A fDragKeyModifiers = [DnDUtilities extractJavaExtKeyModifiersFromJavaExtModifiers:fModifiers];
4632N/A fDragMouseModifiers = [DnDUtilities extractJavaExtMouseModifiersFromJavaExtModifiers:fModifiers];
4632N/A [view dragImage:dragImage at:dragOrigin offset:dragOffset event:dragEvent pasteboard:pb source:view slideBack:YES];
4632N/A NSRect fileLocationRect = NSMakeRect(0, 0, 0, 0); // This should be set based on the filename.
4632N/A BOOL success = [view dragFile:fileName fromRect:fileLocationRect slideBack:YES event:dragEvent];
4632N/A NSRect fileLocationRect = NSMakeRect(0, 0, 0, 0); // This should be set based on all filenames.
4632N/A BOOL success = [view dragPromisedFilesOfTypes:fileTypesArray fromRect:fileLocationRect source:view slideBack:YES event:dragEvent];
4632N/A // We have a problem here... we don't send DragSource dragEnter/Exit messages outside of our own process
4632N/A // This means that if you drag outside of the app and drop, even if it's valid, a dragDropFinished is posted without dragEnter
4632N/A // I'm worried that this might confuse Java, so we're going to send a "bogus" dragEnter if necessary (only if the drag succeeded)
4632N/A JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
4639N/A JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
4632N/A // We have to do this, otherwise AppKit doesn't know we're finished dragging. Yup, it's that bad.
4632N/A [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread)
4632N/A/******************************** BEGIN NSDraggingSource Interface ********************************/
4632N/A if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
4632N/A jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp];
4632N/A JNF_MEMBER_CACHE(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V");
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
4632N/A DLog4(@"[CDragSource draggedImage beganAt]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
4632N/A- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation {
4632N/A DLog4(@"[CDragSource draggedImage endedAt:]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
4632N/A //DLog4(@"[CDragSource draggedImage moved]: (%d, %d) %@\n", (int) screenPoint.x, (int) screenPoint.y, self);
4632N/A NSDragOperation currentOp = [DnDUtilities nsDragOperationForModifiers:[NSEvent modifierFlags]];
4632N/A NSDragOperation allowedOp = [DnDUtilities mapJavaDragOperationToNS:fSourceActions] & currentOp;
4632N/A if (notifyJava) {
4632N/A if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
4632N/A DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
4632N/A JNF_MEMBER_CACHE(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
4632N/A/******************************** END NSDraggingSource Interface ********************************/
4632N/A- (void) postDragEnter {
4632N/A if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions];
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
4632N/A- (void) postDragExit {
4632N/A JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)