15
15
16
16
17
17
import org .eclipse .swt .*;
18
- import org .eclipse .swt .graphics .*;
19
18
import org .eclipse .swt .internal .*;
20
19
import org .eclipse .swt .internal .gtk .*;
21
20
import org .eclipse .swt .internal .gtk3 .*;
@@ -188,8 +187,13 @@ public void clearContents() {
188
187
*/
189
188
public void clearContents (int clipboards ) {
190
189
checkWidget ();
191
- ClipboardProxy proxy = ClipboardProxy ._getInstance (display );
192
- proxy .clear (this , clipboards );
190
+ if (GTK .GTK4 ) {
191
+ ClipboardProxyGTK4 proxy = ClipboardProxyGTK4 ._getInstance (display );
192
+ proxy .clear (this , clipboards );
193
+ } else {
194
+ ClipboardProxy proxy = ClipboardProxy ._getInstance (display );
195
+ proxy .clear (this , clipboards );
196
+ }
193
197
}
194
198
195
199
/**
@@ -290,14 +294,12 @@ public Object getContents(Transfer transfer) {
290
294
* @since 3.1
291
295
*/
292
296
public Object getContents (Transfer transfer , int clipboards ) {
293
- checkWidget ();
294
- if (transfer == null ) DND .error (SWT .ERROR_NULL_ARGUMENT );
295
-
296
- if (GTK .GTK4 ) {
297
- Object result = getContents_gtk4 (transfer , clipboards );
298
- return result ;
297
+ if (GTK .GTK4 ) {
298
+ return getContents_gtk4 (transfer , clipboards );
299
299
}
300
300
301
+ checkWidget ();
302
+ if (transfer == null ) DND .error (SWT .ERROR_NULL_ARGUMENT );
301
303
long selection_data = 0 ;
302
304
int [] typeIds = transfer .getTypeIds ();
303
305
boolean textTransfer = transfer .getTypeNames ()[0 ].equals ("UTF8_STRING" );
@@ -312,9 +314,9 @@ public Object getContents(Transfer transfer, int clipboards) {
312
314
if (selection_data != 0 ) {
313
315
TransferData tdata = new TransferData ();
314
316
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 );
317
+ tdata .gtk3 (). pValue = GTK3 .gtk_selection_data_get_data (selection_data );
318
+ tdata .gtk3 (). length = GTK3 .gtk_selection_data_get_length (selection_data );
319
+ tdata .gtk3 (). format = GTK3 .gtk_selection_data_get_format (selection_data );
318
320
result = transfer .nativeToJava (tdata );
319
321
GTK3 .gtk_selection_data_free (selection_data );
320
322
selection_data = 0 ;
@@ -327,65 +329,11 @@ public Object getContents(Transfer transfer, int clipboards) {
327
329
}
328
330
329
331
private Object getContents_gtk4 (Transfer transfer , int clipboards ) {
332
+ checkWidget ();
333
+ if (transfer == null ) DND .error (SWT .ERROR_NULL_ARGUMENT );
330
334
331
- long contents = GTK4 .gdk_clipboard_get_content (Clipboard .GTKCLIPBOARD );
332
- if (contents == 0 ) return null ;
333
- long value = OS .g_malloc (OS .GValue_sizeof ());
334
- C .memset (value , 0 , OS .GValue_sizeof ());
335
-
336
- //Pasting of text (TextTransfer/RTFTransfer)
337
- if (transfer .getTypeNames ()[0 ].equals ("text/plain" ) || transfer .getTypeNames ()[0 ].equals ("text/rtf" )) {
338
- OS .g_value_init (value , OS .G_TYPE_STRING ());
339
- if (!GTK4 .gdk_content_provider_get_value (contents , value , null )) return null ;
340
- long cStr = OS .g_value_get_string (value );
341
- long [] items_written = new long [1 ];
342
- long utf16Ptr = OS .g_utf8_to_utf16 (cStr , -1 , null , items_written , null );
343
- OS .g_free (cStr );
344
- if (utf16Ptr == 0 ) return null ;
345
- int length = (int )items_written [0 ];
346
- char [] buffer = new char [length ];
347
- C .memmove (buffer , utf16Ptr , length * 2 );
348
- OS .g_free (utf16Ptr );
349
- String str = new String (buffer );
350
- if (transfer .getTypeNames ()[0 ].equals ("text/rtf" ) && !str .contains ("{\\ rtf1" )) {
351
- return null ;
352
- }
353
- if (transfer .getTypeNames ()[0 ].equals ("text/plain" ) && str .contains ("{\\ rtf1" )){
354
- return null ;
355
- }
356
- return str ;
357
- }
358
- //Pasting of Image
359
- if (transfer .getTypeIds ()[0 ] == (int )GDK .GDK_TYPE_PIXBUF ()) {
360
- ImageData imgData = null ;
361
- OS .g_value_init (value , GDK .GDK_TYPE_PIXBUF ());
362
- if (!GTK4 .gdk_content_provider_get_value (contents , value , null )) return null ;
363
- long pixbufObj = OS .g_value_get_object (value );
364
- if (pixbufObj != 0 ) {
365
- Image img = Image .gtk_new_from_pixbuf (Display .getCurrent (), SWT .BITMAP , pixbufObj );
366
- imgData = img .getImageData ();
367
- img .dispose ();
368
- }
369
- return imgData ;
370
- }
371
- //Pasting of HTML
372
- if (transfer .getTypeNames ()[0 ].equals ("text/html" )) {
373
- OS .g_value_init (value , OS .G_TYPE_STRING ());
374
- if (!GTK4 .gdk_content_provider_get_value (contents , value , null )) return null ;
375
- long cStr = OS .g_value_get_string (value );
376
- long [] items_written = new long [1 ];
377
- long utf16Ptr = OS .g_utf8_to_utf16 (cStr , -1 , null , items_written , null );
378
- OS .g_free (cStr );
379
- if (utf16Ptr == 0 ) return null ;
380
- int length = (int )items_written [0 ];
381
- char [] buffer = new char [length ];
382
- C .memmove (buffer , utf16Ptr , length * 2 );
383
- OS .g_free (utf16Ptr );
384
- String str = new String (buffer );
385
- return str ;
386
- }
387
- //TODO: [GTK4] Other cases
388
- return null ;
335
+ ClipboardProxyGTK4 proxy = ClipboardProxyGTK4 ._getInstance (display );
336
+ return proxy .getData (this , transfer , clipboards );
389
337
}
390
338
391
339
/**
@@ -525,9 +473,16 @@ public void setContents(Object[] data, Transfer[] dataTypes, int clipboards) {
525
473
DND .error (SWT .ERROR_INVALID_ARGUMENT );
526
474
}
527
475
}
528
- ClipboardProxy proxy = ClipboardProxy ._getInstance (display );
529
- if (!proxy .setData (this , data , dataTypes , clipboards )) {
530
- DND .error (DND .ERROR_CANNOT_SET_CLIPBOARD );
476
+ if (GTK .GTK4 ) {
477
+ ClipboardProxyGTK4 proxy = ClipboardProxyGTK4 ._getInstance (display );
478
+ if (!proxy .setData (this , data , dataTypes , clipboards )) {
479
+ DND .error (DND .ERROR_CANNOT_SET_CLIPBOARD );
480
+ }
481
+ } else {
482
+ ClipboardProxy proxy = ClipboardProxy ._getInstance (display );
483
+ if (!proxy .setData (this , data , dataTypes , clipboards )) {
484
+ DND .error (DND .ERROR_CANNOT_SET_CLIPBOARD );
485
+ }
531
486
}
532
487
}
533
488
@@ -625,6 +580,7 @@ public String[] getAvailableTypeNames() {
625
580
if (GTK .GTK4 ) {
626
581
long formatsCStr = GTK4 .gdk_content_formats_to_string (GTK4 .gdk_clipboard_get_formats (Clipboard .GTKCLIPBOARD ));
627
582
String formatsStr = Converter .cCharPtrToJavaString (formatsCStr , true );
583
+ System .out .println (formatsStr );
628
584
String [] types = formatsStr .split (" " );
629
585
return types ;
630
586
}
@@ -723,4 +679,6 @@ long gtk_clipboard_wait_for_contents(long clipboard, long target) {
723
679
}
724
680
return selection_data ;
725
681
}
682
+
683
+
726
684
}
0 commit comments