Mercurial > projects > dwt-win
comparison dwt/dnd/TableDropTargetEffect.d @ 135:242e33c0e383
Added dnd source, ByteArrayTransfer,Clipboard completed
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 13 Feb 2008 04:51:22 +0100 |
parents | |
children | 3665cb9211b2 |
comparison
equal
deleted
inserted
replaced
134:fa7d7d66b9ed | 135:242e33c0e383 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.dnd.TableDropTargetEffect; | |
14 | |
15 import dwt.graphics.Point; | |
16 import dwt.internal.win32.OS; | |
17 import dwt.widgets.Table; | |
18 import dwt.widgets.TableItem; | |
19 | |
20 /** | |
21 * This class provides a default drag under effect (eg. select, insert and scroll) | |
22 * when a drag occurs over a <code>Table</code>. | |
23 * | |
24 * <p>Classes that wish to provide their own drag under effect for a <code>Table</code> | |
25 * can extend the <code>TableDropTargetEffect</code> and override any applicable methods | |
26 * in <code>TableDropTargetEffect</code> to display their own drag under effect.</p> | |
27 * | |
28 * Subclasses that override any methods of this class must call the corresponding | |
29 * <code>super</code> method to get the default drag under effect implementation. | |
30 * | |
31 * <p>The feedback value is either one of the FEEDBACK constants defined in | |
32 * class <code>DND</code> which is applicable to instances of this class, | |
33 * or it must be built by <em>bitwise OR</em>'ing together | |
34 * (that is, using the <code>int</code> "|" operator) two or more | |
35 * of those <code>DND</code> effect constants. | |
36 * </p> | |
37 * <p> | |
38 * <dl> | |
39 * <dt><b>Feedback:</b></dt> | |
40 * <dd>FEEDBACK_SELECT, FEEDBACK_SCROLL</dd> | |
41 * </dl> | |
42 * </p> | |
43 * | |
44 * @see DropTargetAdapter | |
45 * @see DropTargetEvent | |
46 * | |
47 * @since 3.3 | |
48 */ | |
49 public class TableDropTargetEffect : DropTargetEffect { | |
50 static final int SCROLL_HYSTERESIS = 200; // milli seconds | |
51 | |
52 int scrollIndex = -1; | |
53 long scrollBeginTime; | |
54 TableItem dropHighlight; | |
55 | |
56 /** | |
57 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified | |
58 * <code>Table</code>. | |
59 * | |
60 * @param table the <code>Table</code> over which the user positions the cursor to drop the data | |
61 */ | |
62 public this(Table table) { | |
63 super(table); | |
64 } | |
65 | |
66 int checkEffect(int effect) { | |
67 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. | |
68 if ((effect & DND.FEEDBACK_SELECT) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE; | |
69 if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER; | |
70 return effect; | |
71 } | |
72 | |
73 /** | |
74 * This implementation of <code>dragEnter</code> provides a default drag under effect | |
75 * for the feedback specified in <code>event.feedback</code>. | |
76 * | |
77 * For additional information see <code>DropTargetAdapter.dragEnter</code>. | |
78 * | |
79 * Subclasses that override this method should call <code>super.dragEnter(event)</code> | |
80 * to get the default drag under effect implementation. | |
81 * | |
82 * @param event the information associated with the drag enter event | |
83 * | |
84 * @see DropTargetAdapter | |
85 * @see DropTargetEvent | |
86 */ | |
87 public void dragEnter(DropTargetEvent event) { | |
88 scrollBeginTime = 0; | |
89 scrollIndex = -1; | |
90 dropHighlight = null; | |
91 } | |
92 | |
93 /** | |
94 * This implementation of <code>dragLeave</code> provides a default drag under effect | |
95 * for the feedback specified in <code>event.feedback</code>. | |
96 * | |
97 * For additional information see <code>DropTargetAdapter.dragLeave</code>. | |
98 * | |
99 * Subclasses that override this method should call <code>super.dragLeave(event)</code> | |
100 * to get the default drag under effect implementation. | |
101 * | |
102 * @param event the information associated with the drag leave event | |
103 * | |
104 * @see DropTargetAdapter | |
105 * @see DropTargetEvent | |
106 */ | |
107 public void dragLeave(DropTargetEvent event) { | |
108 Table table = (Table) control; | |
109 int handle = table.handle; | |
110 if (dropHighlight !is null) { | |
111 LVITEM lvItem = new LVITEM (); | |
112 lvItem.stateMask = OS.LVIS_DROPHILITED; | |
113 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); | |
114 dropHighlight = null; | |
115 } | |
116 scrollBeginTime = 0; | |
117 scrollIndex = -1; | |
118 } | |
119 | |
120 /** | |
121 * This implementation of <code>dragOver</code> provides a default drag under effect | |
122 * for the feedback specified in <code>event.feedback</code>. The class description | |
123 * lists the FEEDBACK constants that are applicable to the class. | |
124 * | |
125 * For additional information see <code>DropTargetAdapter.dragOver</code>. | |
126 * | |
127 * Subclasses that override this method should call <code>super.dragOver(event)</code> | |
128 * to get the default drag under effect implementation. | |
129 * | |
130 * @param event the information associated with the drag over event | |
131 * | |
132 * @see DropTargetAdapter | |
133 * @see DropTargetEvent | |
134 * @see DND#FEEDBACK_SELECT | |
135 * @see DND#FEEDBACK_SCROLL | |
136 */ | |
137 public void dragOver(DropTargetEvent event) { | |
138 Table table = (Table) getControl(); | |
139 int effect = checkEffect(event.feedback); | |
140 int handle = table.handle; | |
141 Point coordinates = new Point(event.x, event.y); | |
142 coordinates = table.toControl(coordinates); | |
143 LVHITTESTINFO pinfo = new LVHITTESTINFO(); | |
144 pinfo.x = coordinates.x; | |
145 pinfo.y = coordinates.y; | |
146 OS.SendMessage(handle, OS.LVM_HITTEST, 0, pinfo); | |
147 if ((effect & DND.FEEDBACK_SCROLL) is 0) { | |
148 scrollBeginTime = 0; | |
149 scrollIndex = -1; | |
150 } else { | |
151 if (pinfo.iItem !is -1 && scrollIndex is pinfo.iItem && scrollBeginTime !is 0) { | |
152 if (System.currentTimeMillis() >= scrollBeginTime) { | |
153 int top = Math.max (0, OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)); | |
154 int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); | |
155 int index = (scrollIndex - 1 < top) ? Math.max(0, scrollIndex - 1) : Math.min(count - 1, scrollIndex + 1); | |
156 bool scroll = true; | |
157 if (pinfo.iItem is top) { | |
158 scroll = pinfo.iItem !is index; | |
159 } else { | |
160 RECT itemRect = new RECT (); | |
161 itemRect.left = OS.LVIR_BOUNDS; | |
162 if (OS.SendMessage (handle, OS.LVM_GETITEMRECT, pinfo.iItem, itemRect) !is 0) { | |
163 RECT rect = new RECT (); | |
164 OS.GetClientRect (handle, rect); | |
165 POINT pt = new POINT (); | |
166 pt.x = itemRect.left; | |
167 pt.y = itemRect.top; | |
168 if (OS.PtInRect (rect, pt)) { | |
169 pt.y = itemRect.bottom; | |
170 if (OS.PtInRect (rect, pt)) scroll = false; | |
171 } | |
172 } | |
173 } | |
174 if (scroll) { | |
175 OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0); | |
176 table.redraw(); | |
177 } | |
178 scrollBeginTime = 0; | |
179 scrollIndex = -1; | |
180 } | |
181 } else { | |
182 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; | |
183 scrollIndex = pinfo.iItem; | |
184 } | |
185 } | |
186 | |
187 if (pinfo.iItem !is -1 && (effect & DND.FEEDBACK_SELECT) !is 0) { | |
188 TableItem item = table.getItem(pinfo.iItem); | |
189 if (dropHighlight !is item) { | |
190 LVITEM lvItem = new LVITEM(); | |
191 lvItem.stateMask = OS.LVIS_DROPHILITED; | |
192 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); | |
193 lvItem.state = OS.LVIS_DROPHILITED; | |
194 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, pinfo.iItem, lvItem); | |
195 dropHighlight = item; | |
196 } | |
197 } else { | |
198 if (dropHighlight !is null) { | |
199 LVITEM lvItem = new LVITEM (); | |
200 lvItem.stateMask = OS.LVIS_DROPHILITED; | |
201 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); | |
202 dropHighlight = null; | |
203 } | |
204 } | |
205 } | |
206 } |