static void image_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint32 time, gpointer data) { GdkPixbuf *pixbuf; gchar *text; if (gtk_selection_data_get_length (selection_data) == 0) return; switch (info) { case TARGET_IMAGE: pixbuf = gtk_selection_data_get_pixbuf (selection_data); gtk_image_set_from_pixbuf (GTK_IMAGE (data), pixbuf); g_object_unref (pixbuf); break; case TARGET_TEXT: text = (gchar *)gtk_selection_data_get_text (selection_data); gtk_image_set_from_icon_name (GTK_IMAGE (data), text, GTK_ICON_SIZE_DIALOG); g_free (text); break; default: g_assert_not_reached (); } }
GList * pragha_dnd_plain_text_get_mobj_list (GtkSelectionData *data) { PraghaMusicobject *mobj = NULL; gchar *filename = NULL; GList *list = NULL; CDEBUG(DBG_VERBOSE, "Target: PLAIN_TEXT"); filename = (gchar*)gtk_selection_data_get_text(data); if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { list = append_mobj_list_from_folder(list, filename); } else { mobj = new_musicobject_from_file(filename, NULL); if (G_LIKELY(mobj)) list = g_list_prepend(list, mobj); /* Have to give control to GTK periodically ... */ pragha_process_gtk_events (); } g_free(filename); return g_list_reverse (list); }
void Selection::SelectionReceivedCallback(GtkWidget* widget,GtkSelectionData *selection_data, guint time, Selection *oSelection) { gchar *result; result = (gchar *)gtk_selection_data_get_text (selection_data); if (!result) { /* If we asked for UTF8 and didn't get it, try compound_text; * if we asked for compound_text and didn't get it, try string; * If we asked for anything else and didn't get it, give up. */ if (selection_data->target == oSelection->UTF8_STRING_Atom) { gtk_selection_convert (widget, GDK_SELECTION_PRIMARY, oSelection->COMPOUND_TEXT_Atom, GDK_CURRENT_TIME); } else if (selection_data->target == oSelection->COMPOUND_TEXT_Atom) { gtk_selection_convert (widget, GDK_SELECTION_PRIMARY, GDK_TARGET_STRING, GDK_CURRENT_TIME); } else { oSelection->IsBusy = 0; oSelection->LastClipWord.clear(); } return; } oSelection->IsBusy = 0; oSelection->SelectionReceived(result); g_free (result); }
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); } } }
static void on_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { gchar *text = (gchar*) gtk_selection_data_get_text (selection_data); if (rookie_misc_is_valid_url (text)) rookie_misc_add_download (text); gtk_drag_finish (context, TRUE, FALSE, time); g_free (text); }
static void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint UP(x), gint UP(y), GtkSelectionData *data, guint info, guint ltime) { if (info == TARGET_TEXT_PLAIN) { if (data->format == 8 && data->length > 0) vf->vte_terminal_feed_child(VTE_TERMINAL(widget), (const gchar*) data->data, data->length); } else { gchar *text = (gchar*) gtk_selection_data_get_text(data); if (NZV(text)) vf->vte_terminal_feed_child(VTE_TERMINAL(widget), text, strlen(text)); g_free(text); } gtk_drag_finish(drag_context, TRUE, FALSE, ltime); }
static void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint ltime) { if (info == TARGET_TEXT_PLAIN) { if (gtk_selection_data_get_format(data) == 8 && gtk_selection_data_get_length(data) > 0) vf->vte_terminal_feed_child(VTE_TERMINAL(widget), (const gchar*) gtk_selection_data_get_data(data), gtk_selection_data_get_length(data)); } else { gchar *text = (gchar*) gtk_selection_data_get_text(data); if (!EMPTY(text)) vf->vte_terminal_feed_child(VTE_TERMINAL(widget), text, strlen(text)); g_free(text); } gtk_drag_finish(drag_context, TRUE, FALSE, ltime); }
void JIDList::DataReceived(GtkWidget *wgt, GdkDragContext *context, int x, int y, GtkSelectionData *seldata, guint info, guint time, JIDList *c) { WokXMLTag data("data"); data.Add((const char*)gtk_selection_data_get_text (seldata)); GtkListStore *store; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(glade_xml_get_widget(c->gxml, "list")))); std::list <WokXMLTag *>::iterator jiditer; GtkTreeIter iter; for( jiditer = data.GetFirstTag("dnd", "dnd").GetTagList("item", "xmpp:jid").begin() ; jiditer != data.GetFirstTag("dnd", "dnd").GetTagList("item", "xmpp:jid").end() ; jiditer++) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 1, (*jiditer)->GetAttr("data").c_str(), -1); } //gtk_drag_finish (context, TRUE, FALSE, time); }
void Ctrl::GtkDragDataReceived(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { LLOG("GtkDragDataReceived " << dnd_data_fmt); dnd_data_wait = false; if(dnd_data_fmt == "text") { guchar *s = gtk_selection_data_get_text(data); if(s) { dnd_data = (const char *)s; g_free(s); } } else if(dnd_data_fmt == "image") dnd_data = ImageClipFromPixbufUnref(gtk_selection_data_get_pixbuf(data)); else if(dnd_data_fmt == "files") dnd_data = FilesClipFromUrisFree(gtk_selection_data_get_uris(data)); else dnd_data = GtkDataGet(data); }
void Ctrl::GtkDragDataReceived(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { LLOG("GtkDragDataReceived"); dnd_data_wait = false; if(dnd_data_fmt == "text") { guchar *s = gtk_selection_data_get_text(data); if(s) { dnd_data = (const char *)s; g_free(s); } } else if(dnd_data_fmt == "image") { Image img = ImageFromPixbufUnref(gtk_selection_data_get_pixbuf(data)); dnd_data = StoreAsString(img); // Not very optimal... } else dnd_data = GtkDataGet(data); }
static void on_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { gint length = gtk_selection_data_get_length (data) ; if (length >= 0) { guchar *text = gtk_selection_data_get_text(data); if (text) { BijiManager *manager; BijiNoteObj *ret; BjbMainView *self = BJB_MAIN_VIEW (user_data); BjbSettings *settings; /* FIXME Text is guchar utf 8, conversion to perform */ manager = bjb_window_base_get_manager (self->priv->window); settings = bjb_app_get_settings (g_application_get_default ()); ret = biji_manager_note_new (manager, (gchar*) text, bjb_settings_get_default_location (settings)); switch_to_note_view (self, ret); // maybe AFTER drag finish? g_free (text); } } /* Return false to ensure text is not removed from source * We just want to create a note. */ gtk_drag_finish (context, FALSE, FALSE, time); }
static void glide_window_paste_contents_text_received (GtkClipboard *clipboard, GtkSelectionData *data, gpointer user_data) { GlideWindow *w = (GlideWindow *)user_data; guchar *text = gtk_selection_data_get_text (data); GlideActor *selection; selection = glide_stage_manager_get_selection (w->priv->manager); if (!selection) { ClutterActor *ntext = glide_text_new (); ClutterColor cc; GdkColor c; gtk_color_button_get_color (GTK_COLOR_BUTTON (gtk_builder_get_object (w->priv->builder, "text-color-button")), &c); glide_clutter_color_from_gdk_color (&c, &cc); glide_text_set_color (GLIDE_TEXT (ntext), &cc); glide_text_set_font_name (GLIDE_TEXT (ntext), gtk_font_button_get_font_name (GTK_FONT_BUTTON (gtk_builder_get_object (w->priv->builder, "text-font-button")))); glide_text_set_text (GLIDE_TEXT (ntext), (gchar *)text); glide_stage_manager_add_actor (w->priv->manager, GLIDE_ACTOR (ntext)); } else if (selection && GLIDE_IS_TEXT (selection)) { glide_text_insert_text (GLIDE_TEXT (selection), (gchar *)text, glide_text_get_cursor_position (GLIDE_TEXT (selection))); } g_free (text); }
static void receive_dropped_text (NautilusTreeViewDragDest *dest, GdkDragContext *context, int x, int y) { char *drop_target; guchar *text; if (!dest->details->drag_data) { return; } drop_target = get_drop_target_uri_at_pos (dest, x, y); g_assert (drop_target != NULL); text = gtk_selection_data_get_text (dest->details->drag_data); g_signal_emit (dest, signals[HANDLE_TEXT], 0, (char *) text, drop_target, gdk_drag_context_get_selected_action (context), x, y); g_free (text); g_free (drop_target); }
static void drag_data_received_callback (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *data, guint info, guint32 time, gpointer user_data) { NemoDragInfo *drag_info; char *tmp; const char *tmp_raw; int length; gboolean success; drag_info = &(NEMO_ICON_CONTAINER (widget)->details->dnd_info->drag_info); drag_info->got_drop_data_type = TRUE; drag_info->data_type = info; switch (info) { case NEMO_ICON_DND_GNOME_ICON_LIST: nemo_icon_container_dropped_icon_feedback (widget, data, x, y); break; case NEMO_ICON_DND_URI_LIST: case NEMO_ICON_DND_TEXT: case NEMO_ICON_DND_XDNDDIRECTSAVE: case NEMO_ICON_DND_RAW: /* Save the data so we can do the actual work on drop. */ if (drag_info->selection_data != NULL) { gtk_selection_data_free (drag_info->selection_data); } drag_info->selection_data = gtk_selection_data_copy (data); break; /* Netscape keeps sending us the data, even though we accept the first drag */ case NEMO_ICON_DND_NETSCAPE_URL: if (drag_info->selection_data != NULL) { gtk_selection_data_free (drag_info->selection_data); drag_info->selection_data = gtk_selection_data_copy (data); } break; case NEMO_ICON_DND_ROOTWINDOW_DROP: /* Do nothing, this won't even happen, since we don't want to call get_data twice */ break; } /* this is the second use case of this callback. * we have to do the actual work for the drop. */ if (drag_info->drop_occured) { success = FALSE; switch (info) { case NEMO_ICON_DND_GNOME_ICON_LIST: nemo_icon_container_receive_dropped_icons (NEMO_ICON_CONTAINER (widget), context, x, y); break; case NEMO_ICON_DND_NETSCAPE_URL: receive_dropped_netscape_url (NEMO_ICON_CONTAINER (widget), (char *) gtk_selection_data_get_data (data), context, x, y); success = TRUE; break; case NEMO_ICON_DND_URI_LIST: receive_dropped_uri_list (NEMO_ICON_CONTAINER (widget), (char *) gtk_selection_data_get_data (data), context, x, y); success = TRUE; break; case NEMO_ICON_DND_TEXT: tmp = gtk_selection_data_get_text (data); receive_dropped_text (NEMO_ICON_CONTAINER (widget), (char *) tmp, context, x, y); success = TRUE; g_free (tmp); break; case NEMO_ICON_DND_RAW: length = gtk_selection_data_get_length (data); tmp_raw = gtk_selection_data_get_data (data); receive_dropped_raw (NEMO_ICON_CONTAINER (widget), tmp_raw, length, drag_info->direct_save_uri, context, x, y); success = TRUE; break; case NEMO_ICON_DND_ROOTWINDOW_DROP: /* Do nothing, everything is done by the sender */ break; case NEMO_ICON_DND_XDNDDIRECTSAVE: { const guchar *selection_data; gint selection_length; gint selection_format; selection_data = gtk_selection_data_get_data (drag_info->selection_data); selection_length = gtk_selection_data_get_length (drag_info->selection_data); selection_format = gtk_selection_data_get_format (drag_info->selection_data); if (selection_format == 8 && selection_length == 1 && selection_data[0] == 'F') { gtk_drag_get_data (widget, context, gdk_atom_intern (NEMO_ICON_DND_RAW_TYPE, FALSE), time); return; } else if (selection_format == 8 && selection_length == 1 && selection_data[0] == 'F' && drag_info->direct_save_uri != NULL) { GdkPoint p; GFile *location; location = g_file_new_for_uri (drag_info->direct_save_uri); nemo_file_changes_queue_file_added (location); p.x = x; p.y = y; nemo_file_changes_queue_schedule_position_set ( location, p, gdk_screen_get_number ( gtk_widget_get_screen (widget))); g_object_unref (location); nemo_file_changes_consume_changes (TRUE); success = TRUE; } break; } /* NEMO_ICON_DND_XDNDDIRECTSAVE */ } gtk_drag_finish (context, success, FALSE, time); nemo_icon_container_free_drag_data (NEMO_ICON_CONTAINER (widget)); set_drop_target (NEMO_ICON_CONTAINER (widget), NULL); /* reinitialise it for the next dnd */ drag_info->drop_occured = FALSE; } }
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); }
static void notebook_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, EphyEmbed *embed) { EphyWindow *window; GtkWidget *notebook; GdkAtom target; const guchar *data; target = gtk_selection_data_get_target (selection_data); if (target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB")) return; g_signal_stop_emission_by_name (widget, "drag-data-received"); if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_ARBITRARY_URL)) return; data = gtk_selection_data_get_data (selection_data); if (gtk_selection_data_get_length (selection_data) <= 0 || data == NULL) return; window = EPHY_WINDOW (gtk_widget_get_toplevel (widget)); notebook = ephy_window_get_notebook (window); if (target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE)) { char **split; /* URL_TYPE has format: url \n title */ split = g_strsplit ((const gchar *)data, "\n", 2); if (split != NULL && split[0] != NULL && split[0][0] != '\0') { ephy_link_open (EPHY_LINK (notebook), split[0], embed, embed ? 0 : EPHY_LINK_NEW_TAB); } g_strfreev (split); } else if (target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE)) { char **uris; int i; uris = gtk_selection_data_get_uris (selection_data); if (uris == NULL) return; for (i = 0; i < INSANE_NUMBER_OF_URLS && uris[i] != NULL; i++) { embed = ephy_link_open (EPHY_LINK (notebook), uris[i], embed, (embed && i == 0) ? 0 : EPHY_LINK_NEW_TAB); } g_strfreev (uris); } else { char *text; text = (char *)gtk_selection_data_get_text (selection_data); if (text != NULL) { char *address; address = ephy_embed_utils_normalize_or_autosearch_address (text); ephy_link_open (EPHY_LINK (notebook), address, embed, embed ? 0 : EPHY_LINK_NEW_TAB); g_free (address); g_free (text); } } }
void MainWindow::dragDataRecived(GtkWidget * widget, GdkDragContext * dragContext, gint x, gint y, GtkSelectionData * data, guint info, guint time, MainWindow * win) { GtkWidget * source = gtk_drag_get_source_widget(dragContext); if (source && widget == gtk_widget_get_toplevel(source)) { gtk_drag_finish(dragContext, false, false, time); return; } guchar * text = gtk_selection_data_get_text(data); if (text) { win->control->clipboardPasteText((const char *) text); g_free(text); gtk_drag_finish(dragContext, true, false, time); return; } GdkPixbuf * image = gtk_selection_data_get_pixbuf(data); if (image) { win->control->clipboardPasteImage(image); gdk_pixbuf_unref(image); gtk_drag_finish(dragContext, true, false, time); return; } // TODO LOW PRIO: use x and y for insert location! gchar ** uris = gtk_selection_data_get_uris(data); if (uris) { for (int i = 0; uris[i] != NULL && i < 3; i++) { const char * uri = uris[i]; // TODO LOW PRIO: check first if its an image // GSList * imageFormats = gdk_pixbuf_get_formats(); // for(GSList * l = imageFormats; l != NULL; l = l->next) { // GdkPixbufFormat * f = (GdkPixbufFormat *)l->data; // printf("", f); // } // // g_slist_free(imageFormats); GFile * file = g_file_new_for_uri(uri); GError * err = NULL; GCancellable * cancel = g_cancellable_new(); int cancelTimeout = g_timeout_add(3000, (GSourceFunc) cancellable_cancel, cancel); GFileInputStream * in = g_file_read(file, cancel, &err); if (g_cancellable_is_cancelled(cancel)) { continue; } g_object_unref(file); if (err == NULL) { GdkPixbuf * pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } g_input_stream_close(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } if (pixbuf) { win->control->clipboardPasteImage(pixbuf); gdk_pixbuf_unref(pixbuf); } } else { g_error_free(err); } if (!g_cancellable_is_cancelled(cancel)) { g_source_remove(cancelTimeout); } g_object_unref(cancel); //TODO LOW PRIO: handle .xoj, .pdf and Images printf("open uri: %s\n", uris[i]); } gtk_drag_finish(dragContext, true, false, time); g_strfreev(uris); } gtk_drag_finish(dragContext, false, false, time); }