/** * g_paste_clipboard_set_image: * @self: a #GPasteClipboard instance * * Put the image from the intern GtkClipboard in the #GPasteClipboard * * Returns: (transfer full): The new image if it was modified, or NULL */ G_PASTE_VISIBLE GdkPixbuf * g_paste_clipboard_set_image (GPasteClipboard *self) { g_return_val_if_fail (G_PASTE_IS_CLIPBOARD (self), NULL); GPasteClipboardPrivate *priv = self->priv; GdkPixbuf *image = gtk_clipboard_wait_for_image (priv->real); GdkPixbuf *ret = image; if (image) { gchar *checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA256, (guchar *) gdk_pixbuf_get_pixels (image), -1); if (g_strcmp0 (checksum, self->priv->image_checksum) != 0) _g_paste_clipboard_select_image (self, image, checksum); else ret = NULL; g_free (checksum); } return ret; }
Php::Value GtkClipboard_::wait_for_image() { GdkPixbuf *ret = gtk_clipboard_wait_for_image (GTK_CLIPBOARD(instance)); GdkPixbuf_ *return_parsed = new GdkPixbuf_(); return_parsed->set_instance(ret); return Php::Object("GdkPixbuf", return_parsed); }
static void paste_image (GtkMenuItem *item, gpointer data) { GtkClipboard *clipboard; GdkPixbuf *pixbuf; clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); pixbuf = gtk_clipboard_wait_for_image (clipboard); if (pixbuf) { gtk_image_set_from_pixbuf (GTK_IMAGE (data), pixbuf); g_object_unref (pixbuf); } }
static jobject get_data_image(JNIEnv* env) { GdkPixbuf* pixbuf; guchar *data; jbyteArray data_array; jobject buffer, result; int w,h,stride; pixbuf = gtk_clipboard_wait_for_image(get_clipboard()); if (pixbuf == NULL) { return NULL; } if (!gdk_pixbuf_get_has_alpha(pixbuf)) { GdkPixbuf *tmp_buf = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0); g_object_unref(pixbuf); pixbuf = tmp_buf; } w = gdk_pixbuf_get_width(pixbuf); h = gdk_pixbuf_get_height(pixbuf); stride = gdk_pixbuf_get_rowstride(pixbuf); data = gdk_pixbuf_get_pixels(pixbuf); //Actually, we are converting RGBA to BGRA, but that's the same operation data = (guchar*) convert_BGRA_to_RGBA((int*)data, stride, h); data_array = env->NewByteArray(stride*h); EXCEPTION_OCCURED(env); env->SetByteArrayRegion(data_array, 0, stride*h, (jbyte*)data); EXCEPTION_OCCURED(env); buffer = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, data_array); result = env->NewObject(jGtkPixelsCls, jGtkPixelsInit, w, h, buffer); EXCEPTION_OCCURED(env); g_free(data); g_object_unref(pixbuf); return result; }
// work out what format the clipboard data is in, and paste accordingly void clipboard_paste(void) { GtkSelectionData *sel_data; GtkClipboard *clipboard; GdkPixbuf *pixbuf; gchar *text; if (ui.cur_layer == NULL) return; ui.cur_item_type = ITEM_PASTE; clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); // try xournal data sel_data = gtk_clipboard_wait_for_contents( clipboard, gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE)); #ifdef WIN32 // avoid a win32 bug showing images as xournal data if (gtk_selection_data_get_data_type(sel_data)!=gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE)) { gtk_selection_data_free(sel_data); sel_data = NULL; } #endif ui.cur_item_type = ITEM_NONE; if (sel_data != NULL) { clipboard_paste_from_xournal(sel_data); return; } // try image data pixbuf = gtk_clipboard_wait_for_image(clipboard); if (pixbuf != NULL) { clipboard_paste_image(pixbuf); return; } // try text data text = gtk_clipboard_wait_for_text(clipboard); if (text != NULL) { clipboard_paste_text(text); return; } }
static VALUE rg_wait_for_image(VALUE self) { GdkPixbuf* pixbuf = gtk_clipboard_wait_for_image(_SELF(self)); return GOBJ2RVAL(pixbuf); }
void remmina_rdp_cliprdr_get_clipboard_data(RemminaProtocolWidget* gp, RemminaPluginRdpUiObject* ui) { RDP_CB_DATA_RESPONSE_EVENT* event; GtkClipboard* clipboard; UINT8* inbuf = NULL; UINT8* outbuf = NULL; GdkPixbuf *image = NULL; int size = 0; rfContext* rfi = GET_DATA(gp); clipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD); if (clipboard) { switch (ui->clipboard.format) { case CB_FORMAT_TEXT: case CB_FORMAT_UNICODETEXT: case CB_FORMAT_HTML: { inbuf = (UINT8*)gtk_clipboard_wait_for_text(clipboard); break; } case CB_FORMAT_PNG: case CB_FORMAT_JPEG: case CB_FORMAT_DIB: { image = gtk_clipboard_wait_for_image(clipboard); break; } } } /* No data received, send nothing */ if (inbuf != NULL || image != NULL) { switch (ui->clipboard.format) { case CB_FORMAT_TEXT: case CB_FORMAT_HTML: { size = strlen((char*)inbuf); outbuf = lf2crlf(inbuf, &size); break; } case CB_FORMAT_UNICODETEXT: { size = strlen((char*)inbuf); inbuf = lf2crlf(inbuf, &size); size = (ConvertToUnicode(CP_UTF8, 0, (CHAR*)inbuf, -1, (WCHAR**)&outbuf, 0) + 1) * 2; g_free(inbuf); break; } case CB_FORMAT_PNG: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "png", NULL, NULL); outbuf = (UINT8*) malloc(buffersize); memcpy(outbuf, data, buffersize); size = buffersize; g_object_unref(image); break; } case CB_FORMAT_JPEG: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "jpeg", NULL, NULL); outbuf = (UINT8*) malloc(buffersize); memcpy(outbuf, data, buffersize); size = buffersize; g_object_unref(image); break; } case CB_FORMAT_DIB: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "bmp", NULL, NULL); size = buffersize - 14; outbuf = (UINT8*) malloc(size); memcpy(outbuf, data + 14, size); g_object_unref(image); break; } } } event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataResponse, NULL, NULL); event->data = outbuf; event->size = size; freerdp_channels_send_event(rfi->instance->context->channels, (wMessage*) event); }
gboolean e_composer_paste_image (EMsgComposer *composer, GtkClipboard *clipboard) { EHTMLEditor *editor; EHTMLEditorView *html_editor_view; EAttachmentStore *store; EAttachmentView *view; GdkPixbuf *pixbuf = NULL; gchar *filename = NULL; gchar *uri = NULL; gboolean success = FALSE; GError *error = NULL; g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE); g_return_val_if_fail (GTK_IS_CLIPBOARD (clipboard), FALSE); view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); /* Extract the image data from the clipboard. */ pixbuf = gtk_clipboard_wait_for_image (clipboard); g_return_val_if_fail (pixbuf != NULL, FALSE); /* Reserve a temporary file. */ filename = e_mktemp (NULL); if (filename == NULL) { g_set_error ( &error, G_FILE_ERROR, g_file_error_from_errno (errno), "Could not create temporary file: %s", g_strerror (errno)); goto exit; } /* Save the pixbuf as a temporary file in image/png format. */ if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) goto exit; /* Convert the filename to a URI. */ uri = g_filename_to_uri (filename, NULL, &error); if (uri == NULL) goto exit; /* In HTML mode, paste the image into the message body. * In text mode, add the image to the attachment store. */ editor = e_msg_composer_get_editor (composer); html_editor_view = e_html_editor_get_view (editor); if (e_html_editor_view_get_html_mode (html_editor_view)) { EHTMLEditorSelection *selection; selection = e_html_editor_view_get_selection (html_editor_view); e_html_editor_selection_insert_image (selection, uri); e_html_editor_selection_scroll_to_caret (selection); } else { EAttachment *attachment; attachment = e_attachment_new_for_uri (uri); e_attachment_store_add_attachment (store, attachment); e_attachment_load_async ( attachment, (GAsyncReadyCallback) e_attachment_load_handle_error, composer); g_object_unref (attachment); } success = TRUE; exit: if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); } g_object_unref (pixbuf); g_free (filename); g_free (uri); return success; }
void remmina_rdp_cliprdr_get_clipboard_data(RemminaProtocolWidget* gp, RemminaPluginRdpUiObject* ui) { TRACE_CALL(__func__); GtkClipboard* gtkClipboard; UINT8* inbuf = NULL; UINT8* outbuf = NULL; GdkPixbuf *image = NULL; int size = 0; rfContext* rfi = GET_PLUGIN_DATA(gp); RemminaPluginRdpEvent rdp_event = { 0 }; CLIPRDR_FORMAT_DATA_RESPONSE* pFormatDataResponse; gtkClipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD); if (gtkClipboard) { switch (ui->clipboard.format) { case CF_TEXT: case CF_UNICODETEXT: case CB_FORMAT_HTML: { inbuf = (UINT8*)gtk_clipboard_wait_for_text(gtkClipboard); break; } case CB_FORMAT_PNG: case CB_FORMAT_JPEG: case CF_DIB: case CF_DIBV5: { image = gtk_clipboard_wait_for_image(gtkClipboard); break; } } } /* No data received, send nothing */ if (inbuf != NULL || image != NULL) { switch (ui->clipboard.format) { case CF_TEXT: case CB_FORMAT_HTML: { size = strlen((char*)inbuf); outbuf = lf2crlf(inbuf, &size); break; } case CF_UNICODETEXT: { size = strlen((char*)inbuf); inbuf = lf2crlf(inbuf, &size); size = (ConvertToUnicode(CP_UTF8, 0, (CHAR*)inbuf, -1, (WCHAR**)&outbuf, 0) ) * sizeof(WCHAR); g_free(inbuf); break; } case CB_FORMAT_PNG: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "png", NULL, NULL); outbuf = (UINT8*)malloc(buffersize); memcpy(outbuf, data, buffersize); size = buffersize; g_object_unref(image); break; } case CB_FORMAT_JPEG: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "jpeg", NULL, NULL); outbuf = (UINT8*)malloc(buffersize); memcpy(outbuf, data, buffersize); size = buffersize; g_object_unref(image); break; } case CF_DIB: case CF_DIBV5: { gchar* data; gsize buffersize; gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "bmp", NULL, NULL); size = buffersize - 14; outbuf = (UINT8*)malloc(size); memcpy(outbuf, data + 14, size); g_object_unref(image); break; } } } pFormatDataResponse = (CLIPRDR_FORMAT_DATA_RESPONSE*)malloc(sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); if (!pFormatDataResponse) { if (outbuf) free(outbuf); return; } ZeroMemory(pFormatDataResponse, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); rdp_event.type = REMMINA_RDP_EVENT_TYPE_CLIPBOARD_SEND_CLIENT_FORMAT_DATA_RESPONSE; rdp_event.clipboard_formatdataresponse.pFormatDataResponse = pFormatDataResponse; pFormatDataResponse->msgFlags = CB_RESPONSE_OK; pFormatDataResponse->dataLen = size; pFormatDataResponse->requestedFormatData = outbuf; remmina_rdp_event_event_push(gp, &rdp_event); }
CAMLprim value ml_gtk_clipboard_wait_for_image (value c) { GdkPixbuf *res = gtk_clipboard_wait_for_image (GtkClipboard_val(c)); return (res != NULL ? ml_some(Val_GdkPixbuf_new(res)) : Val_unit); }