Mercurial > projects > dwt-win
comparison dwt/dnd/TreeDropTargetEffect.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | 35669d0d0dc5 |
children | e2affbeb686d |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwt.dnd.TreeDropTargetEffect; | 13 module dwt.dnd.TreeDropTargetEffect; |
14 | 14 |
15 import dwt.DWT; | |
15 import dwt.graphics.Point; | 16 import dwt.graphics.Point; |
16 import dwt.internal.win32.OS; | 17 import dwt.internal.win32.OS; |
18 import dwt.widgets.Event; | |
17 import dwt.widgets.Tree; | 19 import dwt.widgets.Tree; |
18 import dwt.widgets.TreeItem; | 20 import dwt.widgets.TreeItem; |
19 | 21 |
20 import dwt.dnd.DropTargetEffect; | 22 import dwt.dnd.DropTargetEffect; |
21 import dwt.dnd.DropTargetEvent; | 23 import dwt.dnd.DropTargetEvent; |
57 */ | 59 */ |
58 public class TreeDropTargetEffect : DropTargetEffect { | 60 public class TreeDropTargetEffect : DropTargetEffect { |
59 static final int SCROLL_HYSTERESIS = 200; // milli seconds | 61 static final int SCROLL_HYSTERESIS = 200; // milli seconds |
60 static final int EXPAND_HYSTERESIS = 1000; // milli seconds | 62 static final int EXPAND_HYSTERESIS = 1000; // milli seconds |
61 | 63 |
62 int dropIndex; | 64 int /*long*/ dropIndex; |
63 int scrollIndex; | 65 int scrollIndex; |
64 long scrollBeginTime; | 66 long scrollBeginTime; |
65 int expandIndex; | 67 int /*long*/ expandIndex; |
66 long expandBeginTime; | 68 long expandBeginTime; |
67 TreeItem insertItem; | 69 TreeItem insertItem; |
68 bool insertBefore; | 70 bool insertBefore; |
69 | 71 |
70 /** | 72 /** |
169 coordinates = tree.toControl(coordinates); | 171 coordinates = tree.toControl(coordinates); |
170 TVHITTESTINFO lpht; | 172 TVHITTESTINFO lpht; |
171 lpht.pt.x = coordinates.x; | 173 lpht.pt.x = coordinates.x; |
172 lpht.pt.y = coordinates.y; | 174 lpht.pt.y = coordinates.y; |
173 OS.SendMessage (handle, OS.TVM_HITTEST, 0, &lpht); | 175 OS.SendMessage (handle, OS.TVM_HITTEST, 0, &lpht); |
174 int hItem = cast(int) lpht.hItem; | 176 auto hItem = lpht.hItem; |
175 if ((effect & DND.FEEDBACK_SCROLL) is 0) { | 177 if ((effect & DND.FEEDBACK_SCROLL) is 0) { |
176 scrollBeginTime = 0; | 178 scrollBeginTime = 0; |
177 scrollIndex = -1; | 179 scrollIndex = -1; |
178 } else { | 180 } else { |
179 if (hItem !is -1 && scrollIndex is hItem && scrollBeginTime !is 0) { | 181 if (hItem !is cast(HTREEITEM)-1 && cast(HTREEITEM)scrollIndex is hItem && scrollBeginTime !is 0) { |
180 if (System.currentTimeMillis() >= scrollBeginTime) { | 182 if (System.currentTimeMillis() >= scrollBeginTime) { |
181 int topItem = OS.SendMessage(handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); | 183 auto topItem = cast(HTREEITEM)OS.SendMessage(handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); |
182 int nextItem = OS.SendMessage(handle, OS.TVM_GETNEXTITEM, hItem is topItem ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE, hItem); | 184 auto nextItem = cast(HTREEITEM)OS.SendMessage(handle, OS.TVM_GETNEXTITEM, hItem is topItem ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE, hItem); |
183 bool scroll = true; | 185 bool scroll = true; |
184 if (hItem is topItem) { | 186 if (hItem is topItem) { |
185 scroll = nextItem !is 0; | 187 scroll = nextItem !is null; |
186 } else { | 188 } else { |
187 RECT itemRect; | 189 RECT itemRect; |
188 itemRect.left = nextItem; | 190 if (OS.TreeView_GetItemRect (handle, nextItem, &itemRect, true)) { |
189 if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, &itemRect) !is 0) { | |
190 RECT rect; | 191 RECT rect; |
191 OS.GetClientRect (handle, &rect); | 192 OS.GetClientRect (handle, &rect); |
192 POINT pt; | 193 POINT pt; |
193 pt.x = itemRect.left; | 194 pt.x = itemRect.left; |
194 pt.y = itemRect.top; | 195 pt.y = itemRect.top; |
205 scrollBeginTime = 0; | 206 scrollBeginTime = 0; |
206 scrollIndex = -1; | 207 scrollIndex = -1; |
207 } | 208 } |
208 } else { | 209 } else { |
209 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; | 210 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; |
210 scrollIndex = hItem; | 211 scrollIndex = cast(int)hItem; |
211 } | 212 } |
212 } | 213 } |
213 if ((effect & DND.FEEDBACK_EXPAND) is 0) { | 214 if ((effect & DND.FEEDBACK_EXPAND) is 0) { |
214 expandBeginTime = 0; | 215 expandBeginTime = 0; |
215 expandIndex = -1; | 216 expandIndex = -1; |
216 } else { | 217 } else { |
217 if (hItem !is -1 && expandIndex is hItem && expandBeginTime !is 0) { | 218 if (cast(int)hItem !is -1 && expandIndex is cast(int)hItem && expandBeginTime !is 0) { |
218 if (System.currentTimeMillis() >= expandBeginTime) { | 219 if (System.currentTimeMillis() >= expandBeginTime) { |
219 if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem) !is 0) { | 220 if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem) !is 0) { |
220 TVITEM tvItem; | 221 TreeItem item = cast(TreeItem)tree.getDisplay().findWidget(tree.handle, cast(int)hItem); |
221 tvItem.hItem = cast(HANDLE) hItem; | 222 if (item !is null && !item.getExpanded()) { |
222 tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; | 223 item.setExpanded(true); |
223 OS.SendMessage (handle, OS.TVM_GETITEM, 0, &tvItem); | |
224 if ((tvItem.state & OS.TVIS_EXPANDED) is 0) { | |
225 OS.SendMessage (handle, OS.TVM_EXPAND, OS.TVE_EXPAND, hItem); | |
226 tree.redraw(); | 224 tree.redraw(); |
225 Event expandEvent = new Event (); | |
226 expandEvent.item = item; | |
227 tree.notifyListeners(DWT.Expand, expandEvent); | |
227 } | 228 } |
228 } | 229 } |
229 expandBeginTime = 0; | 230 expandBeginTime = 0; |
230 expandIndex = -1; | 231 expandIndex = -1; |
231 } | 232 } |
232 } else { | 233 } else { |
233 expandBeginTime = System.currentTimeMillis() + EXPAND_HYSTERESIS; | 234 expandBeginTime = System.currentTimeMillis() + EXPAND_HYSTERESIS; |
234 expandIndex = hItem; | 235 expandIndex = cast(int)hItem; |
235 } | 236 } |
236 } | 237 } |
237 if (dropIndex !is -1 && (dropIndex !is hItem || (effect & DND.FEEDBACK_SELECT) is 0)) { | 238 if (dropIndex !is -1 && (dropIndex !is cast(int)hItem || (effect & DND.FEEDBACK_SELECT) is 0)) { |
238 TVITEM tvItem; | 239 TVITEM tvItem; |
239 tvItem.hItem = cast(HANDLE) dropIndex; | 240 tvItem.hItem = cast(HANDLE) dropIndex; |
240 tvItem.mask = OS.TVIF_STATE; | 241 tvItem.mask = OS.TVIF_STATE; |
241 tvItem.stateMask = OS.TVIS_DROPHILITED; | 242 tvItem.stateMask = OS.TVIS_DROPHILITED; |
242 tvItem.state = 0; | 243 tvItem.state = 0; |
243 OS.SendMessage (handle, OS.TVM_SETITEM, 0, &tvItem); | 244 OS.SendMessage (handle, OS.TVM_SETITEM, 0, &tvItem); |
244 dropIndex = -1; | 245 dropIndex = -1; |
245 } | 246 } |
246 if (hItem !is -1 && hItem !is dropIndex && (effect & DND.FEEDBACK_SELECT) !is 0) { | 247 if (cast(int)hItem !is -1 && cast(int)hItem !is dropIndex && (effect & DND.FEEDBACK_SELECT) !is 0) { |
247 TVITEM tvItem; | 248 TVITEM tvItem; |
248 tvItem.hItem = cast(HANDLE) hItem; | 249 tvItem.hItem = cast(HANDLE) hItem; |
249 tvItem.mask = OS.TVIF_STATE; | 250 tvItem.mask = OS.TVIF_STATE; |
250 tvItem.stateMask = OS.TVIS_DROPHILITED; | 251 tvItem.stateMask = OS.TVIS_DROPHILITED; |
251 tvItem.state = OS.TVIS_DROPHILITED; | 252 tvItem.state = OS.TVIS_DROPHILITED; |
252 OS.SendMessage (handle, OS.TVM_SETITEM, 0, &tvItem); | 253 OS.SendMessage (handle, OS.TVM_SETITEM, 0, &tvItem); |
253 dropIndex = hItem; | 254 dropIndex = cast(int)hItem; |
254 } | 255 } |
255 if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0 || (effect & DND.FEEDBACK_INSERT_AFTER) !is 0) { | 256 if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0 || (effect & DND.FEEDBACK_INSERT_AFTER) !is 0) { |
256 bool before = (effect & DND.FEEDBACK_INSERT_BEFORE) !is 0; | 257 bool before = (effect & DND.FEEDBACK_INSERT_BEFORE) !is 0; |
257 /* | 258 /* |
258 * Bug in Windows. When TVM_SETINSERTMARK is used to set | 259 * Bug in Windows. When TVM_SETINSERTMARK is used to set |
261 * the insert mark properly. The fix is to hide and show | 262 * the insert mark properly. The fix is to hide and show |
262 * the insert mark whenever an item is expanded or collapsed. | 263 * the insert mark whenever an item is expanded or collapsed. |
263 * Since the insert mark can not be queried from the tree, | 264 * Since the insert mark can not be queried from the tree, |
264 * use the Tree API rather than calling the OS directly. | 265 * use the Tree API rather than calling the OS directly. |
265 */ | 266 */ |
266 TreeItem item = cast(TreeItem)tree.getDisplay().findWidget(tree.handle, hItem); | 267 TreeItem item = cast(TreeItem)tree.getDisplay().findWidget(tree.handle, cast(int)hItem); |
267 if (item !is null) { | 268 if (item !is null) { |
268 if (item !is insertItem || before !is insertBefore) { | 269 if (item !is insertItem || before !is insertBefore) { |
269 tree.setInsertMark(item, before); | 270 tree.setInsertMark(item, before); |
270 } | 271 } |
271 insertItem = item; | 272 insertItem = item; |