1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2019 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2025 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
@@ -570,7 +570,6 @@ public TransferData[] getAvailableTypes() {
570
570
public TransferData [] getAvailableTypes (int clipboards ) {
571
571
checkWidget ();
572
572
573
- //TODO: [GTK4] This currently will not work in GTK4
574
573
TransferData [] result = null ;
575
574
if ((clipboards & DND .CLIPBOARD ) != 0 ) {
576
575
int [] types = getAvailableClipboardTypes ();
@@ -656,6 +655,10 @@ public String[] getAvailableTypeNames() {
656
655
}
657
656
658
657
private int [] getAvailablePrimaryTypes () {
658
+ if (GTK .GTK4 ) {
659
+ return gtk4_getAvailableTypes (GTKPRIMARYCLIPBOARD );
660
+ }
661
+
659
662
int [] types = new int [0 ];
660
663
long selection_data = gtk_clipboard_wait_for_contents (GTKPRIMARYCLIPBOARD , TARGET );
661
664
if (selection_data != 0 ) {
@@ -674,6 +677,9 @@ private int[] getAvailablePrimaryTypes() {
674
677
return types ;
675
678
}
676
679
private int [] getAvailableClipboardTypes () {
680
+ if (GTK .GTK4 ) {
681
+ return gtk4_getAvailableTypes (GTKCLIPBOARD );
682
+ }
677
683
678
684
int [] types = new int [0 ];
679
685
long selection_data = gtk_clipboard_wait_for_contents (GTKCLIPBOARD , TARGET );
@@ -693,6 +699,21 @@ private int[] getAvailableClipboardTypes () {
693
699
return types ;
694
700
}
695
701
702
+ int [] gtk4_getAvailableTypes (long clipboard ) {
703
+ long formats = GTK4 .gdk_clipboard_get_formats (clipboard );
704
+ long [] n_gtypes = new long [1 ];
705
+ long gtypes = GTK4 .gdk_content_formats_get_gtypes (formats , n_gtypes );
706
+
707
+ int gtypes_length = (int ) n_gtypes [0 ];
708
+ int [] types = new int [gtypes_length ];
709
+ for (int i = 0 ; i < gtypes_length ; ++i ) {
710
+ long [] ptr = new long [1 ];
711
+ C .memmove (ptr , gtypes + i * C .PTR_SIZEOF , C .PTR_SIZEOF );
712
+ types [i ] = (int ) ptr [0 ];
713
+ }
714
+ return types ;
715
+ }
716
+
696
717
long gtk_clipboard_wait_for_contents (long clipboard , long target ) {
697
718
long startTime = System .currentTimeMillis ();
698
719
String key = "org.eclipse.swt.internal.gtk.dispatchEvent" ;
0 commit comments