Commit 864a22da64e402b0e8adc5584025e7ec8549e1ad
1 parent
dab61a03
Exists in
master
and in
1 other branch
Moving selection management methods to protocol library.
Showing
7 changed files
with
49 additions
and
195 deletions
Show diff stats
src/clipboard/copy.c
| @@ -30,8 +30,16 @@ | @@ -30,8 +30,16 @@ | ||
| 30 | #include <clipboard.h> | 30 | #include <clipboard.h> |
| 31 | #include <lib3270/selection.h> | 31 | #include <lib3270/selection.h> |
| 32 | 32 | ||
| 33 | - static void do_copy(v3270 *terminal) | 33 | + static void do_copy(v3270 *terminal, gboolean cut) |
| 34 | { | 34 | { |
| 35 | + lib3270_selection * selection = lib3270_get_selection(terminal->host,cut); | ||
| 36 | + | ||
| 37 | + if(selection) | ||
| 38 | + { | ||
| 39 | + terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /* | ||
| 35 | // Get selection bounds. | 43 | // Get selection bounds. |
| 36 | unsigned int row; | 44 | unsigned int row; |
| 37 | unsigned int col; | 45 | unsigned int col; |
| @@ -80,7 +88,7 @@ | @@ -80,7 +88,7 @@ | ||
| 80 | } | 88 | } |
| 81 | 89 | ||
| 82 | terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); | 90 | terminal->selection.blocks = g_list_append(terminal->selection.blocks,selection); |
| 83 | - | 91 | + */ |
| 84 | } | 92 | } |
| 85 | 93 | ||
| 86 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_SELECT_FORMAT format, gboolean cut) | 94 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_SELECT_FORMAT format, gboolean cut) |
| @@ -90,17 +98,13 @@ | @@ -90,17 +98,13 @@ | ||
| 90 | v3270 * terminal = GTK_V3270(widget); | 98 | v3270 * terminal = GTK_V3270(widget); |
| 91 | 99 | ||
| 92 | // Have data? Clear it? | 100 | // Have data? Clear it? |
| 93 | - v3270_clear_clipboard(terminal); | 101 | + v3270_clear_selection(terminal); |
| 94 | 102 | ||
| 95 | terminal->selection.format = format; | 103 | terminal->selection.format = format; |
| 96 | - do_copy(terminal); | 104 | + do_copy(terminal,cut); |
| 97 | 105 | ||
| 98 | v3270_update_system_clipboard(widget); | 106 | v3270_update_system_clipboard(widget); |
| 99 | 107 | ||
| 100 | - if(cut) | ||
| 101 | - { | ||
| 102 | - lib3270_erase_selected(terminal->host); | ||
| 103 | - } | ||
| 104 | } | 108 | } |
| 105 | 109 | ||
| 106 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) | 110 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) |
| @@ -109,13 +113,9 @@ | @@ -109,13 +113,9 @@ | ||
| 109 | 113 | ||
| 110 | v3270 * terminal = GTK_V3270(widget); | 114 | v3270 * terminal = GTK_V3270(widget); |
| 111 | 115 | ||
| 112 | - do_copy(terminal); | 116 | + do_copy(terminal,cut); |
| 113 | 117 | ||
| 114 | v3270_update_system_clipboard(widget); | 118 | v3270_update_system_clipboard(widget); |
| 115 | 119 | ||
| 116 | - if(cut) | ||
| 117 | - { | ||
| 118 | - lib3270_erase_selected(terminal->host); | ||
| 119 | - } | ||
| 120 | } | 120 | } |
| 121 | 121 |
src/clipboard/selection.c
| @@ -28,6 +28,7 @@ | @@ -28,6 +28,7 @@ | ||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include <clipboard.h> | 30 | #include <clipboard.h> |
| 31 | + #include <lib3270/selection.h> | ||
| 31 | 32 | ||
| 32 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 33 | 34 | ||
| @@ -38,43 +39,11 @@ static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED | @@ -38,43 +39,11 @@ static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED | ||
| 38 | if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | 39 | if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) |
| 39 | { | 40 | { |
| 40 | v3270_unselect(GTK_WIDGET(obj)); | 41 | v3270_unselect(GTK_WIDGET(obj)); |
| 41 | - v3270_clear_clipboard(terminal); | 42 | + v3270_clear_selection(terminal); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | -/// @brief Get formatted contents as single text. | ||
| 47 | -static gchar * get_copy_as_text(v3270 * terminal) | ||
| 48 | -{ | ||
| 49 | - GList * element = terminal->selection.blocks; | ||
| 50 | - GString * string = g_string_new(""); | ||
| 51 | - | ||
| 52 | - while(element) | ||
| 53 | - { | ||
| 54 | - struct selection * block = ((struct selection *) element->data); | ||
| 55 | - unsigned int row, col, src = 0; | ||
| 56 | - | ||
| 57 | - for(row=0; row < block->bounds.height; row++) | ||
| 58 | - { | ||
| 59 | - for(col=0; col<block->bounds.width; col++) | ||
| 60 | - { | ||
| 61 | - if(block->contents[src].attr & LIB3270_ATTR_SELECTED) | ||
| 62 | - g_string_append_c(string,block->contents[src].chr); | ||
| 63 | - | ||
| 64 | - src++; | ||
| 65 | - | ||
| 66 | - } | ||
| 67 | - g_string_append_c(string,'\n'); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - element = g_list_next(element); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - g_autofree char * text = g_string_free(string,FALSE); | ||
| 74 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 75 | - | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | 47 | static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) |
| 79 | { | 48 | { |
| 80 | v3270 * terminal = GTK_V3270(obj); | 49 | v3270 * terminal = GTK_V3270(obj); |
| @@ -85,7 +54,7 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | @@ -85,7 +54,7 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | ||
| 85 | 54 | ||
| 86 | if(terminal->selection.blocks) | 55 | if(terminal->selection.blocks) |
| 87 | { | 56 | { |
| 88 | - g_autofree gchar * converted = get_copy_as_text(terminal); | 57 | + g_autofree gchar * converted = v3270_get_copy_as_text(terminal); |
| 89 | gtk_selection_data_set_text(selection,converted,-1); | 58 | gtk_selection_data_set_text(selection,converted,-1); |
| 90 | } | 59 | } |
| 91 | 60 | ||
| @@ -102,11 +71,11 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | @@ -102,11 +71,11 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | ||
| 102 | * @param terminal Pointer to the terminal Widget. | 71 | * @param terminal Pointer to the terminal Widget. |
| 103 | * | 72 | * |
| 104 | */ | 73 | */ |
| 105 | -void v3270_clear_clipboard(v3270 *terminal) | 74 | +void v3270_clear_selection(v3270 *terminal) |
| 106 | { | 75 | { |
| 107 | if(terminal->selection.blocks) | 76 | if(terminal->selection.blocks) |
| 108 | { | 77 | { |
| 109 | - g_list_free_full(terminal->selection.blocks,g_free); | 78 | + g_list_free_full(terminal->selection.blocks,(GDestroyNotify) lib3270_free); |
| 110 | terminal->selection.blocks = NULL; | 79 | terminal->selection.blocks = NULL; |
| 111 | } | 80 | } |
| 112 | } | 81 | } |
| @@ -136,49 +105,6 @@ LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | @@ -136,49 +105,6 @@ LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | ||
| 136 | return NULL; | 105 | return NULL; |
| 137 | } | 106 | } |
| 138 | 107 | ||
| 139 | -LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) | ||
| 140 | -{ | ||
| 141 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
| 142 | - return get_copy_as_text(GTK_V3270(widget)); | ||
| 143 | -} | ||
| 144 | - | ||
| 145 | - /* | ||
| 146 | -LIB3270_EXPORT void v3270_set_copy(GtkWidget *widget, const gchar *text) | ||
| 147 | -{ | ||
| 148 | - v3270 * terminal; | ||
| 149 | - gchar * isotext; | ||
| 150 | - | ||
| 151 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
| 152 | - | ||
| 153 | - terminal = GTK_V3270(widget); | ||
| 154 | - v3270_clear_clipboard(terminal); | ||
| 155 | - | ||
| 156 | - if(!text) | ||
| 157 | - { | ||
| 158 | - // No string, signal clipboard clear and return | ||
| 159 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 160 | - return; | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - // Received text, replace the selection buffer | ||
| 164 | - terminal->selection.format = V3270_SELECT_TEXT; | ||
| 165 | - isotext = g_convert(text, -1, lib3270_get_display_charset(terminal->host), "UTF-8", NULL, NULL, NULL); | ||
| 166 | - | ||
| 167 | - if(!isotext) | ||
| 168 | - { | ||
| 169 | - // No string, signal clipboard clear and return | ||
| 170 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 171 | - return; | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - terminal->selection.text = lib3270_strdup(isotext); | ||
| 175 | - | ||
| 176 | - g_free(isotext); | ||
| 177 | - | ||
| 178 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
| 179 | -} | ||
| 180 | - */ | ||
| 181 | - | ||
| 182 | void v3270_update_system_clipboard(GtkWidget *widget) | 108 | void v3270_update_system_clipboard(GtkWidget *widget) |
| 183 | { | 109 | { |
| 184 | v3270 * terminal = GTK_V3270(widget); | 110 | v3270 * terminal = GTK_V3270(widget); |
src/clipboard/text.c
| @@ -28,109 +28,43 @@ | @@ -28,109 +28,43 @@ | ||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include <clipboard.h> | 30 | #include <clipboard.h> |
| 31 | + #include <lib3270/selection.h> | ||
| 31 | 32 | ||
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 32 | 34 | ||
| 33 | -const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut) | 35 | +/// @brief Get formatted contents as single text. |
| 36 | +gchar * v3270_get_copy_as_text(v3270 * terminal) | ||
| 34 | { | 37 | { |
| 35 | - /* | ||
| 36 | - char * text; | ||
| 37 | - v3270 * terminal = GTK_V3270(widget); | 38 | + GList * element = terminal->selection.blocks; |
| 39 | + GString * string = g_string_new(""); | ||
| 38 | 40 | ||
| 39 | - v3270_clear_clipboard(terminal); | ||
| 40 | - | ||
| 41 | - if(cut) | ||
| 42 | - text = lib3270_cut_selected(terminal->host); | ||
| 43 | - else | ||
| 44 | - text = lib3270_get_selected(terminal->host); | ||
| 45 | - | ||
| 46 | - if(!text) | ||
| 47 | - { | ||
| 48 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
| 49 | - lib3270_ring_bell(terminal->host); | ||
| 50 | - return NULL; | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - if(terminal->selection.format == V3270_SELECT_TABLE) | 41 | + while(element) |
| 54 | { | 42 | { |
| 55 | - // Convert text to table | ||
| 56 | - gchar **ln = g_strsplit(text,"\n",-1); | ||
| 57 | - int width = lib3270_get_width(terminal->host); | ||
| 58 | - gboolean cols[width]; | ||
| 59 | - int l; | ||
| 60 | - GString * buffer; | 43 | + lib3270_selection * block = ((lib3270_selection *) element->data); |
| 44 | + unsigned int row, col, src = 0; | ||
| 61 | 45 | ||
| 62 | - memset(cols,0,sizeof(gboolean)*width); | ||
| 63 | - | ||
| 64 | - // Find column delimiters | ||
| 65 | - for(l=0;ln[l];l++) | 46 | + for(row=0; row < block->bounds.height; row++) |
| 66 | { | 47 | { |
| 67 | - int c; | ||
| 68 | - gchar * ptr = ln[l]; | ||
| 69 | - | ||
| 70 | - for(c=0;c<width && *ptr;c++) | 48 | + for(col=0; col<block->bounds.width; col++) |
| 71 | { | 49 | { |
| 72 | - if(!g_ascii_isspace(*ptr)) | ||
| 73 | - cols[c] = TRUE; | 50 | + if(block->contents[src].flags & LIB3270_ATTR_SELECTED) |
| 51 | + g_string_append_c(string,block->contents[src].chr); | ||
| 74 | 52 | ||
| 75 | - ptr++; | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - // Read screen contents | ||
| 81 | - buffer = g_string_sized_new(strlen(text)); | ||
| 82 | - for(l=0;ln[l];l++) | ||
| 83 | - { | ||
| 84 | - int col = 0; | ||
| 85 | - gchar * src = ln[l]; | ||
| 86 | - | ||
| 87 | - while(col < width && *src) | ||
| 88 | - { | ||
| 89 | - if(col) | ||
| 90 | - g_string_append_c(buffer,'\t'); | ||
| 91 | - | ||
| 92 | - // Find column start | ||
| 93 | - while(!cols[col] && col < width && *src) | ||
| 94 | - { | ||
| 95 | - col++; | ||
| 96 | - src++; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - if(col < width && *src) | ||
| 100 | - { | ||
| 101 | - gchar tmp[width+1]; | ||
| 102 | - gchar * dst = tmp; | ||
| 103 | - | ||
| 104 | - // Copy column content | ||
| 105 | - while(cols[col] && col < width && *src) | ||
| 106 | - { | ||
| 107 | - *dst = *src; | ||
| 108 | - col++; | ||
| 109 | - dst++; | ||
| 110 | - src++; | ||
| 111 | - } | ||
| 112 | - *dst = 0; | ||
| 113 | - g_string_append(buffer,g_strstrip(tmp)); | ||
| 114 | - } | 53 | + src++; |
| 115 | 54 | ||
| 116 | } | 55 | } |
| 117 | - g_string_append_c(buffer,'\n'); | ||
| 118 | - | 56 | + g_string_append_c(string,'\n'); |
| 119 | } | 57 | } |
| 120 | 58 | ||
| 121 | - g_strfreev(ln); | ||
| 122 | - g_free(text); | ||
| 123 | - | ||
| 124 | - text = g_string_free(buffer,FALSE); | 59 | + element = g_list_next(element); |
| 125 | } | 60 | } |
| 126 | 61 | ||
| 127 | - return terminal->selection.text = text; | ||
| 128 | - */ | ||
| 129 | - | ||
| 130 | - return NULL; | 62 | + g_autofree char * text = g_string_free(string,FALSE); |
| 63 | + return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 131 | 64 | ||
| 132 | } | 65 | } |
| 133 | 66 | ||
| 67 | + | ||
| 134 | LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding) | 68 | LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding) |
| 135 | { | 69 | { |
| 136 | gchar * buffer = NULL; | 70 | gchar * buffer = NULL; |
| @@ -254,3 +188,10 @@ LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const | @@ -254,3 +188,10 @@ LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const | ||
| 254 | g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, next); | 188 | g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, next); |
| 255 | 189 | ||
| 256 | } | 190 | } |
| 191 | + | ||
| 192 | +LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) | ||
| 193 | +{ | ||
| 194 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
| 195 | + return v3270_get_copy_as_text(GTK_V3270(widget)); | ||
| 196 | +} | ||
| 197 | + |
src/include/clipboard.h
| @@ -45,23 +45,11 @@ | @@ -45,23 +45,11 @@ | ||
| 45 | CLIPBOARD_TYPE_TEXT, | 45 | CLIPBOARD_TYPE_TEXT, |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | - struct selection | ||
| 49 | - { | ||
| 50 | - struct { | ||
| 51 | - unsigned int row; | ||
| 52 | - unsigned int col; | ||
| 53 | - unsigned int width; | ||
| 54 | - unsigned int height; | ||
| 55 | - | ||
| 56 | - } bounds; ///< @brief Clipboard rectangle. | ||
| 57 | - | ||
| 58 | - struct v3270_character contents[1]; | ||
| 59 | - | ||
| 60 | - }; | ||
| 61 | - | ||
| 62 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); | 48 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); |
| 63 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); | 49 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); |
| 64 | 50 | ||
| 51 | + /// @brief Get formatted contents as single text. | ||
| 52 | + G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); | ||
| 65 | 53 | ||
| 66 | 54 | ||
| 67 | #endif // V3270_CLIPBOARD_H_INCLUDED | 55 | #endif // V3270_CLIPBOARD_H_INCLUDED |
src/include/internals.h
| @@ -174,7 +174,7 @@ | @@ -174,7 +174,7 @@ | ||
| 174 | G_GNUC_INTERNAL void v3270_draw_alt_status(v3270 *terminal); | 174 | G_GNUC_INTERNAL void v3270_draw_alt_status(v3270 *terminal); |
| 175 | G_GNUC_INTERNAL void v3270_draw_ins_status(v3270 *terminal); | 175 | G_GNUC_INTERNAL void v3270_draw_ins_status(v3270 *terminal); |
| 176 | 176 | ||
| 177 | - G_GNUC_INTERNAL void v3270_clear_clipboard(v3270 *terminal); | 177 | + G_GNUC_INTERNAL void v3270_clear_selection(v3270 *terminal); |
| 178 | 178 | ||
| 179 | G_GNUC_INTERNAL void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr); | 179 | G_GNUC_INTERNAL void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr); |
| 180 | 180 |
src/include/terminal.h
| @@ -119,8 +119,7 @@ G_BEGIN_DECLS | @@ -119,8 +119,7 @@ G_BEGIN_DECLS | ||
| 119 | 119 | ||
| 120 | int baddr; ///< @brief Selection address. | 120 | int baddr; ///< @brief Selection address. |
| 121 | V3270_SELECT_FORMAT format; ///< @brief Copy format. | 121 | V3270_SELECT_FORMAT format; ///< @brief Copy format. |
| 122 | - | ||
| 123 | - GList * blocks; ///< @brief Selection blocks. | 122 | + GList * blocks; ///< @brief Selection blocks. |
| 124 | 123 | ||
| 125 | } selection; | 124 | } selection; |
| 126 | 125 |
src/terminal/widget.c
| @@ -660,7 +660,7 @@ static void v3270_destroy(GtkWidget *widget) | @@ -660,7 +660,7 @@ static void v3270_destroy(GtkWidget *widget) | ||
| 660 | terminal->input_method = NULL; | 660 | terminal->input_method = NULL; |
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | - v3270_clear_clipboard(terminal); | 663 | + v3270_clear_selection(terminal); |
| 664 | 664 | ||
| 665 | if(terminal->session_name) | 665 | if(terminal->session_name) |
| 666 | { | 666 | { |