J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2007 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package sun.awt.windows; |
| 27 | |
| 28 | import java.awt.Component; |
| 29 | import java.awt.Cursor; |
| 30 | |
| 31 | import java.awt.datatransfer.Transferable; |
| 32 | |
| 33 | import java.awt.dnd.DragGestureEvent; |
| 34 | import java.awt.dnd.InvalidDnDOperationException; |
| 35 | |
| 36 | import java.awt.event.InputEvent; |
| 37 | |
| 38 | import java.util.Map; |
| 39 | |
| 40 | import sun.awt.dnd.SunDragSourceContextPeer; |
| 41 | |
| 42 | /** |
| 43 | * <p> |
| 44 | * TBC |
| 45 | * </p> |
| 46 | * |
| 47 | * @since JDK1.2 |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | final class WDragSourceContextPeer extends SunDragSourceContextPeer { |
| 52 | public void startSecondaryEventLoop(){ |
| 53 | WToolkit.startSecondaryEventLoop(); |
| 54 | } |
| 55 | public void quitSecondaryEventLoop(){ |
| 56 | WToolkit.quitSecondaryEventLoop(); |
| 57 | } |
| 58 | |
| 59 | private static final WDragSourceContextPeer theInstance = |
| 60 | new WDragSourceContextPeer(null); |
| 61 | |
| 62 | /** |
| 63 | * construct a new WDragSourceContextPeer. package private |
| 64 | */ |
| 65 | |
| 66 | private WDragSourceContextPeer(DragGestureEvent dge) { |
| 67 | super(dge); |
| 68 | } |
| 69 | |
| 70 | static WDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { |
| 71 | theInstance.setTrigger(dge); |
| 72 | return theInstance; |
| 73 | } |
| 74 | |
| 75 | protected void startDrag(Transferable trans, |
| 76 | long[] formats, Map formatMap) { |
| 77 | |
| 78 | long nativeCtxtLocal = 0; |
| 79 | |
| 80 | nativeCtxtLocal = createDragSource(getTrigger().getComponent(), |
| 81 | trans, |
| 82 | getTrigger().getTriggerEvent(), |
| 83 | getTrigger().getSourceAsDragGestureRecognizer().getSourceActions(), |
| 84 | formats, |
| 85 | formatMap); |
| 86 | |
| 87 | if (nativeCtxtLocal == 0) { |
| 88 | throw new InvalidDnDOperationException("failed to create native peer"); |
| 89 | } |
| 90 | |
| 91 | setNativeContext(nativeCtxtLocal); |
| 92 | |
| 93 | WDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(trans); |
| 94 | |
| 95 | doDragDrop(getNativeContext(), getCursor()); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * downcall into native code |
| 100 | */ |
| 101 | |
| 102 | native long createDragSource(Component component, |
| 103 | Transferable transferable, |
| 104 | InputEvent nativeTrigger, |
| 105 | int actions, |
| 106 | long[] formats, |
| 107 | Map formatMap); |
| 108 | |
| 109 | /** |
| 110 | * downcall into native code |
| 111 | */ |
| 112 | |
| 113 | native void doDragDrop(long nativeCtxt, Cursor cursor); |
| 114 | |
| 115 | protected native void setNativeCursor(long nativeCtxt, Cursor c, int cType); |
| 116 | |
| 117 | } |