Commit 0bbb8fbbd0069be924e4106424f0e1f7bed5b381
1 parent
5372ee82
Exists in
master
and in
1 other branch
Working in the internal data for "smart paste" action.
Showing
5 changed files
with
184 additions
and
2 deletions
Show diff stats
src/include/clipboard.h
@@ -45,14 +45,43 @@ | @@ -45,14 +45,43 @@ | ||
45 | CLIPBOARD_TYPE_TEXT, | 45 | CLIPBOARD_TYPE_TEXT, |
46 | CLIPBOARD_TYPE_CSV, | 46 | CLIPBOARD_TYPE_CSV, |
47 | CLIPBOARD_TYPE_HTML, | 47 | CLIPBOARD_TYPE_HTML, |
48 | + CLIPBOARD_TYPE_V3270_UNPROTECTED | ||
48 | }; | 49 | }; |
49 | 50 | ||
51 | + /// @brief Column from selection. | ||
50 | struct ColumnDescription | 52 | struct ColumnDescription |
51 | { | 53 | { |
52 | unsigned int begin; | 54 | unsigned int begin; |
53 | unsigned int width; | 55 | unsigned int width; |
54 | }; | 56 | }; |
55 | 57 | ||
58 | + /// @brief Selection data for sending to another application. | ||
59 | + struct SelectionHeader | ||
60 | + { | ||
61 | + unsigned int length; ///< @brief Length of the data block. | ||
62 | + unsigned int build; ///< @brief V3270 build id. | ||
63 | + }; | ||
64 | + | ||
65 | + /// @brief Header of a list of fields. | ||
66 | + struct SelectionBlockHeader | ||
67 | + { | ||
68 | + /// @brief Cursor address. | ||
69 | + unsigned int cursor_address; | ||
70 | + | ||
71 | + /// @brief Number of records; | ||
72 | + unsigned int records; | ||
73 | + }; | ||
74 | + | ||
75 | + /// @brief Header for a field prefix. | ||
76 | + struct SelectionFieldHeader | ||
77 | + { | ||
78 | + /// @brief Field address. | ||
79 | + unsigned short baddr; | ||
80 | + | ||
81 | + /// @brief Field length. | ||
82 | + unsigned short length; | ||
83 | + | ||
84 | + }; | ||
56 | 85 | ||
57 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); | 86 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); |
58 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); | 87 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); |
@@ -63,6 +92,7 @@ | @@ -63,6 +92,7 @@ | ||
63 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); | 92 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); |
64 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal); | 93 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal); |
65 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter); | 94 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter); |
95 | + G_GNUC_INTERNAL gchar * v3270_get_copy_as_data_block(v3270 * terminal); | ||
66 | 96 | ||
67 | #endif // V3270_CLIPBOARD_H_INCLUDED | 97 | #endif // V3270_CLIPBOARD_H_INCLUDED |
68 | 98 |
src/selection/copy.c
@@ -53,6 +53,14 @@ | @@ -53,6 +53,14 @@ | ||
53 | terminal->selection.format = format; | 53 | terminal->selection.format = format; |
54 | do_copy(terminal,cut); | 54 | do_copy(terminal,cut); |
55 | 55 | ||
56 | +#ifdef DEBUG | ||
57 | + { | ||
58 | + // DEBUG DATA BLOCK | ||
59 | + g_free(v3270_get_copy_as_data_block(terminal)); | ||
60 | + } | ||
61 | + | ||
62 | +#endif // DEBUG | ||
63 | + | ||
56 | v3270_update_system_clipboard(widget); | 64 | v3270_update_system_clipboard(widget); |
57 | 65 | ||
58 | } | 66 | } |
@@ -0,0 +1,126 @@ | @@ -0,0 +1,126 @@ | ||
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 | + #define ALLOCATION_BLOCK_LENGTH 4096 | ||
34 | + | ||
35 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
36 | + | ||
37 | +/// @brief Get a list of all selected and unprotected contents. | ||
38 | +static GList * getUnprotected(const lib3270_selection *selection) | ||
39 | +{ | ||
40 | + GList * list = NULL; | ||
41 | + unsigned int row; | ||
42 | + const lib3270_selection_element * element = selection->contents; | ||
43 | + | ||
44 | + for(row=0; row < selection->bounds.height; row++) | ||
45 | + { | ||
46 | + unsigned int col = 0; | ||
47 | + | ||
48 | + // Find selected and unprotected entries. | ||
49 | + while(col < selection->bounds.width) | ||
50 | + { | ||
51 | + if((element[col].attribute.visual & LIB3270_ATTR_SELECTED) && !(element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT)) | ||
52 | + { | ||
53 | + // Element is selected and not protected, get the length. | ||
54 | + unsigned short start = col; | ||
55 | + unsigned short length = 0; | ||
56 | + while(col < selection->bounds.width) | ||
57 | + { | ||
58 | + if( !(element[col].attribute.visual & LIB3270_ATTR_SELECTED) || (element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT)) | ||
59 | + break; | ||
60 | + | ||
61 | + col++; | ||
62 | + length++; | ||
63 | + } | ||
64 | + | ||
65 | + debug( | ||
66 | + "Row:%u Col: %u Length: %u", | ||
67 | + row + selection->bounds.row, | ||
68 | + start + selection->bounds.col, | ||
69 | + (unsigned int) length | ||
70 | + ); | ||
71 | + | ||
72 | + } | ||
73 | + else | ||
74 | + { | ||
75 | + col++; | ||
76 | + } | ||
77 | + | ||
78 | + } | ||
79 | + | ||
80 | + element += selection->bounds.width; | ||
81 | + | ||
82 | + } | ||
83 | + | ||
84 | + return list; | ||
85 | +} | ||
86 | + | ||
87 | +gchar * v3270_get_copy_as_data_block(v3270 * terminal) | ||
88 | +{ | ||
89 | + | ||
90 | + GList * element; | ||
91 | + size_t szBlock = ALLOCATION_BLOCK_LENGTH + sizeof(struct SelectionHeader); | ||
92 | + struct SelectionHeader * header = (struct SelectionHeader *) g_malloc0(szBlock+1); | ||
93 | + | ||
94 | + // Initialize header. | ||
95 | + header->build = BUILD_DATE; | ||
96 | + header->length = sizeof(struct SelectionHeader); | ||
97 | + | ||
98 | + // Insert elements. | ||
99 | + for(element = terminal->selection.blocks; element; element = element->next) | ||
100 | + { | ||
101 | + lib3270_selection * block = ((lib3270_selection *) element->data); | ||
102 | + size_t length = (block->bounds.height * block->bounds.width); | ||
103 | + | ||
104 | + if( (header->length+length) >= szBlock ) | ||
105 | + { | ||
106 | + szBlock += ALLOCATION_BLOCK_LENGTH + header->length + length; | ||
107 | + header = (struct SelectionHeader *) g_realloc(header,szBlock+1); | ||
108 | + } | ||
109 | + | ||
110 | + // Setup block header | ||
111 | + struct SelectionBlockHeader * blockheader = (struct SelectionBlockHeader *) (((unsigned char *) header) + header->length); | ||
112 | + header->length += sizeof(* blockheader); | ||
113 | + | ||
114 | + blockheader->cursor_address = block->cursor_address; | ||
115 | + blockheader->records = 0; | ||
116 | + | ||
117 | + // Get values. | ||
118 | + GList * values = getUnprotected((const lib3270_selection *) element->data); | ||
119 | + | ||
120 | + | ||
121 | + g_list_free_full(values,g_free); | ||
122 | + | ||
123 | + } | ||
124 | + | ||
125 | + return (gchar *) g_realloc((gpointer) header, header->length+1); | ||
126 | +} |
src/selection/linux/copy.c
@@ -90,6 +90,19 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | @@ -90,6 +90,19 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | ||
90 | } | 90 | } |
91 | break; | 91 | break; |
92 | 92 | ||
93 | + case CLIPBOARD_TYPE_V3270_UNPROTECTED: | ||
94 | + { | ||
95 | + g_autofree gchar *data = v3270_get_copy_as_data_block(terminal); | ||
96 | + gtk_selection_data_set( | ||
97 | + selection, | ||
98 | + gdk_atom_intern_static_string("application/x-v3270-unprotected"), | ||
99 | + 8, | ||
100 | + (guchar *) data, | ||
101 | + ((struct SelectionHeader *) data)->length | ||
102 | + ); | ||
103 | + } | ||
104 | + break; | ||
105 | + | ||
93 | default: | 106 | default: |
94 | g_warning("Unexpected clipboard type %d\n",target); | 107 | g_warning("Unexpected clipboard type %d\n",target); |
95 | } | 108 | } |
@@ -114,8 +127,9 @@ void v3270_update_system_clipboard(GtkWidget *widget) | @@ -114,8 +127,9 @@ void v3270_update_system_clipboard(GtkWidget *widget) | ||
114 | // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | 127 | // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html |
115 | // | 128 | // |
116 | static const GtkTargetEntry internal_targets[] = { | 129 | static const GtkTargetEntry internal_targets[] = { |
117 | - { "text/csv", 0, CLIPBOARD_TYPE_CSV }, | ||
118 | - { "text/html", 0, CLIPBOARD_TYPE_HTML } | 130 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV }, |
131 | + { "text/html", 0, CLIPBOARD_TYPE_HTML }, | ||
132 | + { "application/x-v3270-unprotected", 0, CLIPBOARD_TYPE_V3270_UNPROTECTED }, | ||
119 | }; | 133 | }; |
120 | 134 | ||
121 | GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); | 135 | GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); |
@@ -153,3 +167,4 @@ void v3270_update_system_clipboard(GtkWidget *widget) | @@ -153,3 +167,4 @@ void v3270_update_system_clipboard(GtkWidget *widget) | ||
153 | g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | 167 | g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); |
154 | 168 | ||
155 | } | 169 | } |
170 | + |
v3270.cbp
@@ -146,6 +146,9 @@ | @@ -146,6 +146,9 @@ | ||
146 | <Unit filename="src/selection/copy.c"> | 146 | <Unit filename="src/selection/copy.c"> |
147 | <Option compilerVar="CC" /> | 147 | <Option compilerVar="CC" /> |
148 | </Unit> | 148 | </Unit> |
149 | + <Unit filename="src/selection/datablock.c"> | ||
150 | + <Option compilerVar="CC" /> | ||
151 | + </Unit> | ||
149 | <Unit filename="src/selection/html.c"> | 152 | <Unit filename="src/selection/html.c"> |
150 | <Option compilerVar="CC" /> | 153 | <Option compilerVar="CC" /> |
151 | </Unit> | 154 | </Unit> |