diff options
author | Arun Thondapu <arunkumar.thondapu@in.ibm.com> | 2013-05-01 17:58:21 +0530 |
---|---|---|
committer | Arun Thondapu <arunkumar.thondapu@in.ibm.com> | 2013-05-01 18:15:48 +0530 |
commit | aa3c6d8a75ecd3aa62e9b9ee7768d59f601718ad (patch) | |
tree | 41a1d8051fd2d6d5e6875a4c70b6ef06a89baa2f /bundles | |
parent | bcac6ad70ee319247deb043444a858ffd48b487d (diff) | |
download | eclipse.platform.swt-aa3c6d8a75ecd3aa62e9b9ee7768d59f601718ad.tar.gz eclipse.platform.swt-aa3c6d8a75ecd3aa62e9b9ee7768d59f601718ad.tar.xz eclipse.platform.swt-aa3c6d8a75ecd3aa62e9b9ee7768d59f601718ad.zip |
Bug 392774 - [GTK3] Need to implement
Table/TreeDragSourceEffect.getDragSourceImage
Diffstat (limited to 'bundles')
9 files changed, 144 insertions, 71 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java index 0dca6b0a22..7af9356a17 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java @@ -299,9 +299,13 @@ void drag(Event dragEvent) { Image image = event.image; long /*int*/ context = OS.gtk_drag_begin(control.handle, targetList, actions, 1, 0); if (context != 0 && image != null) { - long /*int*/ pixbuf = ImageList.createPixbuf(image); - OS.gtk_drag_set_icon_pixbuf(context, pixbuf, 0, 0); - OS.g_object_unref(pixbuf); + if (OS.GTK3) { + OS.gtk_drag_set_icon_surface(context, image.surface); + } else { + long /*int*/ pixbuf = ImageList.createPixbuf(image); + OS.gtk_drag_set_icon_pixbuf(context, pixbuf, 0, 0); + OS.g_object_unref(pixbuf); + } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java index aee782f2bd..398a4fc6a6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java @@ -12,6 +12,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.cairo.Cairo; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.widgets.*; @@ -77,14 +78,12 @@ public class TableDragSourceEffect extends DragSourceEffect { Image getDragSourceImage(DragSourceEvent event) { if (dragSourceImage != null) dragSourceImage.dispose(); - dragSourceImage = null; - + dragSourceImage = null; + Table table = (Table) control; //TEMPORARY CODE if (table.isListening(SWT.EraseItem) || table.isListening (SWT.PaintItem)) return null; - if (OS.GTK3) 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 @@ -100,23 +99,26 @@ public class TableDragSourceEffect extends DragSourceEffect { 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); + long /*int*/ icon = OS.gtk_tree_view_create_row_drag_icon (handle, path); + dragSourceImage = Image.gtk_new (display, SWT.ICON, icon, 0); OS.gtk_tree_path_free (path); } 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]; + long /*int*/ [] icons = 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); - if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) { - OS.gdk_pixmap_get_size(pixmaps[i], w, h); + icons[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path); + if (OS.GTK3) { + w[0] = Cairo.cairo_xlib_surface_get_width(icons[i]); + h[0] = Cairo.cairo_xlib_surface_get_height(icons[i]); + } else if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) { + OS.gdk_pixmap_get_size(icons[i], w, h); } else { - OS.gdk_drawable_get_size(pixmaps[i], w, h); + OS.gdk_drawable_get_size(icons[i], w, h); } width = Math.max(width, w[0]); height = rect.y + h[0] - yy[0]; @@ -124,27 +126,42 @@ public class TableDragSourceEffect extends DragSourceEffect { hh[i] = h[0]; OS.gtk_tree_path_free (path); } - long /*int*/ source = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), width, height, -1); - long /*int*/ gcSource = OS.gdk_gc_new(source); - long /*int*/ mask = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), 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]); + if (OS.GTK3) { + long /*int*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, width, height); + if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + long /*int*/ cairo = Cairo.cairo_create(surface); + if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); + Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); + for (int i=0; i<count; i++) { + Cairo.cairo_set_source_surface (cairo, icons[i], 2, yy[i] - yy[0] + 2); + Cairo.cairo_rectangle(cairo, 0, yy[i] - yy[0], width, hh[i]); + Cairo.cairo_fill(cairo); + Cairo.cairo_surface_destroy(icons[i]); + } + Cairo.cairo_destroy(cairo); + dragSourceImage = Image.gtk_new (display, SWT.ICON, surface, 0); + } else { + long /*int*/ source = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), width, height, -1); + long /*int*/ gcSource = OS.gdk_gc_new(source); + long /*int*/ mask = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), 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, icons[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(icons[i]); + } + OS.g_object_unref(gcSource); + OS.g_object_unref(gcMask); + dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask); } - 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; -} + } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java index d7a7f544bb..0df42a302e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java @@ -12,6 +12,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.cairo.Cairo; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.widgets.*; @@ -76,19 +77,17 @@ public class TreeDragSourceEffect extends DragSourceEffect { Image getDragSourceImage(DragSourceEvent event) { if (dragSourceImage != null) dragSourceImage.dispose(); - dragSourceImage = null; - + dragSourceImage = null; + Tree tree = (Tree) control; //TEMPORARY CODE if (tree.isListening(SWT.EraseItem) || tree.isListening (SWT.PaintItem)) return null; - - if (OS.GTK3) 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. - */ + * 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 = tree.handle; long /*int*/ selection = OS.gtk_tree_view_get_selection (handle); long /*int*/ [] model = null; @@ -99,23 +98,26 @@ public class TreeDragSourceEffect extends DragSourceEffect { Display display = tree.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); + long /*int*/ icon = OS.gtk_tree_view_create_row_drag_icon (handle, path); + dragSourceImage = Image.gtk_new (display, SWT.ICON, icon, 0); OS.gtk_tree_path_free (path); } 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]; + long /*int*/ [] icons = 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); - if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) { - OS.gdk_pixmap_get_size(pixmaps[i], w, h); + icons[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path); + if (OS.GTK3) { + w[0] = Cairo.cairo_xlib_surface_get_width(icons[i]); + h[0] = Cairo.cairo_xlib_surface_get_height(icons[i]); + } else if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) { + OS.gdk_pixmap_get_size(icons[i], w, h); } else { - OS.gdk_drawable_get_size(pixmaps[i], w, h); + OS.gdk_drawable_get_size(icons[i], w, h); } width = Math.max(width, w[0]); height = rect.y + h[0] - yy[0]; @@ -123,27 +125,42 @@ public class TreeDragSourceEffect extends DragSourceEffect { hh[i] = h[0]; OS.gtk_tree_path_free (path); } - long /*int*/ source = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), width, height, -1); - long /*int*/ gcSource = OS.gdk_gc_new(source); - long /*int*/ mask = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), 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]); + if (OS.GTK3) { + long /*int*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, width, height); + if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + long /*int*/ cairo = Cairo.cairo_create(surface); + if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); + Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); + for (int i=0; i<count; i++) { + Cairo.cairo_set_source_surface (cairo, icons[i], 2, yy[i] - yy[0] + 2); + Cairo.cairo_rectangle(cairo, 0, yy[i] - yy[0], width, hh[i]); + Cairo.cairo_fill(cairo); + Cairo.cairo_surface_destroy(icons[i]); + } + Cairo.cairo_destroy(cairo); + dragSourceImage = Image.gtk_new (display, SWT.ICON, surface, 0); + } else { + long /*int*/ source = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), width, height, -1); + long /*int*/ gcSource = OS.gdk_gc_new(source); + long /*int*/ mask = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), 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, icons[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(icons[i]); + } + OS.g_object_unref(gcSource); + OS.g_object_unref(gcMask); + dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask); } - 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; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 7dab5cae2f..4380b5db65 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -9715,6 +9715,24 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1drag_1set_1icon_1pixbuf) } #endif +#ifndef NO__1gtk_1drag_1set_1icon_1surface +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1drag_1set_1icon_1surface) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1drag_1set_1icon_1surface_FUNC); +/* + gtk_drag_set_icon_surface(arg0, arg1); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_drag_set_icon_surface) + if (fp) { + ((void (CALLING_CONVENTION*)(jintLong, jintLong))fp)(arg0, arg1); + } + } + OS_NATIVE_EXIT(env, that, _1gtk_1drag_1set_1icon_1surface_FUNC); +} +#endif + #ifndef NO__1gtk_1editable_1copy_1clipboard JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1editable_1copy_1clipboard) (JNIEnv *env, jclass that, jintLong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h index 59978fde8b..5a0fdf0521 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h @@ -554,6 +554,7 @@ #define gtk_css_provider_load_from_data_LIB LIB_GTK #define gtk_css_provider_new_LIB LIB_GTK #define gtk_icon_set_render_icon_pixbuf_LIB LIB_GTK +#define gtk_drag_set_icon_surface_LIB LIB_GTK #ifndef g_thread_supported #define g_thread_supported() 0 diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index bcfe4aaa8a..a35540aee0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -717,6 +717,7 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1drag_1finish", "_1gtk_1drag_1get_1data", "_1gtk_1drag_1set_1icon_1pixbuf", + "_1gtk_1drag_1set_1icon_1surface", "_1gtk_1editable_1copy_1clipboard", "_1gtk_1editable_1cut_1clipboard", "_1gtk_1editable_1delete_1selection", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index b702d8c3c6..a951b2e234 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -727,6 +727,7 @@ typedef enum { _1gtk_1drag_1finish_FUNC, _1gtk_1drag_1get_1data_FUNC, _1gtk_1drag_1set_1icon_1pixbuf_FUNC, + _1gtk_1drag_1set_1icon_1surface_FUNC, _1gtk_1editable_1copy_1clipboard_FUNC, _1gtk_1editable_1cut_1clipboard_FUNC, _1gtk_1editable_1delete_1selection_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index 2185af4d77..6acb26ba74 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -7005,6 +7005,16 @@ public static final void gtk_drag_set_icon_pixbuf(long /*int*/ context, long /*i lock.unlock(); } } +/** @method flags=dynamic */ +public static final native void _gtk_drag_set_icon_surface(long /*int*/ context, long /*int*/ surface); +public static final void gtk_drag_set_icon_surface(long /*int*/ context, long /*int*/ surface) { + lock.lock(); + try { + _gtk_drag_set_icon_surface(context, surface); + } finally { + lock.unlock(); + } +} /** @param editable cast=(GtkEditable *) */ public static final native void _gtk_editable_copy_clipboard(long /*int*/ editable); public static final void gtk_editable_copy_clipboard(long /*int*/ editable) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index b8ec1055d2..61beb09f55 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -1227,17 +1227,21 @@ public ImageData getImageData() { * * @param device the device on which to allocate the color * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>) - * @param pixmap the OS handle for the image + * @param imageHandle the OS handle for the image * @param mask the OS handle for the image mask * * @noreference This method is not intended to be referenced by clients. */ -public static Image gtk_new(Device device, int type, long /*int*/ pixmap, long /*int*/ mask) { +public static Image gtk_new(Device device, int type, long /*int*/ imageHandle, long /*int*/ mask) { Image image = new Image(device); image.type = type; - image.pixmap = pixmap; + if (OS.GTK3) { + image.surface = imageHandle; + } else { + image.pixmap = imageHandle; + if (OS.USE_CAIRO) image.createSurface(); + } image.mask = mask; - if (OS.USE_CAIRO) image.createSurface(); return image; } |