1 /******************************************************************************* 2 * Copyright (c) 2000, 2007 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Port to the D programming language: 11 * Frank Benoit <benoit@tionex.de> 12 *******************************************************************************/ 13 module org.eclipse.swt.dnd.DNDListener; 14 15 import java.lang.all; 16 17 18 import org.eclipse.swt.internal.SWTEventListener; 19 import org.eclipse.swt.widgets.Event; 20 import org.eclipse.swt.widgets.TypedListener; 21 import org.eclipse.swt.widgets.Widget; 22 import org.eclipse.swt.dnd.DND; 23 import org.eclipse.swt.dnd.DNDEvent; 24 import org.eclipse.swt.dnd.DragSourceEvent; 25 import org.eclipse.swt.dnd.DragSourceEffect; 26 import org.eclipse.swt.dnd.DragSource; 27 import org.eclipse.swt.dnd.DragSourceListener; 28 import org.eclipse.swt.dnd.DropTargetEvent; 29 import org.eclipse.swt.dnd.DropTargetListener; 30 import org.eclipse.swt.dnd.DropTargetEffect; 31 import org.eclipse.swt.dnd.DropTarget; 32 33 34 class DNDListener : TypedListener { 35 Widget dndWidget; 36 /** 37 * DNDListener constructor comment. 38 * @param listener org.eclipse.swt.internal.SWTEventListener 39 */ 40 this(SWTEventListener listener) { 41 super(listener); 42 } 43 public override void handleEvent (Event e) { 44 switch (e.type) { 45 case DND.DragStart: { 46 DragSourceEvent event = new DragSourceEvent(cast(DNDEvent)e); 47 DragSourceEffect sourceEffect = (cast(DragSource) dndWidget).getDragSourceEffect(); 48 if (sourceEffect !is null) { 49 sourceEffect.dragStart (event); 50 } 51 (cast(DragSourceListener) eventListener).dragStart (event); 52 event.updateEvent(cast(DNDEvent)e); 53 break; 54 } 55 case DND.DragEnd: { 56 DragSourceEvent event = new DragSourceEvent(cast(DNDEvent)e); 57 DragSourceEffect sourceEffect = (cast(DragSource) dndWidget).getDragSourceEffect(); 58 if (sourceEffect !is null) { 59 sourceEffect.dragFinished (event); 60 } 61 (cast(DragSourceListener) eventListener).dragFinished (event); 62 event.updateEvent(cast(DNDEvent)e); 63 break; 64 } 65 case DND.DragSetData: { 66 DragSourceEvent event = new DragSourceEvent(cast(DNDEvent)e); 67 DragSourceEffect sourceEffect = (cast(DragSource) dndWidget).getDragSourceEffect(); 68 if (sourceEffect !is null) { 69 sourceEffect.dragSetData (event); 70 } 71 (cast(DragSourceListener) eventListener).dragSetData (event); 72 event.updateEvent(cast(DNDEvent)e); 73 break; 74 } 75 case DND.DragEnter: { 76 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 77 (cast(DropTargetListener) eventListener).dragEnter (event); 78 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 79 if (dropEffect !is null) { 80 dropEffect.dragEnter (event); 81 } 82 event.updateEvent(cast(DNDEvent)e); 83 break; 84 } 85 case DND.DragLeave: { 86 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 87 (cast(DropTargetListener) eventListener).dragLeave (event); 88 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 89 if (dropEffect !is null) { 90 dropEffect.dragLeave (event); 91 } 92 event.updateEvent(cast(DNDEvent)e); 93 break; 94 } 95 case DND.DragOver: { 96 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 97 (cast(DropTargetListener) eventListener).dragOver (event); 98 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 99 if (dropEffect !is null) { 100 dropEffect.dragOver (event); 101 } 102 event.updateEvent(cast(DNDEvent)e); 103 break; 104 } 105 case DND.Drop: { 106 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 107 (cast(DropTargetListener) eventListener).drop (event); 108 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 109 if (dropEffect !is null) { 110 dropEffect.drop (event); 111 } 112 event.updateEvent(cast(DNDEvent)e); 113 break; 114 } 115 case DND.DropAccept: { 116 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 117 (cast(DropTargetListener) eventListener).dropAccept (event); 118 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 119 if (dropEffect !is null) { 120 dropEffect.dropAccept (event); 121 } 122 event.updateEvent(cast(DNDEvent)e); 123 break; 124 } 125 case DND.DragOperationChanged: { 126 DropTargetEvent event = new DropTargetEvent(cast(DNDEvent)e); 127 (cast(DropTargetListener) eventListener).dragOperationChanged (event); 128 DropTargetEffect dropEffect = (cast(DropTarget) dndWidget).getDropTargetEffect(); 129 if (dropEffect !is null) { 130 dropEffect.dragOperationChanged (event); 131 } 132 event.updateEvent(cast(DNDEvent)e); 133 break; 134 } 135 default: 136 137 } 138 } 139 }