diff options
author | Veronika Irvine <veronika> | 2006-02-08 19:10:41 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2006-02-08 19:10:41 +0000 |
commit | 00da0905d97ffea48b43d35672001260f4e19536 (patch) | |
tree | b0b462c4d1ac300e82d96ab30f947f436a7a092e | |
parent | 5be5fff68efd319c9da7258093d3f3f2cda599f7 (diff) | |
download | eclipse.platform.swt-00da0905d97ffea48b43d35672001260f4e19536.tar.gz eclipse.platform.swt-00da0905d97ffea48b43d35672001260f4e19536.tar.xz eclipse.platform.swt-00da0905d97ffea48b43d35672001260f4e19536.zip |
Add drag over image support
6 files changed, 74 insertions, 48 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java index e283d835fd..852293158a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java @@ -12,8 +12,10 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.internal.Callback; +import org.eclipse.swt.internal.carbon.CGPoint; import org.eclipse.swt.internal.carbon.EventRecord; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.internal.carbon.Point; @@ -100,6 +102,7 @@ public class DragSource extends Widget { Control control; Listener controlListener; Transfer[] transferAgents = new Transfer[0]; + DragAndDropEffect effect; static final String DRAGSOURCEID = "DragSource"; //$NON-NLS-1$ static Callback DragSendDataProc; @@ -169,6 +172,15 @@ public DragSource(Control control, int style) { onDispose(); } }); + + // Drag and drop effect + if (control instanceof Tree) { + effect = new TreeDragAndDropEffect((Tree)control); + } else if (control instanceof Table) { + effect = new TableDragAndDropEffect((Table)control); + } else { + effect = new NoDragAndDropEffect(control); + } } static int checkStyle (int style) { @@ -300,27 +312,38 @@ void drag(Event dragEvent) { OS.SetDragAllowableActions(theDrag[0], operations, true); OS.SetDragAllowableActions(theDrag[0], operations, false); - EventRecord theEvent = new EventRecord(); - theEvent.message = OS.kEventMouseMoved; - theEvent.modifiers = (short)OS.GetCurrentEventKeyModifiers(); - theEvent.what = (short)OS.osEvt; - theEvent.where_h = (short)pt.h; - theEvent.where_v = (short)pt.v; - int result = OS.TrackDrag(theDrag[0], theEvent, theRegion); - - int operation = DND.DROP_NONE; - if (result == OS.noErr) { - int[] outAction = new int[1]; - OS.GetDragDropAction(theDrag[0], outAction); - operation = osOpToOp(outAction[0]); + ImageData imageData = effect.getDragSourceImage(dragEvent.x, dragEvent.y); + Image image = null; + try { + if (imageData != null) { + image = new Image(getDisplay(), imageData); + CGPoint imageOffsetPt = new CGPoint(); + imageOffsetPt.x = 5; + imageOffsetPt.y = 5; + OS.SetDragImageWithCGImage(theDrag[0], image.handle, imageOffsetPt, 0); //kDragStandardTranslucency + } + EventRecord theEvent = new EventRecord(); + theEvent.message = OS.kEventMouseMoved; + theEvent.modifiers = (short)OS.GetCurrentEventKeyModifiers(); + theEvent.what = (short)OS.osEvt; + theEvent.where_h = pt.h; + theEvent.where_v = pt.v; + int result = OS.TrackDrag(theDrag[0], theEvent, theRegion); + int operation = DND.DROP_NONE; + if (result == OS.noErr) { + int[] outAction = new int[1]; + OS.GetDragDropAction(theDrag[0], outAction); + operation = osOpToOp(outAction[0]); + } + event = new DNDEvent(); + event.widget = this; + event.time = (int)System.currentTimeMillis(); + event.doit = result == OS.noErr; + event.detail = operation; + notifyListeners(DND.DragEnd, event); + } finally { + if (image != null) image.dispose(); } - - event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.doit = result == OS.noErr; - event.detail = operation; - notifyListeners(DND.DragEnd, event); } finally { if (theRegion != 0) OS.DisposeRgn(theRegion); } 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 c6bb3a326d..042eca8d29 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 @@ -72,7 +72,7 @@ public class DropTarget extends Widget { Control control; Listener controlListener; Transfer[] transferAgents = new Transfer[0]; - DragUnderEffect effect; + DragAndDropEffect effect; // Track application selections TransferData selectedDataType; @@ -165,13 +165,13 @@ public DropTarget(Control control, int style) { } }); - // Drag under effect + // Drag and drop 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); } dragOverHeartbeat = new Runnable() { @@ -203,7 +203,7 @@ public DropTarget(Control control, int style) { selectedDataType = null; selectedOperation = DND.DROP_NONE; notifyListeners(DND.DragOver, event); - effect.show(event.feedback, event.x, event.y); + effect.showDropTargetEffect(event.feedback, event.x, event.y); if (event.dataType != null) { for (int i = 0; i < allowedTypes.length; i++) { if (allowedTypes[i].type == event.dataType.type) { @@ -326,7 +326,7 @@ protected void checkSubclass () { int dragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { updateDragOverHover(0, null); - effect.show(DND.FEEDBACK_NONE, 0, 0); + effect.showDropTargetEffect(DND.FEEDBACK_NONE, 0, 0); if (keyOperation == -1) return OS.dragNotAcceptedErr; @@ -417,7 +417,7 @@ int dragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDr if (message == OS.kDragTrackingLeaveWindow) { updateDragOverHover(0, null); - effect.show(DND.FEEDBACK_NONE, 0, 0); + effect.showDropTargetEffect(DND.FEEDBACK_NONE, 0, 0); OS.SetThemeCursor(OS.kThemeArrowCursor); if (keyOperation == -1) return OS.dragNotAcceptedErr; keyOperation = -1; @@ -488,7 +488,7 @@ int dragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDr OS.SetDragDropAction(theDrag, opToOsOp(selectedOperation)); - effect.show(event.feedback, event.x, event.y); + effect.showDropTargetEffect(event.feedback, event.x, event.y); switch (selectedOperation) { case DND.DROP_COPY: 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/TableDragAndDropEffect.java index dd40aba88e..5386cfed29 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/TableDragAndDropEffect.java @@ -18,7 +18,7 @@ import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.widgets.*; -class TableDragUnderEffect extends DragUnderEffect { +class TableDragAndDropEffect extends DragAndDropEffect { Table table; TableItem scrollItem; long scrollBeginTime; @@ -26,13 +26,13 @@ class TableDragUnderEffect extends DragUnderEffect { static Callback AcceptDragProc; static { - AcceptDragProc = new Callback(TableDragUnderEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ + AcceptDragProc = new Callback(TableDragAndDropEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ int acceptDragProc = AcceptDragProc.getAddress(); if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); } static final int SCROLL_HYSTERESIS = 150; // milli seconds -TableDragUnderEffect(Table table) { +TableDragAndDropEffect(Table table) { this.table = table; DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); OS.GetDataBrowserCallbacks (table.handle, callbacks); @@ -43,7 +43,7 @@ TableDragUnderEffect(Table table) { static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { DropTarget target = FindDropTarget(theControl, theDrag); if (target == null || target.effect == null) return 0; - TableDragUnderEffect effect = (TableDragUnderEffect)target.effect; + TableDragAndDropEffect effect = (TableDragAndDropEffect)target.effect; return effect.acceptDragProc(theControl, itemID, property, theRect, theDrag); } @@ -87,7 +87,7 @@ Widget getItem(int x, int y) { return item; } -void show(int effect, int x, int y) { +void showDropTargetEffect(int effect, int x, int y) { effect = checkEffect(effect); TableItem item = (TableItem)getItem(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/TreeDragAndDropEffect.java index ae48df2486..d1185123ff 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/TreeDragAndDropEffect.java @@ -18,7 +18,7 @@ import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.widgets.*; -class TreeDragUnderEffect extends DragUnderEffect { +class TreeDragAndDropEffect extends DragAndDropEffect { Tree tree; int currentEffect = DND.FEEDBACK_NONE; @@ -35,14 +35,14 @@ class TreeDragUnderEffect extends DragUnderEffect { static Callback AcceptDragProc; static { - AcceptDragProc = new Callback(TreeDragUnderEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ + AcceptDragProc = new Callback(TreeDragAndDropEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ int acceptDragProc = AcceptDragProc.getAddress(); if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); } static final int SCROLL_HYSTERESIS = 150; // milli seconds static final int EXPAND_HYSTERESIS = 300; // milli seconds -TreeDragUnderEffect(Tree tree) { +TreeDragAndDropEffect(Tree tree) { this.tree = tree; DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); OS.GetDataBrowserCallbacks (tree.handle, callbacks); @@ -53,7 +53,7 @@ TreeDragUnderEffect(Tree tree) { static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { DropTarget target = FindDropTarget(theControl, theDrag); if (target == null || target.effect == null) return 0; - TreeDragUnderEffect effect = (TreeDragUnderEffect)target.effect; + TreeDragAndDropEffect effect = (TreeDragAndDropEffect)target.effect; return effect.acceptDragProc(theControl, itemID, property, theRect, theDrag); } @@ -136,7 +136,7 @@ void setInsertMark(TreeItem item, boolean before) { tree.setInsertMark(item, before); } -void show(int effect, int x, int y) { +void showDropTargetEffect(int effect, int x, int y) { effect = checkEffect(effect); TreeItem item = (TreeItem)getItem(x, y); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/NoDragUnderEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DragAndDropEffect.java index b0930d78a1..57db5407bd 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/NoDragUnderEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DragAndDropEffect.java @@ -10,11 +10,15 @@ *******************************************************************************/ package org.eclipse.swt.dnd; - +import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; -class NoDragUnderEffect extends DragUnderEffect { +abstract class DragAndDropEffect { + +Widget getItem(int x, int y){return null;} + +ImageData getDragSourceImage(int x, int y){return null;} + +void showDropTargetEffect(int effect, int x, int y) {} -NoDragUnderEffect(Control control) {} -void show(int effect, int x, int y){} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DragUnderEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/NoDragAndDropEffect.java index 3317f77a6f..5b84a94b3b 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/DragUnderEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common/org/eclipse/swt/dnd/NoDragAndDropEffect.java @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.swt.dnd; -import org.eclipse.swt.widgets.*; -abstract class DragUnderEffect { - -void show(int effect, int x, int y) {} +import org.eclipse.swt.widgets.*; -Widget getItem(int x, int y){return null;} +class NoDragAndDropEffect extends DragAndDropEffect { +NoDragAndDropEffect(Control control) {} +void showDropTargetEffect(int effect, int x, int y){} } |