< prev index next >

modules/javafx.graphics/src/main/native-glass/gtk/GlassSystemClipboard.cpp

Print this page




 311     if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
 312         GdkPixbuf *tmp_buf = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
 313         g_object_unref(pixbuf);
 314         pixbuf = tmp_buf;
 315     }
 316     w = gdk_pixbuf_get_width(pixbuf);
 317     h = gdk_pixbuf_get_height(pixbuf);
 318     stride = gdk_pixbuf_get_rowstride(pixbuf);
 319 
 320     data = gdk_pixbuf_get_pixels(pixbuf);
 321 
 322     //Actually, we are converting RGBA to BGRA, but that's the same operation
 323     data = (guchar*) convert_BGRA_to_RGBA((int*)data, stride, h);
 324 
 325     data_array = env->NewByteArray(stride*h);
 326     EXCEPTION_OCCURED(env);
 327     env->SetByteArrayRegion(data_array, 0, stride*h, (jbyte*)data);
 328     EXCEPTION_OCCURED(env);
 329 
 330     buffer = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, data_array);

 331     result = env->NewObject(jGtkPixelsCls, jGtkPixelsInit, w, h, buffer);
 332     EXCEPTION_OCCURED(env);
 333 
 334     g_free(data);
 335     g_object_unref(pixbuf);
 336 
 337     return result;
 338 
 339 }
 340 
 341 static jobject get_data_raw(JNIEnv *env, const char* mime, gboolean string_data)
 342 {
 343     GtkSelectionData *data;
 344     const guchar *raw_data;
 345     jsize length;
 346     jbyteArray array;
 347     jobject result = NULL;
 348     data = gtk_clipboard_wait_for_contents(get_clipboard(), gdk_atom_intern(mime, FALSE));
 349     if (data != NULL) {
 350         raw_data = glass_gtk_selection_data_get_data_with_length(data, &length);
 351         if (string_data) {
 352             result = env->NewStringUTF((const char*)raw_data);
 353             EXCEPTION_OCCURED(env);
 354         } else {
 355             array = env->NewByteArray(length);
 356             EXCEPTION_OCCURED(env);
 357             env->SetByteArrayRegion(array, 0, length, (const jbyte*)raw_data);
 358             EXCEPTION_OCCURED(env);
 359             result = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, array);

 360         }
 361         gtk_selection_data_free(data);
 362     }
 363     return result;
 364 }
 365 
 366 static jobject jclipboard = NULL;
 367 static gulong owner_change_handler_id = 0;
 368 
 369 static void clipboard_owner_changed_callback(GtkClipboard *clipboard, GdkEventOwnerChange *event, jobject obj)
 370 {
 371     (void)clipboard;
 372     (void)event;
 373     (void)obj;
 374 
 375     is_clipboard_owner = is_clipboard_updated_by_glass;
 376     is_clipboard_updated_by_glass = FALSE;
 377     mainEnv->CallVoidMethod(obj, jClipboardContentChanged);
 378     CHECK_JNI_EXCEPTION(mainEnv)
 379 }




 311     if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
 312         GdkPixbuf *tmp_buf = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
 313         g_object_unref(pixbuf);
 314         pixbuf = tmp_buf;
 315     }
 316     w = gdk_pixbuf_get_width(pixbuf);
 317     h = gdk_pixbuf_get_height(pixbuf);
 318     stride = gdk_pixbuf_get_rowstride(pixbuf);
 319 
 320     data = gdk_pixbuf_get_pixels(pixbuf);
 321 
 322     //Actually, we are converting RGBA to BGRA, but that's the same operation
 323     data = (guchar*) convert_BGRA_to_RGBA((int*)data, stride, h);
 324 
 325     data_array = env->NewByteArray(stride*h);
 326     EXCEPTION_OCCURED(env);
 327     env->SetByteArrayRegion(data_array, 0, stride*h, (jbyte*)data);
 328     EXCEPTION_OCCURED(env);
 329 
 330     buffer = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, data_array);
 331     EXCEPTION_OCCURED(env);
 332     result = env->NewObject(jGtkPixelsCls, jGtkPixelsInit, w, h, buffer);
 333     EXCEPTION_OCCURED(env);
 334 
 335     g_free(data);
 336     g_object_unref(pixbuf);
 337 
 338     return result;
 339 
 340 }
 341 
 342 static jobject get_data_raw(JNIEnv *env, const char* mime, gboolean string_data)
 343 {
 344     GtkSelectionData *data;
 345     const guchar *raw_data;
 346     jsize length;
 347     jbyteArray array;
 348     jobject result = NULL;
 349     data = gtk_clipboard_wait_for_contents(get_clipboard(), gdk_atom_intern(mime, FALSE));
 350     if (data != NULL) {
 351         raw_data = glass_gtk_selection_data_get_data_with_length(data, &length);
 352         if (string_data) {
 353             result = env->NewStringUTF((const char*)raw_data);
 354             EXCEPTION_OCCURED(env);
 355         } else {
 356             array = env->NewByteArray(length);
 357             EXCEPTION_OCCURED(env);
 358             env->SetByteArrayRegion(array, 0, length, (const jbyte*)raw_data);
 359             EXCEPTION_OCCURED(env);
 360             result = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, array);
 361             EXCEPTION_OCCURED(env);
 362         }
 363         gtk_selection_data_free(data);
 364     }
 365     return result;
 366 }
 367 
 368 static jobject jclipboard = NULL;
 369 static gulong owner_change_handler_id = 0;
 370 
 371 static void clipboard_owner_changed_callback(GtkClipboard *clipboard, GdkEventOwnerChange *event, jobject obj)
 372 {
 373     (void)clipboard;
 374     (void)event;
 375     (void)obj;
 376 
 377     is_clipboard_owner = is_clipboard_updated_by_glass;
 378     is_clipboard_updated_by_glass = FALSE;
 379     mainEnv->CallVoidMethod(obj, jClipboardContentChanged);
 380     CHECK_JNI_EXCEPTION(mainEnv)
 381 }


< prev index next >