src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java

Print this page




 124             if (fDragCImage == null) {
 125                 throw new InvalidDnDOperationException("Drag image is not ready.");
 126             }
 127 
 128             dragImageOffset = fDragImageOffset;
 129         } else {
 130 
 131             fDragCImage = null;
 132             dragImageOffset = new Point(0, 0);
 133         }
 134 
 135         try {
 136             //It sure will be LWComponentPeer instance as rootComponent is a Window
 137             PlatformWindow platformWindow = ((LWComponentPeer)rootComponent.getPeer()).getPlatformWindow();
 138             long nativeViewPtr = CPlatformWindow.getNativeViewPtr(platformWindow);
 139             if (nativeViewPtr == 0L) throw new InvalidDnDOperationException("Unsupported platform window implementation");
 140 
 141             // Create native dragging source:
 142             final long nativeDragSource = createNativeDragSource(component, nativeViewPtr, transferable, triggerEvent,
 143                 (int) (dragOrigin.getX()), (int) (dragOrigin.getY()), extModifiers,
 144                 clickCount, timestamp, fDragCImage, dragImageOffset.x, dragImageOffset.y,
 145                 getDragSourceContext().getSourceActions(), formats, formatMap);
 146 
 147             if (nativeDragSource == 0)
 148                 throw new InvalidDnDOperationException("");
 149 
 150             setNativeContext(nativeDragSource);
 151         }
 152 
 153         catch (Exception e) {
 154             throw new InvalidDnDOperationException("failed to create native peer: " + e);
 155         }
 156 
 157         SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
 158 
 159         CCursorManager.getInstance().setCursor(getCursor());
 160 
 161         // Create a new thread to run the dragging operation since it's synchronous, only coming back
 162         // after dragging is finished. This leaves the AWT event thread free to handle AWT events which
 163         // are posted during dragging by native event handlers.
 164 


 467         }
 468 
 469         return null;
 470     }
 471 
 472     /**
 473      * upcall from native code - reset hovering component
 474      */
 475     private void resetHovering() {
 476         hoveringComponent = null;
 477     }
 478 
 479     @Override
 480     protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
 481         CCursorManager.getInstance().setCursor(c);
 482     }
 483 
 484     // Native support:
 485     private native long createNativeDragSource(Component component, long nativePeer, Transferable transferable,
 486         InputEvent triggerEvent, int dragPosX, int dragPosY, int extModifiers, int clickCount, long timestamp,
 487         CImage nsDragImage, int dragImageOffsetX, int dragImageOffsetY,
 488         int sourceActions, long[] formats, Map formatMap);
 489 
 490     private native void doDragging(long nativeDragSource);
 491 
 492     private native void releaseNativeDragSource(long nativeDragSource);
 493 }


 124             if (fDragCImage == null) {
 125                 throw new InvalidDnDOperationException("Drag image is not ready.");
 126             }
 127 
 128             dragImageOffset = fDragImageOffset;
 129         } else {
 130 
 131             fDragCImage = null;
 132             dragImageOffset = new Point(0, 0);
 133         }
 134 
 135         try {
 136             //It sure will be LWComponentPeer instance as rootComponent is a Window
 137             PlatformWindow platformWindow = ((LWComponentPeer)rootComponent.getPeer()).getPlatformWindow();
 138             long nativeViewPtr = CPlatformWindow.getNativeViewPtr(platformWindow);
 139             if (nativeViewPtr == 0L) throw new InvalidDnDOperationException("Unsupported platform window implementation");
 140 
 141             // Create native dragging source:
 142             final long nativeDragSource = createNativeDragSource(component, nativeViewPtr, transferable, triggerEvent,
 143                 (int) (dragOrigin.getX()), (int) (dragOrigin.getY()), extModifiers,
 144                 clickCount, timestamp, fDragCImage != null ? fDragCImage.ptr : 0L, dragImageOffset.x, dragImageOffset.y,
 145                 getDragSourceContext().getSourceActions(), formats, formatMap);
 146 
 147             if (nativeDragSource == 0)
 148                 throw new InvalidDnDOperationException("");
 149 
 150             setNativeContext(nativeDragSource);
 151         }
 152 
 153         catch (Exception e) {
 154             throw new InvalidDnDOperationException("failed to create native peer: " + e);
 155         }
 156 
 157         SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
 158 
 159         CCursorManager.getInstance().setCursor(getCursor());
 160 
 161         // Create a new thread to run the dragging operation since it's synchronous, only coming back
 162         // after dragging is finished. This leaves the AWT event thread free to handle AWT events which
 163         // are posted during dragging by native event handlers.
 164 


 467         }
 468 
 469         return null;
 470     }
 471 
 472     /**
 473      * upcall from native code - reset hovering component
 474      */
 475     private void resetHovering() {
 476         hoveringComponent = null;
 477     }
 478 
 479     @Override
 480     protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
 481         CCursorManager.getInstance().setCursor(c);
 482     }
 483 
 484     // Native support:
 485     private native long createNativeDragSource(Component component, long nativePeer, Transferable transferable,
 486         InputEvent triggerEvent, int dragPosX, int dragPosY, int extModifiers, int clickCount, long timestamp,
 487         long nsDragImagePtr, int dragImageOffsetX, int dragImageOffsetY,
 488         int sourceActions, long[] formats, Map formatMap);
 489 
 490     private native void doDragging(long nativeDragSource);
 491 
 492     private native void releaseNativeDragSource(long nativeDragSource);
 493 }