summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeronika Irvine <veronika>2002-10-21 18:21:01 +0000
committerVeronika Irvine <veronika>2002-10-21 18:21:01 +0000
commitccb1621e86ec1e366f7345535e8b1aeebd65f08f (patch)
tree6ea8f7cd8c578f9d75e311bc1450ab4114ee7b8c
parent3ce358e1b9f688d0f92464d74a73597dda5fa631 (diff)
downloadeclipse.platform.swt-ccb1621e86ec1e366f7345535e8b1aeebd65f08f.tar.gz
eclipse.platform.swt-ccb1621e86ec1e366f7345535e8b1aeebd65f08f.tar.xz
eclipse.platform.swt-ccb1621e86ec1e366f7345535e8b1aeebd65f08f.zip
Adding check for already existing Drop target or Drag source for widget
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java18
2 files changed, 23 insertions, 9 deletions
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 ce9835f5a9..e4c85e7315 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
@@ -103,7 +103,8 @@ public class DragSource extends Widget {
private Listener controlListener;
private int dataEffect;
-
+
+ private static final String DRAGSOURCEID = "DragSource";
/**
* Creates a new <code>DragSource</code> to handle dragging from the specified <code>Control</code>.
* Creating an instance of a DragSource may cause system resources to be allocated depending on the platform.
@@ -116,6 +117,8 @@ public class DragSource extends Widget {
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_INIT_DRAG - unable to initiate drag source</li>
* </ul>
*
* @see DragSource#dispose
@@ -128,11 +131,11 @@ public class DragSource extends Widget {
public DragSource(Control control, int style) {
super (control, checkStyle (style));
-
this.control = control;
-
+ if (control.getData(DRAGSOURCEID) != null)
+ DND.error(DND.ERROR_CANNOT_INIT_DRAG);
+ control.setData(DRAGSOURCEID, this);
createCOMInterfaces();
-
this.AddRef();
controlListener = new Listener () {
@@ -232,7 +235,8 @@ private void onDispose () {
control.removeListener(SWT.Dispose, controlListener);
control.removeListener(SWT.DragDetect, controlListener);
}
- controlListener = null;
+ controlListener = null;
+ control.setData(DRAGSOURCEID, null);
control = null;
transferAgents = null;
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 698d0769d1..d64d99ac47 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
@@ -7,7 +7,6 @@ package org.eclipse.swt.dnd;
* http://www.eclipse.org/legal/cpl-v10.html
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.ole.win32.*;
import org.eclipse.swt.internal.ole.win32.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
@@ -88,6 +87,7 @@ public class DropTarget extends Widget {
private int iDataObject;
+ private static final String DROPTARGETID = "DropTarget";
/**
* Creates a new <code>DropTarget</code> to allow data to be dropped on the specified
* <code>Control</code>.
@@ -99,6 +99,13 @@ public class DropTarget extends Widget {
* @param style the bitwise OR'ing of allowed operations; this may be a combination of any of
* DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
*
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_INIT_DROP - unable to initiate drop target</li>
+ * </ul>
+ *
* @see DropTarget#dispose
* @see DropTarget#checkSubclass
* @see DND#DROP_NONE
@@ -109,11 +116,13 @@ public class DropTarget extends Widget {
public DropTarget(Control control, int style) {
super (control, checkStyle(style));
-
this.control = control;
-
+ if (control.getData(DROPTARGETID) != null)
+ DND.error(DND.ERROR_CANNOT_INIT_DROP);
+ control.setData(DROPTARGETID, this);
createCOMInterfaces();
-
+ this.AddRef();
+
int result = 0;
if ((result = COM.CoLockObjectExternal(iDropTarget.getAddress(), true, true)) != COM.S_OK)
DND.error(DND.ERROR_CANNOT_INIT_DROP, result);
@@ -214,6 +223,7 @@ private void onDispose () {
if (controlListener != null)
control.removeListener(SWT.Dispose, controlListener);
controlListener = null;
+ control.setData(DROPTARGETID, null);
transferAgents = null;
control = null;