diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java index 16419832aa6..65e9c736424 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -570,7 +570,6 @@ public TransferData[] getAvailableTypes() { public TransferData[] getAvailableTypes(int clipboards) { checkWidget(); - //TODO: [GTK4] This currently will not work in GTK4 TransferData[] result = null; if ((clipboards & DND.CLIPBOARD) != 0) { int[] types = getAvailableClipboardTypes(); @@ -656,27 +655,36 @@ public String[] getAvailableTypeNames() { } private int[] getAvailablePrimaryTypes() { - int[] types = new int[0]; - long selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, TARGET); - if (selection_data != 0) { - try { - int length = GTK3.gtk_selection_data_get_length(selection_data); - int format = GTK3.gtk_selection_data_get_format(selection_data); - long data = GTK3.gtk_selection_data_get_data(selection_data); - if (length != 0) { - types = new int[length * 8 / format]; - C.memmove(types, data, length); - } - } finally { - GTK3.gtk_selection_data_free(selection_data); - } + if (GTK.GTK4) { + return gtk4_getAvailableTypes(GTKPRIMARYCLIPBOARD); } - return types; + return gtk3_getAvailableTypes(GTKPRIMARYCLIPBOARD); } private int[] getAvailableClipboardTypes () { + if (GTK.GTK4) { + return gtk4_getAvailableTypes(GTKCLIPBOARD); + } + return gtk3_getAvailableTypes(GTKCLIPBOARD); +} + +private int[] gtk4_getAvailableTypes(long clipboard) { + long formats = GTK4.gdk_clipboard_get_formats(clipboard); + long[] n_gtypes = new long[1]; + long gtypes = GTK4.gdk_content_formats_get_gtypes(formats, n_gtypes); + + int gtypes_length = (int) n_gtypes[0]; + int[] types = new int[gtypes_length]; + for (int i = 0 ; i < gtypes_length ; ++i) { + long[] ptr = new long[1]; + C.memmove(ptr, gtypes + i * C.PTR_SIZEOF, C.PTR_SIZEOF); + types[i] = (int) ptr[0]; + } + return types; +} +private int[] gtk3_getAvailableTypes(long clipboard) { int[] types = new int[0]; - long selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, TARGET); + long selection_data = gtk_clipboard_wait_for_contents(clipboard, TARGET); if (selection_data != 0) { try { int length = GTK3.gtk_selection_data_get_length(selection_data); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java index d5e95c3939d..a745aa13026 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -141,23 +141,23 @@ public Object nativeToJava(TransferData transferData){ @Override protected int[] getTypeIds() { - if (OS.isX11()) { - return new int[] {UTF8_STRING_ID, COMPOUND_TEXT_ID, STRING_ID}; - } if(GTK.GTK4) { return new int[] {(int) OS.G_TYPE_STRING()}; } + if (OS.isX11()) { + return new int[] {UTF8_STRING_ID, COMPOUND_TEXT_ID, STRING_ID}; + } return new int[] {UTF8_STRING_ID, STRING_ID, TEXT_PLAIN_UTF8_ID}; } @Override protected String[] getTypeNames() { - if (OS.isX11()) { - return new String[] {UTF8_STRING, COMPOUND_TEXT, STRING}; - } if(GTK.GTK4) { return new String[] {"text/plain", STRING}; } + if (OS.isX11()) { + return new String[] {UTF8_STRING, COMPOUND_TEXT, STRING}; + } return new String[] {UTF8_STRING, STRING, TEXT_PLAIN_UTF8}; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c index 5f5d0f27f5c..94e2da0252f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c @@ -127,6 +127,22 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gdk_1content_1formats_1builder_1new) } #endif +#ifndef NO_gdk_1content_1formats_1get_1gtypes +JNIEXPORT jlong JNICALL GTK4_NATIVE(gdk_1content_1formats_1get_1gtypes) + (JNIEnv *env, jclass that, jlong arg0, jlongArray arg1) +{ + jlong *lparg1=NULL; + jlong rc = 0; + GTK4_NATIVE_ENTER(env, that, gdk_1content_1formats_1get_1gtypes_FUNC); + if (arg1) if ((lparg1 = (*env)->GetLongArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jlong)gdk_content_formats_get_gtypes((GdkContentFormats *)arg0, (gsize *)lparg1); +fail: + if (arg1 && lparg1) (*env)->ReleaseLongArrayElements(env, arg1, lparg1, 0); + GTK4_NATIVE_EXIT(env, that, gdk_1content_1formats_1get_1gtypes_FUNC); + return rc; +} +#endif + #ifndef NO_gdk_1content_1formats_1to_1string JNIEXPORT jlong JNICALL GTK4_NATIVE(gdk_1content_1formats_1to_1string) (JNIEnv *env, jclass that, jlong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h index 592504691a4..31777b68e62 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h @@ -31,6 +31,7 @@ typedef enum { gdk_1content_1formats_1builder_1add_1mime_1type_FUNC, gdk_1content_1formats_1builder_1free_1to_1formats_FUNC, gdk_1content_1formats_1builder_1new_FUNC, + gdk_1content_1formats_1get_1gtypes_FUNC, gdk_1content_1formats_1to_1string_FUNC, gdk_1content_1provider_1get_1value_FUNC, gdk_1content_1provider_1new_1for_1value_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java index de9c210566d..31902ed25bb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java @@ -818,6 +818,11 @@ public class GTK4 { public static final native long gdk_content_provider_new_union(long[] providers, int n_providers); /** @param formats cast=(GdkContentFormats *) */ public static final native long gdk_content_formats_to_string(long formats); + /** + * @param formats cast=(GdkContentFormats *) + * @param n_gtypes cast=(gsize *) + */ + public static final native long gdk_content_formats_get_gtypes(long formats, long[] n_gtypes); public static final native long gtk_gesture_rotate_new();