|
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,27 +655,36 @@ public String[] getAvailableTypeNames() {
|
656 | 655 | }
|
657 | 656 |
|
658 | 657 | private int[] getAvailablePrimaryTypes() {
|
659 |
| - int[] types = new int[0]; |
660 |
| - long selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, TARGET); |
661 |
| - if (selection_data != 0) { |
662 |
| - try { |
663 |
| - int length = GTK3.gtk_selection_data_get_length(selection_data); |
664 |
| - int format = GTK3.gtk_selection_data_get_format(selection_data); |
665 |
| - long data = GTK3.gtk_selection_data_get_data(selection_data); |
666 |
| - if (length != 0) { |
667 |
| - types = new int[length * 8 / format]; |
668 |
| - C.memmove(types, data, length); |
669 |
| - } |
670 |
| - } finally { |
671 |
| - GTK3.gtk_selection_data_free(selection_data); |
672 |
| - } |
| 658 | + if (GTK.GTK4) { |
| 659 | + return gtk4_getAvailableTypes(GTKPRIMARYCLIPBOARD); |
673 | 660 | }
|
674 |
| - return types; |
| 661 | + return gtk3_getAvailableTypes(GTKPRIMARYCLIPBOARD); |
675 | 662 | }
|
676 | 663 | private int[] getAvailableClipboardTypes () {
|
| 664 | + if (GTK.GTK4) { |
| 665 | + return gtk4_getAvailableTypes(GTKCLIPBOARD); |
| 666 | + } |
| 667 | + return gtk3_getAvailableTypes(GTKCLIPBOARD); |
| 668 | +} |
| 669 | + |
| 670 | +private int[] gtk4_getAvailableTypes(long clipboard) { |
| 671 | + long formats = GTK4.gdk_clipboard_get_formats(clipboard); |
| 672 | + long[] n_gtypes = new long[1]; |
| 673 | + long gtypes = GTK4.gdk_content_formats_get_gtypes(formats, n_gtypes); |
| 674 | + |
| 675 | + int gtypes_length = (int) n_gtypes[0]; |
| 676 | + int[] types = new int[gtypes_length]; |
| 677 | + for (int i = 0 ; i < gtypes_length ; ++i) { |
| 678 | + long[] ptr = new long[1]; |
| 679 | + C.memmove(ptr, gtypes + i * C.PTR_SIZEOF, C.PTR_SIZEOF); |
| 680 | + types[i] = (int) ptr[0]; |
| 681 | + } |
| 682 | + return types; |
| 683 | +} |
677 | 684 |
|
| 685 | +private int[] gtk3_getAvailableTypes(long clipboard) { |
678 | 686 | int[] types = new int[0];
|
679 |
| - long selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, TARGET); |
| 687 | + long selection_data = gtk_clipboard_wait_for_contents(clipboard, TARGET); |
680 | 688 | if (selection_data != 0) {
|
681 | 689 | try {
|
682 | 690 | int length = GTK3.gtk_selection_data_get_length(selection_data);
|
|
0 commit comments