Commit a7a3d00fa7874fd2dd1c71604ea39c4d8fa9f1cc
1 parent
5084f86c
Exists in
master
and in
1 other branch
Using separated code for linux & windows clipboard interaction.
Showing
5 changed files
with
299 additions
and
176 deletions
Show diff stats
src/include/clipboard.h
| @@ -53,6 +53,5 @@ | @@ -53,6 +53,5 @@ | ||
| 53 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); | 53 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); |
| 54 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter); | 54 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter); |
| 55 | 55 | ||
| 56 | - | ||
| 57 | #endif // V3270_CLIPBOARD_H_INCLUDED | 56 | #endif // V3270_CLIPBOARD_H_INCLUDED |
| 58 | 57 |
src/selection/copy.c
| @@ -39,56 +39,6 @@ | @@ -39,56 +39,6 @@ | ||
| 39 | terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); | 39 | terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | - /* | ||
| 43 | - // Get selection bounds. | ||
| 44 | - unsigned int row; | ||
| 45 | - unsigned int col; | ||
| 46 | - unsigned int width; | ||
| 47 | - unsigned int height; | ||
| 48 | - | ||
| 49 | - if(lib3270_get_selection_rectangle(terminal->host, &row, &col, &width, &height) != 0) | ||
| 50 | - return; | ||
| 51 | - | ||
| 52 | - debug("Selecion rectangle starts on %u,%u with size of %ux%u", | ||
| 53 | - row, col, | ||
| 54 | - width, height | ||
| 55 | - ); | ||
| 56 | - | ||
| 57 | - // Allocate buffer | ||
| 58 | - struct selection * selection = g_malloc0(sizeof(struct selection) + (sizeof(struct v3270_character) * (width * height))); | ||
| 59 | - | ||
| 60 | - selection->bounds.row = row; | ||
| 61 | - selection->bounds.col = col; | ||
| 62 | - selection->bounds.width = width; | ||
| 63 | - selection->bounds.height = height; | ||
| 64 | - | ||
| 65 | - // Copy terminal buffer | ||
| 66 | - unsigned int r, c; | ||
| 67 | - | ||
| 68 | - int pos = 0; | ||
| 69 | - for(r=0;r < selection->bounds.height; r++) | ||
| 70 | - { | ||
| 71 | - // Get starting address. | ||
| 72 | - int baddr = lib3270_translate_to_address(terminal->host, selection->bounds.row+r+1, selection->bounds.col+1); | ||
| 73 | - if(baddr < 0) | ||
| 74 | - { | ||
| 75 | - g_message("Can't convert coordinate %u,%d",selection->bounds.row+r+1,selection->bounds.col+1); | ||
| 76 | - gdk_display_beep(gdk_display_get_default()); | ||
| 77 | - return; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - for(c=0;c < selection->bounds.width; c++) | ||
| 81 | - { | ||
| 82 | - lib3270_get_contents(terminal->host,baddr,baddr,&selection->contents[pos].chr,&selection->contents[pos].attr); | ||
| 83 | - debug("pos=%d baddr=%u char=%c",pos,baddr,selection->contents[pos].chr); | ||
| 84 | - pos++; | ||
| 85 | - baddr++; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); | ||
| 91 | - */ | ||
| 92 | } | 42 | } |
| 93 | 43 | ||
| 94 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_SELECT_FORMAT format, gboolean cut) | 44 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_SELECT_FORMAT format, gboolean cut) |
| @@ -105,14 +55,6 @@ | @@ -105,14 +55,6 @@ | ||
| 105 | 55 | ||
| 106 | v3270_update_system_clipboard(widget); | 56 | v3270_update_system_clipboard(widget); |
| 107 | 57 | ||
| 108 | -/* | ||
| 109 | -#ifdef DEBUG | ||
| 110 | - gchar *columns = v3270_get_copy_as_table(terminal,"---"); | ||
| 111 | - debug("Output:\n%s",columns); | ||
| 112 | - g_free(columns); | ||
| 113 | -#endif // DEBUG | ||
| 114 | -*/ | ||
| 115 | - | ||
| 116 | } | 58 | } |
| 117 | 59 | ||
| 118 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) | 60 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) |
| @@ -0,0 +1,150 @@ | @@ -0,0 +1,150 @@ | ||
| 1 | +/* | ||
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
| 5 | + * | ||
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
| 7 | + * | ||
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
| 10 | + * Free Software Foundation. | ||
| 11 | + * | ||
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
| 15 | + * obter mais detalhes. | ||
| 16 | + * | ||
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como - possui - linhas de código. | ||
| 22 | + * | ||
| 23 | + * Contatos: | ||
| 24 | + * | ||
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
| 27 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include <clipboard.h> | ||
| 31 | + #include <lib3270/selection.h> | ||
| 32 | + | ||
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 34 | + | ||
| 35 | +static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
| 36 | +{ | ||
| 37 | + v3270 * terminal = GTK_V3270(obj); | ||
| 38 | + | ||
| 39 | + if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | ||
| 40 | + { | ||
| 41 | + v3270_unselect(GTK_WIDGET(obj)); | ||
| 42 | + v3270_clear_selection(terminal); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
| 48 | +{ | ||
| 49 | + v3270 * terminal = GTK_V3270(obj); | ||
| 50 | + | ||
| 51 | + if(!terminal->selection.blocks) | ||
| 52 | + { | ||
| 53 | + return; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + switch(target) | ||
| 57 | + { | ||
| 58 | + case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | ||
| 59 | + { | ||
| 60 | + gchar *text; | ||
| 61 | + | ||
| 62 | + if(terminal->selection.format == V3270_SELECT_TABLE) | ||
| 63 | + { | ||
| 64 | + text = v3270_get_copy_as_table(terminal,"\t"); | ||
| 65 | + } | ||
| 66 | + else | ||
| 67 | + { | ||
| 68 | + text = v3270_get_copy_as_text(terminal); | ||
| 69 | + } | ||
| 70 | + gtk_selection_data_set_text(selection,text,-1); | ||
| 71 | + g_free(text); | ||
| 72 | + } | ||
| 73 | + break; | ||
| 74 | + | ||
| 75 | + case CLIPBOARD_TYPE_CSV: | ||
| 76 | + { | ||
| 77 | + g_autofree gchar *text = v3270_get_copy_as_table(terminal,";"); | ||
| 78 | + debug("Selection:\n%s",text); | ||
| 79 | + gtk_selection_data_set( | ||
| 80 | + selection, | ||
| 81 | + gdk_atom_intern_static_string("text/csv"), | ||
| 82 | + 8, | ||
| 83 | + (guchar *) text, | ||
| 84 | + strlen(text) | ||
| 85 | + ); | ||
| 86 | + } | ||
| 87 | + break; | ||
| 88 | + | ||
| 89 | + default: | ||
| 90 | + g_warning("Unexpected clipboard type %d\n",target); | ||
| 91 | + } | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +void v3270_update_system_clipboard(GtkWidget *widget) | ||
| 95 | +{ | ||
| 96 | + v3270 * terminal = GTK_V3270(widget); | ||
| 97 | + | ||
| 98 | + if(!terminal->selection.blocks) | ||
| 99 | + { | ||
| 100 | + // No clipboard data, return. | ||
| 101 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 102 | + return; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + // Has clipboard data, inform system. | ||
| 106 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
| 107 | + | ||
| 108 | + // Create target list | ||
| 109 | + // | ||
| 110 | + // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | ||
| 111 | + // | ||
| 112 | + static const GtkTargetEntry internal_targets[] = { | ||
| 113 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV } | ||
| 114 | + }; | ||
| 115 | + | ||
| 116 | + GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); | ||
| 117 | + GtkTargetEntry * targets; | ||
| 118 | + int n_targets; | ||
| 119 | + | ||
| 120 | + gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); | ||
| 121 | + | ||
| 122 | + targets = gtk_target_table_new_from_list(list, &n_targets); | ||
| 123 | + | ||
| 124 | +#ifdef DEBUG | ||
| 125 | + { | ||
| 126 | + int ix; | ||
| 127 | + for(ix = 0; ix < n_targets; ix++) { | ||
| 128 | + debug("target(%d)=\"%s\"",ix,targets[ix].target); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | +#endif // DEBUG | ||
| 132 | + | ||
| 133 | + if(gtk_clipboard_set_with_owner( | ||
| 134 | + clipboard, | ||
| 135 | + targets, | ||
| 136 | + n_targets, | ||
| 137 | + (GtkClipboardGetFunc) clipboard_get, | ||
| 138 | + (GtkClipboardClearFunc) clipboard_clear, | ||
| 139 | + G_OBJECT(widget) | ||
| 140 | + )) | ||
| 141 | + { | ||
| 142 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + gtk_target_table_free(targets, n_targets); | ||
| 146 | + gtk_target_list_unref(list); | ||
| 147 | + | ||
| 148 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
| 149 | + | ||
| 150 | +} |
src/selection/selection.c
| @@ -32,65 +32,6 @@ | @@ -32,65 +32,6 @@ | ||
| 32 | 32 | ||
| 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 34 | 34 | ||
| 35 | -static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
| 36 | -{ | ||
| 37 | - v3270 * terminal = GTK_V3270(obj); | ||
| 38 | - | ||
| 39 | - if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | ||
| 40 | - { | ||
| 41 | - v3270_unselect(GTK_WIDGET(obj)); | ||
| 42 | - v3270_clear_selection(terminal); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
| 48 | -{ | ||
| 49 | - v3270 * terminal = GTK_V3270(obj); | ||
| 50 | - | ||
| 51 | - if(!terminal->selection.blocks) | ||
| 52 | - { | ||
| 53 | - return; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - switch(target) | ||
| 57 | - { | ||
| 58 | - case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | ||
| 59 | - { | ||
| 60 | - gchar *text; | ||
| 61 | - | ||
| 62 | - if(terminal->selection.format == V3270_SELECT_TABLE) | ||
| 63 | - { | ||
| 64 | - text = v3270_get_copy_as_table(terminal,"\t"); | ||
| 65 | - } | ||
| 66 | - else | ||
| 67 | - { | ||
| 68 | - text = v3270_get_copy_as_text(terminal); | ||
| 69 | - } | ||
| 70 | - gtk_selection_data_set_text(selection,text,-1); | ||
| 71 | - g_free(text); | ||
| 72 | - } | ||
| 73 | - break; | ||
| 74 | - | ||
| 75 | - case CLIPBOARD_TYPE_CSV: | ||
| 76 | - { | ||
| 77 | - g_autofree gchar *text = v3270_get_copy_as_table(terminal,";"); | ||
| 78 | - debug("Selection:\n%s",text); | ||
| 79 | - gtk_selection_data_set( | ||
| 80 | - selection, | ||
| 81 | - gdk_atom_intern_static_string("text/csv"), | ||
| 82 | - 8, | ||
| 83 | - (guchar *) text, | ||
| 84 | - strlen(text) | ||
| 85 | - ); | ||
| 86 | - } | ||
| 87 | - break; | ||
| 88 | - | ||
| 89 | - default: | ||
| 90 | - g_warning("Unexpected clipboard type %d\n",target); | ||
| 91 | - } | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | /** | 35 | /** |
| 95 | * Clear clipboard contents. | 36 | * Clear clipboard contents. |
| 96 | * | 37 | * |
| @@ -131,64 +72,6 @@ LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | @@ -131,64 +72,6 @@ LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | ||
| 131 | return NULL; | 72 | return NULL; |
| 132 | } | 73 | } |
| 133 | 74 | ||
| 134 | -void v3270_update_system_clipboard(GtkWidget *widget) | ||
| 135 | -{ | ||
| 136 | - v3270 * terminal = GTK_V3270(widget); | ||
| 137 | - | ||
| 138 | - if(!terminal->selection.blocks) | ||
| 139 | - { | ||
| 140 | - // No clipboard data, return. | ||
| 141 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 142 | - return; | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - // Has clipboard data, inform system. | ||
| 146 | - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
| 147 | - | ||
| 148 | - // Create target list | ||
| 149 | - // | ||
| 150 | - // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | ||
| 151 | - // | ||
| 152 | - static const GtkTargetEntry internal_targets[] = { | ||
| 153 | - { "text/csv", 0, CLIPBOARD_TYPE_CSV } | ||
| 154 | - }; | ||
| 155 | - | ||
| 156 | - GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); | ||
| 157 | - GtkTargetEntry * targets; | ||
| 158 | - int n_targets; | ||
| 159 | - | ||
| 160 | - gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); | ||
| 161 | - | ||
| 162 | - targets = gtk_target_table_new_from_list(list, &n_targets); | ||
| 163 | - | ||
| 164 | -#ifdef DEBUG | ||
| 165 | - { | ||
| 166 | - int ix; | ||
| 167 | - for(ix = 0; ix < n_targets; ix++) { | ||
| 168 | - debug("target(%d)=\"%s\"",ix,targets[ix].target); | ||
| 169 | - } | ||
| 170 | - } | ||
| 171 | -#endif // DEBUG | ||
| 172 | - | ||
| 173 | - if(gtk_clipboard_set_with_owner( | ||
| 174 | - clipboard, | ||
| 175 | - targets, | ||
| 176 | - n_targets, | ||
| 177 | - (GtkClipboardGetFunc) clipboard_get, | ||
| 178 | - (GtkClipboardClearFunc) clipboard_clear, | ||
| 179 | - G_OBJECT(widget) | ||
| 180 | - )) | ||
| 181 | - { | ||
| 182 | - gtk_clipboard_set_can_store(clipboard,targets,1); | ||
| 183 | - } | ||
| 184 | - | ||
| 185 | - gtk_target_table_free(targets, n_targets); | ||
| 186 | - gtk_target_list_unref(list); | ||
| 187 | - | ||
| 188 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
| 189 | - | ||
| 190 | -} | ||
| 191 | - | ||
| 192 | LIB3270_EXPORT void v3270_unselect(GtkWidget *widget) | 75 | LIB3270_EXPORT void v3270_unselect(GtkWidget *widget) |
| 193 | { | 76 | { |
| 194 | v3270_disable_updates(widget); | 77 | v3270_disable_updates(widget); |
| @@ -0,0 +1,149 @@ | @@ -0,0 +1,149 @@ | ||
| 1 | +/* | ||
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
| 5 | + * | ||
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
| 7 | + * | ||
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
| 10 | + * Free Software Foundation. | ||
| 11 | + * | ||
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
| 15 | + * obter mais detalhes. | ||
| 16 | + * | ||
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
| 22 | + * | ||
| 23 | + * Contatos: | ||
| 24 | + * | ||
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
| 27 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include <clipboard.h> | ||
| 31 | + #include <lib3270/selection.h> | ||
| 32 | + | ||
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 34 | +static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
| 35 | +{ | ||
| 36 | + v3270 * terminal = GTK_V3270(obj); | ||
| 37 | + | ||
| 38 | + if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | ||
| 39 | + { | ||
| 40 | + v3270_unselect(GTK_WIDGET(obj)); | ||
| 41 | + v3270_clear_selection(terminal); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
| 47 | +{ | ||
| 48 | + v3270 * terminal = GTK_V3270(obj); | ||
| 49 | + | ||
| 50 | + if(!terminal->selection.blocks) | ||
| 51 | + { | ||
| 52 | + return; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + switch(target) | ||
| 56 | + { | ||
| 57 | + case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | ||
| 58 | + { | ||
| 59 | + gchar *text; | ||
| 60 | + | ||
| 61 | + if(terminal->selection.format == V3270_SELECT_TABLE) | ||
| 62 | + { | ||
| 63 | + text = v3270_get_copy_as_table(terminal,"\t"); | ||
| 64 | + } | ||
| 65 | + else | ||
| 66 | + { | ||
| 67 | + text = v3270_get_copy_as_text(terminal); | ||
| 68 | + } | ||
| 69 | + gtk_selection_data_set_text(selection,text,-1); | ||
| 70 | + g_free(text); | ||
| 71 | + } | ||
| 72 | + break; | ||
| 73 | + | ||
| 74 | + case CLIPBOARD_TYPE_CSV: | ||
| 75 | + { | ||
| 76 | + g_autofree gchar *text = v3270_get_copy_as_table(terminal,";"); | ||
| 77 | + debug("Selection:\n%s",text); | ||
| 78 | + gtk_selection_data_set( | ||
| 79 | + selection, | ||
| 80 | + gdk_atom_intern_static_string("text/csv"), | ||
| 81 | + 8, | ||
| 82 | + (guchar *) text, | ||
| 83 | + strlen(text) | ||
| 84 | + ); | ||
| 85 | + } | ||
| 86 | + break; | ||
| 87 | + | ||
| 88 | + default: | ||
| 89 | + g_warning("Unexpected clipboard type %d\n",target); | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +void v3270_update_system_clipboard(GtkWidget *widget) | ||
| 94 | +{ | ||
| 95 | + v3270 * terminal = GTK_V3270(widget); | ||
| 96 | + | ||
| 97 | + if(!terminal->selection.blocks) | ||
| 98 | + { | ||
| 99 | + // No clipboard data, return. | ||
| 100 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 101 | + return; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // Has clipboard data, inform system. | ||
| 105 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
| 106 | + | ||
| 107 | + // Create target list | ||
| 108 | + // | ||
| 109 | + // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | ||
| 110 | + // | ||
| 111 | + static const GtkTargetEntry internal_targets[] = { | ||
| 112 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV } | ||
| 113 | + }; | ||
| 114 | + | ||
| 115 | + GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); | ||
| 116 | + GtkTargetEntry * targets; | ||
| 117 | + int n_targets; | ||
| 118 | + | ||
| 119 | + gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); | ||
| 120 | + | ||
| 121 | + targets = gtk_target_table_new_from_list(list, &n_targets); | ||
| 122 | + | ||
| 123 | +#ifdef DEBUG | ||
| 124 | + { | ||
| 125 | + int ix; | ||
| 126 | + for(ix = 0; ix < n_targets; ix++) { | ||
| 127 | + debug("target(%d)=\"%s\"",ix,targets[ix].target); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | +#endif // DEBUG | ||
| 131 | + | ||
| 132 | + if(gtk_clipboard_set_with_owner( | ||
| 133 | + clipboard, | ||
| 134 | + targets, | ||
| 135 | + n_targets, | ||
| 136 | + (GtkClipboardGetFunc) clipboard_get, | ||
| 137 | + (GtkClipboardClearFunc) clipboard_clear, | ||
| 138 | + G_OBJECT(widget) | ||
| 139 | + )) | ||
| 140 | + { | ||
| 141 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + gtk_target_table_free(targets, n_targets); | ||
| 145 | + gtk_target_list_unref(list); | ||
| 146 | + | ||
| 147 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
| 148 | + | ||
| 149 | +} |