Skip to content

Commit 168cf73

Browse files
committed
Fail to get text from the clipboard when text is Latin-1 encoded but transfer data type is UTF8_STRING
1 parent a13a22d commit 168cf73

File tree

1 file changed

+16
-10
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd

1 file changed

+16
-10
lines changed

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

+16-10
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,29 @@ public Object getContents(Transfer transfer, int clipboards) {
300300

301301
long selection_data = 0;
302302
int[] typeIds = transfer.getTypeIds();
303+
boolean textTransfer = transfer.getTypeNames()[0].equals("UTF8_STRING");
304+
Object result = null;
303305
for (int i = 0; i < typeIds.length; i++) {
304306
if ((clipboards & DND.CLIPBOARD) != 0) {
305307
selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, typeIds[i]);
306308
}
307-
if (selection_data != 0) break;
308-
if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) {
309+
if (selection_data == 0 && (clipboards & DND.SELECTION_CLIPBOARD) != 0) {
309310
selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, typeIds[i]);
310311
}
312+
if (selection_data != 0) {
313+
TransferData tdata = new TransferData();
314+
tdata.type = GTK3.gtk_selection_data_get_data_type(selection_data);
315+
tdata.pValue = GTK3.gtk_selection_data_get_data(selection_data);
316+
tdata.length = GTK3.gtk_selection_data_get_length(selection_data);
317+
tdata.format = GTK3.gtk_selection_data_get_format(selection_data);
318+
result = transfer.nativeToJava(tdata);
319+
GTK3.gtk_selection_data_free(selection_data);
320+
selection_data = 0;
321+
}
322+
if (result != null || !textTransfer) {
323+
break;
324+
}
311325
}
312-
if (selection_data == 0) return null;
313-
TransferData tdata = new TransferData();
314-
tdata.type = GTK3.gtk_selection_data_get_data_type(selection_data);
315-
tdata.pValue = GTK3.gtk_selection_data_get_data(selection_data);
316-
tdata.length = GTK3.gtk_selection_data_get_length(selection_data);
317-
tdata.format = GTK3.gtk_selection_data_get_format(selection_data);
318-
Object result = transfer.nativeToJava(tdata);
319-
GTK3.gtk_selection_data_free(selection_data);
320326
return result;
321327
}
322328

0 commit comments

Comments
 (0)