Skip to content

Commit b7ad47c

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 b7ad47c

File tree

1 file changed

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

1 file changed

+27
-13
lines changed

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,33 +290,47 @@ public Object getContents(Transfer transfer) {
290290
* @since 3.1
291291
*/
292292
public Object getContents(Transfer transfer, int clipboards) {
293+
Object result;
294+
293295
checkWidget();
294296
if (transfer == null) DND.error(SWT.ERROR_NULL_ARGUMENT);
295297

296298
if(GTK.GTK4) {
297-
Object result = getContents_gtk4(transfer, clipboards);
298-
return result;
299+
result = getContents_gtk4(transfer, clipboards);
300+
} else {
301+
result = getContents_gtk3(transfer, clipboards);
299302
}
303+
return result;
304+
}
300305

301-
long selection_data = 0;
306+
private Object getContents_gtk3(Transfer transfer, int clipboards) {
307+
boolean textTransfer = transfer.getTypeNames()[0].equals("UTF8_STRING");
302308
int[] typeIds = transfer.getTypeIds();
309+
Object result = null;
310+
303311
for (int i = 0; i < typeIds.length; i++) {
312+
long selection_data = 0;
313+
304314
if ((clipboards & DND.CLIPBOARD) != 0) {
305315
selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, typeIds[i]);
306316
}
307-
if (selection_data != 0) break;
308-
if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) {
317+
if (selection_data == 0 && (clipboards & DND.SELECTION_CLIPBOARD) != 0) {
309318
selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, typeIds[i]);
310319
}
320+
if (selection_data != 0) {
321+
TransferData tdata = new TransferData();
322+
323+
tdata.type = GTK3.gtk_selection_data_get_data_type(selection_data);
324+
tdata.pValue = GTK3.gtk_selection_data_get_data(selection_data);
325+
tdata.length = GTK3.gtk_selection_data_get_length(selection_data);
326+
tdata.format = GTK3.gtk_selection_data_get_format(selection_data);
327+
result = transfer.nativeToJava(tdata);
328+
GTK3.gtk_selection_data_free(selection_data);
329+
}
330+
if (result != null || !textTransfer) {
331+
break;
332+
}
311333
}
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);
320334
return result;
321335
}
322336

0 commit comments

Comments
 (0)