From 2b230fbbf3b970054dd9e8dafaf77770ce90cd14 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 14 Oct 2020 22:30:49 -0300 Subject: [PATCH] Enabling copy-as-image action. --- src/include/v3270/selection.h | 2 +- src/selection/copy.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/terminal/actions/table.c | 15 +++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/include/v3270/selection.h b/src/include/v3270/selection.h index f645594..5d80391 100644 --- a/src/include/v3270/selection.h +++ b/src/include/v3270/selection.h @@ -60,7 +60,7 @@ LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget); - LIB3270_EXPORT void v3270_copy_as_image(GtkWidget *widget); + LIB3270_EXPORT void v3270_copy_as_pixbuff(GtkWidget *widget); // Selections diff --git a/src/selection/copy.c b/src/selection/copy.c index de17395..55ebfab 100644 --- a/src/selection/copy.c +++ b/src/selection/copy.c @@ -111,3 +111,43 @@ v3270_emit_copy_state(widget); } + + LIB3270_EXPORT void v3270_copy_as_pixbuff(GtkWidget *widget) { + + g_return_if_fail(GTK_IS_V3270(widget)); + v3270 * terminal = GTK_V3270(widget); + + debug("%s",__FUNCTION__); + + do_copy(terminal,V3270_COPY_FORMATTED,0); + + // + // Export only in HTML format + // + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); + + GtkTargetList * list = gtk_target_list_new(NULL,0); + + gtk_target_list_add_image_targets(list,CLIPBOARD_TYPE_PIXBUFF,TRUE); + + int n_targets; + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); + + if(gtk_clipboard_set_with_owner( + clipboard, + targets, + n_targets, + (GtkClipboardGetFunc) v3270_clipboard_get, + (GtkClipboardClearFunc) v3270_clipboard_clear, + G_OBJECT(widget) + )) + { + gtk_clipboard_set_can_store(clipboard,targets,1); + } + + gtk_target_table_free(targets, n_targets); + gtk_target_list_unref(list); + + v3270_emit_copy_state(widget); + + } diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index b88892b..6ffe53e 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -37,6 +37,7 @@ // static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action * action); + static int fire_copy_as_pixbuff(GtkWidget *widget, const struct _v3270_action * action); /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -82,6 +83,15 @@ }, { + .name = "copy-pixbuff", + .group = LIB3270_ACTION_GROUP_SELECTION, + .label = N_( "Copy as image" ), + .summary = N_("Copy selection in image format"), + .description = N_("Replace current clipboard contents with the selected area in image format"), + .activate = fire_copy_as_pixbuff + }, + + { .name = "copy-append", .keys = "c", .flags = (V3270_ACTION_FLAGS) V3270_COPY_APPEND, @@ -340,6 +350,11 @@ return 0; } + static int fire_copy_as_pixbuff(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { + v3270_copy_as_pixbuff(widget); + return 0; + } + /* int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { -- libgit2 0.21.2