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