/** * This implementation of <code>javaToNative</code> converts an ImageData object represented by * java <code>ImageData</code> to a platform specific representation. * * @param object a java <code>ImageData</code> containing the ImageData to be converted * @param transferData an empty <code>TransferData</code> object that will be filled in on return * with the platform specific format of the data * @see Transfer#nativeToJava */ public void javaToNative(Object object, TransferData transferData) { if (!checkImage(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } if (OS.GTK_VERSION < OS.VERSION(2, 4, 0)) return; ImageData imgData = (ImageData) object; if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); Image image = new Image(Display.getCurrent(), imgData); long /*int*/ pixbuf = ImageList.createPixbuf(image); if (pixbuf != 0) { String typeStr = ""; if (transferData.type == JPEG_ID) typeStr = "jpeg"; else if (transferData.type == PNG_ID) typeStr = "png"; else if (transferData.type == BMP_ID) typeStr = "bmp"; else if (transferData.type == EPS_ID) typeStr = "eps"; else if (transferData.type == PCX_ID) typeStr = "pcx"; else if (transferData.type == PPM_ID) typeStr = "ppm"; else if (transferData.type == RGB_ID) typeStr = "rgb"; else if (transferData.type == TGA_ID) typeStr = "tga"; else if (transferData.type == XBM_ID) typeStr = "xbm"; else if (transferData.type == XPM_ID) typeStr = "xpm"; else if (transferData.type == XV_ID) typeStr = "xv"; byte[] type = Converter.wcsToMbcs(null, typeStr, true); long /*int*/[] buffer = new long /*int*/[1]; long /*int*/[] len = new long /*int*/[1]; if (type == null) return; OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null); OS.g_object_unref(pixbuf); transferData.pValue = buffer[0]; transferData.length = (int) (len[0] + 3) / 4 * 4; transferData.result = 1; transferData.format = 32; } image.dispose(); }
Image getDragSourceImage(DragSourceEvent event) { if (dragSourceImage != null) dragSourceImage.dispose(); dragSourceImage = null; Table table = (Table) control; if (OS.GTK_VERSION < OS.VERSION(2, 2, 0)) return null; // TEMPORARY CODE if (table.isListening(SWT.EraseItem) || table.isListening(SWT.PaintItem)) return null; /* * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults * in versions smaller than 2.2.4 if the model is NULL. The fix is * to give a valid pointer instead. */ long /*int*/ handle = table.handle; long /*int*/ selection = OS.gtk_tree_view_get_selection(handle); long /*int*/[] model = OS.GTK_VERSION < OS.VERSION(2, 2, 4) ? new long /*int*/[1] : null; long /*int*/ list = OS.gtk_tree_selection_get_selected_rows(selection, model); if (list == 0) return null; int count = Math.min(10, OS.g_list_length(list)); Display display = table.getDisplay(); if (count == 1) { long /*int*/ path = OS.g_list_nth_data(list, 0); long /*int*/ pixmap = OS.gtk_tree_view_create_row_drag_icon(handle, path); dragSourceImage = Image.gtk_new(display, SWT.ICON, pixmap, 0); } else { int width = 0, height = 0; int[] w = new int[1], h = new int[1]; int[] yy = new int[count], hh = new int[count]; long /*int*/[] pixmaps = new long /*int*/[count]; GdkRectangle rect = new GdkRectangle(); for (int i = 0; i < count; i++) { long /*int*/ path = OS.g_list_nth_data(list, i); OS.gtk_tree_view_get_cell_area(handle, path, 0, rect); pixmaps[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path); OS.gdk_drawable_get_size(pixmaps[i], w, h); width = Math.max(width, w[0]); height = rect.y + h[0] - yy[0]; yy[i] = rect.y; hh[i] = h[0]; } long /*int*/ source = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1); long /*int*/ gcSource = OS.gdk_gc_new(source); long /*int*/ mask = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, 1); long /*int*/ gcMask = OS.gdk_gc_new(mask); GdkColor color = new GdkColor(); color.pixel = 0; OS.gdk_gc_set_foreground(gcMask, color); OS.gdk_draw_rectangle(mask, gcMask, 1, 0, 0, width, height); color.pixel = 1; OS.gdk_gc_set_foreground(gcMask, color); for (int i = 0; i < count; i++) { OS.gdk_draw_drawable(source, gcSource, pixmaps[i], 0, 0, 0, yy[i] - yy[0], -1, -1); OS.gdk_draw_rectangle(mask, gcMask, 1, 0, yy[i] - yy[0], width, hh[i]); OS.g_object_unref(pixmaps[i]); } OS.g_object_unref(gcSource); OS.g_object_unref(gcMask); dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask); } OS.g_list_free(list); return dragSourceImage; }