Commit ff8a1c99168fa72c33424b662c6e24d16d759bb4
1 parent
39d44a90
Exists in
master
and in
1 other branch
Adding html support in the "copy as table" method.
Showing
4 changed files
with
100 additions
and
15 deletions
Show diff stats
src/include/clipboard.h
... | ... | @@ -47,8 +47,17 @@ |
47 | 47 | CLIPBOARD_TYPE_HTML, |
48 | 48 | }; |
49 | 49 | |
50 | + struct ColumnDescription | |
51 | + { | |
52 | + unsigned int begin; | |
53 | + unsigned int width; | |
54 | + }; | |
55 | + | |
56 | + | |
50 | 57 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); |
51 | 58 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); |
59 | + G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal); | |
60 | + | |
52 | 61 | |
53 | 62 | /// @brief Get formatted contents as single text. |
54 | 63 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); | ... | ... |
src/selection/html.c
... | ... | @@ -143,8 +143,92 @@ static gchar * get_as_div(v3270 * terminal) |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | +/// @brief Get formatted contents as HTML TABLE. | |
147 | +static gchar * get_as_table(v3270 * terminal) | |
148 | +{ | |
149 | + GList * element = terminal->selection.blocks; | |
150 | + GString * string = g_string_new(""); | |
151 | + | |
152 | + unsigned int width = lib3270_get_width(terminal->host); | |
153 | + g_autofree gchar * line = g_malloc0(width+1); | |
154 | + | |
155 | + GList * column; | |
156 | + | |
157 | + g_string_append_printf( | |
158 | + string, | |
159 | + "<table style=\"font-family:%s,monospace\"><tbody>", | |
160 | + terminal->font.family | |
161 | + ); | |
162 | + | |
163 | + // Get contents | |
164 | + GList * columns = v3270_getColumns_from_selection(terminal); | |
165 | + | |
166 | + while(element) | |
167 | + { | |
168 | + lib3270_selection * block = ((lib3270_selection *) element->data); | |
169 | + | |
170 | + unsigned int row, col, src = 0; | |
171 | + | |
172 | + for(row=0; row < block->bounds.height; row++) | |
173 | + { | |
174 | + | |
175 | + // Build text line with selected data. | |
176 | + memset(line,' ',width); | |
177 | + for(col=0; col<block->bounds.width; col++) | |
178 | + { | |
179 | + if(block->contents[src].flags & LIB3270_ATTR_SELECTED) | |
180 | + { | |
181 | + line[block->bounds.col+col] = block->contents[src].chr; | |
182 | + } | |
183 | + | |
184 | + src++; | |
185 | + } | |
186 | + | |
187 | + g_string_append(string,"<tr>"); | |
188 | + | |
189 | + // Extract columns | |
190 | + for(column = columns; column; column = column->next) | |
191 | + { | |
192 | + struct ColumnDescription * columndescription = (struct ColumnDescription *) column->data; | |
193 | + | |
194 | + g_string_append_printf(string,"<td>"); | |
195 | + g_string_append_len(string,line+columndescription->begin,columndescription->width); | |
196 | + g_string_append(string,"</td>"); | |
197 | + | |
198 | + } | |
199 | + | |
200 | + g_string_append(string,"</tr>"); | |
201 | + | |
202 | +#ifdef DEBUG | |
203 | + g_string_append_c(string,'\n'); | |
204 | +#endif // DEBUG | |
205 | + | |
206 | + } | |
207 | + | |
208 | + element = g_list_next(element); | |
209 | + } | |
210 | + | |
211 | + g_list_free_full(columns,g_free); | |
212 | + | |
213 | +#ifdef DEBUG | |
214 | + g_string_append_c(string,'\n'); | |
215 | +#endif // DEBUG | |
216 | + | |
217 | + g_string_append(string,"</tbody></table>"); | |
218 | + | |
219 | + return g_string_free(string,FALSE); | |
220 | + | |
221 | +} | |
222 | + | |
223 | + | |
146 | 224 | gchar * v3270_get_copy_as_html(v3270 * terminal) |
147 | 225 | { |
148 | - g_autofree char * text = get_as_div(terminal); | |
226 | + g_autofree char * text = NULL; | |
227 | + | |
228 | + if(terminal->selection.format == V3270_SELECT_TABLE) | |
229 | + text = get_as_table(terminal); | |
230 | + else | |
231 | + text = get_as_div(terminal); | |
232 | + | |
149 | 233 | return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); |
150 | 234 | } | ... | ... |
src/selection/linux/copy.c
... | ... | @@ -59,18 +59,15 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa |
59 | 59 | { |
60 | 60 | gchar *text; |
61 | 61 | |
62 | +#ifdef DEBUG | |
63 | + text = v3270_get_copy_as_html(terminal); | |
64 | +#else | |
62 | 65 | if(terminal->selection.format == V3270_SELECT_TABLE) |
63 | - { | |
64 | 66 | text = v3270_get_copy_as_table(terminal,"\t"); |
65 | - } | |
66 | 67 | else |
67 | - { | |
68 | -#ifdef DEBUG | |
69 | - text = v3270_get_copy_as_html(terminal); | |
70 | -#else | |
71 | 68 | text = v3270_get_copy_as_text(terminal); |
72 | 69 | #endif // DEBUG |
73 | - } | |
70 | + | |
74 | 71 | gtk_selection_data_set_text(selection,text,-1); |
75 | 72 | g_free(text); |
76 | 73 | } | ... | ... |
src/selection/table.c
... | ... | @@ -31,11 +31,6 @@ |
31 | 31 | #include <ctype.h> |
32 | 32 | #include <lib3270/selection.h> |
33 | 33 | |
34 | - struct ColumnDescription { | |
35 | - unsigned int begin; | |
36 | - unsigned int width; | |
37 | - }; | |
38 | - | |
39 | 34 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
40 | 35 | |
41 | 36 | /// @brief Check if column has data. |
... | ... | @@ -70,7 +65,7 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col) |
70 | 65 | } |
71 | 66 | |
72 | 67 | /// @brief Get column list. |
73 | -GList * getColumns(v3270 * terminal) | |
68 | +GList * v3270_getColumns_from_selection(v3270 * terminal) | |
74 | 69 | { |
75 | 70 | unsigned int col = 0; |
76 | 71 | GList *rc = NULL; |
... | ... | @@ -108,7 +103,7 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) |
108 | 103 | { |
109 | 104 | GString * string = g_string_new(""); |
110 | 105 | |
111 | - GList * columns = getColumns(terminal); | |
106 | + GList * columns = v3270_getColumns_from_selection(terminal); | |
112 | 107 | |
113 | 108 | debug("columns=%p",columns); |
114 | 109 | ... | ... |