Mercurial > projects > dwt-mac
annotate dwt/dnd/DropTarget.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | a9ab4c738ed8 |
children | d32621bf0f90 |
rev | line source |
---|---|
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
45 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
7 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
10 *******************************************************************************/ |
45 | 11 module dwt.dnd.DropTarget; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
12 |
45 | 13 import dwt.dwthelper.utils; |
14 | |
15 import java.util.ArrayList; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
16 |
45 | 17 import dwt.DWT; |
18 import dwt.DWTError; | |
19 import dwt.DWTException; | |
20 import dwt.internal.Callback; | |
21 import dwt.internal.cocoa.NSApplication; | |
22 import dwt.internal.cocoa.NSArray; | |
23 import dwt.internal.cocoa.NSCursor; | |
24 import dwt.internal.cocoa.NSEvent; | |
25 import dwt.internal.cocoa.NSMutableArray; | |
26 import dwt.internal.cocoa.NSObject; | |
27 import dwt.internal.cocoa.NSPasteboard; | |
28 import dwt.internal.cocoa.NSPoint; | |
29 import dwt.internal.cocoa.NSRect; | |
30 import dwt.internal.cocoa.NSScreen; | |
31 import dwt.internal.cocoa.NSString; | |
32 import dwt.internal.cocoa.NSURL; | |
33 import dwt.internal.cocoa.OS; | |
34 import dwt.internal.cocoa.id; | |
35 import dwt.widgets.Control; | |
36 import dwt.widgets.Display; | |
37 import dwt.widgets.Event; | |
38 import dwt.widgets.Listener; | |
39 import dwt.widgets.Table; | |
40 import dwt.widgets.Tree; | |
41 import dwt.widgets.Widget; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 * Class <code>DropTarget</code> defines the target object for a drag and drop transfer. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
46 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
47 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
48 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
49 * <p>This class identifies the <code>Control</code> over which the user must position the cursor |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
50 * in order to drop the data being transferred. It also specifies what data types can be dropped on |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
51 * this control and what operations can be performed. You may have several DropTragets in an |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 * application but there can only be a one to one mapping between a <code>Control</code> and a <code>DropTarget</code>. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
53 * The DropTarget can receive data from within the same application or from other applications |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
54 * (such as text dragged from a text editor like Word).</p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
55 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
56 * <code><pre> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
57 * int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
58 * Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
59 * DropTarget target = new DropTarget(label, operations); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
60 * target.setTransfer(types); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
61 * </code></pre> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
62 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
63 * <p>The application is notified of data being dragged over this control and of when a drop occurs by |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
64 * implementing the interface <code>DropTargetListener</code> which uses the class |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
65 * <code>DropTargetEvent</code>. The application can modify the type of drag being performed |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
66 * on this Control at any stage of the drag by modifying the <code>event.detail</code> field or the |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
67 * <code>event.currentDataType</code> field. When the data is dropped, it is the responsibility of |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
68 * the application to copy this data for its own purposes. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
69 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
70 * <code><pre> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
71 * target.addDropListener (new DropTargetListener() { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
72 * public void dragEnter(DropTargetEvent event) {}; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
73 * public void dragOver(DropTargetEvent event) {}; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
74 * public void dragLeave(DropTargetEvent event) {}; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
75 * public void dragOperationChanged(DropTargetEvent event) {}; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
76 * public void dropAccept(DropTargetEvent event) {} |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
77 * public void drop(DropTargetEvent event) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
78 * // A drop has occurred, copy over the data |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
79 * if (event.data is null) { // no data to copy, indicate failure in event.detail |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
80 * event.detail = DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
81 * return; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
82 * } |
45 | 83 * label.setText ((String) event.data); // data copied to label text |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
84 * } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
85 * }); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
86 * </pre></code> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
87 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
88 * <dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
89 * <dt><b>Styles</b></dt> <dd>DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
90 * <dt><b>Events</b></dt> <dd>DND.DragEnter, DND.DragLeave, DND.DragOver, DND.DragOperationChanged, |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
91 * DND.DropAccept, DND.Drop </dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
92 * </dl> |
45 | 93 * |
94 * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a> | |
95 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a> | |
96 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
97 */ |
45 | 98 public class DropTarget extends Widget { |
99 | |
100 static Callback dropTarget2Args, dropTarget3Args; | |
101 static int /*long*/ proc2Args, proc3Args; | |
102 | |
103 static { | |
104 Class clazz = DropTarget.class; | |
105 | |
106 dropTarget2Args = new Callback(clazz, "dropTargetProc", 2); | |
107 proc2Args = dropTarget2Args.getAddress(); | |
108 if (proc2Args is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
109 | |
110 dropTarget3Args = new Callback(clazz, "dropTargetProc", 3); | |
111 proc3Args = dropTarget3Args.getAddress(); | |
112 if (proc3Args is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
113 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
114 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
115 Control control; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
116 Listener controlListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
117 Transfer[] transferAgents = new Transfer[0]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
118 DropTargetEffect dropEffect; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
119 int feedback = DND.FEEDBACK_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
120 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
121 // Track application selections |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
122 TransferData selectedDataType; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
123 int selectedOperation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
124 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
125 // workaround - There is no event for "operation changed" so track operation based on key state |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
126 int keyOperation = -1; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
127 |
45 | 128 static final String DEFAULT_DROP_TARGET_EFFECT = "DEFAULT_DROP_TARGET_EFFECT"; //$NON-NLS-1$ |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
129 |
45 | 130 void addDragHandlers() { |
131 // Our strategy here is to dynamically add methods to the control's class that are required | |
132 // by NSDraggingDestination. Then, when setTransfer is called, we just register | |
133 // the types with the Control's NSView and AppKit will call the methods in the protocol | |
134 // when a drag goes over the view. | |
135 | |
136 int /*long*/ cls = OS.object_getClass(control.view.id); | |
137 | |
138 if (cls is 0) { | |
139 DND.error(DND.ERROR_CANNOT_INIT_DROP); | |
140 } | |
141 | |
142 // If we already added it, no need to do it again. | |
143 int /*long*/ procPtr = OS.class_getMethodImplementation(cls, OS.sel_draggingEnded_); | |
144 if (procPtr is proc3Args) return; | |
145 | |
146 // Add the NSDraggingDestination callbacks | |
147 OS.class_addMethod(cls, OS.sel_draggingEntered_, proc3Args, "@:@"); | |
148 OS.class_addMethod(cls, OS.sel_draggingUpdated_, proc3Args, "@:@"); | |
149 OS.class_addMethod(cls, OS.sel_draggingExited_, proc3Args, "@:@"); | |
150 OS.class_addMethod(cls, OS.sel_performDragOperation_, proc3Args, "@:@"); | |
151 OS.class_addMethod(cls, OS.sel_wantsPeriodicDraggingUpdates, proc2Args, "@:"); | |
152 } | |
153 | |
154 /** | |
155 * Adds the listener to the collection of listeners who will | |
156 * be notified when a drag and drop operation is in progress, by sending | |
157 * it one of the messages defined in the <code>DropTargetListener</code> | |
158 * interface. | |
159 * | |
160 * <p><ul> | |
161 * <li><code>dragEnter</code> is called when the cursor has entered the drop target boundaries | |
162 * <li><code>dragLeave</code> is called when the cursor has left the drop target boundaries and just before | |
163 * the drop occurs or is cancelled. | |
164 * <li><code>dragOperationChanged</code> is called when the operation being performed has changed | |
165 * (usually due to the user changing the selected modifier key(s) while dragging) | |
166 * <li><code>dragOver</code> is called when the cursor is moving over the drop target | |
167 * <li><code>dropAccept</code> is called just before the drop is performed. The drop target is given | |
168 * the chance to change the nature of the drop or veto the drop by setting the <code>event.detail</code> field | |
169 * <li><code>drop</code> is called when the data is being dropped | |
170 * </ul></p> | |
171 * | |
172 * @param listener the listener which should be notified | |
173 * | |
174 * @exception IllegalArgumentException <ul> | |
175 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
176 * </ul> | |
177 * @exception DWTException <ul> | |
178 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
179 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
180 * </ul> | |
181 * | |
182 * @see DropTargetListener | |
183 * @see #getDropListeners | |
184 * @see #removeDropListener | |
185 * @see DropTargetEvent | |
186 */ | |
187 public void addDropListener(DropTargetListener listener) { | |
188 if (listener is null) DND.error (DWT.ERROR_NULL_ARGUMENT); | |
189 DNDListener typedListener = new DNDListener (listener); | |
190 typedListener.dndWidget = this; | |
191 addListener (DND.DragEnter, typedListener); | |
192 addListener (DND.DragLeave, typedListener); | |
193 addListener (DND.DragOver, typedListener); | |
194 addListener (DND.DragOperationChanged, typedListener); | |
195 addListener (DND.Drop, typedListener); | |
196 addListener (DND.DropAccept, typedListener); | |
197 } | |
198 | |
199 static int checkStyle (int style) { | |
200 if (style is DWT.NONE) return DND.DROP_MOVE; | |
201 return style; | |
202 } | |
203 | |
204 protected void checkSubclass () { | |
205 String name = getClass().getName (); | |
206 String validName = DropTarget.class.getName(); | |
207 if (!validName.equals(name)) { | |
208 DND.error (DWT.ERROR_INVALID_SUBCLASS); | |
209 } | |
210 } | |
211 | |
212 int draggingEntered(NSObject sender) { | |
213 selectedDataType = null; | |
214 selectedOperation = 0; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
215 |
45 | 216 DNDEvent event = new DNDEvent(); |
217 if (!setEventData(sender, event)) { | |
218 keyOperation = -1; | |
219 if (OS.PTR_SIZEOF is 4) OS.SetThemeCursor(OS.kThemeNotAllowedCursor); | |
220 return OS.NSDragOperationNone; | |
221 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
222 |
45 | 223 int allowedOperations = event.operations; |
224 TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; | |
225 System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length); | |
226 | |
227 notifyListeners(DND.DragEnter, event); | |
228 | |
229 if (event.detail is DND.DROP_DEFAULT) { | |
230 event.detail = (allowedOperations & DND.DROP_MOVE) !is 0 ? DND.DROP_MOVE : DND.DROP_NONE; | |
231 } | |
232 | |
233 selectedDataType = null; | |
234 for (int i = 0; i < allowedDataTypes.length; i++) { | |
235 if (allowedDataTypes[i].type is event.dataType.type) { | |
236 selectedDataType = allowedDataTypes[i]; | |
237 break; | |
238 } | |
239 } | |
240 | |
241 selectedOperation = DND.DROP_NONE; | |
242 if (selectedDataType !is null && (allowedOperations & event.detail) !is 0) { | |
243 selectedOperation = event.detail; | |
244 } | |
245 | |
246 int osOperation = opToOsOp(selectedOperation); | |
247 | |
248 if (OS.PTR_SIZEOF is 4) { | |
249 switch (selectedOperation) { | |
250 case DND.DROP_COPY: | |
251 OS.SetThemeCursor(OS.kThemeCopyArrowCursor); | |
252 break; | |
253 case DND.DROP_LINK: | |
254 OS.SetThemeCursor(OS.kThemeAliasArrowCursor); | |
255 break; | |
256 case DND.DROP_MOVE: | |
257 NSCursor.arrowCursor().set(); | |
258 break; | |
259 default: | |
260 OS.SetThemeCursor(OS.kThemeNotAllowedCursor); | |
261 } | |
262 } | |
263 return osOperation; | |
264 } | |
265 | |
266 void draggingExited(NSObject sender) { | |
267 NSCursor.arrowCursor().set(); | |
268 if (keyOperation is -1) return; | |
269 keyOperation = -1; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
270 |
45 | 271 DNDEvent event = new DNDEvent(); |
272 event.widget = this; | |
273 event.time = (int)System.currentTimeMillis(); | |
274 event.detail = DND.DROP_NONE; | |
275 notifyListeners(DND.DragLeave, event); | |
276 } | |
277 | |
278 int draggingUpdated(NSObject sender) { | |
279 if (sender is null) return OS.NSDragOperationNone; | |
280 int oldKeyOperation = keyOperation; | |
281 | |
282 DNDEvent event = new DNDEvent(); | |
283 if (!setEventData(sender, event)) { | |
284 keyOperation = -1; | |
285 if (OS.PTR_SIZEOF is 4) OS.SetThemeCursor(OS.kThemeNotAllowedCursor); | |
286 return OS.NSDragOperationNone; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
287 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
288 |
45 | 289 int allowedOperations = event.operations; |
290 TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; | |
291 System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length); | |
292 | |
293 if (keyOperation is oldKeyOperation) { | |
294 event.type = DND.DragOver; | |
295 event.dataType = selectedDataType; | |
296 event.detail = selectedOperation; | |
297 } else { | |
298 event.type = DND.DragOperationChanged; | |
299 event.dataType = selectedDataType; | |
300 } | |
301 notifyListeners(event.type, event); | |
302 if (event.detail is DND.DROP_DEFAULT) { | |
303 event.detail = (allowedOperations & DND.DROP_MOVE) !is 0 ? DND.DROP_MOVE : DND.DROP_NONE; | |
304 } | |
305 | |
306 selectedDataType = null; | |
307 for (int i = 0; i < allowedDataTypes.length; i++) { | |
308 if (allowedDataTypes[i].type is event.dataType.type) { | |
309 selectedDataType = allowedDataTypes[i]; | |
310 break; | |
311 } | |
312 } | |
313 | |
314 selectedOperation = DND.DROP_NONE; | |
315 if (selectedDataType !is null && ((allowedOperations & event.detail) is event.detail)) { | |
316 selectedOperation = event.detail; | |
317 } | |
318 return opToOsOp(selectedOperation); | |
319 } | |
320 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
321 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
322 * Creates a new <code>DropTarget</code> to allow data to be dropped on the specified |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
323 * <code>Control</code>. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
324 * Creating an instance of a DropTarget may cause system resources to be allocated |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
325 * depending on the platform. It is therefore mandatory that the DropTarget instance |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
326 * be disposed when no longer required. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
327 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
328 * @param control the <code>Control</code> over which the user positions the cursor to drop the data |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
329 * @param style the bitwise OR'ing of allowed operations; this may be a combination of any of |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
330 * DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
331 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
332 * @exception DWTException <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
333 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
334 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
335 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
336 * @exception DWTError <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
337 * <li>ERROR_CANNOT_INIT_DROP - unable to initiate drop target; this will occur if more than one |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
338 * drop target is created for a control or if the operating system will not allow the creation |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
339 * of the drop target</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
340 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
341 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
342 * <p>NOTE: ERROR_CANNOT_INIT_DROP should be an DWTException, since it is a |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
343 * recoverable error, but can not be changed due to backward compatibility.</p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
344 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
345 * @see Widget#dispose |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
346 * @see DropTarget#checkSubclass |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
347 * @see DND#DROP_NONE |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
348 * @see DND#DROP_COPY |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
349 * @see DND#DROP_MOVE |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
350 * @see DND#DROP_LINK |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
351 */ |
45 | 352 public DropTarget(Control control, int style) { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
353 super(control, checkStyle(style)); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
354 this.control = control; |
45 | 355 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
356 if (control.getData(DND.DROP_TARGET_KEY) !is null) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
357 DND.error(DND.ERROR_CANNOT_INIT_DROP); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
358 } |
45 | 359 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
360 control.setData(DND.DROP_TARGET_KEY, this); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
361 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
362 controlListener = new Listener () { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
363 public void handleEvent (Event event) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
364 if (!DropTarget.this.isDisposed()) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
365 DropTarget.this.dispose(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
366 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
367 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
368 }; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
369 control.addListener (DWT.Dispose, controlListener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
370 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
371 this.addListener(DWT.Dispose, new Listener() { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
372 public void handleEvent (Event event) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
373 onDispose(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
374 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
375 }); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
376 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
377 Object effect = control.getData(DEFAULT_DROP_TARGET_EFFECT); |
45 | 378 if (effect instanceof DropTargetEffect) { |
379 dropEffect = (DropTargetEffect) effect; | |
380 } else if (control instanceof Table) { | |
381 dropEffect = new TableDropTargetEffect((Table) control); | |
382 } else if (control instanceof Tree) { | |
383 dropEffect = new TreeDropTargetEffect((Tree) control); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
384 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
385 |
45 | 386 addDragHandlers(); |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
387 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
388 |
45 | 389 static int /*long*/ dropTargetProc(int /*long*/ id, int /*long*/ sel) { |
390 Display display = Display.findDisplay(Thread.currentThread()); | |
391 if (display is null || display.isDisposed()) return 0; | |
392 Widget widget = display.findWidget(id); | |
393 if (widget is null) return 0; | |
394 DropTarget dt = (DropTarget)widget.getData(DND.DROP_TARGET_KEY); | |
395 if (dt is null) return 0; | |
396 | |
397 if (sel is OS.sel_wantsPeriodicDraggingUpdates) { | |
398 return dt.wantsPeriodicDraggingUpdates() ? 1 : 0; | |
399 } | |
400 | |
401 return 0; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
402 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
403 |
45 | 404 static int /*long*/ dropTargetProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { |
405 Display display = Display.findDisplay(Thread.currentThread()); | |
406 if (display is null || display.isDisposed()) return 0; | |
407 Widget widget = display.findWidget(id); | |
408 if (widget is null) return 0; | |
409 DropTarget dt = (DropTarget)widget.getData(DND.DROP_TARGET_KEY); | |
410 if (dt is null) return 0; | |
411 | |
412 // arg0 is _always_ the sender, and implements NSDraggingInfo. | |
413 // Looks like an NSObject for our purposes, though. | |
414 NSObject sender = new NSObject(arg0); | |
415 | |
416 if (sel is OS.sel_draggingEntered_) { | |
417 return dt.draggingEntered(sender); | |
418 } else if (sel is OS.sel_draggingUpdated_) { | |
419 return dt.draggingUpdated(sender); | |
420 } else if (sel is OS.sel_draggingExited_) { | |
421 dt.draggingExited(sender); | |
422 } else if (sel is OS.sel_performDragOperation_) { | |
423 return dt.performDragOperation(sender) ? 1 : 0; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
424 } |
45 | 425 |
426 return 0; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
427 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
428 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
429 /** |
45 | 430 * Returns the Control which is registered for this DropTarget. This is the control over which the |
431 * user positions the cursor to drop the data. | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
432 * |
45 | 433 * @return the Control which is registered for this DropTarget |
434 */ | |
435 public Control getControl () { | |
436 return control; | |
437 } | |
438 | |
439 /** | |
440 * Returns an array of listeners who will be notified when a drag and drop | |
441 * operation is in progress, by sending it one of the messages defined in | |
442 * the <code>DropTargetListener</code> interface. | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
443 * |
45 | 444 * @return the listeners who will be notified when a drag and drop |
445 * operation is in progress | |
446 * | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
447 * @exception DWTException <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
448 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
449 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
450 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
451 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
452 * @see DropTargetListener |
45 | 453 * @see #addDropListener |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
454 * @see #removeDropListener |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
455 * @see DropTargetEvent |
45 | 456 * |
457 * @since 3.4 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
458 */ |
45 | 459 public DropTargetListener[] getDropListeners() { |
460 Listener[] listeners = getListeners(DND.DragEnter); | |
461 int length = listeners.length; | |
462 DropTargetListener[] dropListeners = new DropTargetListener[length]; | |
463 int count = 0; | |
464 for (int i = 0; i < length; i++) { | |
465 Listener listener = listeners[i]; | |
466 if (listener instanceof DNDListener) { | |
467 dropListeners[count] = (DropTargetListener) ((DNDListener) listener).getEventListener(); | |
468 count++; | |
469 } | |
470 } | |
471 if (count is length) return dropListeners; | |
472 DropTargetListener[] result = new DropTargetListener[count]; | |
473 System.arraycopy(dropListeners, 0, result, 0, count); | |
474 return result; | |
475 } | |
476 | |
477 /** | |
478 * Returns the drop effect for this DropTarget. This drop effect will be | |
479 * used during a drag and drop to display the drag under effect on the | |
480 * target widget. | |
481 * | |
482 * @return the drop effect that is registered for this DropTarget | |
483 * | |
484 * @since 3.3 | |
485 */ | |
486 public DropTargetEffect getDropTargetEffect() { | |
487 return dropEffect; | |
488 } | |
489 | |
490 int getOperationFromKeyState() { | |
491 // The NSDraggingInfo object already combined the modifier keys with the | |
492 // drag source's allowed events. This might be better accomplished by diffing | |
493 // the base drag source mask with the active drag state mask instead of snarfing | |
494 // the current event. | |
495 | |
496 // See documentation on [NSDraggingInfo draggingSourceOperationMask] for the | |
497 // correct Cocoa behavior. Control + Option or Command is NSDragOperationGeneric, | |
498 // or DND.DROP_DEFAULT in the DWT. | |
499 NSEvent currEvent = NSApplication.sharedApplication().currentEvent(); | |
500 int /*long*/ modifiers = currEvent.modifierFlags(); | |
501 bool option = (modifiers & OS.NSAlternateKeyMask) is OS.NSAlternateKeyMask; | |
502 bool control = (modifiers & OS.NSControlKeyMask) is OS.NSControlKeyMask; | |
503 if (control && option) return DND.DROP_DEFAULT; | |
504 if (control) return DND.DROP_LINK; | |
505 if (option) return DND.DROP_COPY; | |
506 return DND.DROP_DEFAULT; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
507 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
508 |
45 | 509 /** |
510 * Returns a list of the data types that can be transferred to this DropTarget. | |
511 * | |
512 * @return a list of the data types that can be transferred to this DropTarget | |
513 */ | |
514 public Transfer[] getTransfer() { | |
515 return transferAgents; | |
516 } | |
517 | |
518 void onDispose () { | |
519 if (control is null) | |
520 return; | |
521 if (controlListener !is null) | |
522 control.removeListener(DWT.Dispose, controlListener); | |
523 controlListener = null; | |
524 control.setData(DND.DROP_TARGET_KEY, null); | |
525 transferAgents = null; | |
526 | |
527 // Unregister the control as a drop target. | |
528 control.view.unregisterDraggedTypes(); | |
529 control = null; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
530 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
531 |
45 | 532 int opToOsOp(int operation) { |
533 int osOperation = 0; | |
534 if ((operation & DND.DROP_COPY) !is 0){ | |
535 osOperation |= OS.NSDragOperationCopy; | |
536 } | |
537 if ((operation & DND.DROP_LINK) !is 0) { | |
538 osOperation |= OS.NSDragOperationLink; | |
539 } | |
540 if ((operation & DND.DROP_MOVE) !is 0) { | |
541 osOperation |= OS.NSDragOperationMove; | |
542 } | |
543 if ((operation & DND.DROP_TARGET_MOVE) !is 0) { | |
544 osOperation |= OS.NSDragOperationDelete; | |
545 } | |
546 return osOperation; | |
547 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
548 |
45 | 549 int osOpToOp(int /*long*/ osOperation){ |
550 int operation = 0; | |
551 if ((osOperation & OS.NSDragOperationCopy) !is 0){ | |
552 operation |= DND.DROP_COPY; | |
553 } | |
554 if ((osOperation & OS.NSDragOperationLink) !is 0) { | |
555 operation |= DND.DROP_LINK; | |
556 } | |
557 if ((osOperation & OS.NSDragOperationDelete) !is 0) { | |
558 operation |= DND.DROP_TARGET_MOVE; | |
559 } | |
560 if ((osOperation & OS.NSDragOperationMove) !is 0) { | |
561 operation |= DND.DROP_MOVE; | |
562 } | |
563 if (osOperation is OS.NSDragOperationEvery) { | |
564 operation = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; | |
565 } | |
566 return operation; | |
567 } | |
568 | |
569 bool performDragOperation(NSObject sender) { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
570 DNDEvent event = new DNDEvent(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
571 event.widget = this; |
45 | 572 event.time = (int)System.currentTimeMillis(); |
573 | |
574 if (dropEffect !is null) { | |
575 NSPoint mouseLocation = sender.draggingLocation(); | |
576 NSPoint globalLoc = sender.draggingDestinationWindow().convertBaseToScreen(mouseLocation); | |
577 event.item = dropEffect.getItem((int)globalLoc.x, (int)globalLoc.y); | |
578 } | |
579 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
580 event.detail = DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
581 notifyListeners(DND.DragLeave, event); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
582 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
583 event = new DNDEvent(); |
45 | 584 if (!setEventData(sender, event)) { |
585 return false; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
586 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
587 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
588 keyOperation = -1; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
589 int allowedOperations = event.operations; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
590 TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
591 System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, event.dataTypes.length); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
592 event.dataType = selectedDataType; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
593 event.detail = selectedOperation; |
45 | 594 notifyListeners(DND.DropAccept, event); |
595 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
596 selectedDataType = null; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
597 if (event.dataType !is null) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
598 for (int i = 0; i < allowedDataTypes.length; i++) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
599 if (allowedDataTypes[i].type is event.dataType.type) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
600 selectedDataType = allowedDataTypes[i]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
601 break; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
602 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
603 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
604 } |
45 | 605 |
606 selectedOperation = DND.DROP_NONE; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
607 if (selectedDataType !is null && (event.detail & allowedOperations) !is 0) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
608 selectedOperation = event.detail; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
609 } |
45 | 610 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
611 if (selectedOperation is DND.DROP_NONE) { |
45 | 612 return false; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
613 } |
45 | 614 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
615 // ask drag source for dropped data |
45 | 616 NSPasteboard pasteboard = sender.draggingPasteboard(); |
617 NSObject data = null; | |
618 NSMutableArray types = NSMutableArray.arrayWithCapacity(10); | |
619 | |
620 for (int i = 0; i < transferAgents.length; i++){ | |
621 Transfer transfer = transferAgents[i]; | |
622 String[] typeNames = transfer.getTypeNames(); | |
623 int[] typeIds = transfer.getTypeIds(); | |
624 | |
625 for (int j = 0; j < typeNames.length; j++) { | |
626 if (selectedDataType.type is typeIds[j]) { | |
627 types.addObject(NSString.stringWith(typeNames[j])); | |
628 break; | |
629 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
630 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
631 } |
45 | 632 |
633 NSString type = pasteboard.availableTypeFromArray(types); | |
634 TransferData tdata = new TransferData(); | |
635 | |
636 if (type !is null) { | |
637 tdata.type = Transfer.registerType(type.getString()); | |
638 if (type.isEqual(OS.NSStringPboardType) || | |
639 type.isEqual(OS.NSHTMLPboardType) || | |
640 type.isEqual(OS.NSRTFPboardType)) { | |
641 tdata.data = pasteboard.stringForType(type); | |
642 } else if (type.isEqual(OS.NSURLPboardType)) { | |
643 tdata.data = NSURL.URLFromPasteboard(pasteboard); | |
644 } else if (type.isEqual(OS.NSFilenamesPboardType)) { | |
645 tdata.data = new NSArray(pasteboard.propertyListForType(type).id); | |
646 } else { | |
647 tdata.data = pasteboard.dataForType(type); | |
648 } | |
649 } | |
650 | |
651 if (tdata.data !is null) { | |
652 data = tdata.data; | |
653 } | |
654 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
655 // Get Data in a Java format |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
656 Object object = null; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
657 for (int i = 0; i < transferAgents.length; i++) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
658 Transfer transfer = transferAgents[i]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
659 if (transfer !is null && transfer.isSupportedType(selectedDataType)) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
660 selectedDataType.data = data; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
661 object = transfer.nativeToJava(selectedDataType); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
662 break; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
663 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
664 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
665 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
666 if (object is null) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
667 selectedOperation = DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
668 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
669 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
670 event.dataType = selectedDataType; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
671 event.detail = selectedOperation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
672 event.data = object; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
673 notifyListeners(DND.Drop, event); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
674 selectedOperation = DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
675 if ((allowedOperations & event.detail) is event.detail) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
676 selectedOperation = event.detail; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
677 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
678 //notify source of action taken |
45 | 679 return (selectedOperation !is DND.DROP_NONE); |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
680 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
681 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
682 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
683 * Removes the listener from the collection of listeners who will |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
684 * be notified when a drag and drop operation is in progress. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
685 * |
45 | 686 * @param listener the listener which should no longer be notified |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
687 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
688 * @exception IllegalArgumentException <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
689 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
690 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
691 * @exception DWTException <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
692 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
693 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
694 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
695 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
696 * @see DropTargetListener |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
697 * @see #addDropListener |
45 | 698 * @see #getDropListeners |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
699 */ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
700 public void removeDropListener(DropTargetListener listener) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
701 if (listener is null) DND.error (DWT.ERROR_NULL_ARGUMENT); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
702 removeListener (DND.DragEnter, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
703 removeListener (DND.DragLeave, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
704 removeListener (DND.DragOver, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
705 removeListener (DND.DragOperationChanged, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
706 removeListener (DND.Drop, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
707 removeListener (DND.DropAccept, listener); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
708 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
709 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
710 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
711 * Specifies the drop effect for this DropTarget. This drop effect will be |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
712 * used during a drag and drop to display the drag under effect on the |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
713 * target widget. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
714 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
715 * @param effect the drop effect that is registered for this DropTarget |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
716 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
717 * @since 3.3 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
718 */ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
719 public void setDropTargetEffect(DropTargetEffect effect) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
720 dropEffect = effect; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
721 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
722 |
45 | 723 bool setEventData(NSObject draggingState, DNDEvent event) { |
724 if (draggingState is null) return false; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
725 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
726 // get allowed operations |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
727 int style = getStyle(); |
45 | 728 int /*long*/ allowedActions = draggingState.draggingSourceOperationMask(); |
729 int operations = osOpToOp(allowedActions) & style; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
730 if (operations is DND.DROP_NONE) return false; |
45 | 731 |
732 // get current operation | |
733 int operation = getOperationFromKeyState(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
734 keyOperation = operation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
735 if (operation is DND.DROP_DEFAULT) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
736 if ((style & DND.DROP_DEFAULT) is 0) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
737 operation = (operations & DND.DROP_MOVE) !is 0 ? DND.DROP_MOVE : DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
738 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
739 } else { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
740 if ((operation & operations) is 0) operation = DND.DROP_NONE; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
741 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
742 |
45 | 743 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
744 // get allowed transfer types |
45 | 745 NSPasteboard dragPBoard = draggingState.draggingPasteboard(); |
746 NSArray draggedTypes = dragPBoard.types(); | |
747 if (draggedTypes is null) return false; | |
748 | |
749 int /*long*/ draggedTypeCount = draggedTypes.count(); | |
750 | |
751 TransferData[] dataTypes = new TransferData[(int)draggedTypeCount]; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
752 int index = -1; |
45 | 753 for (int i = 0; i < draggedTypeCount; i++) { |
754 id draggedType = draggedTypes.objectAtIndex(i); | |
755 NSString nativeDataType = new NSString(draggedType); | |
756 TransferData data = new TransferData(); | |
757 data.type = Transfer.registerType(nativeDataType.getString()); | |
758 | |
759 for (int j = 0; j < transferAgents.length; j++) { | |
760 Transfer transfer = transferAgents[j]; | |
761 if (transfer !is null && transfer.isSupportedType(data)) { | |
762 dataTypes[++index] = data; | |
763 break; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
764 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
765 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
766 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
767 if (index is -1) return false; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
768 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
769 if (index < dataTypes.length - 1) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
770 TransferData[] temp = new TransferData[index + 1]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
771 System.arraycopy(dataTypes, 0, temp, 0, index + 1); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
772 dataTypes = temp; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
773 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
774 |
45 | 775 // Convert from window-relative to global coordinates, and flip it. |
776 NSPoint mouse = draggingState.draggingLocation(); | |
777 NSPoint globalMouse = draggingState.draggingDestinationWindow().convertBaseToScreen(mouse); | |
778 NSArray screens = NSScreen.screens(); | |
779 NSRect screenRect = new NSScreen(screens.objectAtIndex(0)).frame(); | |
780 globalMouse.y = screenRect.height - globalMouse.y; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
781 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
782 event.widget = this; |
45 | 783 event.x = (int)globalMouse.x; |
784 event.y = (int)globalMouse.y; | |
785 event.time = (int)System.currentTimeMillis(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
786 event.feedback = DND.FEEDBACK_SELECT; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
787 event.dataTypes = dataTypes; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
788 event.dataType = dataTypes[0]; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
789 event.operations = operations; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
790 event.detail = operation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
791 if (dropEffect !is null) { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
792 event.item = dropEffect.getItem(event.x, event.y); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
793 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
794 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
795 return true; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
796 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
797 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
798 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
799 * Specifies the data types that can be transferred to this DropTarget. If data is |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
800 * being dragged that does not match one of these types, the drop target will be notified of |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
801 * the drag and drop operation but the currentDataType will be null and the operation |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
802 * will be DND.NONE. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
803 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
804 * @param transferAgents a list of Transfer objects which define the types of data that can be |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
805 * dropped on this target |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
806 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
807 * @exception IllegalArgumentException <ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
808 * <li>ERROR_NULL_ARGUMENT - if transferAgents is null</li> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
809 * </ul> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
810 */ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
811 public void setTransfer(Transfer[] transferAgents){ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
812 if (transferAgents is null) DND.error(DWT.ERROR_NULL_ARGUMENT); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
813 this.transferAgents = transferAgents; |
45 | 814 |
815 | |
816 // Register the types as valid drop types in Cocoa. | |
817 // Accumulate all of the transfer types into a list. | |
818 ArrayList typeStrings = new ArrayList(); | |
819 | |
820 for (int i = 0; i < this.transferAgents.length; i++) { | |
821 String[] types = transferAgents[i].getTypeNames(); | |
822 | |
823 for (int j = 0; j < types.length; j++) { | |
824 typeStrings.add(types[j]); | |
825 } | |
826 } | |
827 | |
828 // Convert to an NSArray of NSStrings so we can register with the Control. | |
829 int typeStringCount = typeStrings.size(); | |
830 NSMutableArray nsTypeStrings = NSMutableArray.arrayWithCapacity(typeStringCount); | |
831 | |
832 for (int i = 0; i < typeStringCount; i++) { | |
833 nsTypeStrings.addObject(NSString.stringWith((String)typeStrings.get(i))); | |
834 } | |
835 | |
836 control.view.registerForDraggedTypes(nsTypeStrings); | |
837 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
838 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
839 |
45 | 840 // By returning true we get draggingUpdated messages even when the mouse isn't moving. |
841 bool wantsPeriodicDraggingUpdates() { | |
842 return true; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
843 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
844 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
845 } |