blob: db4078b8da87c5e929d85e54f51b4766349df1e3 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 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
26package sun.awt.motif;
27
28import java.awt.Component;
29import java.awt.Cursor;
30import java.awt.Window;
31
32import java.awt.datatransfer.Transferable;
33
34import java.awt.dnd.DragSourceContext;
35import java.awt.dnd.DragSourceDragEvent;
36import java.awt.dnd.DragSourceDropEvent;
37import java.awt.dnd.DragSourceEvent;
38import java.awt.dnd.DragGestureEvent;
39import java.awt.dnd.InvalidDnDOperationException;
40
41import java.awt.event.InputEvent;
42
43import java.util.Map;
44
45import sun.awt.SunToolkit;
46
47import sun.awt.dnd.SunDragSourceContextPeer;
48import sun.awt.dnd.SunDropTargetContextPeer;
49
50/**
51 * The X11DragSourceContextPeer class is the class responsible for handling
52 * the interaction between the XDnD/Motif DnD subsystem and Java drag sources.
53 *
54 * @since 1.5
55 */
56final class X11DragSourceContextPeer extends SunDragSourceContextPeer {
57
58 private static final X11DragSourceContextPeer theInstance =
59 new X11DragSourceContextPeer(null);
60
61 /**
62 * construct a new X11DragSourceContextPeer
63 */
64
65 private X11DragSourceContextPeer(DragGestureEvent dge) {
66 super(dge);
67 }
68
69 static X11DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
70 theInstance.setTrigger(dge);
71 return theInstance;
72 }
73
74 protected void startDrag(Transferable transferable,
75 long[] formats, Map formatMap) {
76 Component component = getTrigger().getComponent();
77 Component c = null;
78 MWindowPeer wpeer = null;
79
80 for (c = component; c != null && !(c instanceof java.awt.Window);
81 c = MComponentPeer.getParent_NoClientCode(c));
82
83 if (c instanceof Window) {
84 wpeer = (MWindowPeer)c.getPeer();
85 }
86
87 if (wpeer == null) {
88 throw new InvalidDnDOperationException(
89 "Cannot find top-level for the drag source component");
90 }
91
92 startDrag(component,
93 wpeer,
94 transferable,
95 getTrigger().getTriggerEvent(),
96 getCursor(),
97 getCursor() == null ? 0 : getCursor().getType(),
98 getDragSourceContext().getSourceActions(),
99 formats,
100 formatMap);
101
102 /* This implementation doesn't use native context */
103 setNativeContext(0);
104
105 SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
106 }
107
108 /**
109 * downcall into native code
110 */
111
112 private native long startDrag(Component component,
113 MWindowPeer wpeer,
114 Transferable transferable,
115 InputEvent nativeTrigger,
116 Cursor c, int ctype, int actions,
117 long[] formats, Map formatMap);
118
119 /**
120 * set cursor
121 */
122
123 public void setCursor(Cursor c) throws InvalidDnDOperationException {
124 SunToolkit.awtLock();
125 super.setCursor(c);
126 SunToolkit.awtUnlock();
127 }
128
129 protected native void setNativeCursor(long nativeCtxt, Cursor c, int cType);
130
131}