1 11 package org.eclipse.swt.dnd; 12 13 import org.eclipse.swt.graphics.*; 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.widgets.*; 16 17 46 public class TableDropTargetEffect extends DropTargetEffect { 47 static final int SCROLL_HYSTERESIS = 200; 49 int scrollIndex = -1; 50 long scrollBeginTime; 51 TableItem dropHighlight; 52 53 59 public TableDropTargetEffect(Table table) { 60 super(table); 61 } 62 63 int checkEffect(int effect) { 64 if ((effect & DND.FEEDBACK_SELECT) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE; 66 if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER; 67 return effect; 68 } 69 70 84 public void dragEnter(DropTargetEvent event) { 85 scrollBeginTime = 0; 86 scrollIndex = -1; 87 dropHighlight = null; 88 } 89 90 104 public void dragLeave(DropTargetEvent event) { 105 Table table = (Table) control; 106 int handle = table.handle; 107 if (dropHighlight != null) { 108 LVITEM lvItem = new LVITEM (); 109 lvItem.stateMask = OS.LVIS_DROPHILITED; 110 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); 111 dropHighlight = null; 112 } 113 scrollBeginTime = 0; 114 scrollIndex = -1; 115 } 116 117 134 public void dragOver(DropTargetEvent event) { 135 Table table = (Table) getControl(); 136 int effect = checkEffect(event.feedback); 137 int handle = table.handle; 138 Point coordinates = new Point(event.x, event.y); 139 coordinates = table.toControl(coordinates); 140 LVHITTESTINFO pinfo = new LVHITTESTINFO(); 141 pinfo.x = coordinates.x; 142 pinfo.y = coordinates.y; 143 OS.SendMessage(handle, OS.LVM_HITTEST, 0, pinfo); 144 if ((effect & DND.FEEDBACK_SCROLL) == 0) { 145 scrollBeginTime = 0; 146 scrollIndex = -1; 147 } else { 148 if (pinfo.iItem != -1 && scrollIndex == pinfo.iItem && scrollBeginTime != 0) { 149 if (System.currentTimeMillis() >= scrollBeginTime) { 150 int top = Math.max (0, OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)); 151 int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); 152 int index = (scrollIndex - 1 < top) ? Math.max(0, scrollIndex - 1) : Math.min(count - 1, scrollIndex + 1); 153 boolean scroll = true; 154 if (pinfo.iItem == top) { 155 scroll = pinfo.iItem != index; 156 } else { 157 RECT itemRect = new RECT (); 158 itemRect.left = OS.LVIR_BOUNDS; 159 if (OS.SendMessage (handle, OS.LVM_GETITEMRECT, pinfo.iItem, itemRect) != 0) { 160 RECT rect = new RECT (); 161 OS.GetClientRect (handle, rect); 162 POINT pt = new POINT (); 163 pt.x = itemRect.left; 164 pt.y = itemRect.top; 165 if (OS.PtInRect (rect, pt)) { 166 pt.y = itemRect.bottom; 167 if (OS.PtInRect (rect, pt)) scroll = false; 168 } 169 } 170 } 171 if (scroll) { 172 OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0); 173 table.redraw(); 174 } 175 scrollBeginTime = 0; 176 scrollIndex = -1; 177 } 178 } else { 179 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; 180 scrollIndex = pinfo.iItem; 181 } 182 } 183 184 if (pinfo.iItem != -1 && (effect & DND.FEEDBACK_SELECT) != 0) { 185 TableItem item = table.getItem(pinfo.iItem); 186 if (dropHighlight != item) { 187 LVITEM lvItem = new LVITEM(); 188 lvItem.stateMask = OS.LVIS_DROPHILITED; 189 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); 190 lvItem.state = OS.LVIS_DROPHILITED; 191 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, pinfo.iItem, lvItem); 192 dropHighlight = item; 193 } 194 } else { 195 if (dropHighlight != null) { 196 LVITEM lvItem = new LVITEM (); 197 lvItem.stateMask = OS.LVIS_DROPHILITED; 198 OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); 199 dropHighlight = null; 200 } 201 } 202 } 203 } 204 | Popular Tags |