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 35 public class TableDragSourceEffect extends DragSourceEffect { 36 Image dragSourceImage = null; 37 38 44 public TableDragSourceEffect(Table table) { 45 super(table); 46 } 47 48 57 public void dragFinished(DragSourceEvent event) { 58 if (dragSourceImage != null) dragSourceImage.dispose(); 59 dragSourceImage = null; 60 } 61 62 73 public void dragStart(DragSourceEvent event) { 74 event.image = getDragSourceImage(event); 75 } 76 77 Image getDragSourceImage(DragSourceEvent event) { 78 if (dragSourceImage != null) dragSourceImage.dispose(); 79 dragSourceImage = null; 80 Table table = (Table) control; 81 TableItem[] selection = table.getSelection(); 82 if (selection.length == 0) return null; 83 int tableImageList = OS.SendMessage (table.handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0); 84 if (tableImageList != 0) { 85 int count = Math.min(selection.length, 10); 86 Rectangle bounds = selection[0].getBounds(0); 87 for (int i = 1; i < count; i++) { 88 bounds = bounds.union(selection[i].getBounds(0)); 89 } 90 int hDC = OS.GetDC(0); 91 int hDC1 = OS.CreateCompatibleDC(hDC); 92 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) { 93 if ((table.getStyle() & SWT.RIGHT_TO_LEFT) != 0) { 94 OS.SetLayout(hDC1, OS.LAYOUT_RTL | OS.LAYOUT_BITMAPORIENTATIONPRESERVED); 95 } 96 } 97 int bitmap = OS.CreateCompatibleBitmap(hDC, bounds.width, bounds.height); 98 int hOldBitmap = OS.SelectObject(hDC1, bitmap); 99 RECT rect = new RECT(); 100 rect.right = bounds.width; 101 rect.bottom = bounds.height; 102 int hBrush = OS.GetStockObject(OS.WHITE_BRUSH); 103 OS.FillRect(hDC1, rect, hBrush); 104 for (int i = 0; i < count; i++) { 105 TableItem selected = selection[i]; 106 Rectangle cell = selected.getBounds(0); 107 POINT pt = new POINT(); 108 int imageList = OS.SendMessage (table.handle, OS.LVM_CREATEDRAGIMAGE, table.indexOf(selected), pt); 109 OS.ImageList_Draw(imageList, 0, hDC1, cell.x - bounds.x, cell.y - bounds.y, OS.ILD_SELECTED); 110 OS.ImageList_Destroy(imageList); 111 } 112 OS.SelectObject(hDC1, hOldBitmap); 113 OS.DeleteDC (hDC1); 114 OS.ReleaseDC (0, hDC); 115 Display display = table.getDisplay(); 116 dragSourceImage = Image.win32_new(display, SWT.BITMAP, bitmap); 117 return dragSourceImage; 118 } 119 return null; 120 } 121 } 122 | Popular Tags |