1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
415 fDragImage = [[NSImage alloc] initWithSize:NSMakeSize(21, 21)];
416 NSSize imageSize = [fDragImage size];
417
418 NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
419 pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4
420 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:32];
421
422 [fDragImage addRepresentation:imageRep];
423 fDragImageOffset = NSMakePoint(0, 0);
424
425 [imageRep release];
426 }
427 }
428
429 - (NSEvent*)nsDragEvent:(BOOL)isDrag
430 {
431 // Get NSView for the drag source:
432 NSWindow* window = [fView window];
433
434 NSInteger windowNumber = [window windowNumber];
435 NSGraphicsContext* graphicsContext = [NSGraphicsContext graphicsContextWithWindow:window];
436
437 // Convert mouse coordinates to NS:
438 NSPoint eventLocation = [fView convertPoint:NSMakePoint(fDragPos.x, fDragPos.y) toView:nil];
439 eventLocation.y = [[fView window] frame].size.height - eventLocation.y;
440
441 // Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000):
442 NSTimeInterval timeStamp = fTriggerEventTimeStamp / 1000;
443
444 // Convert fModifiers (extModifiers) to NS:
445 NSEventType mouseButtons = 0;
446 float pressure = 0.0;
447 if (isDrag) {
448 mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseDownButtons:fModifiers];
449 pressure = 1.0;
450 } else {
451 mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseUpButtons:fModifiers];
452 }
453
454 // Convert fModifiers (extModifiers) to NS:
455 NSUInteger modifiers = JavaModifiersToNsKeyModifiers(fModifiers, TRUE);
456
457 // Just a dummy value ...
458 NSInteger eventNumber = 0;
459
460 // Make a native autoreleased dragging event:
461 NSEvent* dragEvent = [NSEvent mouseEventWithType:mouseButtons location:eventLocation
462 modifierFlags:modifiers timestamp:timeStamp windowNumber:windowNumber context:graphicsContext
463 eventNumber:eventNumber clickCount:fClickCount pressure:pressure];
464
465 return dragEvent;
466 }
467
468 - (void)doDrag
469 {
470 AWT_ASSERT_APPKIT_THREAD;
471
472 DLog2(@"[CDragSource doDrag]: %@\n", self);
473
474 // Set up Java environment:
475 JNIEnv *env = [ThreadUtilities getJNIEnv];
476
477 // Set up the pasteboard:
478 NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
479 [self declareTypesToPasteboard:pb withEnv:env];
480
481 // Make a native autoreleased NS dragging event:
482 NSEvent *dragEvent = [self nsDragEvent:YES];
|
1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
415 fDragImage = [[NSImage alloc] initWithSize:NSMakeSize(21, 21)];
416 NSSize imageSize = [fDragImage size];
417
418 NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
419 pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4
420 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:32];
421
422 [fDragImage addRepresentation:imageRep];
423 fDragImageOffset = NSMakePoint(0, 0);
424
425 [imageRep release];
426 }
427 }
428
429 - (NSEvent*)nsDragEvent:(BOOL)isDrag
430 {
431 // Get NSView for the drag source:
432 NSWindow* window = [fView window];
433
434 NSInteger windowNumber = [window windowNumber];
435
436 // Convert mouse coordinates to NS:
437 NSPoint eventLocation = [fView convertPoint:NSMakePoint(fDragPos.x, fDragPos.y) toView:nil];
438 eventLocation.y = [[fView window] frame].size.height - eventLocation.y;
439
440 // Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000):
441 NSTimeInterval timeStamp = fTriggerEventTimeStamp / 1000;
442
443 // Convert fModifiers (extModifiers) to NS:
444 NSEventType mouseButtons = 0;
445 float pressure = 0.0;
446 if (isDrag) {
447 mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseDownButtons:fModifiers];
448 pressure = 1.0;
449 } else {
450 mouseButtons = (NSEventType) [DnDUtilities mapJavaExtModifiersToNSMouseUpButtons:fModifiers];
451 }
452
453 // Convert fModifiers (extModifiers) to NS:
454 NSUInteger modifiers = JavaModifiersToNsKeyModifiers(fModifiers, TRUE);
455
456 // Just a dummy value ...
457 NSInteger eventNumber = 0;
458 // NSEvent.context is deprecated and unused
459 NSGraphicsContext* unusedPassNil = nil;
460
461 // Make a native autoreleased dragging event:
462 NSEvent* dragEvent = [NSEvent mouseEventWithType:mouseButtons location:eventLocation
463 modifierFlags:modifiers timestamp:timeStamp windowNumber:windowNumber context:unusedPassNil
464 eventNumber:eventNumber clickCount:fClickCount pressure:pressure];
465
466 return dragEvent;
467 }
468
469 - (void)doDrag
470 {
471 AWT_ASSERT_APPKIT_THREAD;
472
473 DLog2(@"[CDragSource doDrag]: %@\n", self);
474
475 // Set up Java environment:
476 JNIEnv *env = [ThreadUtilities getJNIEnv];
477
478 // Set up the pasteboard:
479 NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
480 [self declareTypesToPasteboard:pb withEnv:env];
481
482 // Make a native autoreleased NS dragging event:
483 NSEvent *dragEvent = [self nsDragEvent:YES];
|