diff options
author | Veronika Irvine <veronika> | 2006-02-08 20:01:03 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2006-02-08 20:01:03 +0000 |
commit | 6d57a85cdffe2d0764c0d0a75e7dc90c1289ce1f (patch) | |
tree | 35bbf9d96035e29c9617dd9ed7b3353c432da8b9 | |
parent | 67ca7cc4f3dbbc15230a02c87fdbb628c3cffaf8 (diff) | |
download | eclipse.platform.swt-6d57a85cdffe2d0764c0d0a75e7dc90c1289ce1f.tar.gz eclipse.platform.swt-6d57a85cdffe2d0764c0d0a75e7dc90c1289ce1f.tar.xz eclipse.platform.swt-6d57a85cdffe2d0764c0d0a75e7dc90c1289ce1f.zip |
adding support for drag over image
2 files changed, 143 insertions, 7 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java index ac73970af9..03f2911d45 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java @@ -73,7 +73,7 @@ public class DropTarget extends Widget { Control control; Listener controlListener; Transfer[] transferAgents = new Transfer[0]; - DragUnderEffect effect; + DragAndDropEffect effect; // Track application selections TransferData selectedDataType; @@ -206,11 +206,11 @@ public DropTarget(Control control, int style) { // Drag under effect if (control instanceof Tree) { - effect = new TreeDragUnderEffect((Tree)control); + effect = new TreeDragAndDropEffect((Tree)control); } else if (control instanceof Table) { - effect = new TableDragUnderEffect((Table)control); + effect = new TableDragAndDropEffect((Table)control); } else { - effect = new NoDragUnderEffect(control); + effect = new NoDragAndDropEffect(control); } if (control.isVisible()) registerDropTarget(); @@ -243,7 +243,7 @@ public DropTarget(Control control, int style) { event.item = effect.getItem(dragOverEvent.x, dragOverEvent.y); notifyListeners(DND.DragOver, event); - effect.show(event.feedback, event.x, event.y); + effect.showDropTargetEffect(event.feedback, event.x, event.y); selectedDataType = null; if (event.dataType != null) { @@ -361,7 +361,7 @@ void dragProcCallback(int widget, int client_data, int call_data) { if (callbackData.reason == OS.XmCR_DROP_SITE_LEAVE_MESSAGE) { updateDragOverHover(0, null); - effect.show(DND.FEEDBACK_NONE, 0, 0); + effect.showDropTargetEffect(DND.FEEDBACK_NONE, 0, 0); if (callbackData.dropSiteStatus == OS.XmDROP_SITE_INVALID) { return; @@ -429,7 +429,7 @@ void dragProcCallback(int widget, int client_data, int call_data) { selectedOperation = event.detail; } - effect.show(event.feedback, event.x, event.y); + effect.showDropTargetEffect(event.feedback, event.x, event.y); callbackData.dropSiteStatus = (byte)OS.XmDROP_SITE_VALID; callbackData.operation = opToOsOp(selectedOperation); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDragAndDropEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDragAndDropEffect.java new file mode 100755 index 0000000000..20133b8069 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDragAndDropEffect.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.dnd; + +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.widgets.*; + +class TableDragAndDropEffect extends DragAndDropEffect { + Table table; + + int currentEffect = DND.FEEDBACK_NONE; + TableItem currentItem; + + PaintListener paintListener; + TableItem dropSelection = null; + + TableItem scrollItem; + long scrollBeginTime; + + static final int SCROLL_HYSTERESIS = 150; // milli seconds + +TableDragAndDropEffect(Table table) { + this.table = table; +} +int checkEffect(int effect) { + // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. + if ((effect & DND.FEEDBACK_SELECT) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE; + if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER; + return effect; +} +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 table. + 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 setDropSelection (TableItem item) { + if (item == dropSelection) return; + if (dropSelection != null && !dropSelection.isDisposed()) { + Rectangle bounds = dropSelection.getBounds(0); + table.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); + } + dropSelection = item; + if (dropSelection != null && !dropSelection.isDisposed()) { + Rectangle bounds = dropSelection.getBounds(0); + table.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); + } + if (dropSelection == null) { + if (paintListener != null) { + table.removePaintListener(paintListener); + paintListener = null; + } + } else { + if (paintListener == null) { + paintListener = new PaintListener() { + public void paintControl(PaintEvent e) { + if (dropSelection == null || dropSelection.isDisposed()) return; + GC gc = e.gc; + boolean xor = gc.getXORMode(); + gc.setXORMode(true); + Rectangle bounds = dropSelection.getBounds(0); + gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); + gc.setXORMode(xor); + } + }; + table.addPaintListener(paintListener); + } + } +} +void show(int effect, int x, int y) { + effect = checkEffect(effect); + TableItem item = (TableItem)getItem(x, y); + + if ((effect & DND.FEEDBACK_SCROLL) == 0) { + scrollBeginTime = 0; + scrollItem = null; + } else { + if (item != null && item.equals(scrollItem) && scrollBeginTime != 0) { + if (System.currentTimeMillis() >= scrollBeginTime) { + Rectangle area = table.getClientArea(); + int headerHeight = table.getHeaderHeight(); + int itemHeight= table.getItemHeight(); + Point pt = new Point(x, y); + pt = table.getDisplay().map(null, table, pt); + TableItem nextItem = null; + if (pt.y < area.y + headerHeight + 2 * itemHeight) { + int index = Math.max(0, table.indexOf(item)-1); + nextItem = table.getItem(index); + } + if (pt.y > area.y + area.height - 2 * itemHeight) { + int index = Math.min(table.getItemCount()-1, table.indexOf(item)+1); + nextItem = table.getItem(index); + } + if (nextItem != null) table.showItem(nextItem); + scrollBeginTime = 0; + scrollItem = null; + } + } else { + scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; + scrollItem = item; + } + } + + if ((effect & DND.FEEDBACK_SELECT) != 0) { + if (currentItem != item || (currentEffect & DND.FEEDBACK_SELECT) == 0) { + setDropSelection(item); + currentEffect = effect; + currentItem = item; + } + } else { + setDropSelection(null); + } +} +} |