Skip to content

Commit 3129e06

Browse files
Jason Wangakurtakov
authored andcommitted
Bug 476 - SWT clipboard HTML transfer doesn't work
+ implemented HTML transfer in gtk4 clipboard snipper Signed-off-by: Jason Wang
1 parent 565d5de commit 3129e06

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ private Object getContents_gtk4(Transfer transfer, int clipboards) {
349349
}
350350
return str;
351351
}
352+
//Pasting of Image
352353
if(transfer.getTypeIds()[0] == (int)GDK.GDK_TYPE_PIXBUF()) {
353354
ImageData imgData = null;
354355
OS.g_value_init(value, GDK.GDK_TYPE_PIXBUF());
@@ -361,6 +362,22 @@ private Object getContents_gtk4(Transfer transfer, int clipboards) {
361362
}
362363
return imgData;
363364
}
365+
//Pasting of HTML
366+
if(transfer.getTypeNames()[0].equals("text/html")) {
367+
OS.g_value_init(value, OS.G_TYPE_STRING());
368+
if (!GTK4.gdk_content_provider_get_value (contents, value, null)) return null;
369+
long cStr = OS.g_value_get_string(value);
370+
long [] items_written = new long [1];
371+
long utf16Ptr = OS.g_utf8_to_utf16(cStr, -1, null, items_written, null);
372+
OS.g_free(cStr);
373+
if (utf16Ptr == 0) return null;
374+
int length = (int)items_written[0];
375+
char[] buffer = new char[length];
376+
C.memmove(buffer, utf16Ptr, length * 2);
377+
OS.g_free(utf16Ptr);
378+
String str = new String(buffer);
379+
return str;
380+
}
364381
//TODO: [GTK4] Other cases
365382
return null;
366383
}

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ClipboardProxy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ private long setProviderFromType(String string, Object data) {
270270
}
271271
image.dispose();
272272
}
273+
if(string.equals("text/html")) {
274+
long value = OS.g_malloc (OS.GValue_sizeof());
275+
C.memset (value, 0, OS.GValue_sizeof ());
276+
OS.g_value_init(value, OS.G_TYPE_STRING());
277+
OS.g_value_set_string(value, Converter.javaStringToCString((String)data));
278+
provider = GTK4.gdk_content_provider_new_for_value(value);
279+
}
280+
273281
}
274282
return provider;
275283
}

0 commit comments

Comments
 (0)