diff options
author | Steve Northover <steve> | 2007-01-17 20:24:01 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2007-01-17 20:24:01 +0000 |
commit | 87a5577180665113b16265c4ebf6e25ec051e930 (patch) | |
tree | c388005af47aba48cc24eb441a386e98e9352312 /bundles/org.eclipse.swt/Eclipse SWT Drag and Drop | |
parent | f47b3e2ede05e46adfeccf944bb1b7ef0c909fb7 (diff) | |
download | eclipse.platform.swt-87a5577180665113b16265c4ebf6e25ec051e930.tar.gz eclipse.platform.swt-87a5577180665113b16265c4ebf6e25ec051e930.tar.xz eclipse.platform.swt-87a5577180665113b16265c4ebf6e25ec051e930.zip |
142947 - [DND] Classes to provide drag under feedback should be public
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Drag and Drop')
6 files changed, 125 insertions, 140 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 e9d2fa0f94..901b2d3444 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 @@ -177,6 +177,10 @@ public DragSource(Control control, int style) { Object effect = control.getData(DEFAULT_DRAG_SOURCE_EFFECT); if (effect instanceof DragSourceEffect) { dragEffect = (DragSourceEffect) effect; + } else if (control instanceof Tree) { + dragEffect = new TreeDragSourceEffect((Tree) control); + } else if (control instanceof Table) { + dragEffect = new TableDragSourceEffect((Table) control); } } 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 d3eabbf5cc..2746408c24 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 @@ -171,9 +171,9 @@ public DropTarget(Control control, int style) { if (effect instanceof DropTargetEffect) { dropEffect = (DropTargetEffect) effect; } else if (control instanceof Table) { - dropEffect = new TableDropTargetEffect(); + dropEffect = new TableDropTargetEffect((Table) control); } else if (control instanceof Tree) { - dropEffect = new TreeDropTargetEffect(); + dropEffect = new TreeDropTargetEffect((Tree) control); } dragOverHeartbeat = new Runnable() { @@ -201,7 +201,9 @@ public DropTarget(Control control, int style) { event.dataType = selectedDataType; event.operations = dragOverEvent.operations; event.detail = selectedOperation; - event.item = getItem(getControl(), event.x, event.y); + if (dropEffect != null) { + event.item = dropEffect.getItem(event.x, event.y); + } selectedDataType = null; selectedOperation = DND.DROP_NONE; notifyListeners(DND.DragOver, event); @@ -519,11 +521,11 @@ public Control getControl () { } /** - * Specifies the drop effect for this DropTarget. This drop effect will be + * 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. - * - * @param effect the drop effect that is registered for this DropTarget + * + * @return the drop effect that is registered for this DropTarget * * @since 3.3 */ @@ -531,47 +533,6 @@ public DropTargetEffect getDropTargetEffect() { return dropEffect; } -Widget getItem(Control control, int x, int y) { - org.eclipse.swt.graphics.Point coordinates = new org.eclipse.swt.graphics.Point(x, y); - coordinates = control.toControl(coordinates); - Item item = null; - - if (control instanceof Table) { - Table table = (Table) control; - item = table.getItem(coordinates); - if (item == null) { - org.eclipse.swt.graphics.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++) { - org.eclipse.swt.graphics.Point pt = new org.eclipse.swt.graphics.Point(x1, coordinates.y); - item = table.getItem(pt); - if (item != null) { - break; - } - } - } - } - } else if (control instanceof Tree) { - Tree tree = (Tree) control; - item = tree.getItem(coordinates); - if (item == null) { - org.eclipse.swt.graphics.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++) { - org.eclipse.swt.graphics.Point pt = new org.eclipse.swt.graphics.Point(x1, coordinates.y); - item = tree.getItem(pt); - if (item != null) { - break; - } - } - } - } - } - return item; -} - int getOperationFromKeyState(int theDrag) { short[] modifiers = new short[1]; OS.GetDragModifiers(theDrag, modifiers, null, null); @@ -764,7 +725,9 @@ boolean setEventData(int theDrag, DNDEvent event) { event.dataType = dataTypes[0]; event.operations = operations; event.detail = operation; - event.item = getItem(getControl(), event.x, event.y); + if (dropEffect != null) { + event.item = dropEffect.getItem(event.x, event.y); + } return true; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java new file mode 100644 index 0000000000..e2402bf730 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007 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.widgets.*; + +/** + * This class provides default implementations to display a source image + * when a drag is initiated from a <code>Table</code>. + * + * <p>Classes that wish to provide their own source image for a <code>Table</code> can + * extend the <code>DragSourceAdapter</code> class, override the + * <code>DragSourceAdapter.dragStart</code> method and set the field + * <code>DragSourceEvent.image</code> with their own image.</p> + * + * Subclasses that override any methods of this class must call the corresponding + * <code>super</code> method to get the default drag source effect implementation. + * + * @see DragSourceAdapter + * @see DragSourceEvent + * + * @since 3.3 + */ +public class TableDragSourceEffect extends DragSourceEffect { + /** + * Creates a new <code>TableDragSourceEffect</code> to handle drag effect + * from the specified <code>Table</code>. + * + * @param table the <code>Table</code> that the user clicks on to initiate the drag + **/ + public TableDragSourceEffect(Table table) { + super(table); + } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java index 11745a15d1..9f1ae034cb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java @@ -17,7 +17,7 @@ import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.widgets.*; -/*public*/ class TableDropTargetEffect extends DropTargetEffect { +public class TableDropTargetEffect extends DropTargetEffect { static final int SCROLL_HYSTERESIS = 150; // milli seconds TableItem scrollItem; @@ -46,16 +46,22 @@ import org.eclipse.swt.widgets.*; return (DropTarget)widget.getData(DropTarget.DROPTARGETID); } + /** + * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified + * <code>Table</code>. + * + * @param table the <code>Table</code> over which the user positions the cursor to drop the data + */ + public TableDropTargetEffect(Table table) { + super(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; } - - boolean checkWidget(DropTargetEvent event) { - return ((DropTarget) event.widget).getControl() instanceof Table; - } /** * This implementation of <code>dragEnter</code> provides a default drag under effect @@ -72,9 +78,8 @@ import org.eclipse.swt.widgets.*; * @see DropTargetEvent */ public void dragEnter(DropTargetEvent event) { - if (!checkWidget(event)) return; if (callbacks == null) { - Table table = (Table)((DropTarget)event.widget).getControl(); + Table table = (Table) control; DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); OS.GetDataBrowserCallbacks (table.handle, callbacks); callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); @@ -121,8 +126,7 @@ import org.eclipse.swt.widgets.*; * @see DND#FEEDBACK_SCROLL */ public void dragOver(DropTargetEvent event) { - if (!checkWidget(event)) return; - Table table = (Table)((DropTarget)event.widget).getControl(); + Table table = (Table) control; int effect = checkEffect(event.feedback); TableItem item = (TableItem)getItem(table, event.x, event.y); @@ -160,24 +164,4 @@ import org.eclipse.swt.widgets.*; // store current effect for selection feedback ((DropTarget)event.widget).feedback = effect; } - - Widget getItem(Table table, 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; - } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java new file mode 100644 index 0000000000..d78790cbeb --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007 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.widgets.*; + +/** + * This class provides default implementations to display a source image + * when a drag is initiated from a <code>Tree</code>. + * + * <p>Classes that wish to provide their own source image for a <code>Table</code> can + * extend <code>DragSourceAdapter</code> class and override the <code>DragSourceAdapter.dragStart</code> + * method and set the field <code>DragSourceEvent.image</code> with their own image.</p> + * + * Subclasses that override any methods of this class must call the corresponding + * <code>super</code> method to get the default drag under effect implementation. + * + * @see DragSourceAdapter + * @see DragSourceEvent + * + * @since 3.3 + */ +public class TreeDragSourceEffect extends DragSourceEffect { + /** + * Creates a new <code>TreeDragSourceEffect</code> to handle drag effect + * from the specified <code>Tree</code>. + * + * @param table the <code>Tree</code> that the user clicks on to initiate the drag + **/ + public TreeDragSourceEffect(Tree tree) { + super(tree); + } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java index 1ab944460b..e33b1bcce9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java @@ -17,7 +17,7 @@ import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.widgets.*; -/*public*/ class TreeDropTargetEffect extends DropTargetEffect { +public class TreeDropTargetEffect extends DropTargetEffect { static final int SCROLL_HYSTERESIS = 150; // milli seconds static final int EXPAND_HYSTERESIS = 300; // milli seconds @@ -61,6 +61,16 @@ import org.eclipse.swt.widgets.*; return (DropTarget)widget.getData(DropTarget.DROPTARGETID); } + /** + * Creates a new <code>TreeDropTargetEffect</code> to handle the drag under effect on the specified + * <code>Tree</code>. + * + * @param tree the <code>Tree</code> over which the user positions the cursor to drop the data + */ + public TreeDropTargetEffect(Tree tree) { + super(tree); + } + 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; @@ -68,10 +78,6 @@ import org.eclipse.swt.widgets.*; return effect; } - boolean checkWidget(DropTargetEvent event) { - return ((DropTarget) event.widget).getControl() instanceof Tree; - } - /** * This implementation of <code>dragEnter</code> provides a default drag under effect * for the feedback specified in <code>event.feedback</code>. @@ -87,9 +93,8 @@ import org.eclipse.swt.widgets.*; * @see DropTargetEvent */ public void dragEnter(DropTargetEvent event) { - if (!checkWidget(event)) return; if (callbacks == null) { - Tree table = (Tree)((DropTarget)event.widget).getControl(); + Tree table = (Tree) control; DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); OS.GetDataBrowserCallbacks (table.handle, callbacks); callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); @@ -117,8 +122,7 @@ import org.eclipse.swt.widgets.*; * @see DropTargetEvent */ public void dragLeave(DropTargetEvent event) { - if (!checkWidget(event)) return; - Tree tree = (Tree)((DropTarget)event.widget).getControl(); + Tree tree = (Tree) control; if (insertItem != null) { setInsertMark(tree, null, false); insertItem = null; @@ -148,8 +152,7 @@ import org.eclipse.swt.widgets.*; * @see DND#FEEDBACK_SCROLL */ public void dragOver(DropTargetEvent event) { - if (!checkWidget(event)) return; - Tree tree = (Tree)((DropTarget)event.widget).getControl(); + Tree tree = (Tree) control; TreeItem item = (TreeItem)getItem(tree, event.x, event.y); int effect = checkEffect(event.feedback); if ((effect & DND.FEEDBACK_EXPAND) == 0) { @@ -221,58 +224,6 @@ import org.eclipse.swt.widgets.*; ((DropTarget)event.widget).feedback = effect; } - Widget getItem(Tree tree, 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; - } - - TreeItem nextItem(Tree tree, TreeItem item) { - if (item == null) return null; - if (item.getExpanded()) return item.getItem(0); - TreeItem childItem = item; - TreeItem parentItem = childItem.getParentItem(); - int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); - int count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); - while (true) { - if (index + 1 < count) return parentItem == null ? tree.getItem(index + 1) : parentItem.getItem(index + 1); - if (parentItem == null) return null; - childItem = parentItem; - parentItem = childItem.getParentItem(); - index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); - count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); - } - } - - TreeItem previousItem(Tree tree, TreeItem item) { - if (item == null) return null; - TreeItem childItem = item; - TreeItem parentItem = childItem.getParentItem(); - int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); - if (index == 0) return parentItem; - TreeItem nextItem = parentItem == null ? tree.getItem(index-1) : parentItem.getItem(index-1); - int count = nextItem.getItemCount(); - while (count > 0 && nextItem.getExpanded()) { - nextItem = nextItem.getItem(count - 1); - count = nextItem.getItemCount(); - } - return nextItem; - } - void setInsertMark(Tree tree, TreeItem item, boolean before) { if (item == insertItem && before == insertBefore) return; insertItem = item; |