@@ -290,33 +290,47 @@ public Object getContents(Transfer transfer) {
290
290
* @since 3.1
291
291
*/
292
292
public Object getContents (Transfer transfer , int clipboards ) {
293
+ Object result ;
294
+
293
295
checkWidget ();
294
296
if (transfer == null ) DND .error (SWT .ERROR_NULL_ARGUMENT );
295
297
296
298
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 );
299
302
}
303
+ return result ;
304
+ }
300
305
301
- long selection_data = 0 ;
306
+ private Object getContents_gtk3 (Transfer transfer , int clipboards ) {
307
+ boolean textTransfer = transfer .getTypeNames ()[0 ].equals ("UTF8_STRING" );
302
308
int [] typeIds = transfer .getTypeIds ();
309
+ Object result = null ;
310
+
303
311
for (int i = 0 ; i < typeIds .length ; i ++) {
312
+ long selection_data = 0 ;
313
+
304
314
if ((clipboards & DND .CLIPBOARD ) != 0 ) {
305
315
selection_data = gtk_clipboard_wait_for_contents (GTKCLIPBOARD , typeIds [i ]);
306
316
}
307
- if (selection_data != 0 ) break ;
308
- if ((clipboards & DND .SELECTION_CLIPBOARD ) != 0 ) {
317
+ if (selection_data == 0 && (clipboards & DND .SELECTION_CLIPBOARD ) != 0 ) {
309
318
selection_data = gtk_clipboard_wait_for_contents (GTKPRIMARYCLIPBOARD , typeIds [i ]);
310
319
}
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
+ }
311
333
}
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 );
320
334
return result ;
321
335
}
322
336
0 commit comments