diff options
author | Veronika Irvine <veronika> | 2006-01-17 21:31:51 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2006-01-17 21:31:51 +0000 |
commit | 64605ca991b55a1d0eb43e382d0c6cb2dad19bc2 (patch) | |
tree | ba771843285bfb321c49cf1f95abfa4b3178b9b2 /bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse | |
parent | 75cdfc44c76a4d9bf742837d4c0e9103d21e063d (diff) | |
download | eclipse.platform.swt-64605ca991b55a1d0eb43e382d0c6cb2dad19bc2.tar.gz eclipse.platform.swt-64605ca991b55a1d0eb43e382d0c6cb2dad19bc2.tar.xz eclipse.platform.swt-64605ca991b55a1d0eb43e382d0c6cb2dad19bc2.zip |
Improve drag under effect support
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse')
3 files changed, 43 insertions, 13 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java index 0c1d5a2689..c6bb3a326d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java @@ -199,6 +199,7 @@ public DropTarget(Control control, int style) { event.dataType = selectedDataType; event.operations = dragOverEvent.operations; event.detail = selectedOperation; + event.item = effect.getItem(event.x, event.y); selectedDataType = null; selectedOperation = DND.DROP_NONE; notifyListeners(DND.DragOver, event); @@ -333,7 +334,8 @@ int dragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { event.widget = this; event.time = (int)System.currentTimeMillis(); event.detail = DND.DROP_NONE; - notifyListeners(DND.DragLeave, event); + notifyListeners(DND.DragLeave, event); + event = new DNDEvent(); if (!setEventData(theDrag, event)) { return OS.dragNotAcceptedErr; @@ -347,6 +349,7 @@ int dragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { selectedDataType = null; selectedOperation = DND.DROP_NONE; notifyListeners(DND.DropAccept, event); + if (event.dataType != null) { for (int i = 0; i < allowedDataTypes.length; i++) { if (allowedDataTypes[i].type == event.dataType.type) { @@ -537,18 +540,6 @@ public Transfer[] getTransfer() { return transferAgents; } -public void notifyListeners (int eventType, Event event) { - org.eclipse.swt.graphics.Point coordinates = new org.eclipse.swt.graphics.Point(event.x, event.y); - coordinates = control.toControl(coordinates); - if (this.control instanceof Tree) { - event.item = ((Tree)control).getItem(coordinates); - } - if (this.control instanceof Table) { - event.item = ((Table)control).getItem(coordinates); - } - super.notifyListeners(eventType, event); -} - void onDispose () { if (control == null) return; @@ -708,6 +699,7 @@ boolean setEventData(int theDrag, DNDEvent event) { event.dataType = dataTypes[0]; event.operations = operations; event.detail = operation; + event.item = effect.getItem(event.x, event.y); return true; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragUnderEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragUnderEffect.java index b8751dbfb2..a0f1b6d487 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragUnderEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragUnderEffect.java @@ -23,6 +23,25 @@ class TableDragUnderEffect extends DragUnderEffect { TableDragUnderEffect(Table table) { this.table = table; } +Widget getItem(int x, int y) { + Point coordinates = new Point(x, y); + coordinates = table.toControl(coordinates); + TableItem item = table.getItem(coordinates); + if (item == null) { + Rectangle area = table.getClientArea(); + if (area.contains(coordinates)) { + // Scan across the width of the tree. + for (int x1 = area.x; x1 < area.x + area.width; x1++) { + Point pt = new Point(x1, coordinates.y); + item = table.getItem(pt); + if (item != null) { + break; + } + } + } + } + return item; +} void show(int effect, int x, int y) { TableItem item = null; if (effect != DND.FEEDBACK_NONE) item = findItem(x, y); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragUnderEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragUnderEffect.java index 15254814d8..dd2e571250 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragUnderEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragUnderEffect.java @@ -24,6 +24,25 @@ class TreeDragUnderEffect extends DragUnderEffect { TreeDragUnderEffect(Tree tree) { this.tree = tree; } +Widget getItem(int x, int y) { + Point coordinates = new Point(x, y); + coordinates = tree.toControl(coordinates); + TreeItem item = tree.getItem(coordinates); + if (item == null) { + Rectangle area = tree.getClientArea(); + if (area.contains(coordinates)) { + // Scan across the width of the tree. + for (int x1 = area.x; x1 < area.x + area.width; x1++) { + Point pt = new Point(x1, coordinates.y); + item = tree.getItem(pt); + if (item != null) { + break; + } + } + } + } + return item; +} void show(int effect, int x, int y) { TreeItem item = null; if (effect != DND.FEEDBACK_NONE) item = findItem(x, y); |