Skip to content

Commit 662c4fb

Browse files
author
Duong Nguyen
committed
Bug 78856 - [Clipboard] SWT has no support for Image copy to clipboard
1 parent 7d48164 commit 662c4fb

File tree

4 files changed

+241
-0
lines changed

4 files changed

+241
-0
lines changed

bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.gtk.OS.properties

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,21 @@ OS__gdk_pixbuf_get_rowstride_0=cast=(const GdkPixbuf *)
17021702
OS__gdk_pixbuf_get_width=
17031703
OS__gdk_pixbuf_get_width_0=cast=(const GdkPixbuf *)
17041704

1705+
OS__gdk_pixbuf_loader_close=
1706+
OS__gdk_pixbuf_loader_close_0=cast=(GdkPixbufLoader *)
1707+
OS__gdk_pixbuf_loader_close_1=cast=(GError **)
1708+
1709+
OS__gdk_pixbuf_loader_get_pixbuf=
1710+
OS__gdk_pixbuf_loader_get_pixbuf_0=cast=(GdkPixbufLoader *)
1711+
1712+
OS__gdk_pixbuf_loader_new=
1713+
1714+
OS__gdk_pixbuf_loader_write=
1715+
OS__gdk_pixbuf_loader_write_0=cast=(GdkPixbufLoader *)
1716+
OS__gdk_pixbuf_loader_write_1=cast=(const guchar *)
1717+
OS__gdk_pixbuf_loader_write_2=cast=(gsize)
1718+
OS__gdk_pixbuf_loader_write_3=cast=(GError **)
1719+
17051720
OS__gdk_pixbuf_new=
17061721
OS__gdk_pixbuf_new_0=cast=(GdkColorspace)
17071722
OS__gdk_pixbuf_new_1=cast=(gboolean)
@@ -1748,6 +1763,14 @@ OS__gdk_pixbuf_render_to_drawable_alpha_10=cast=(GdkRgbDither)
17481763
OS__gdk_pixbuf_render_to_drawable_alpha_11=
17491764
OS__gdk_pixbuf_render_to_drawable_alpha_12=
17501765

1766+
OS__gdk_pixbuf_save_to_buffer=flags=dynamic
1767+
OS__gdk_pixbuf_save_to_buffer_0=cast=(GdkPixbuf *)
1768+
OS__gdk_pixbuf_save_to_buffer_1=cast=(gchar **)
1769+
OS__gdk_pixbuf_save_to_buffer_2=cast=(gsize *)
1770+
OS__gdk_pixbuf_save_to_buffer_3=cast=(const char *)
1771+
OS__gdk_pixbuf_save_to_buffer_4=cast=(GError **)
1772+
OS__gdk_pixbuf_save_to_buffer_5=cast=(char *)
1773+
17511774
OS__gdk_pixbuf_scale=
17521775
OS__gdk_pixbuf_scale_0=cast=(const GdkPixbuf *)
17531776
OS__gdk_pixbuf_scale_1=cast=(GdkPixbuf *)
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2000, 2004 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* IBM Corporation - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.swt.dnd;
12+
13+
import org.eclipse.swt.SWT;
14+
import org.eclipse.swt.graphics.*;
15+
import org.eclipse.swt.internal.Converter;
16+
import org.eclipse.swt.internal.gtk.*;
17+
import org.eclipse.swt.widgets.*;
18+
19+
/**
20+
* The class <code>ImageTransfer</code> provides a platform specific mechanism
21+
* for converting a Image represented as a java <code>ImageData</code> to a
22+
* platform specific representation of the data and vice versa.
23+
* See <code>Transfer</code> for additional information.
24+
*
25+
* <p>An example of a java <code>ImageData</code> is shown
26+
* below:</p>
27+
*
28+
* <code><pre>
29+
* Image image = new Image("C:\temp\img1.gif");
30+
* ImageData imgData = image.getImageData();
31+
* </code></pre>
32+
*/
33+
public class ImageTransfer extends ByteArrayTransfer {
34+
35+
private static ImageTransfer _instance = new ImageTransfer();
36+
37+
private static final String JPEG = "image/jpge"; //$NON-NLS-1$
38+
private static final int JPEG_ID = registerType(JPEG);
39+
private static final String PNG = "image/png"; //$NON-NLS-1$
40+
private static final int PNG_ID = registerType(PNG);
41+
private static final String BMP = "image/bmp"; //$NON-NLS-1$
42+
private static final int BMP_ID = registerType(BMP);
43+
private static final String EPS = "image/eps"; //$NON-NLS-1$
44+
private static final int EPS_ID = registerType(EPS);
45+
private static final String PCX = "image/pcx"; //$NON-NLS-1$
46+
private static final int PCX_ID = registerType(PCX);
47+
private static final String PPM = "image/ppm"; //$NON-NLS-1$
48+
private static final int PPM_ID = registerType(PPM);
49+
private static final String RGB = "image/ppm"; //$NON-NLS-1$
50+
private static final int RGB_ID = registerType(RGB);
51+
private static final String TGA = "image/tga"; //$NON-NLS-1$
52+
private static final int TGA_ID = registerType(TGA);
53+
private static final String XBM = "image/xbm"; //$NON-NLS-1$
54+
private static final int XBM_ID = registerType(XBM);
55+
private static final String XPM = "image/xpm"; //$NON-NLS-1$
56+
private static final int XPM_ID = registerType(XPM);
57+
private static final String XV = "image/xv"; //$NON-NLS-1$
58+
private static final int XV_ID = registerType(XV);
59+
60+
private ImageTransfer() {}
61+
62+
/**
63+
* Returns the singleton instance of the ImageTransfer class.
64+
*
65+
* @return the singleton instance of the ImageTransfer class
66+
*/
67+
public static ImageTransfer getInstance () {
68+
return _instance;
69+
}
70+
71+
/**
72+
* This implementation of <code>javaToNative</code> converts an ImageData object represented
73+
* by java <code>ImageData</code> to a platform specific representation.
74+
* For additional information see <code>Transfer#javaToNative</code>.
75+
*
76+
* @param object a java <code>ImageData</code> containing the ImageData to be
77+
* converted
78+
* @param transferData an empty <code>TransferData</code> object; this
79+
* object will be filled in on return with the platform specific format of the data
80+
*/
81+
public void javaToNative(Object object, TransferData transferData) {
82+
if (!checkImage(object) || !isSupportedType(transferData)) {
83+
DND.error(DND.ERROR_INVALID_DATA);
84+
}
85+
if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) return;
86+
87+
ImageData imgData = (ImageData)object;
88+
if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
89+
Image image = new Image(Display.getCurrent(), imgData);
90+
int /*long*/ pixmap = image.pixmap;
91+
int width = imgData.width;
92+
int height = imgData.height;
93+
int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height);
94+
if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
95+
int /*long*/ colormap = OS.gdk_colormap_get_system();
96+
OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
97+
98+
String typeStr = "";
99+
if (transferData.type == JPEG_ID) typeStr = "jpeg";
100+
if (transferData.type == PNG_ID) typeStr = "png";
101+
if (transferData.type == BMP_ID) typeStr = "bmp";
102+
if (transferData.type == EPS_ID) typeStr = "eps";
103+
if (transferData.type == PCX_ID) typeStr = "pcx";
104+
if (transferData.type == PPM_ID) typeStr = "ppm";
105+
if (transferData.type == RGB_ID) typeStr = "rgb";
106+
if (transferData.type == TGA_ID) typeStr = "tga";
107+
if (transferData.type == XBM_ID) typeStr = "xbm";
108+
if (transferData.type == XPM_ID) typeStr = "xpm";
109+
if (transferData.type == XV_ID) typeStr = "xv";
110+
byte[] type = Converter.wcsToMbcs(null, typeStr , true);
111+
int /*long*/ [] buffer = new int /*long*/ [1];
112+
int [] len = new int [1];
113+
if (type == null) return;
114+
OS.gdk_pixbuf_save_to_buffer(pixbuf, buffer, len, type , null, null);
115+
OS.g_object_unref(pixbuf);
116+
image.dispose();
117+
transferData.pValue = buffer[0];
118+
transferData.length = len[0];
119+
transferData.result = 1;
120+
transferData.format = 32;
121+
}
122+
123+
/**
124+
* This implementation of <code>nativeToJava</code> converts a platform specific
125+
* representation of an <code>ImageData</code> to java.
126+
* For additional information see <code>Transfer#nativeToJava</code>.
127+
*
128+
* @param transferData the platform specific representation of the data to be
129+
* been converted
130+
* @return a java <code>ImageData</code> the imageData of the image if
131+
* conversion was successful; otherwise null
132+
*/
133+
public Object nativeToJava(TransferData transferData) {
134+
ImageData imgData = null;
135+
if (transferData.length > 0)
136+
{
137+
int /*long*/ loader = OS.gdk_pixbuf_loader_new();
138+
OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null);
139+
OS.gdk_pixbuf_loader_close(loader, null);
140+
int /*long*/ pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader);
141+
if (pixbuf != 0) {
142+
OS.g_object_ref(pixbuf);
143+
int /*long*/ [] pixmap_return = new int /*long*/ [1];
144+
OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, null, 0);
145+
int /*long*/ handle = pixmap_return[0];
146+
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
147+
OS.g_object_unref(loader);
148+
Image img = Image.gtk_new(Display.getCurrent(), SWT.BITMAP, handle, 0);
149+
imgData = img.getImageData();
150+
img.dispose();
151+
}
152+
}
153+
return imgData;
154+
}
155+
156+
protected int[] getTypeIds(){
157+
return new int[]{JPEG_ID, PNG_ID, BMP_ID, EPS_ID, PCX_ID, PPM_ID, RGB_ID, TGA_ID, XBM_ID, XPM_ID, XV_ID};
158+
}
159+
160+
protected String[] getTypeNames(){
161+
return new String[]{JPEG, PNG, BMP, EPS, PCX, PPM, RGB, TGA, XBM, XPM, XV};
162+
}
163+
164+
boolean checkImage(Object object) {
165+
if (object == null || !(object instanceof ImageData)) return false;
166+
return true;
167+
}
168+
169+
protected boolean validate(Object object) {
170+
return checkImage(object);
171+
}
172+
}

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#define gdk_display_get_default_LIB "libgdk-x11-2.0.so.0"
8383
#define gdk_display_supports_cursor_color_LIB "libgdk-x11-2.0.so.0"
8484
#define gdk_draw_pixbuf_LIB "libgdk-x11-2.0.so.0"
85+
#define gdk_pixbuf_save_to_buffer_LIB "libgdk-x11-2.0.so.0"
8586
#define gdk_screen_get_default_LIB "libgdk-x11-2.0.so.0"
8687
#define gdk_screen_get_monitor_at_point_LIB "libgdk-x11-2.0.so.0"
8788
#define gdk_screen_get_monitor_at_window_LIB "libgdk-x11-2.0.so.0"

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,42 @@ public static final int gdk_pixbuf_get_width(int /*long*/ pixbuf) {
29832983
lock.unlock();
29842984
}
29852985
}
2986+
public static final native int /*long*/ _gdk_pixbuf_loader_new();
2987+
public static final int /*long*/ gdk_pixbuf_loader_new() {
2988+
lock.lock();
2989+
try {
2990+
return _gdk_pixbuf_loader_new();
2991+
} finally {
2992+
lock.unlock();
2993+
}
2994+
}
2995+
public static final native boolean _gdk_pixbuf_loader_close(int /*long*/ loader, int /*long*/ [] error);
2996+
public static final boolean gdk_pixbuf_loader_close(int /*long*/ loader, int /*long*/ [] error) {
2997+
lock.lock();
2998+
try {
2999+
return _gdk_pixbuf_loader_close(loader, error);
3000+
} finally {
3001+
lock.unlock();
3002+
}
3003+
}
3004+
public static final native int /*long*/ _gdk_pixbuf_loader_get_pixbuf(int /*long*/ loader);
3005+
public static final int /*long*/ gdk_pixbuf_loader_get_pixbuf(int /*long*/ loader) {
3006+
lock.lock();
3007+
try {
3008+
return _gdk_pixbuf_loader_get_pixbuf(loader);
3009+
} finally {
3010+
lock.unlock();
3011+
}
3012+
}
3013+
public static final native boolean _gdk_pixbuf_loader_write(int /*long*/ loader, int /*long*/ buffer, int count, int /*long*/ [] error);
3014+
public static final boolean gdk_pixbuf_loader_write(int /*long*/ loader, int /*long*/ buffer, int count, int /*long*/ [] error) {
3015+
lock.lock();
3016+
try {
3017+
return _gdk_pixbuf_loader_write(loader, buffer, count, error);
3018+
} finally {
3019+
lock.unlock();
3020+
}
3021+
}
29863022
public static final native int /*long*/ _gdk_pixbuf_new(int colorspace, boolean has_alpha, int bits_per_sample, int width, int height);
29873023
public static final int /*long*/ gdk_pixbuf_new(int colorspace, boolean has_alpha, int bits_per_sample, int width, int height) {
29883024
lock.lock();
@@ -3028,6 +3064,15 @@ public static final void gdk_pixbuf_render_pixmap_and_mask(int /*long*/ pixbuf,
30283064
lock.unlock();
30293065
}
30303066
}
3067+
public static final native boolean _gdk_pixbuf_save_to_buffer(int /*long*/ pixbuf, int /*long*/ [] buffer, int [] buffer_size, byte [] type, int /*long*/ [] error, byte [] terminate);
3068+
public static final boolean gdk_pixbuf_save_to_buffer(int /*long*/ pixbuf, int /*long*/ [] buffer, int [] buffer_size, byte [] type, int /*long*/ [] error, byte [] terminate) {
3069+
lock.lock();
3070+
try {
3071+
return _gdk_pixbuf_save_to_buffer(pixbuf, buffer, buffer_size, type, error, terminate);
3072+
} finally {
3073+
lock.unlock();
3074+
}
3075+
}
30313076
public static final native void _gdk_pixbuf_scale(int /*long*/ src, int /*long*/ dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, int interp_type);
30323077
public static final void gdk_pixbuf_scale(int /*long*/ src, int /*long*/ dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, int interp_type) {
30333078
lock.lock();

0 commit comments

Comments
 (0)