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