< prev index next >

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

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include "glass_dnd.h"
  26 #include "glass_general.h"
  27 #include "glass_evloop.h"
  28 
  29 #include "com_sun_glass_events_DndEvent.h"
  30 #include "com_sun_glass_ui_gtk_GtkDnDClipboard.h"
  31 
  32 #include <jni.h>
  33 #include <cstring>
  34 
  35 #include <gtk/gtk.h>
  36 #include <gdk/gdkx.h>
  37 #include "glass_wrapper.h"
  38 #include <gdk/gdkkeysyms.h>
  39 
  40 /************************* COMMON *********************************************/
  41 static jint translate_gdk_action_to_glass(GdkDragAction action)
  42 {
  43     jint result = 0;
  44     result |= (action & GDK_ACTION_COPY)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_COPY : 0;
  45     result |= (action & GDK_ACTION_MOVE)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_MOVE : 0;
  46     result |= (action & GDK_ACTION_LINK)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_REFERENCE : 0;
  47     return result;
  48 }
  49 
  50 static GdkDragAction translate_glass_action_to_gdk(jint action)
  51 {
  52     int result = 0;
  53     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_COPY)? GDK_ACTION_COPY : 0;
  54     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_MOVE)? GDK_ACTION_MOVE : 0;
  55     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_REFERENCE)? GDK_ACTION_LINK : 0;
  56     return static_cast<GdkDragAction>(result);
  57 }


 674     gsize size;
 675     const char * type;
 676     GdkPixbuf *pixbuf = NULL;
 677     gboolean result = FALSE;
 678 
 679     if (target == TARGET_MIME_PNG_ATOM) {
 680         type = "png";
 681     } else if (target == TARGET_MIME_JPEG_ATOM) {
 682         type = "jpeg";
 683     } else if (target == TARGET_MIME_TIFF_ATOM) {
 684         type = "tiff";
 685     } else if (target == TARGET_MIME_BMP_ATOM) {
 686         type = "bmp";
 687     } else {
 688         return FALSE;
 689     }
 690 
 691     mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
 692 
 693     if (!EXCEPTION_OCCURED(mainEnv)
 694             && glass_gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &size, type, NULL)) {
 695         gdk_property_change(requestor, property, target,
 696                 8, GDK_PROP_MODE_REPLACE, (guchar *)buffer, size);
 697         result = TRUE;
 698     }
 699     g_object_unref(pixbuf);
 700     return result;
 701 }
 702 
 703 static gboolean dnd_source_set_uri_list(GdkWindow *requestor, GdkAtom property)
 704 {
 705     const gchar* url = NULL;
 706     jstring jurl = NULL;
 707 
 708     jobjectArray files_array = NULL;
 709     gsize files_cnt = 0;
 710 
 711     if (jurl = (jstring) dnd_source_get_data("text/uri-list")) {
 712         url = mainEnv->GetStringUTFChars(jurl, NULL);
 713     }
 714 


 771                     jsize nraw = mainEnv->GetArrayLength(byteArray);
 772 
 773                     gdk_property_change(requestor, property, target,
 774                             8, GDK_PROP_MODE_REPLACE, (guchar *) raw, nraw);
 775 
 776                     mainEnv->ReleaseByteArrayElements(byteArray, raw, JNI_ABORT);
 777                     is_data_set = TRUE;
 778                 }
 779             }
 780         }
 781     }
 782 
 783     g_free(target_name);
 784     return is_data_set;
 785 }
 786 
 787 static void process_dnd_source_selection_req(GdkWindow *window, GdkEventSelection* event)
 788 {
 789     (void)window;
 790 
 791     GdkWindow *requestor = gdk_x11_window_foreign_new_for_display(
 792             gdk_display_get_default(),
 793             event->requestor);



 794 
 795     gboolean is_data_set = FALSE;
 796     if (event->target == TARGET_UTF8_STRING_ATOM
 797             || event->target == TARGET_MIME_TEXT_PLAIN_ATOM) {
 798         is_data_set = dnd_source_set_utf8_string(requestor, event->property);
 799     } else if (event->target == TARGET_STRING_ATOM) {
 800         is_data_set = dnd_source_set_string(requestor, event->property);
 801 //    } else if (event->target == TARGET_COMPOUND_TEXT_ATOM) { // XXX compound text
 802     } else if (target_is_image(event->target)) {
 803         is_data_set = dnd_source_set_image(requestor, event->property, event->target);
 804     } else if (event->target == TARGET_MIME_URI_LIST_ATOM) {
 805         is_data_set = dnd_source_set_uri_list(requestor, event->property);
 806     } else {
 807         is_data_set = dnd_source_set_raw(requestor, event->property, event->target);
 808     }
 809 
 810     gdk_selection_send_notify(event->requestor, event->selection, event->target,
 811                                (is_data_set) ? event->property : GDK_NONE, event->time);
 812 }
 813 




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include "glass_dnd.h"
  26 #include "glass_general.h"
  27 #include "glass_evloop.h"
  28 
  29 #include "com_sun_glass_events_DndEvent.h"
  30 #include "com_sun_glass_ui_gtk_GtkDnDClipboard.h"
  31 
  32 #include <jni.h>
  33 #include <cstring>
  34 
  35 #include <gtk/gtk.h>
  36 #include <gdk/gdkx.h>

  37 #include <gdk/gdkkeysyms.h>
  38 
  39 /************************* COMMON *********************************************/
  40 static jint translate_gdk_action_to_glass(GdkDragAction action)
  41 {
  42     jint result = 0;
  43     result |= (action & GDK_ACTION_COPY)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_COPY : 0;
  44     result |= (action & GDK_ACTION_MOVE)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_MOVE : 0;
  45     result |= (action & GDK_ACTION_LINK)? com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_REFERENCE : 0;
  46     return result;
  47 }
  48 
  49 static GdkDragAction translate_glass_action_to_gdk(jint action)
  50 {
  51     int result = 0;
  52     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_COPY)? GDK_ACTION_COPY : 0;
  53     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_MOVE)? GDK_ACTION_MOVE : 0;
  54     result |= (action & com_sun_glass_ui_gtk_GtkDnDClipboard_ACTION_REFERENCE)? GDK_ACTION_LINK : 0;
  55     return static_cast<GdkDragAction>(result);
  56 }


 673     gsize size;
 674     const char * type;
 675     GdkPixbuf *pixbuf = NULL;
 676     gboolean result = FALSE;
 677 
 678     if (target == TARGET_MIME_PNG_ATOM) {
 679         type = "png";
 680     } else if (target == TARGET_MIME_JPEG_ATOM) {
 681         type = "jpeg";
 682     } else if (target == TARGET_MIME_TIFF_ATOM) {
 683         type = "tiff";
 684     } else if (target == TARGET_MIME_BMP_ATOM) {
 685         type = "bmp";
 686     } else {
 687         return FALSE;
 688     }
 689 
 690     mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
 691 
 692     if (!EXCEPTION_OCCURED(mainEnv)
 693             && gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &size, type, NULL, NULL)) {
 694         gdk_property_change(requestor, property, target,
 695                 8, GDK_PROP_MODE_REPLACE, (guchar *)buffer, size);
 696         result = TRUE;
 697     }
 698     g_object_unref(pixbuf);
 699     return result;
 700 }
 701 
 702 static gboolean dnd_source_set_uri_list(GdkWindow *requestor, GdkAtom property)
 703 {
 704     const gchar* url = NULL;
 705     jstring jurl = NULL;
 706 
 707     jobjectArray files_array = NULL;
 708     gsize files_cnt = 0;
 709 
 710     if (jurl = (jstring) dnd_source_get_data("text/uri-list")) {
 711         url = mainEnv->GetStringUTFChars(jurl, NULL);
 712     }
 713 


 770                     jsize nraw = mainEnv->GetArrayLength(byteArray);
 771 
 772                     gdk_property_change(requestor, property, target,
 773                             8, GDK_PROP_MODE_REPLACE, (guchar *) raw, nraw);
 774 
 775                     mainEnv->ReleaseByteArrayElements(byteArray, raw, JNI_ABORT);
 776                     is_data_set = TRUE;
 777                 }
 778             }
 779         }
 780     }
 781 
 782     g_free(target_name);
 783     return is_data_set;
 784 }
 785 
 786 static void process_dnd_source_selection_req(GdkWindow *window, GdkEventSelection* event)
 787 {
 788     (void)window;
 789 
 790 #ifdef GLASS_GTK3
 791     GdkWindow *requestor = (event->requestor);
 792 #else
 793     GdkWindow *requestor =
 794         gdk_x11_window_foreign_new_for_display(gdk_display_get_default(), event->requestor);
 795 #endif
 796 
 797     gboolean is_data_set = FALSE;
 798     if (event->target == TARGET_UTF8_STRING_ATOM
 799             || event->target == TARGET_MIME_TEXT_PLAIN_ATOM) {
 800         is_data_set = dnd_source_set_utf8_string(requestor, event->property);
 801     } else if (event->target == TARGET_STRING_ATOM) {
 802         is_data_set = dnd_source_set_string(requestor, event->property);
 803 //    } else if (event->target == TARGET_COMPOUND_TEXT_ATOM) { // XXX compound text
 804     } else if (target_is_image(event->target)) {
 805         is_data_set = dnd_source_set_image(requestor, event->property, event->target);
 806     } else if (event->target == TARGET_MIME_URI_LIST_ATOM) {
 807         is_data_set = dnd_source_set_uri_list(requestor, event->property);
 808     } else {
 809         is_data_set = dnd_source_set_raw(requestor, event->property, event->target);
 810     }
 811 
 812     gdk_selection_send_notify(event->requestor, event->selection, event->target,
 813                                (is_data_set) ? event->property : GDK_NONE, event->time);
 814 }
 815 


< prev index next >