Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/dnd/ImageTransfer.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | c01d033c633a |
children |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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 module org.eclipse.swt.dnd.ImageTransfer; | |
12 | |
13 import org.eclipse.swt.SWT; | |
14 import org.eclipse.swt.graphics.Image; | |
15 import org.eclipse.swt.graphics.ImageData; | |
16 import org.eclipse.swt.internal.Converter; | |
17 import org.eclipse.swt.internal.gtk.OS; | |
18 import org.eclipse.swt.widgets.Display; | |
19 import org.eclipse.swt.dnd.ByteArrayTransfer; | |
20 import org.eclipse.swt.dnd.TransferData; | |
21 import org.eclipse.swt.dnd.DND; | |
22 | |
23 import java.lang.all; | |
24 | |
25 /** | |
26 * The class <code>ImageTransfer</code> provides a platform specific mechanism | |
27 * for converting an Image represented as a java <code>ImageData</code> to a | |
28 * platform specific representation of the data and vice versa. | |
29 * | |
30 * <p>An example of a java <code>ImageData</code> is shown below:</p> | |
31 * | |
32 * <code><pre> | |
33 * Image image = new Image(display, "C:\temp\img1.gif"); | |
34 * ImageData imgData = image.getImageData(); | |
35 * </code></pre> | |
36 * | |
37 * @see Transfer | |
38 * | |
39 * @since 3.4 | |
40 */ | |
41 public class ImageTransfer : ByteArrayTransfer { | |
42 | |
43 private static ImageTransfer _instance; | |
44 | |
45 private static const String JPEG = "image/jpge"; //$NON-NLS-1$ | |
46 private static int JPEG_ID; | |
47 private static const String PNG = "image/png"; //$NON-NLS-1$ | |
48 private static int PNG_ID; | |
49 private static const String BMP = "image/bmp"; //$NON-NLS-1$ | |
50 private static int BMP_ID; | |
51 private static const String EPS = "image/eps"; //$NON-NLS-1$ | |
52 private static int EPS_ID; | |
53 private static const String PCX = "image/pcx"; //$NON-NLS-1$ | |
54 private static int PCX_ID; | |
55 private static const String PPM = "image/ppm"; //$NON-NLS-1$ | |
56 private static int PPM_ID; | |
57 private static const String RGB = "image/ppm"; //$NON-NLS-1$ | |
58 private static int RGB_ID; | |
59 private static const String TGA = "image/tga"; //$NON-NLS-1$ | |
60 private static int TGA_ID; | |
61 private static const String XBM = "image/xbm"; //$NON-NLS-1$ | |
62 private static int XBM_ID; | |
63 private static const String XPM = "image/xpm"; //$NON-NLS-1$ | |
64 private static int XPM_ID; | |
65 private static const String XV = "image/xv"; //$NON-NLS-1$ | |
66 private static int XV_ID; | |
67 | |
68 static this(){ | |
69 JPEG_ID = registerType(JPEG); | |
70 PNG_ID = registerType(PNG); | |
71 BMP_ID = registerType(BMP); | |
72 EPS_ID = registerType(EPS); | |
73 PCX_ID = registerType(PCX); | |
74 PPM_ID = registerType(PPM); | |
75 RGB_ID = registerType(RGB); | |
76 TGA_ID = registerType(TGA); | |
77 XBM_ID = registerType(XBM); | |
78 XPM_ID = registerType(XPM); | |
79 XV_ID = registerType(XV); | |
80 _instance = new ImageTransfer(); | |
81 } | |
82 | |
83 private this() { | |
84 } | |
85 | |
86 /** | |
87 * Returns the singleton instance of the ImageTransfer class. | |
88 * | |
89 * @return the singleton instance of the ImageTransfer class | |
90 */ | |
91 public static ImageTransfer getInstance () { | |
92 return _instance; | |
93 } | |
94 | |
95 /** | |
96 * This implementation of <code>javaToNative</code> converts an ImageData object represented | |
97 * by java <code>ImageData</code> to a platform specific representation. | |
98 * | |
99 * @param object a java <code>ImageData</code> containing the ImageData to be converted | |
100 * @param transferData an empty <code>TransferData</code> object that will | |
101 * be filled in on return with the platform specific format of the data | |
102 * | |
103 * @see Transfer#nativeToJava | |
104 */ | |
105 public void javaToNative(Object object, TransferData transferData) { | |
106 if (!checkImage(object) || !isSupportedType(transferData)) { | |
107 DND.error(DND.ERROR_INVALID_DATA); | |
108 } | |
109 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0)) return; | |
110 | |
111 ImageData imgData = cast(ImageData)object; | |
112 if (imgData is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
113 Image image = new Image(Display.getCurrent(), imgData); | |
114 auto pixmap = image.pixmap; | |
115 int width = imgData.width; | |
116 int height = imgData.height; | |
117 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height); | |
118 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
119 auto colormap = OS.gdk_colormap_get_system(); | |
120 OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height); | |
121 | |
122 String typeStr = ""; | |
123 if (transferData.type is cast(void*)JPEG_ID) typeStr = "jpeg"; | |
124 if (transferData.type is cast(void*)PNG_ID) typeStr = "png"; | |
125 if (transferData.type is cast(void*)BMP_ID) typeStr = "bmp"; | |
126 if (transferData.type is cast(void*)EPS_ID) typeStr = "eps"; | |
127 if (transferData.type is cast(void*)PCX_ID) typeStr = "pcx"; | |
128 if (transferData.type is cast(void*)PPM_ID) typeStr = "ppm"; | |
129 if (transferData.type is cast(void*)RGB_ID) typeStr = "rgb"; | |
130 if (transferData.type is cast(void*)TGA_ID) typeStr = "tga"; | |
131 if (transferData.type is cast(void*)XBM_ID) typeStr = "xbm"; | |
132 if (transferData.type is cast(void*)XPM_ID) typeStr = "xpm"; | |
133 if (transferData.type is cast(void*)XV_ID) typeStr = "xv"; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
51
diff
changeset
|
134 auto type = typeStr.ptr; |
25 | 135 char* buffer; |
136 uint len; | |
137 if (type is null) return; | |
138 OS.gdk_pixbuf_save_to_buffer0(pixbuf, &buffer, &len, type, null); | |
139 OS.g_object_unref(pixbuf); | |
140 image.dispose(); | |
141 transferData.pValue = buffer; | |
142 transferData.length = (len + 3) / 4 * 4; | |
143 transferData.result = 1; | |
144 transferData.format = 32; | |
145 } | |
146 | |
147 /** | |
148 * This implementation of <code>nativeToJava</code> converts a platform specific | |
149 * representation of an image to java <code>ImageData</code>. | |
150 * | |
151 * @param transferData the platform specific representation of the data to be converted | |
152 * @return a java <code>ImageData</code> of the image if the conversion was successful; | |
153 * otherwise null | |
154 * | |
155 * @see Transfer#javaToNative | |
156 */ | |
157 public Object nativeToJava(TransferData transferData) { | |
158 ImageData imgData = null; | |
159 if (transferData.length > 0) | |
160 { | |
161 auto loader = OS.gdk_pixbuf_loader_new(); | |
162 OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null); | |
163 OS.gdk_pixbuf_loader_close(loader, null); | |
164 auto pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader); | |
165 if (pixbuf !is null) { | |
166 OS.g_object_ref(pixbuf); | |
167 GdkPixmap* pixmap_return; | |
168 OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap_return, null, 0); | |
169 auto handle = pixmap_return; | |
170 if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
171 OS.g_object_unref(loader); | |
172 Image img = Image.gtk_new(Display.getCurrent(), SWT.BITMAP, handle, null); | |
173 imgData = img.getImageData(); | |
174 img.dispose(); | |
175 } | |
176 } | |
177 return imgData; | |
178 } | |
179 | |
180 protected int[] getTypeIds(){ | |
181 return [JPEG_ID, PNG_ID, BMP_ID, EPS_ID, PCX_ID, PPM_ID, RGB_ID, TGA_ID, XBM_ID, XPM_ID, XV_ID]; | |
182 } | |
183 | |
184 protected String[] getTypeNames(){ | |
185 return [JPEG, PNG, BMP, EPS, PCX, PPM, RGB, TGA, XBM, XPM, XV]; | |
186 } | |
187 | |
188 bool checkImage(Object object) { | |
189 if (object is null || !( null !is cast(ImageData)object )) return false; | |
190 return true; | |
191 } | |
192 | |
193 protected bool validate(Object object) { | |
194 return checkImage(object); | |
195 } | |
196 } |