Mercurial > projects > dwt-win
diff dwt/dnd/DropTargetEffect.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | 242e33c0e383 |
children | fd9c62a2998e |
line wrap: on
line diff
--- a/dwt/dnd/DropTargetEffect.d Mon May 05 00:12:38 2008 +0200 +++ b/dwt/dnd/DropTargetEffect.d Sat May 17 17:34:28 2008 +0200 @@ -17,8 +17,8 @@ import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.widgets.Control; -import dwt.widgets.Item; import dwt.widgets.Table; +import dwt.widgets.TableItem; import dwt.widgets.Tree; import dwt.widgets.TreeItem; import dwt.widgets.Widget; @@ -107,38 +107,39 @@ Widget getItem(Table table, int x, int y) { Point coordinates = new Point(x, y); coordinates = table.toControl(coordinates); - Item item = table.getItem(coordinates); - if (item is null) { - Rectangle area = table.getClientArea(); - if (area.contains(coordinates)) { - // Scan across the width of the table. - for (int x1 = area.x; x1 < area.x + area.width; x1++) { - Point pt = new Point(x1, coordinates.y); - item = table.getItem(pt); - if (item !is null) { - break; - } - } - } + TableItem item = table.getItem(coordinates); + if (item !is null) return item; + Rectangle area = table.getClientArea(); + int tableBottom = area.y + area.height; + int itemCount = table.getItemCount(); + for (int i=table.getTopIndex(); i<itemCount; i++) { + item = table.getItem(i); + Rectangle rect = item.getBounds(); + rect.x = area.x; + rect.width = area.width; + if (rect.contains(coordinates)) return item; + if (rect.y > tableBottom) break; } - return item; + return null; } Widget getItem(Tree tree, int x, int y) { - Point coordinates = new Point(x, y); - coordinates = tree.toControl(coordinates); - Item item = tree.getItem(coordinates); + Point point = new Point(x, y); + point = tree.toControl(point); + TreeItem item = tree.getItem(point); if (item is null) { Rectangle area = tree.getClientArea(); - if (area.contains(coordinates)) { - // Scan across the width of the tree. - for (int x1 = area.x; x1 < area.x + area.width; x1++) { - Point pt = new Point(x1, coordinates.y); - item = tree.getItem(pt); - if (item !is null) { - break; - } + if (area.contains(point)) { + int treeBottom = area.y + area.height; + item = tree.getTopItem(); + while (item !is null) { + Rectangle rect = item.getBounds(); + int itemBottom = rect.y + rect.height; + if (rect.y <= point.y && point.y < itemBottom) return item; + if (itemBottom > treeBottom) break; + item = nextItem(tree, item); } + return null; } } return item; @@ -146,7 +147,7 @@ TreeItem nextItem(Tree tree, TreeItem item) { if (item is null) return null; - if (item.getExpanded()) return item.getItem(0); + if (item.getExpanded() && item.getItemCount() > 0) return item.getItem(0); TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); int index = parentItem is null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);