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 (); } }
JNIEXPORT jlong JNICALL Java_org_gnome_gtk_GtkSelectionData_gtk_1selection_1data_1get_1pixbuf ( JNIEnv* env, jclass cls, jlong _self ) { GdkPixbuf* result; jlong _result; GtkSelectionData* self; // convert parameter self self = (GtkSelectionData*) _self; // call function result = gtk_selection_data_get_pixbuf(self); // cleanup parameter self // translate return value to JNI type _result = (jlong) result; // cleanup return value if (result != NULL) { bindings_java_memory_cleanup((GObject*)result, FALSE); } // and finally return _result; }
/** * gimp_clipboard_get_buffer: * @gimp: pointer to #Gimp * * Retrieves either image data from %GDK_SELECTION_CLIPBOARD or from * the global cut buffer of @gimp. * * The returned #GimpBuffer needs to be unref'ed when it's no longer * needed. * * Return value: a reference to a #GimpBuffer or %NULL if there's no * image data **/ GimpBuffer * gimp_clipboard_get_buffer (Gimp *gimp) { GimpClipboard *gimp_clip; GtkClipboard *clipboard; GdkAtom atom; GimpBuffer *buffer = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (clipboard && gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) && (atom = gimp_clipboard_wait_for_buffer (gimp)) != GDK_NONE) { GtkSelectionData *data; gimp_set_busy (gimp); data = gtk_clipboard_wait_for_contents (clipboard, atom); if (data) { GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data); gtk_selection_data_free (data); if (pixbuf) { buffer = gimp_buffer_new_from_pixbuf (pixbuf, _("Clipboard")); g_object_unref (pixbuf); } } gimp_unset_busy (gimp); } gimp_clip = gimp_clipboard_get (gimp); if (! buffer && gimp_clip->buffer) buffer = g_object_ref (gimp_clip->buffer); return buffer; }
/** * gtk_selection_data_get_texture: * @selection_data: a #GtkSelectionData * * Gets the contents of the selection data as a #GdkPixbuf. * * Returns: (nullable) (transfer full): if the selection data * contained a recognized image type and it could be converted to a * #GdkTexture, a newly allocated texture is returned, otherwise * %NULL. If the result is non-%NULL it must be freed with * g_object_unref(). **/ GdkTexture * gtk_selection_data_get_texture (const GtkSelectionData *selection_data) { GdkTexture *texture; GdkPixbuf *pixbuf; g_return_val_if_fail (selection_data != NULL, NULL); pixbuf = gtk_selection_data_get_pixbuf (selection_data); if (pixbuf == NULL) return NULL; texture = gdk_texture_new_for_pixbuf (pixbuf); g_object_unref (pixbuf); return texture; }
static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint32 time, gpointer data) { GdkPixbuf *pixbuf; if (selection_data->length > 0) { pixbuf = gtk_selection_data_get_pixbuf (selection_data); gtk_image_set_from_pixbuf (GTK_IMAGE (data), pixbuf); g_object_unref (pixbuf); } }
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); }
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); }
static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint32 time, gpointer data) { GtkWidget *image = GTK_WIDGET (data); GdkPixbuf *pixbuf; if (gtk_selection_data_get_length (selection_data) < 0) return; pixbuf = gtk_selection_data_get_pixbuf (selection_data); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); }
void gimp_container_tree_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, GimpContainerTreeView *tree_view) { GimpViewable *dest_viewable; GtkTreeViewDropPosition drop_pos; gboolean success = FALSE; if (gimp_container_tree_view_drop_status (tree_view, context, x, y, time, NULL, NULL, NULL, NULL, &dest_viewable, &drop_pos)) { GimpContainerTreeViewClass *tree_view_class; tree_view_class = GIMP_CONTAINER_TREE_VIEW_GET_CLASS (tree_view); switch (info) { case GIMP_DND_TYPE_URI_LIST: case GIMP_DND_TYPE_TEXT_PLAIN: case GIMP_DND_TYPE_NETSCAPE_URL: if (tree_view_class->drop_uri_list) { GList *uri_list; uri_list = gimp_selection_data_get_uri_list (selection_data); if (uri_list) { tree_view_class->drop_uri_list (tree_view, uri_list, dest_viewable, drop_pos); g_list_free_full (uri_list, (GDestroyNotify) g_free); success = TRUE; } } break; case GIMP_DND_TYPE_COLOR: if (tree_view_class->drop_color) { GimpRGB color; if (gimp_selection_data_get_color (selection_data, &color)) { tree_view_class->drop_color (tree_view, &color, dest_viewable, drop_pos); success = TRUE; } } break; case GIMP_DND_TYPE_SVG: case GIMP_DND_TYPE_SVG_XML: if (tree_view_class->drop_svg) { const guchar *stream; gsize stream_length; stream = gimp_selection_data_get_stream (selection_data, &stream_length); if (stream) { tree_view_class->drop_svg (tree_view, (const gchar *) stream, stream_length, dest_viewable, drop_pos); success = TRUE; } } break; case GIMP_DND_TYPE_COMPONENT: if (tree_view_class->drop_component) { GimpImage *image = NULL; GimpChannelType component; if (tree_view->dnd_gimp) image = gimp_selection_data_get_component (selection_data, tree_view->dnd_gimp, &component); if (image) { tree_view_class->drop_component (tree_view, image, component, dest_viewable, drop_pos); success = TRUE; } } break; case GIMP_DND_TYPE_PIXBUF: if (tree_view_class->drop_pixbuf) { GdkPixbuf *pixbuf; pixbuf = gtk_selection_data_get_pixbuf (selection_data); if (pixbuf) { tree_view_class->drop_pixbuf (tree_view, pixbuf, dest_viewable, drop_pos); g_object_unref (pixbuf); success = TRUE; } } break; default: break; } } gtk_drag_finish (context, success, FALSE, time); }
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); }
/** * dnd_clarity_drag_data_received: * * Used by the drag and drop of a jpg. When the drop is performed, this * acts on the receipt of the data from the source widget and applies * the jpg to the track. * */ void dnd_clarity_drag_data_received(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { g_return_if_fail(CLARITY_IS_CANVAS(widget)); g_return_if_fail (dc); g_return_if_fail (data); g_return_if_fail (gtk_selection_data_get_data(data)); g_return_if_fail (gtk_selection_data_get_length(data) > 0); /* mozilla bug 402394 */ #if DEBUG printf ("data length = %d\n", gtk_selection_data_get_length(data->length)); printf ("data->data = %s\n", gtk_selection_data_get_data(data)); #endif AlbumItem *item; GList *tracks; gchar *url = NULL; Fetch_Cover *fcover; gchar *filename = NULL; gboolean image_status = FALSE; gchar *image_error = NULL; /* For use with DND_IMAGE_JPEG */ GdkPixbuf *pixbuf; GError *error = NULL; ClarityCanvas *ccanvas = CLARITY_CANVAS(widget); /* Find the display cover item in the cover display */ item = clarity_canvas_get_current_album_item(ccanvas); if (!item) { /* looks like there are no covers yet something got dragged into it */ gtk_drag_finish(dc, FALSE, FALSE, time); return; } tracks = item->tracks; switch (info) { case DND_IMAGE_JPEG: #if DEBUG printf ("Using DND_IMAGE_JPEG\n"); #endif pixbuf = gtk_selection_data_get_pixbuf(data); if (pixbuf != NULL) { /* initialise the url string with a safe value as not used if already have image */ url = "local image"; /* Initialise a fetchcover object */ fcover = fetchcover_new(url, tracks); clarity_canvas_block_change(ccanvas, TRUE); /* find the filename with which to save the pixbuf to */ if (fetchcover_select_filename(fcover)) { filename = g_build_filename(fcover->dir, fcover->filename, NULL); if (!gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, NULL)) { /* Save failed for some reason */ if (error->message) fcover->err_msg = g_strdup(error->message); else fcover->err_msg = "Saving image to file failed. No internal error message was returned."; g_error_free(error); } else { /* Image successfully saved */ image_status = TRUE; } } /* record any errors and free the fetchcover */ if (fcover->err_msg != NULL) image_error = g_strdup(fcover->err_msg); free_fetchcover(fcover); g_object_unref(pixbuf); clarity_canvas_block_change(ccanvas, FALSE); } else { /* despite the data being of type image/jpeg, the pixbuf is NULL */ image_error = "jpeg data flavour was used but the data did not contain a GdkPixbuf object"; } break; case DND_TEXT_PLAIN: #if DEBUG printf ("Defaulting to using DND_TEXT_PLAIN\n"); #endif #ifdef HAVE_CURL /* initialise the url string with the data from the dnd */ url = g_strdup ((gchar *) gtk_selection_data_get_data(data)); /* Initialise a fetchcover object */ fcover = fetchcover_new (url, tracks); clarity_canvas_block_change(ccanvas, TRUE); if (fetchcover_net_retrieve_image (fcover)) { #if DEBUG printf ("Successfully retrieved\n"); printf ("Url of fetch cover: %s\n", fcover->url->str); printf ("filename of fetch cover: %s\n", fcover->filename); #endif filename = g_build_filename(fcover->dir, fcover->filename, NULL); image_status = TRUE; } /* record any errors and free the fetchcover */ if (fcover->err_msg != NULL) image_error = g_strdup(fcover->err_msg); free_fetchcover (fcover); clarity_canvas_block_change(ccanvas, FALSE); #else image_error = g_strdup(_("Item had to be downloaded but gtkpod was not compiled with curl.")); image_status = FALSE; #endif } if (!image_status || filename == NULL) { gtkpod_warning(_("Error occurred dropping an image onto the clarity display: %s\n"), image_error); if (image_error) g_free(image_error); if (filename) g_free(filename); gtk_drag_finish(dc, FALSE, FALSE, time); return; } clarity_util_update_coverart(tracks, filename); if (image_error) g_free(image_error); g_free(filename); gtkpod_statusbar_message(_("Successfully set new cover art for selected tracks")); gtk_drag_finish(dc, FALSE, FALSE, time); return; }