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