comparison dwt/dnd/DropTarget.d @ 99:d32621bf0f90

Ported dwt.dnd.DropTarget
author Jacob Carlborg <doob@me.com>
date Wed, 31 Dec 2008 13:16:18 +0100
parents d8635bb48c7c
children a2d82e6fd054
comparison
equal deleted inserted replaced
98:5acb3346c926 99:d32621bf0f90
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *
11 * Port to the D programming language:
12 * Jacob Carlborg <doob@me.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.dnd.DropTarget; 14 module dwt.dnd.DropTarget;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14
15 import java.util.ArrayList;
16 17
17 import dwt.DWT; 18 import dwt.DWT;
18 import dwt.DWTError; 19 import dwt.DWTError;
19 import dwt.DWTException; 20 import dwt.DWTException;
20 import dwt.internal.Callback;
21 import dwt.internal.cocoa.NSApplication; 21 import dwt.internal.cocoa.NSApplication;
22 import dwt.internal.cocoa.NSArray; 22 import dwt.internal.cocoa.NSArray;
23 import dwt.internal.cocoa.NSCursor; 23 import dwt.internal.cocoa.NSCursor;
24 import dwt.internal.cocoa.NSEvent; 24 import dwt.internal.cocoa.NSEvent;
25 import dwt.internal.cocoa.NSMutableArray; 25 import dwt.internal.cocoa.NSMutableArray;
38 import dwt.widgets.Listener; 38 import dwt.widgets.Listener;
39 import dwt.widgets.Table; 39 import dwt.widgets.Table;
40 import dwt.widgets.Tree; 40 import dwt.widgets.Tree;
41 import dwt.widgets.Widget; 41 import dwt.widgets.Widget;
42 42
43 import dwt.dnd.DND;
44 import dwt.dnd.DNDEvent;
45 import dwt.dnd.DNDListener;
46 import dwt.dnd.DropTargetEffect;
47 import dwt.dnd.DropTargetListener;
48 import dwt.dnd.TableDropTargetEffect;
49 import dwt.dnd.Transfer;
50 import dwt.dnd.TransferData;
51 import dwt.dwthelper.array;
52 import dwt.internal.objc.cocoa.Cocoa;
53 import objc = dwt.internal.objc.runtime;
54
43 /** 55 /**
44 * 56 *
45 * Class <code>DropTarget</code> defines the target object for a drag and drop transfer. 57 * Class <code>DropTarget</code> defines the target object for a drag and drop transfer.
46 * 58 *
47 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 59 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
93 * 105 *
94 * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a> 106 * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
95 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a> 107 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a>
96 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 108 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
97 */ 109 */
98 public class DropTarget extends Widget { 110 public class DropTarget : Widget {
99 111
100 static Callback dropTarget2Args, dropTarget3Args; 112 static objc.IMP proc2Args, proc3Args;
101 static int /*long*/ proc2Args, proc3Args; 113
102 114 static this () {
103 static { 115 proc2Args = cast(objc.IMP) &dropTargetProc2;
104 Class clazz = DropTarget.class; 116 proc3Args = cast(objc.IMP) &dropTargetProc3;
105
106 dropTarget2Args = new Callback(clazz, "dropTargetProc", 2);
107 proc2Args = dropTarget2Args.getAddress();
108 if (proc2Args is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS);
109
110 dropTarget3Args = new Callback(clazz, "dropTargetProc", 3);
111 proc3Args = dropTarget3Args.getAddress();
112 if (proc3Args is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS);
113 } 117 }
114 118
115 Control control; 119 Control control;
116 Listener controlListener; 120 Listener controlListener;
117 Transfer[] transferAgents = new Transfer[0]; 121 Transfer[] transferAgents;
118 DropTargetEffect dropEffect; 122 DropTargetEffect dropEffect;
119 int feedback = DND.FEEDBACK_NONE; 123 int feedback = DND.FEEDBACK_NONE;
120 124
121 // Track application selections 125 // Track application selections
122 TransferData selectedDataType; 126 TransferData selectedDataType;
123 int selectedOperation; 127 int selectedOperation;
124 128
125 // workaround - There is no event for "operation changed" so track operation based on key state 129 // workaround - There is no event for "operation changed" so track operation based on key state
126 int keyOperation = -1; 130 int keyOperation = -1;
127 131
128 static final String DEFAULT_DROP_TARGET_EFFECT = "DEFAULT_DROP_TARGET_EFFECT"; //$NON-NLS-1$ 132 static const String DEFAULT_DROP_TARGET_EFFECT = "DEFAULT_DROP_TARGET_EFFECT"; //$NON-NLS-1$
129 133
130 void addDragHandlers() { 134 void addDragHandlers() {
131 // Our strategy here is to dynamically add methods to the control's class that are required 135 // Our strategy here is to dynamically add methods to the control's class that are required
132 // by NSDraggingDestination. Then, when setTransfer is called, we just register 136 // by NSDraggingDestination. Then, when setTransfer is called, we just register
133 // the types with the Control's NSView and AppKit will call the methods in the protocol 137 // the types with the Control's NSView and AppKit will call the methods in the protocol
134 // when a drag goes over the view. 138 // when a drag goes over the view.
135 139
136 int /*long*/ cls = OS.object_getClass(control.view.id); 140 objc.Class cls = OS.object_getClass(control.view.id);
137 141
138 if (cls is 0) { 142 if (cls is null) {
139 DND.error(DND.ERROR_CANNOT_INIT_DROP); 143 DND.error(DND.ERROR_CANNOT_INIT_DROP);
140 } 144 }
141 145
142 // If we already added it, no need to do it again. 146 // If we already added it, no need to do it again.
143 int /*long*/ procPtr = OS.class_getMethodImplementation(cls, OS.sel_draggingEnded_); 147 objc.IMP procPtr = OS.class_getMethodImplementation(cls, OS.sel_draggingEnded_);
144 if (procPtr is proc3Args) return; 148 if (procPtr is proc3Args) return;
145 149
146 // Add the NSDraggingDestination callbacks 150 // Add the NSDraggingDestination callbacks
147 OS.class_addMethod(cls, OS.sel_draggingEntered_, proc3Args, "@:@"); 151 OS.class_addMethod(cls, OS.sel_draggingEntered_, proc3Args, "@:@");
148 OS.class_addMethod(cls, OS.sel_draggingUpdated_, proc3Args, "@:@"); 152 OS.class_addMethod(cls, OS.sel_draggingUpdated_, proc3Args, "@:@");
200 if (style is DWT.NONE) return DND.DROP_MOVE; 204 if (style is DWT.NONE) return DND.DROP_MOVE;
201 return style; 205 return style;
202 } 206 }
203 207
204 protected void checkSubclass () { 208 protected void checkSubclass () {
205 String name = getClass().getName (); 209 String name = this.classinfo.name;
206 String validName = DropTarget.class.getName(); 210 String validName = DropTarget.classinfo.name;
207 if (!validName.equals(name)) { 211 if (!validName.equals(name)) {
208 DND.error (DWT.ERROR_INVALID_SUBCLASS); 212 DND.error (DWT.ERROR_INVALID_SUBCLASS);
209 } 213 }
210 } 214 }
211 215
268 if (keyOperation is -1) return; 272 if (keyOperation is -1) return;
269 keyOperation = -1; 273 keyOperation = -1;
270 274
271 DNDEvent event = new DNDEvent(); 275 DNDEvent event = new DNDEvent();
272 event.widget = this; 276 event.widget = this;
273 event.time = (int)System.currentTimeMillis(); 277 event.time = cast(int)System.currentTimeMillis();
274 event.detail = DND.DROP_NONE; 278 event.detail = DND.DROP_NONE;
275 notifyListeners(DND.DragLeave, event); 279 notifyListeners(DND.DragLeave, event);
276 } 280 }
277 281
278 int draggingUpdated(NSObject sender) { 282 int draggingUpdated(NSObject sender) {
347 * @see DND#DROP_NONE 351 * @see DND#DROP_NONE
348 * @see DND#DROP_COPY 352 * @see DND#DROP_COPY
349 * @see DND#DROP_MOVE 353 * @see DND#DROP_MOVE
350 * @see DND#DROP_LINK 354 * @see DND#DROP_LINK
351 */ 355 */
352 public DropTarget(Control control, int style) { 356 public this(Control control, int style) {
357 transferAgents = new Transfer[0];
358
353 super(control, checkStyle(style)); 359 super(control, checkStyle(style));
354 this.control = control; 360 this.control = control;
355 361
356 if (control.getData(DND.DROP_TARGET_KEY) !is null) { 362 if (control.getData(DND.DROP_TARGET_KEY) !is null) {
357 DND.error(DND.ERROR_CANNOT_INIT_DROP); 363 DND.error(DND.ERROR_CANNOT_INIT_DROP);
358 } 364 }
359 365
360 control.setData(DND.DROP_TARGET_KEY, this); 366 control.setData(DND.DROP_TARGET_KEY, this);
361 367
362 controlListener = new Listener () { 368 controlListener = new class () Listener {
363 public void handleEvent (Event event) { 369 public void handleEvent (Event event) {
364 if (!DropTarget.this.isDisposed()) { 370 if (!this.outer.isDisposed()) {
365 DropTarget.this.dispose(); 371 this.outer.dispose();
366 } 372 }
367 } 373 }
368 }; 374 };
369 control.addListener (DWT.Dispose, controlListener); 375 control.addListener (DWT.Dispose, controlListener);
370 376
371 this.addListener(DWT.Dispose, new Listener() { 377 this.addListener(DWT.Dispose, new class () Listener {
372 public void handleEvent (Event event) { 378 public void handleEvent (Event event) {
373 onDispose(); 379 onDispose();
374 } 380 }
375 }); 381 });
376 382
377 Object effect = control.getData(DEFAULT_DROP_TARGET_EFFECT); 383 Object effect = control.getData(DEFAULT_DROP_TARGET_EFFECT);
378 if (effect instanceof DropTargetEffect) { 384 if (cast(DropTargetEffect) effect) {
379 dropEffect = (DropTargetEffect) effect; 385 dropEffect = cast(DropTargetEffect) effect;
380 } else if (control instanceof Table) { 386 } else if (cast(Table) control) {
381 dropEffect = new TableDropTargetEffect((Table) control); 387 dropEffect = new TableDropTargetEffect(cast(Table) control);
382 } else if (control instanceof Tree) { 388 } else if (cast(Tree) control) {
383 dropEffect = new TreeDropTargetEffect((Tree) control); 389 dropEffect = new TreeDropTargetEffect(cast(Tree) control);
384 } 390 }
385 391
386 addDragHandlers(); 392 addDragHandlers();
387 } 393 }
388 394
389 static int /*long*/ dropTargetProc(int /*long*/ id, int /*long*/ sel) { 395 static objc.id dropTargetProc2(objc.id id, objc.SEL sel) {
390 Display display = Display.findDisplay(Thread.currentThread()); 396 Display display = Display.findDisplay(Thread.currentThread());
391 if (display is null || display.isDisposed()) return 0; 397 if (display is null || display.isDisposed()) return null;
392 Widget widget = display.findWidget(id); 398 Widget widget = display.findWidget(id);
393 if (widget is null) return 0; 399 if (widget is null) return null;
394 DropTarget dt = (DropTarget)widget.getData(DND.DROP_TARGET_KEY); 400 DropTarget dt = cast(DropTarget)widget.getData(DND.DROP_TARGET_KEY);
395 if (dt is null) return 0; 401 if (dt is null) return null;
396 402
397 if (sel is OS.sel_wantsPeriodicDraggingUpdates) { 403 if (sel is OS.sel_wantsPeriodicDraggingUpdates) {
398 return dt.wantsPeriodicDraggingUpdates() ? 1 : 0; 404 return dt.wantsPeriodicDraggingUpdates() ? 1 : 0;
399 } 405 }
400 406
401 return 0; 407 return null;
402 } 408 }
403 409
404 static int /*long*/ dropTargetProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { 410 static objc.id dropTargetProc3(objc.id id, objc.SEL sel, objc.id arg0) {
405 Display display = Display.findDisplay(Thread.currentThread()); 411 Display display = Display.findDisplay(Thread.currentThread());
406 if (display is null || display.isDisposed()) return 0; 412 if (display is null || display.isDisposed()) return null;
407 Widget widget = display.findWidget(id); 413 Widget widget = display.findWidget(id);
408 if (widget is null) return 0; 414 if (widget is null) return null;
409 DropTarget dt = (DropTarget)widget.getData(DND.DROP_TARGET_KEY); 415 DropTarget dt = cast(DropTarget)widget.getData(DND.DROP_TARGET_KEY);
410 if (dt is null) return 0; 416 if (dt is null) return null;
411 417
412 // arg0 is _always_ the sender, and implements NSDraggingInfo. 418 // arg0 is _always_ the sender, and implements NSDraggingInfo.
413 // Looks like an NSObject for our purposes, though. 419 // Looks like an NSObject for our purposes, though.
414 NSObject sender = new NSObject(arg0); 420 NSObject sender = new NSObject(arg0);
415 421
418 } else if (sel is OS.sel_draggingUpdated_) { 424 } else if (sel is OS.sel_draggingUpdated_) {
419 return dt.draggingUpdated(sender); 425 return dt.draggingUpdated(sender);
420 } else if (sel is OS.sel_draggingExited_) { 426 } else if (sel is OS.sel_draggingExited_) {
421 dt.draggingExited(sender); 427 dt.draggingExited(sender);
422 } else if (sel is OS.sel_performDragOperation_) { 428 } else if (sel is OS.sel_performDragOperation_) {
423 return dt.performDragOperation(sender) ? 1 : 0; 429 return dt.performDragOperation(sender) ? cast(objc.id) 1 : null;
424 } 430 }
425 431
426 return 0; 432 return null;
427 } 433 }
428 434
429 /** 435 /**
430 * Returns the Control which is registered for this DropTarget. This is the control over which the 436 * Returns the Control which is registered for this DropTarget. This is the control over which the
431 * user positions the cursor to drop the data. 437 * user positions the cursor to drop the data.
456 * 462 *
457 * @since 3.4 463 * @since 3.4
458 */ 464 */
459 public DropTargetListener[] getDropListeners() { 465 public DropTargetListener[] getDropListeners() {
460 Listener[] listeners = getListeners(DND.DragEnter); 466 Listener[] listeners = getListeners(DND.DragEnter);
461 int length = listeners.length; 467 int length_ = listeners.length;
462 DropTargetListener[] dropListeners = new DropTargetListener[length]; 468 DropTargetListener[] dropListeners = new DropTargetListener[length_];
463 int count = 0; 469 int count = 0;
464 for (int i = 0; i < length; i++) { 470 for (int i = 0; i < length_; i++) {
465 Listener listener = listeners[i]; 471 Listener listener = listeners[i];
466 if (listener instanceof DNDListener) { 472 if (cast(DNDListener) listener) {
467 dropListeners[count] = (DropTargetListener) ((DNDListener) listener).getEventListener(); 473 dropListeners[count] = cast(DropTargetListener) (cast(DNDListener) listener).getEventListener();
468 count++; 474 count++;
469 } 475 }
470 } 476 }
471 if (count is length) return dropListeners; 477 if (count is length_) return dropListeners;
472 DropTargetListener[] result = new DropTargetListener[count]; 478 DropTargetListener[] result = new DropTargetListener[count];
473 System.arraycopy(dropListeners, 0, result, 0, count); 479 System.arraycopy(dropListeners, 0, result, 0, count);
474 return result; 480 return result;
475 } 481 }
476 482
495 501
496 // See documentation on [NSDraggingInfo draggingSourceOperationMask] for the 502 // See documentation on [NSDraggingInfo draggingSourceOperationMask] for the
497 // correct Cocoa behavior. Control + Option or Command is NSDragOperationGeneric, 503 // correct Cocoa behavior. Control + Option or Command is NSDragOperationGeneric,
498 // or DND.DROP_DEFAULT in the DWT. 504 // or DND.DROP_DEFAULT in the DWT.
499 NSEvent currEvent = NSApplication.sharedApplication().currentEvent(); 505 NSEvent currEvent = NSApplication.sharedApplication().currentEvent();
500 int /*long*/ modifiers = currEvent.modifierFlags(); 506 NSUInteger modifiers = currEvent.modifierFlags();
501 bool option = (modifiers & OS.NSAlternateKeyMask) is OS.NSAlternateKeyMask; 507 bool option = (modifiers & OS.NSAlternateKeyMask) is OS.NSAlternateKeyMask;
502 bool control = (modifiers & OS.NSControlKeyMask) is OS.NSControlKeyMask; 508 bool control = (modifiers & OS.NSControlKeyMask) is OS.NSControlKeyMask;
503 if (control && option) return DND.DROP_DEFAULT; 509 if (control && option) return DND.DROP_DEFAULT;
504 if (control) return DND.DROP_LINK; 510 if (control) return DND.DROP_LINK;
505 if (option) return DND.DROP_COPY; 511 if (option) return DND.DROP_COPY;
528 control.view.unregisterDraggedTypes(); 534 control.view.unregisterDraggedTypes();
529 control = null; 535 control = null;
530 } 536 }
531 537
532 int opToOsOp(int operation) { 538 int opToOsOp(int operation) {
533 int osOperation = 0; 539 NSDragOperation osOperation = 0;
534 if ((operation & DND.DROP_COPY) !is 0){ 540 if ((operation & DND.DROP_COPY) !is 0){
535 osOperation |= OS.NSDragOperationCopy; 541 osOperation |= OS.NSDragOperationCopy;
536 } 542 }
537 if ((operation & DND.DROP_LINK) !is 0) { 543 if ((operation & DND.DROP_LINK) !is 0) {
538 osOperation |= OS.NSDragOperationLink; 544 osOperation |= OS.NSDragOperationLink;
541 osOperation |= OS.NSDragOperationMove; 547 osOperation |= OS.NSDragOperationMove;
542 } 548 }
543 if ((operation & DND.DROP_TARGET_MOVE) !is 0) { 549 if ((operation & DND.DROP_TARGET_MOVE) !is 0) {
544 osOperation |= OS.NSDragOperationDelete; 550 osOperation |= OS.NSDragOperationDelete;
545 } 551 }
546 return osOperation; 552 return cast(int) osOperation;
547 } 553 }
548 554
549 int osOpToOp(int /*long*/ osOperation){ 555 int osOpToOp(NSDragOperation osOperation){
550 int operation = 0; 556 int operation = 0;
551 if ((osOperation & OS.NSDragOperationCopy) !is 0){ 557 if ((osOperation & OS.NSDragOperationCopy) !is 0){
552 operation |= DND.DROP_COPY; 558 operation |= DND.DROP_COPY;
553 } 559 }
554 if ((osOperation & OS.NSDragOperationLink) !is 0) { 560 if ((osOperation & OS.NSDragOperationLink) !is 0) {
567 } 573 }
568 574
569 bool performDragOperation(NSObject sender) { 575 bool performDragOperation(NSObject sender) {
570 DNDEvent event = new DNDEvent(); 576 DNDEvent event = new DNDEvent();
571 event.widget = this; 577 event.widget = this;
572 event.time = (int)System.currentTimeMillis(); 578 event.time = cast(int)System.currentTimeMillis();
573 579
574 if (dropEffect !is null) { 580 if (dropEffect !is null) {
575 NSPoint mouseLocation = sender.draggingLocation(); 581 NSPoint mouseLocation = sender.draggingLocation();
576 NSPoint globalLoc = sender.draggingDestinationWindow().convertBaseToScreen(mouseLocation); 582 NSPoint globalLoc = sender.draggingDestinationWindow().convertBaseToScreen(mouseLocation);
577 event.item = dropEffect.getItem((int)globalLoc.x, (int)globalLoc.y); 583 event.item = dropEffect.getItem(cast(int)globalLoc.x, cast(int)globalLoc.y);
578 } 584 }
579 585
580 event.detail = DND.DROP_NONE; 586 event.detail = DND.DROP_NONE;
581 notifyListeners(DND.DragLeave, event); 587 notifyListeners(DND.DragLeave, event);
582 588
723 bool setEventData(NSObject draggingState, DNDEvent event) { 729 bool setEventData(NSObject draggingState, DNDEvent event) {
724 if (draggingState is null) return false; 730 if (draggingState is null) return false;
725 731
726 // get allowed operations 732 // get allowed operations
727 int style = getStyle(); 733 int style = getStyle();
728 int /*long*/ allowedActions = draggingState.draggingSourceOperationMask(); 734 NSDragOperation allowedActions = draggingState.draggingSourceOperationMask();
729 int operations = osOpToOp(allowedActions) & style; 735 int operations = osOpToOp(allowedActions) & style;
730 if (operations is DND.DROP_NONE) return false; 736 if (operations is DND.DROP_NONE) return false;
731 737
732 // get current operation 738 // get current operation
733 int operation = getOperationFromKeyState(); 739 int operation = getOperationFromKeyState();
744 // get allowed transfer types 750 // get allowed transfer types
745 NSPasteboard dragPBoard = draggingState.draggingPasteboard(); 751 NSPasteboard dragPBoard = draggingState.draggingPasteboard();
746 NSArray draggedTypes = dragPBoard.types(); 752 NSArray draggedTypes = dragPBoard.types();
747 if (draggedTypes is null) return false; 753 if (draggedTypes is null) return false;
748 754
749 int /*long*/ draggedTypeCount = draggedTypes.count(); 755 NSUInteger draggedTypeCount = draggedTypes.count();
750 756
751 TransferData[] dataTypes = new TransferData[(int)draggedTypeCount]; 757 TransferData[] dataTypes = new TransferData[draggedTypeCount];
752 int index = -1; 758 int index = -1;
753 for (int i = 0; i < draggedTypeCount; i++) { 759 for (int i = 0; i < draggedTypeCount; i++) {
754 id draggedType = draggedTypes.objectAtIndex(i); 760 id draggedType = draggedTypes.objectAtIndex(i);
755 NSString nativeDataType = new NSString(draggedType); 761 NSString nativeDataType = new NSString(draggedType);
756 TransferData data = new TransferData(); 762 TransferData data = new TransferData();
774 780
775 // Convert from window-relative to global coordinates, and flip it. 781 // Convert from window-relative to global coordinates, and flip it.
776 NSPoint mouse = draggingState.draggingLocation(); 782 NSPoint mouse = draggingState.draggingLocation();
777 NSPoint globalMouse = draggingState.draggingDestinationWindow().convertBaseToScreen(mouse); 783 NSPoint globalMouse = draggingState.draggingDestinationWindow().convertBaseToScreen(mouse);
778 NSArray screens = NSScreen.screens(); 784 NSArray screens = NSScreen.screens();
779 NSRect screenRect = new NSScreen(screens.objectAtIndex(0)).frame(); 785 NSRect screenRect = (new NSScreen(screens.objectAtIndex(0))).frame();
780 globalMouse.y = screenRect.height - globalMouse.y; 786 globalMouse.y = screenRect.height - globalMouse.y;
781 787
782 event.widget = this; 788 event.widget = this;
783 event.x = (int)globalMouse.x; 789 event.x = cast(int)globalMouse.x;
784 event.y = (int)globalMouse.y; 790 event.y = cast(int)globalMouse.y;
785 event.time = (int)System.currentTimeMillis(); 791 event.time = cast(int)System.currentTimeMillis();
786 event.feedback = DND.FEEDBACK_SELECT; 792 event.feedback = DND.FEEDBACK_SELECT;
787 event.dataTypes = dataTypes; 793 event.dataTypes = dataTypes;
788 event.dataType = dataTypes[0]; 794 event.dataType = dataTypes[0];
789 event.operations = operations; 795 event.operations = operations;
790 event.detail = operation; 796 event.detail = operation;
813 this.transferAgents = transferAgents; 819 this.transferAgents = transferAgents;
814 820
815 821
816 // Register the types as valid drop types in Cocoa. 822 // Register the types as valid drop types in Cocoa.
817 // Accumulate all of the transfer types into a list. 823 // Accumulate all of the transfer types into a list.
818 ArrayList typeStrings = new ArrayList(); 824 String[] typeStrings;
819 825
820 for (int i = 0; i < this.transferAgents.length; i++) { 826 for (int i = 0; i < this.transferAgents.length; i++) {
821 String[] types = transferAgents[i].getTypeNames(); 827 String[] types = transferAgents[i].getTypeNames();
822 828
823 for (int j = 0; j < types.length; j++) { 829 for (int j = 0; j < types.length; j++) {
828 // Convert to an NSArray of NSStrings so we can register with the Control. 834 // Convert to an NSArray of NSStrings so we can register with the Control.
829 int typeStringCount = typeStrings.size(); 835 int typeStringCount = typeStrings.size();
830 NSMutableArray nsTypeStrings = NSMutableArray.arrayWithCapacity(typeStringCount); 836 NSMutableArray nsTypeStrings = NSMutableArray.arrayWithCapacity(typeStringCount);
831 837
832 for (int i = 0; i < typeStringCount; i++) { 838 for (int i = 0; i < typeStringCount; i++) {
833 nsTypeStrings.addObject(NSString.stringWith((String)typeStrings.get(i))); 839 nsTypeStrings.addObject(NSString.stringWith(cast(String)typeStrings.get(i)));
834 } 840 }
835 841
836 control.view.registerForDraggedTypes(nsTypeStrings); 842 control.view.registerForDraggedTypes(nsTypeStrings);
837 843
838 } 844 }