static void set_data(GdkAtom target, GtkSelectionData *selection_data, jobject data)
{
    gchar *name = gdk_atom_name(target);
    jstring typeString;
    jobject result;

    if (gtk_targets_include_text(&target, 1)) {
        typeString = mainEnv->NewStringUTF("text/plain");
        result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
            set_text_data(selection_data, (jstring)result);
        }
    } else if (gtk_targets_include_image(&target, 1, TRUE)) {
        typeString = mainEnv->NewStringUTF("application/x-java-rawimage");
        result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
            set_image_data(selection_data, result);
        }
    } else if (target == MIME_TEXT_URI_LIST_TARGET) {
        set_uri_data(selection_data, data);
    } else {
        typeString = mainEnv->NewStringUTF(name);
        result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
            if (mainEnv->IsInstanceOf(result, jStringCls)) {
                set_jstring_data(selection_data, target, (jstring)result);
            } else if (mainEnv->IsInstanceOf(result, jByteBufferCls)) {
                set_bytebuffer_data(selection_data, target, result);
            }
        }
    }

    g_free(name);
}
Esempio n. 2
0
static void
clipboard_get_cb (GtkClipboard     *clipboard,
		  GtkSelectionData *selection_data,
		  guint             info,
		  gpointer          user_data_or_owner)
{
	ClipboardData *clipboard_data = user_data_or_owner;
	GdkAtom        targets[1];
	int            n_targets;

	targets[0] = gtk_selection_data_get_target (selection_data);
	n_targets = 1;

	if (gtk_targets_include_uri (targets, n_targets)) {
		gtk_selection_data_set_uris (selection_data, clipboard_data->uris);
	}
	else if (gtk_targets_include_text (targets, n_targets)) {
		char  *str;
		gsize  len;

		str = clipboard_data_convert_to_text (clipboard_data, FALSE, &len);
		gtk_selection_data_set_text (selection_data, str, len);
		g_free (str);
	}
	else if (gtk_selection_data_get_target (selection_data) == GNOME_COPIED_FILES) {
		char  *str;
		gsize  len;

		str = clipboard_data_convert_to_text (clipboard_data, TRUE, &len);
		gtk_selection_data_set (selection_data, GNOME_COPIED_FILES, 8, (guchar *) str, len);
		g_free (str);
	}
}
static gboolean
gstyle_color_widget_on_drag_drop (GtkWidget        *widget,
                                  GdkDragContext   *context,
                                  gint              x,
                                  gint              y,
                                  guint             time)
{
  GstyleColorWidget *self = (GstyleColorWidget *)widget;
  GdkAtom target;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GDK_IS_DRAG_CONTEXT (context));

  target = gtk_drag_dest_find_target (widget, context, NULL);
  if ((target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET") ||
       target == gdk_atom_intern_static_string ("application/x-color") ||
       gtk_targets_include_text (&target, 1)) &&
      is_in_drop_zone (self, x, y))
    {
      gtk_drag_get_data (widget, context, target, time);
      return TRUE;
    }

  return FALSE;
}
Esempio n. 4
0
File: dnd.c Progetto: polarcat/yad
static void
drop_data_cb (GtkWidget *w, GdkDragContext *dc, gint x, gint y,
	      GtkSelectionData *sel, guint info, guint t, gpointer data)
{
  GdkAtom stgt;

  stgt = gtk_selection_data_get_target (sel);

  if (gtk_targets_include_uri (&stgt, 1))
    {
      gchar **uris;
      gint i = 0;

      uris = gtk_selection_data_get_uris (sel);
      if (!uris)
        return;

      while (uris[i])
	{
	  gchar *dstr = g_uri_unescape_string (uris[i], NULL);
	  if (options.common_data.command)
	    {
	      gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
	      g_spawn_command_line_async (action, NULL);
	      g_free (action);
	    }
	  else
	    {
	      g_printf ("%s\n", dstr);
	      fflush (stdout);
	    }
	  g_free (dstr);
	  i++;
	}
      g_strfreev (uris);
    }
  else if (gtk_targets_include_text (&stgt, 1))
    {
      guchar *str = gtk_selection_data_get_text (sel);
      if (str)
	{
	  gchar *dstr = g_uri_unescape_string ((const gchar *) str, NULL);
	  if (options.common_data.command)
	    {
	      gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
	      g_spawn_command_line_async (action, NULL);
	      g_free (action);
	    }
	  else
	    {
	      g_printf ("%s\n", dstr);
	      fflush (stdout);
	    }
	  g_free (dstr);
	  g_free(str);
	}
    }
}
Esempio n. 5
0
void
caja_get_clipboard_callback (GtkClipboard     *clipboard,
                             GtkSelectionData *selection_data,
                             guint             info,
                             gpointer          user_data)
{
    char **uris;
    GList *l;
    int i;
    CajaClipboardInfo *clipboard_info;
    GdkAtom target;

    clipboard_info =
        caja_clipboard_monitor_get_clipboard_info (caja_clipboard_monitor_get ());

    target = gtk_selection_data_get_target (selection_data);

    if (gtk_targets_include_uri (&target, 1))
    {
        uris = g_malloc ((g_list_length (clipboard_info->files) + 1) * sizeof (char *));
        i = 0;

        for (l = clipboard_info->files; l != NULL; l = l->next)
        {
            uris[i] = caja_file_get_uri (l->data);
            i++;
        }

        uris[i] = NULL;

        gtk_selection_data_set_uris (selection_data, uris);

        g_strfreev (uris);
    }
    else if (gtk_targets_include_text (&target, 1))
    {
        char *str;
        gsize len;

        str = convert_file_list_to_string (clipboard_info, TRUE, &len);
        gtk_selection_data_set_text (selection_data, str, len);
        g_free (str);
    }
    else if (target == copied_files_atom)
    {
        char *str;
        gsize len;

        str = convert_file_list_to_string (clipboard_info, FALSE, &len);
        gtk_selection_data_set (selection_data, copied_files_atom, 8, str, len);
        g_free (str);
    }
}
Esempio n. 6
0
static VALUE
targets_include_text(VALUE self, VALUE rbtargets)
{
    long n;
    GdkAtom *targets = RVAL2GDKATOMS(rbtargets, &n);
    gboolean result;

    result = gtk_targets_include_text(targets, n);

    g_free(targets);

    return result;
}
Esempio n. 7
0
static void
_get_clipboard_callback	(GtkClipboard*		clipboard,
			 GtkSelectionData*	selection_data,
			 guint			info,
			 gpointer               user_data)
{
    g_debug ("_get_clipboard_callback: begin");
    GdkAtom target;
    target = gtk_selection_data_get_target (selection_data);

    // set to a URI string
    if (gtk_targets_include_uri (&target, 1))
    {
	char **uris;
	uris = g_malloc ((clipboard_info.num + 1) * sizeof (char *));

	int i = 0;
	for (i = 0; i < clipboard_info.num; i++)
	{
	    uris[i] = g_file_get_uri (clipboard_info.file_list[i]);
	    i++;
	}
	uris[i] = NULL;

	gtk_selection_data_set_uris (selection_data, uris);
	g_strfreev (uris);
    }
    // set to a UTF-8 encoded string
    else if (gtk_targets_include_text (&target, 1))
    {
	char *str;
       	gsize len;
	str = __convert_file_list_to_string (&clipboard_info, TRUE, &len);

	gtk_selection_data_set_text (selection_data, str, len);
	g_free (str);
    }
    //NOTE: cut or copy
    else if (target == copied_files_atom)
    {
	char *str;
	gsize len;
	str = __convert_file_list_to_string (&clipboard_info, FALSE, &len);

	gtk_selection_data_set (selection_data, copied_files_atom, 8, (const guchar*)str, len);
        g_free (str);
    }
    g_debug ("_get_clipboard_callback: end");
}
Esempio n. 8
0
static void
glide_window_paste_targets_received (GtkClipboard *clipboard,
				     GdkAtom *atoms,
				     gint n_atoms,
				     gpointer data)
{
  GlideWindow *w = (GlideWindow *)data;
  gboolean has_text = FALSE;

  if (gtk_targets_include_text (atoms, n_atoms))
    has_text = TRUE;
  if (has_text)
    {
      gtk_clipboard_request_contents (clipboard, gdk_atom_intern ("TEXT", TRUE), glide_window_paste_contents_text_received, w);
    }
}
static void
gstyle_color_widget_on_drag_data_get (GtkWidget        *widget,
                                      GdkDragContext   *context,
                                      GtkSelectionData *data,
                                      guint             info,
                                      guint             time)
{
  GstyleColorWidget *self = (GstyleColorWidget *)widget;
  GdkAtom target = gtk_selection_data_get_target (data);
  GstyleColor *color;
  guint16 data_rgba[4];
  GdkRGBA rgba;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GDK_IS_DRAG_CONTEXT (context));

  if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color))
    color = self->filtered_color;
  else
    color = self->color;

  if (target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET"))
    gtk_selection_data_set (data, target, 8, (void*)&color, sizeof (gpointer));
  else if (target == gdk_atom_intern_static_string ("application/x-color"))
    {
      gstyle_color_fill_rgba (color, &rgba);
      data_rgba[0] = (guint16) (rgba.red * 65535);
      data_rgba[1] = (guint16) (rgba.green * 65535);
      data_rgba[2] = (guint16) (rgba.blue * 65535);
      data_rgba[3] = (guint16) (rgba.alpha * 65535);

      gtk_selection_data_set (data, target, 16, (void*)&data_rgba, 8);
    }
  else if (gtk_targets_include_text (&target, 1))
    {
      g_autofree gchar *name = NULL;

      name = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_ORIGINAL);
      if (name == NULL)
        name = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGB_HEX6);

      gtk_selection_data_set_text (data, name, -1);
    }
}
Esempio n. 10
0
/**
 * gtk_selection_data_targets_include_text:
 * @selection_data: a #GtkSelectionData object
 * 
 * Given a #GtkSelectionData object holding a list of targets,
 * determines if any of the targets in @targets can be used to
 * provide text.
 * 
 * Returns: %TRUE if @selection_data holds a list of targets,
 *   and a suitable target for text is included, otherwise %FALSE.
 **/
gboolean
gtk_selection_data_targets_include_text (const GtkSelectionData *selection_data)
{
  GdkAtom *targets;
  gint n_targets;
  gboolean result = FALSE;

  g_return_val_if_fail (selection_data != NULL, FALSE);

  init_atoms ();

  if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
    {
      result = gtk_targets_include_text (targets, n_targets);
      g_free (targets);
    }

  return result;
}
static gboolean
gstyle_color_widget_on_drag_motion (GtkWidget      *widget,
                                    GdkDragContext *context,
                                    gint            x,
                                    gint            y,
                                    guint           time)
{
  GstyleColorWidget *self = (GstyleColorWidget *)widget;
  GstylePaletteWidgetDndLockFlags dnd_lock;
  GdkAtom target;
  GdkDragAction drag_action;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GDK_IS_DRAG_CONTEXT (context));

  target = gtk_drag_dest_find_target (widget, context, NULL);
  dnd_lock = get_palette_widget_dnd_lock (self);
  if ((dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DRAG) != 0)
    {
      gdk_drag_status (context, 0, time);
      return FALSE;
    }

  if ((target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET") ||
       target == gdk_atom_intern_static_string ("application/x-color") ||
       gtk_targets_include_text (&target, 1)) &&
      (dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DROP) == 0 &&
      is_in_drop_zone (self, x, y))
    {
      gtk_drag_highlight (widget);

      drag_action = gdk_drag_context_get_actions (context);
      if ((drag_action | GDK_ACTION_COPY) != 0)
        {
          gdk_drag_status (context, GDK_ACTION_COPY, time);
          return TRUE;
        }
    }

  gdk_drag_status (context, 0, time);
  return FALSE;
}
/*
 * Class:     com_sun_glass_ui_gtk_GtkSystemClipboard
 * Method:    mimesFromSystem
 * Signature: ()[Ljava/lang/String;
 */
JNIEXPORT jobjectArray JNICALL Java_com_sun_glass_ui_gtk_GtkSystemClipboard_mimesFromSystem
  (JNIEnv * env, jobject obj)
{
    GdkAtom *targets;
    gint ntargets;
    gint i;
    GdkAtom *convertible;
    GdkAtom *convertible_ptr;
    gchar *name;
    jobjectArray result;
    jstring tmpString;

    init_atoms();

    gtk_clipboard_wait_for_targets(get_clipboard(), &targets, &ntargets);

    convertible = (GdkAtom*) glass_try_malloc0_n(ntargets * 2, sizeof(GdkAtom)); //theoretically, the number can double
    if (!convertible) {
        if (ntargets > 0) {
            glass_throw_oom(env, "Failed to allocate mimes");
        }
        g_free(targets);
        return NULL;
    }

    convertible_ptr = convertible;

    bool uri_list_added = false;
    bool text_added = false;
    bool image_added = false;

    for (i = 0; i < ntargets; ++i) {
        //handle text targets
        //if (targets[i] == TEXT_TARGET || targets[i] == STRING_TARGET || targets[i] == UTF8_STRING_TARGET) {

        if (gtk_targets_include_text(targets + i, 1) && !text_added) {
            *(convertible_ptr++) = MIME_TEXT_PLAIN_TARGET;
            text_added = true;
        } else if (gtk_targets_include_image(targets + i, 1, TRUE) && !image_added) {
            *(convertible_ptr++) = MIME_JAVA_IMAGE;
            image_added = true;
        }
        //TODO text/x-moz-url ? RT-17802

        if (targets[i] == MIME_TEXT_URI_LIST_TARGET) {
            if (uri_list_added) {
                continue;
            }

            gchar** uris = gtk_clipboard_wait_for_uris(get_clipboard());
            if (uris) {
                guint size = g_strv_length(uris);
                guint files_cnt = get_files_count(uris);
                if (files_cnt) {
                    *(convertible_ptr++) = MIME_FILES_TARGET;
                }
                if (size - files_cnt) {
                    *(convertible_ptr++) = MIME_TEXT_URI_LIST_TARGET;
                }
                g_strfreev(uris);
            }
            uri_list_added = true;
        } else {
            *(convertible_ptr++) = targets[i];
        }
    }

    result = env->NewObjectArray(convertible_ptr - convertible, jStringCls, NULL);
    for (i = 0; convertible + i < convertible_ptr; ++i) {
        name = gdk_atom_name(convertible[i]);
        tmpString = env->NewStringUTF(name);
        env->SetObjectArrayElement(result, (jsize)i, tmpString);
        g_free(name);
    }

    g_free(targets);
    g_free(convertible);
    return result;
}
static void
gstyle_color_widget_on_drag_data_received (GtkWidget        *widget,
                                           GdkDragContext   *context,
                                           gint              x,
                                           gint              y,
                                           GtkSelectionData *data,
                                           guint             info,
                                           guint             time)
{
  GstyleColorWidget *self = GSTYLE_COLOR_WIDGET (widget);
  GstyleColor * const *src_color;
  g_autofree gchar *color_string = NULL;
  GstyleColorKind kind;
  GdkAtom target;
  guint16 *data_rgba;
  GdkRGBA rgba;
  gint len;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GDK_IS_DRAG_CONTEXT (context));

  target = gtk_selection_data_get_target (data);
  if (target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET"))
    {
      /* TODO: check if the color widget is coming from a PaletteWidget container */
      src_color = (void*)gtk_selection_data_get_data (data);
      if (*src_color != self->color)
        dnd_color_fill (self, *src_color, self->color);

      gtk_drag_finish (context, TRUE, FALSE, time);

      return;
    }
  else if (target == gdk_atom_intern_static_string ("application/x-color"))
    {
      len = gtk_selection_data_get_length (data);
      if (len < 0 )
        goto failed;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"

      data_rgba = (guint16 *)gtk_selection_data_get_data (data);

#pragma GCC diagnostic pop

      rgba.red = data_rgba[0] / 65535.;
      rgba.green = data_rgba[1] / 65535.;
      rgba.blue = data_rgba[2] / 65535.;
      rgba.alpha = data_rgba[3] / 65535.;

      gstyle_color_set_rgba (self->color, &rgba);
      gtk_drag_finish (context, TRUE, FALSE, time);

      return;
    }
  else if (gtk_targets_include_text (&target, 1))
    {
      color_string = (gchar *)gtk_selection_data_get_text (data);
      if (!gstyle_str_empty0 (color_string))
        {
          if (!gstyle_color_parse_color_string (color_string, &rgba, &kind))
            goto failed;

          gstyle_color_set_rgba (self->color, &rgba);
          gtk_drag_finish (context, TRUE, FALSE, time);
        }
    }

failed:
  gtk_drag_finish (context, FALSE, FALSE, time);
}