changeset 113:2d6116ea306e

Ported dwt.dnd.TreeDropTargetEffect
author Jacob Carlborg <doob@me.com>
date Wed, 31 Dec 2008 15:09:06 +0100
parents a84f60dde47e
children d0d0b721dbcc
files dwt/dnd/TreeDropTargetEffect.d
diffstat 1 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dnd/TreeDropTargetEffect.d	Wed Dec 31 15:02:49 2008 +0100
+++ b/dwt/dnd/TreeDropTargetEffect.d	Wed Dec 31 15:09:06 2008 +0100
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.dnd.TreeDropTargetEffect;
 
@@ -19,6 +22,11 @@
 import dwt.widgets.Tree;
 import dwt.widgets.TreeItem;
 
+import dwt.dnd.DND;
+import dwt.dnd.DropTarget;
+import dwt.dnd.DropTargetEffect;
+import dwt.dnd.DropTargetEvent;
+
 /**
  * This class provides a default drag under effect (eg. select, insert, scroll and expand) 
  * when a drag occurs over a <code>Tree</code>.
@@ -52,9 +60,9 @@
  * 
  * @since 3.3
  */
-public class TreeDropTargetEffect extends DropTargetEffect {
-    static final int SCROLL_HYSTERESIS = 150; // milli seconds
-    static final int EXPAND_HYSTERESIS = 1000; // milli seconds
+public class TreeDropTargetEffect : DropTargetEffect {
+    static const int SCROLL_HYSTERESIS = 150; // milli seconds
+    static const int EXPAND_HYSTERESIS = 1000; // milli seconds
 
     int currentEffect = DND.FEEDBACK_NONE;
     TreeItem currentItem;
@@ -102,7 +110,7 @@
      * 
      * @param tree the <code>Tree</code> over which the user positions the cursor to drop the data
      */
-    public TreeDropTargetEffect(Tree tree) {
+    public this(Tree tree) {
         super(tree);
     }
 
@@ -157,7 +165,7 @@
      * @see DropTargetEvent
      */
     public void dragLeave(DropTargetEvent event) {
-        Tree tree = (Tree) control;
+        Tree tree = cast(Tree) control;
         if (insertItem !is null) {
             setInsertMark(tree, null, false);
             insertItem = null;
@@ -187,21 +195,21 @@
      * @see DND#FEEDBACK_SCROLL
      */
     public void dragOver(DropTargetEvent event) {
-        Tree tree = (Tree) control;
-        TreeItem item = (TreeItem)getItem(tree, event.x, event.y);
+        Tree tree = cast(Tree) control;
+        TreeItem item = cast(TreeItem)getItem(tree, event.x, event.y);
         int effect = checkEffect(event.feedback);       
         if ((effect & DND.FEEDBACK_EXPAND) is 0) {
             expandBeginTime = 0;
             expandItem = null;
         } else {
-            if (item !is null && item.equals(expandItem) && expandBeginTime !is 0) {
+            if (item !is null && item.opEquals(expandItem) && expandBeginTime !is 0) {
                 if (System.currentTimeMillis() >= expandBeginTime) {
                     if (item.getItemCount() > 0 && !item.getExpanded()) {
                         Event e = new Event();
                         e.x = event.x;
                         e.y = event.y;
                         e.item = item;
-                        e.time = (int) System.currentTimeMillis();
+                        e.time = cast(int) System.currentTimeMillis();
                         tree.notifyListeners(DWT.Expand, e);
                         if (item.isDisposed()) return;
                         item.setExpanded(true);
@@ -219,21 +227,21 @@
             scrollBeginTime = 0;
             scrollItem = null;
         } else {
-            if (item !is null && item.equals(scrollItem)  && scrollBeginTime !is 0) {
+            if (item !is null && item.opEquals(scrollItem)  && scrollBeginTime !is 0) {
                 if (System.currentTimeMillis() >= scrollBeginTime) {
                     Rectangle area = tree.getClientArea();
                     int headerHeight = tree.getHeaderHeight();
                     int itemHeight= tree.getItemHeight();
                     Point pt = new Point(event.x, event.y);
                     pt = tree.getDisplay().map(null, tree, pt);
-                    TreeItem nextItem = null;
+                    TreeItem nextItem_ = null;
                     if (pt.y < area.y + headerHeight + 2 * itemHeight) {
-                        nextItem = previousItem(tree, item);
+                        nextItem_ = previousItem(tree, item);
                     }
                     if (pt.y > area.y + area.height - 2 * itemHeight) {
-                        nextItem = nextItem(tree, item);
+                        nextItem_ = nextItem(tree, item);
                     }
-                    if (nextItem !is null) tree.showItem(nextItem);
+                    if (nextItem_ !is null) tree.showItem(nextItem_);
                     scrollBeginTime = 0;
                     scrollItem = null;
                 }
@@ -256,7 +264,7 @@
             setInsertMark(tree, null, false);
         }
         // save current effect for selection feedback
-        ((DropTarget)event.widget).feedback = effect;
+        (cast(DropTarget)event.widget).feedback = effect;
     }
 
     void setInsertMark(Tree tree, TreeItem item, bool before) {