diff dwt/dnd/TreeDropTargetEffect.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children 2d6116ea306e
line wrap: on
line diff
--- a/dwt/dnd/TreeDropTargetEffect.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/dnd/TreeDropTargetEffect.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -8,14 +8,16 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
-module dwt.dnd;
+module dwt.dnd.TreeDropTargetEffect;
+
+import dwt.dwthelper.utils;
 
-import dwt.*;
-import dwt.graphics.*;
-import dwt.internal.Callback;
-import dwt.internal.carbon.DataBrowserCallbacks;
-import dwt.internal.carbon.OS;
-import dwt.widgets.*;
+import dwt.DWT;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Event;
+import dwt.widgets.Tree;
+import dwt.widgets.TreeItem;
 
 /**
  * This class provides a default drag under effect (eg. select, insert, scroll and expand) 
@@ -46,10 +48,11 @@
  * 
  * @see DropTargetAdapter
  * @see DropTargetEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  * 
  * @since 3.3
  */
-public class TreeDropTargetEffect : DropTargetEffect {
+public class TreeDropTargetEffect extends DropTargetEffect {
     static final int SCROLL_HYSTERESIS = 150; // milli seconds
     static final int EXPAND_HYSTERESIS = 1000; // milli seconds
 
@@ -65,33 +68,33 @@
     TreeItem expandItem;
     long expandBeginTime;
     
-    DataBrowserCallbacks callbacks = null;
+//  DataBrowserCallbacks callbacks = null;
     
     int acceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) {
         return (currentEffect & DND.FEEDBACK_SELECT) !is 0 ? 1 : 0;
     }
 
-    static Callback AcceptDragProc;
-    static {
-        AcceptDragProc = new Callback(TreeDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$
-        int acceptDragProc = AcceptDragProc.getAddress();
-        if (acceptDragProc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
-    }
+//  static Callback AcceptDragProc;
+//  static {
+//      AcceptDragProc = new Callback(TreeDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$
+//      int acceptDragProc = AcceptDragProc.getAddress();
+//      if (acceptDragProc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
+//  }
 
-    static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) {
-        DropTarget target = FindDropTarget(theControl, theDrag);
-        if (target is null) return 0;
-        return (target.feedback & DND.FEEDBACK_SELECT) !is 0 ? 1 : 0;
-    }
+//  static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) {
+//      DropTarget target = FindDropTarget(theControl, theDrag);
+//      if (target is null) return 0;
+//      return (target.feedback & DND.FEEDBACK_SELECT) !is 0 ? 1 : 0;
+//  }
     
-    static DropTarget FindDropTarget(int theControl, int theDrag) {
-        if (theControl is 0) return null;
-        Display display = Display.findDisplay(Thread.currentThread());
-        if (display is null || display.isDisposed()) return null;
-        Widget widget = display.findWidget(theControl);
-        if (widget is null) return null;
-        return cast(DropTarget)widget.getData(DND.DROP_TARGET_KEY); 
-    }
+//  static DropTarget FindDropTarget(int theControl, int theDrag) {
+//      if (theControl is 0) return null;
+//      Display display = Display.findDisplay(Thread.currentThread());
+//      if (display is null || display.isDisposed()) return null;
+//      Widget widget = display.findWidget(theControl);
+//      if (widget is null) return null;
+//      return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); 
+//  }
 
     /**
      * Creates a new <code>TreeDropTargetEffect</code> to handle the drag under effect on the specified 
@@ -99,7 +102,7 @@
      * 
      * @param tree the <code>Tree</code> over which the user positions the cursor to drop the data
      */
-    public this(Tree tree) {
+    public TreeDropTargetEffect(Tree tree) {
         super(tree);
     }
 
@@ -125,13 +128,13 @@
      * @see DropTargetEvent
      */
     public void dragEnter(DropTargetEvent event) {
-        if (callbacks is null) {
-            Tree table = cast(Tree) control;
-            DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
-            OS.GetDataBrowserCallbacks (table.handle, callbacks);
-            callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress();
-            OS.SetDataBrowserCallbacks(table.handle, callbacks);
-        }
+//      if (callbacks is null) {
+//          Tree table = (Tree) control;
+//          DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
+//          OS.GetDataBrowserCallbacks (table.handle, callbacks);
+//          callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress();
+//          OS.SetDataBrowserCallbacks(table.handle, callbacks);
+//      }
         insertItem = null;
         expandBeginTime = 0;
         expandItem = null;
@@ -154,7 +157,7 @@
      * @see DropTargetEvent
      */
     public void dragLeave(DropTargetEvent event) {
-        Tree tree = cast(Tree) control;
+        Tree tree = (Tree) control;
         if (insertItem !is null) {
             setInsertMark(tree, null, false);
             insertItem = null;
@@ -184,21 +187,21 @@
      * @see DND#FEEDBACK_SCROLL
      */
     public void dragOver(DropTargetEvent event) {
-        Tree tree = cast(Tree) control;
-        TreeItem item = cast(TreeItem)getItem(tree, event.x, event.y);
+        Tree tree = (Tree) control;
+        TreeItem item = (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.opEquals(expandItem) && expandBeginTime !is 0) {
+            if (item !is null && item.equals(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 = cast(int) System.currentTimeMillis();
+                        e.time = (int) System.currentTimeMillis();
                         tree.notifyListeners(DWT.Expand, e);
                         if (item.isDisposed()) return;
                         item.setExpanded(true);
@@ -216,7 +219,7 @@
             scrollBeginTime = 0;
             scrollItem = null;
         } else {
-            if (item !is null && item.opEquals(scrollItem)  && scrollBeginTime !is 0) {
+            if (item !is null && item.equals(scrollItem)  && scrollBeginTime !is 0) {
                 if (System.currentTimeMillis() >= scrollBeginTime) {
                     Rectangle area = tree.getClientArea();
                     int headerHeight = tree.getHeaderHeight();
@@ -253,7 +256,7 @@
             setInsertMark(tree, null, false);
         }
         // save current effect for selection feedback
-        (cast(DropTarget)event.widget).feedback = effect;
+        ((DropTarget)event.widget).feedback = effect;
     }
 
     void setInsertMark(Tree tree, TreeItem item, bool before) {