1 11 package org.eclipse.swt.dnd; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.internal.win32.*; 16 import org.eclipse.swt.widgets.*; 17 18 34 public class TreeDragSourceEffect extends DragSourceEffect { 35 Image dragSourceImage = null; 36 37 43 public TreeDragSourceEffect(Tree tree) { 44 super(tree); 45 } 46 47 56 public void dragFinished(DragSourceEvent event) { 57 if (dragSourceImage != null) dragSourceImage.dispose(); 58 dragSourceImage = null; 59 } 60 61 72 public void dragStart(DragSourceEvent event) { 73 event.image = getDragSourceImage(event); 74 } 75 76 Image getDragSourceImage(DragSourceEvent event) { 77 if (dragSourceImage != null) dragSourceImage.dispose(); 78 dragSourceImage = null; 79 Tree tree = (Tree) control; 80 TreeItem[] selection = tree.getSelection(); 81 if (selection.length == 0) return null; 82 int treeImageList = OS.SendMessage (tree.handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0); 83 if (treeImageList != 0) { 84 int count = Math.min(selection.length, 10); 85 Rectangle bounds = selection[0].getBounds(0); 86 for (int i = 1; i < count; i++) { 87 bounds = bounds.union(selection[i].getBounds(0)); 88 } 89 int hDC = OS.GetDC(tree.handle); 90 int hDC1 = OS.CreateCompatibleDC(hDC); 91 int bitmap = OS.CreateCompatibleBitmap(hDC, bounds.width, bounds.height); 92 int hOldBitmap = OS.SelectObject(hDC1, bitmap); 93 RECT rect = new RECT(); 94 rect.right = bounds.width; 95 rect.bottom = bounds.height; 96 int hBrush = OS.GetStockObject(OS.WHITE_BRUSH); 97 OS.FillRect(hDC1, rect, hBrush); 98 for (int i = 0; i < count; i++) { 99 TreeItem selected = selection[i]; 100 Rectangle cell = selected.getBounds(0); 101 int imageList = OS.SendMessage(tree.handle, OS.TVM_CREATEDRAGIMAGE, 0, selected.handle); 102 OS.ImageList_Draw(imageList, 0, hDC1, cell.x - bounds.x, cell.y - bounds.y, OS.ILD_SELECTED); 103 OS.ImageList_Destroy(imageList); 104 } 105 OS.SelectObject(hDC1, hOldBitmap); 106 OS.DeleteDC (hDC1); 107 OS.ReleaseDC (tree.handle, hDC); 108 Display display = tree.getDisplay(); 109 dragSourceImage = Image.win32_new(display, SWT.BITMAP, bitmap); 110 return dragSourceImage; 111 } 112 return null; 113 } 114 } 115 | Popular Tags |