comparison dwt/dnd/TableDropTargetEffect.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 23a31de4a3ab
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/ 10 *******************************************************************************/
11 module dwt.dnd; 11 module dwt.dnd.TableDropTargetEffect;
12 12
13 import dwt.DWT; 13 import dwt.dwthelper.utils;
14 import dwt.graphics.*; 14
15 import dwt.internal.Callback; 15 import dwt.graphics.Point;
16 import dwt.internal.carbon.DataBrowserCallbacks; 16 import dwt.graphics.Rectangle;
17 import dwt.internal.carbon.OS; 17 import dwt.widgets.Table;
18 import dwt.widgets.*; 18 import dwt.widgets.TableItem;
19 19
20 /** 20 /**
21 * This class provides a default drag under effect (eg. select, insert and scroll) 21 * This class provides a default drag under effect (eg. select, insert and scroll)
22 * when a drag occurs over a <code>Table</code>. 22 * when a drag occurs over a <code>Table</code>.
23 * 23 *
41 * </dl> 41 * </dl>
42 * </p> 42 * </p>
43 * 43 *
44 * @see DropTargetAdapter 44 * @see DropTargetAdapter
45 * @see DropTargetEvent 45 * @see DropTargetEvent
46 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
46 * 47 *
47 * @since 3.3 48 * @since 3.3
48 */ 49 */
49 public class TableDropTargetEffect : DropTargetEffect { 50 public class TableDropTargetEffect extends DropTargetEffect {
50 static final int SCROLL_HYSTERESIS = 150; // milli seconds 51 static final int SCROLL_HYSTERESIS = 150; // milli seconds
51 52
52 TableItem scrollItem; 53 TableItem scrollItem;
53 long scrollBeginTime; 54 long scrollBeginTime;
54 DataBrowserCallbacks callbacks = null; 55 // DataBrowserCallbacks callbacks = null;
55 56
56 static Callback AcceptDragProc; 57 // static Callback AcceptDragProc;
57 static { 58 // static {
58 AcceptDragProc = new Callback(TableDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ 59 // AcceptDragProc = new Callback(TableDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$
59 int acceptDragProc = AcceptDragProc.getAddress(); 60 // int acceptDragProc = AcceptDragProc.getAddress();
60 if (acceptDragProc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS); 61 // if (acceptDragProc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
61 } 62 // }
62 63
63 static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { 64 // static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) {
64 DropTarget target = FindDropTarget(theControl, theDrag); 65 // DropTarget target = FindDropTarget(theControl, theDrag);
65 if (target is null) return 0; 66 // if (target is null) return 0;
66 return (target.feedback & DND.FEEDBACK_SELECT) !is 0 ? 1 : 0; 67 // return (target.feedback & DND.FEEDBACK_SELECT) !is 0 ? 1 : 0;
67 } 68 // }
68 69
69 static DropTarget FindDropTarget(int theControl, int theDrag) { 70 // static DropTarget FindDropTarget(int theControl, int theDrag) {
70 if (theControl is 0) return null; 71 // if (theControl is 0) return null;
71 Display display = Display.findDisplay(Thread.currentThread()); 72 // Display display = Display.findDisplay(Thread.currentThread());
72 if (display is null || display.isDisposed()) return null; 73 // if (display is null || display.isDisposed()) return null;
73 Widget widget = display.findWidget(theControl); 74 // Widget widget = display.findWidget(theControl);
74 if (widget is null) return null; 75 // if (widget is null) return null;
75 return cast(DropTarget)widget.getData(DND.DROP_TARGET_KEY); 76 // return (DropTarget)widget.getData(DND.DROP_TARGET_KEY);
76 } 77 // }
77 78
78 /** 79 /**
79 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified 80 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified
80 * <code>Table</code>. 81 * <code>Table</code>.
81 * 82 *
82 * @param table the <code>Table</code> over which the user positions the cursor to drop the data 83 * @param table the <code>Table</code> over which the user positions the cursor to drop the data
83 */ 84 */
84 public this(Table table) { 85 public TableDropTargetEffect(Table table) {
85 super(table); 86 super(table);
86 } 87 }
87 88
88 int checkEffect(int effect) { 89 int checkEffect(int effect) {
89 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. 90 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified.
105 * 106 *
106 * @see DropTargetAdapter 107 * @see DropTargetAdapter
107 * @see DropTargetEvent 108 * @see DropTargetEvent
108 */ 109 */
109 public void dragEnter(DropTargetEvent event) { 110 public void dragEnter(DropTargetEvent event) {
110 if (callbacks is null) { 111 // if (callbacks is null) {
111 Table table = cast(Table) control; 112 // Table table = (Table) control;
112 DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); 113 // DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
113 OS.GetDataBrowserCallbacks (table.handle, callbacks); 114 // OS.GetDataBrowserCallbacks (table.handle, callbacks);
114 callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); 115 // callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress();
115 OS.SetDataBrowserCallbacks(table.handle, callbacks); 116 // OS.SetDataBrowserCallbacks(table.handle, callbacks);
116 } 117 // }
117 scrollBeginTime = 0; 118 scrollBeginTime = 0;
118 scrollItem = null; 119 scrollItem = null;
119 } 120 }
120 121
121 /** 122 /**
153 * @see DropTargetEvent 154 * @see DropTargetEvent
154 * @see DND#FEEDBACK_SELECT 155 * @see DND#FEEDBACK_SELECT
155 * @see DND#FEEDBACK_SCROLL 156 * @see DND#FEEDBACK_SCROLL
156 */ 157 */
157 public void dragOver(DropTargetEvent event) { 158 public void dragOver(DropTargetEvent event) {
158 Table table = cast(Table) control; 159 Table table = (Table) control;
159 int effect = checkEffect(event.feedback); 160 int effect = checkEffect(event.feedback);
160 161
161 TableItem item = cast(TableItem)getItem(table, event.x, event.y); 162 TableItem item = (TableItem)getItem(table, event.x, event.y);
162 163
163 if ((effect & DND.FEEDBACK_SCROLL) is 0) { 164 if ((effect & DND.FEEDBACK_SCROLL) is 0) {
164 scrollBeginTime = 0; 165 scrollBeginTime = 0;
165 scrollItem = null; 166 scrollItem = null;
166 } else { 167 } else {
167 if (item !is null && item.opEquals(scrollItem) && scrollBeginTime !is 0) { 168 if (item !is null && item.equals(scrollItem) && scrollBeginTime !is 0) {
168 if (System.currentTimeMillis() >= scrollBeginTime) { 169 if (System.currentTimeMillis() >= scrollBeginTime) {
169 Rectangle area = table.getClientArea(); 170 Rectangle area = table.getClientArea();
170 int headerHeight = table.getHeaderHeight(); 171 int headerHeight = table.getHeaderHeight();
171 int itemHeight= table.getItemHeight(); 172 int itemHeight= table.getItemHeight();
172 Point pt = new Point(event.x, event.y); 173 Point pt = new Point(event.x, event.y);
189 scrollItem = item; 190 scrollItem = item;
190 } 191 }
191 } 192 }
192 193
193 // store current effect for selection feedback 194 // store current effect for selection feedback
194 (cast(DropTarget)event.widget).feedback = effect; 195 ((DropTarget)event.widget).feedback = effect;
195 } 196 }
196 } 197 }