diff options
author | Duong Nguyen <dnguyen> | 2008-01-31 22:58:08 +0000 |
---|---|---|
committer | Duong Nguyen <dnguyen> | 2008-01-31 22:58:08 +0000 |
commit | 561e3d6be0a2f38e577d80d7b6862dd5ba12489f (patch) | |
tree | 6ce5263f275a0af847a737e72b28c30f3410cebc | |
parent | 0fee062424c927acf1e0e0389ddd5c6943ce6f58 (diff) | |
download | eclipse.platform.swt-561e3d6be0a2f38e577d80d7b6862dd5ba12489f.tar.gz eclipse.platform.swt-561e3d6be0a2f38e577d80d7b6862dd5ba12489f.tar.xz eclipse.platform.swt-561e3d6be0a2f38e577d80d7b6862dd5ba12489f.zip |
Bug 215388 - Add API to make the DropTarget more open
5 files changed, 127 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DND.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DND.java index 3f1679e3fb..5fcdc684ec 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DND.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DND.java @@ -198,6 +198,8 @@ public class DND { * for a control using <code>getData(String)</code>. When a drop target * is created for a control, it is stored as a property in the control * using <code>setData(String, Object)</code>. + * + * @since 3.4 */ public static final String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$ @@ -206,6 +208,8 @@ public class DND { * for a control using <code>getData(String)</code>. When a drag source * is created for a control, it is stored as a property in the control * using <code>setData(String, Object)</code>. + * + * @since 3.4 */ public static final String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java index dfbd6e03c2..04c1f8a404 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java @@ -219,6 +219,7 @@ static int checkStyle(int style) { * </ul> * * @see DragSourceListener + * @see #getDragListeners * @see #removeDragListener * @see DragSourceEvent */ @@ -468,6 +469,42 @@ private int GetData(int /*long*/ pFormatetc, int /*long*/ pmedium) { } /** + * Returns an array of listeners who will be notified when a drag and drop + * operation is in progress, by sending it one of the messages defined in + * the <code>DragSourceListener</code> interface. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see DragSourceListener + * @see #addDragListener + * @see #removeDragListener + * @see DragSourceEvent + * + * @since 3.4 + */ +public DragSourceListener[] getDragListeners() { + Listener[] listeners = getListeners(DND.DragStart); + int length = listeners.length; + DragSourceListener[] dragListeners = new DragSourceListener[length]; + int count = 0; + for (int i = 0; i < length; i++) { + Listener listener = listeners[i]; + if (listener instanceof DNDListener) { + SWTEventListener eventListener = ((DNDListener) listener).getEventListener(); + dragListeners[count] = (DragSourceListener) eventListener; + count++; + } + } + if (count == length) return dragListeners; + DragSourceListener[] result = new DragSourceListener[count]; + System.arraycopy(dragListeners, 0, result, 0, count); + return result; +} + +/** * Returns the drag effect that is registered for this DragSource. This drag * effect will be used during a drag and drop operation. * @@ -630,6 +667,7 @@ private int Release() { * * @see DragSourceListener * @see #addDragListener + * @see #getDragListeners */ public void removeDragListener(DragSourceListener listener) { if (listener == null) DND.error(SWT.ERROR_NULL_ARGUMENT); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java index 691f292df7..d4a99c20de 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java @@ -197,6 +197,7 @@ static int checkStyle (int style) { * </ul> * * @see DropTargetListener + * @see #getDropListeners * @see #removeDropListener * @see DropTargetEvent */ @@ -472,6 +473,42 @@ public Control getControl () { } /** + * Returns an array of listeners who will be notified when a drag and drop + * operation is in progress, by sending it one of the messages defined in + * the <code>DropTargetListener</code> interface. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see DropTargetListener + * @see #addDropListener + * @see #removeDropListener + * @see DropTargetEvent + * + * @since 3.4 + */ +public DropTargetListener[] getDropListeners() { + Listener[] listeners = getListeners(DND.DragEnter); + int length = listeners.length; + DropTargetListener[] dropListeners = new DropTargetListener[length]; + int count = 0; + for (int i = 0; i < length; i++) { + Listener listener = listeners[i]; + if (listener instanceof DNDListener) { + SWTEventListener eventListener = ((DNDListener) listener).getEventListener(); + dropListeners[count] = (DropTargetListener) eventListener; + count++; + } + } + if (count == length) return dropListeners; + DropTargetListener[] result = new DropTargetListener[count]; + System.arraycopy(dropListeners, 0, result, 0, count); + return result; +} + +/** * Returns the drop effect for this DropTarget. This drop effect will be * used during a drag and drop to display the drag under effect on the * target widget. @@ -612,6 +649,7 @@ void refresh() { * * @see DropTargetListener * @see #addDropListener + * @see #getDropListeners */ public void removeDropListener(DropTargetListener listener) { if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java index 0184bec91e..86c15daa90 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java @@ -26,6 +26,24 @@ class EventTable { Listener [] listeners; int level; +public Listener[] getListeners(int eventType) { + if (types == null) return new Listener[0]; + int size = 0; + for (int i=0; i<types.length; i++) { + if (types [i] == eventType) size++; + } + Listener[] result = new Listener[size]; + if (size == 0) return result; + int count = 0; + for (int i=0; i<types.length; i++) { + if (types [i] == eventType) { + result[count] = listeners[i]; + count++; + } + } + return result; +} + public void hook (int eventType, Listener listener) { if (types == null) types = new int [4]; if (listeners == null) listeners = new Listener [4]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java index a966baf9b5..45427180d0 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java @@ -172,6 +172,7 @@ void _addListener (int eventType, Listener listener) { * * @see Listener * @see SWT + * @see #getListeners(int) * @see #removeListener(int, Listener) * @see #notifyListeners */ @@ -557,6 +558,32 @@ public Display getDisplay () { return display; } +/** + * Returns an array of listeners who will be notified when an event + * of the given type occurs. The event type is one of the event constants + * defined in class <code>SWT</code>. + * + * @param eventType the type of event to listen for + * @return an array of listeners that will be notified when the event occurs + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Listener + * @see SWT + * @see #addListener(int, Listener) + * @see #removeListener(int, Listener) + * @see #notifyListeners + * + * @since 3.4 + */ +public Listener[] getListeners (int eventType) { + checkWidget(); + return eventTable.getListeners(eventType); +} + Menu getMenu () { return null; } @@ -712,6 +739,7 @@ GC new_GC (GCData data) { * * @see SWT * @see #addListener + * @see #getListeners(int) * @see #removeListener(int, Listener) */ public void notifyListeners (int eventType, Event event) { @@ -860,6 +888,7 @@ void releaseWidget () { * @see Listener * @see SWT * @see #addListener + * @see #getListeners(int) * @see #notifyListeners */ public void removeListener (int eventType, Listener listener) { |