comparison dwt/dnd/TableDropTargetEffect.d @ 109:23a31de4a3ab

Ported dwt.dnd.TableDropTargetEffect
author Jacob Carlborg <doob@me.com>
date Wed, 31 Dec 2008 14:57:48 +0100
parents d8635bb48c7c
children
comparison
equal deleted inserted replaced
108:b0e5cad3d928 109:23a31de4a3ab
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 *
11 * Port to the D programming language:
12 * Jacob Carlborg <doob@me.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.dnd.TableDropTargetEffect; 14 module dwt.dnd.TableDropTargetEffect;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
15 import dwt.graphics.Point; 18 import dwt.graphics.Point;
16 import dwt.graphics.Rectangle; 19 import dwt.graphics.Rectangle;
17 import dwt.widgets.Table; 20 import dwt.widgets.Table;
18 import dwt.widgets.TableItem; 21 import dwt.widgets.TableItem;
22
23 import dwt.dnd.DND;
24 import dwt.dnd.DropTarget;
25 import dwt.dnd.DropTargetEffect;
26 import dwt.dnd.DropTargetEvent;
19 27
20 /** 28 /**
21 * This class provides a default drag under effect (eg. select, insert and scroll) 29 * This class provides a default drag under effect (eg. select, insert and scroll)
22 * when a drag occurs over a <code>Table</code>. 30 * when a drag occurs over a <code>Table</code>.
23 * 31 *
45 * @see DropTargetEvent 53 * @see DropTargetEvent
46 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 54 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
47 * 55 *
48 * @since 3.3 56 * @since 3.3
49 */ 57 */
50 public class TableDropTargetEffect extends DropTargetEffect { 58 public class TableDropTargetEffect : DropTargetEffect {
51 static final int SCROLL_HYSTERESIS = 150; // milli seconds 59 static const int SCROLL_HYSTERESIS = 150; // milli seconds
52 60
53 TableItem scrollItem; 61 TableItem scrollItem;
54 long scrollBeginTime; 62 long scrollBeginTime;
55 // DataBrowserCallbacks callbacks = null; 63 // DataBrowserCallbacks callbacks = null;
56 64
80 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified 88 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified
81 * <code>Table</code>. 89 * <code>Table</code>.
82 * 90 *
83 * @param table the <code>Table</code> over which the user positions the cursor to drop the data 91 * @param table the <code>Table</code> over which the user positions the cursor to drop the data
84 */ 92 */
85 public TableDropTargetEffect(Table table) { 93 public this(Table table) {
86 super(table); 94 super(table);
87 } 95 }
88 96
89 int checkEffect(int effect) { 97 int checkEffect(int effect) {
90 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. 98 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified.
154 * @see DropTargetEvent 162 * @see DropTargetEvent
155 * @see DND#FEEDBACK_SELECT 163 * @see DND#FEEDBACK_SELECT
156 * @see DND#FEEDBACK_SCROLL 164 * @see DND#FEEDBACK_SCROLL
157 */ 165 */
158 public void dragOver(DropTargetEvent event) { 166 public void dragOver(DropTargetEvent event) {
159 Table table = (Table) control; 167 Table table = cast(Table) control;
160 int effect = checkEffect(event.feedback); 168 int effect = checkEffect(event.feedback);
161 169
162 TableItem item = (TableItem)getItem(table, event.x, event.y); 170 TableItem item = cast(TableItem)getItem(table, event.x, event.y);
163 171
164 if ((effect & DND.FEEDBACK_SCROLL) is 0) { 172 if ((effect & DND.FEEDBACK_SCROLL) is 0) {
165 scrollBeginTime = 0; 173 scrollBeginTime = 0;
166 scrollItem = null; 174 scrollItem = null;
167 } else { 175 } else {
168 if (item !is null && item.equals(scrollItem) && scrollBeginTime !is 0) { 176 if (item !is null && item.opEquals(scrollItem) && scrollBeginTime !is 0) {
169 if (System.currentTimeMillis() >= scrollBeginTime) { 177 if (System.currentTimeMillis() >= scrollBeginTime) {
170 Rectangle area = table.getClientArea(); 178 Rectangle area = table.getClientArea();
171 int headerHeight = table.getHeaderHeight(); 179 int headerHeight = table.getHeaderHeight();
172 int itemHeight= table.getItemHeight(); 180 int itemHeight= table.getItemHeight();
173 Point pt = new Point(event.x, event.y); 181 Point pt = new Point(event.x, event.y);
190 scrollItem = item; 198 scrollItem = item;
191 } 199 }
192 } 200 }
193 201
194 // store current effect for selection feedback 202 // store current effect for selection feedback
195 ((DropTarget)event.widget).feedback = effect; 203 (cast(DropTarget)event.widget).feedback = effect;
196 } 204 }
197 } 205 }