Project: SWT
Bug 74241 [DND] Drop Target TreeItem not selected when Font was set
Reported: 2004-09-19 13:35:23 | Status: resolved fixed

Hi, I've implemented Drag and Drop in a Tree. That was done, similiar to Snippet 91 ("drag leaf items in a tree"). Now, when dragging a TreeItem over valid DropTargets, the Target TreeItem becomes selected when hovering over it. But, when I am setting a Font to the TreeItems, hovering over valid Drop Targets does not show the Selection. I have created a Snippet that shows this behaviour (at least on my WinXP), based on Snippet 91: public class Main { public static void main(String[] args) { Display display = Display.getDefault(); Font font = new Font(display, display.getSystemFont().getFontData()[0].getName(), 10, SWT.NORMAL); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.BORDER); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setFont(font); item.setText("item " + i); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setFont(font); subItem.setText("item " + i + " " + j); for (int k = 0; k < 3; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setFont(font); subsubItem.setText("item " + i + " " + j + " " + k); } } } Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; final DragSource source = new DragSource(tree, operations); source.setTransfer(types); final TreeItem[] dragSourceItem = new TreeItem[1]; source.addDragListener(new DragSourceListener() { public void dragStart(DragSourceEvent event) { TreeItem[] selection = tree.getSelection(); if (selection.length > 0 && selection[0].getItemCount() == 0) { event.doit = true; dragSourceItem[0] = selection[0]; } else { event.doit = false; } }; public void dragSetData(DragSourceEvent event) { event.data = dragSourceItem[0].getText(); } public void dragFinished(DragSourceEvent event) { if (event.detail == DND.DROP_MOVE) dragSourceItem[0].dispose(); dragSourceItem[0] = null; } }); DropTarget target = new DropTarget(tree, operations); target.setTransfer(types); target.addDropListener(new DropTargetAdapter() { public void dragOver(DropTargetEvent event) { event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL | DND.FEEDBACK_SELECT; } public void drop(DropTargetEvent event) { if (event.data == null) { event.detail = DND.DROP_NONE; return; } String text = (String) event.data; if (event.item == null) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(text); } else { TreeItem parent = (TreeItem) event.item; TreeItem item = new TreeItem(parent, SWT.NONE); item.setText(text); } } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } In the second line the "font" is created that is set to all TreeItems. As soon as "Font font = null;" is set, everything works, and the selection is set to the TreeItem. But when using any Font (as in this case the System Font), no selection is shown when dragging over a valid drop target. Ben

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java