diff --git a/src/include/clipboard.h b/src/include/clipboard.h
index a710abf..52ffa35 100644
--- a/src/include/clipboard.h
+++ b/src/include/clipboard.h
@@ -47,8 +47,17 @@
CLIPBOARD_TYPE_HTML,
};
+ struct ColumnDescription
+ {
+ unsigned int begin;
+ unsigned int width;
+ };
+
+
G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget);
G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut);
+ G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal);
+
/// @brief Get formatted contents as single text.
G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal);
diff --git a/src/selection/html.c b/src/selection/html.c
index 64374d7..ab5b940 100644
--- a/src/selection/html.c
+++ b/src/selection/html.c
@@ -143,8 +143,92 @@ static gchar * get_as_div(v3270 * terminal)
}
+/// @brief Get formatted contents as HTML TABLE.
+static gchar * get_as_table(v3270 * terminal)
+{
+ GList * element = terminal->selection.blocks;
+ GString * string = g_string_new("");
+
+ unsigned int width = lib3270_get_width(terminal->host);
+ g_autofree gchar * line = g_malloc0(width+1);
+
+ GList * column;
+
+ g_string_append_printf(
+ string,
+ "
",
+ terminal->font.family
+ );
+
+ // Get contents
+ GList * columns = v3270_getColumns_from_selection(terminal);
+
+ while(element)
+ {
+ lib3270_selection * block = ((lib3270_selection *) element->data);
+
+ unsigned int row, col, src = 0;
+
+ for(row=0; row < block->bounds.height; row++)
+ {
+
+ // Build text line with selected data.
+ memset(line,' ',width);
+ for(col=0; colbounds.width; col++)
+ {
+ if(block->contents[src].flags & LIB3270_ATTR_SELECTED)
+ {
+ line[block->bounds.col+col] = block->contents[src].chr;
+ }
+
+ src++;
+ }
+
+ g_string_append(string,"");
+
+ // Extract columns
+ for(column = columns; column; column = column->next)
+ {
+ struct ColumnDescription * columndescription = (struct ColumnDescription *) column->data;
+
+ g_string_append_printf(string,"");
+ g_string_append_len(string,line+columndescription->begin,columndescription->width);
+ g_string_append(string," | ");
+
+ }
+
+ g_string_append(string,"
");
+
+#ifdef DEBUG
+ g_string_append_c(string,'\n');
+#endif // DEBUG
+
+ }
+
+ element = g_list_next(element);
+ }
+
+ g_list_free_full(columns,g_free);
+
+#ifdef DEBUG
+ g_string_append_c(string,'\n');
+#endif // DEBUG
+
+ g_string_append(string,"
");
+
+ return g_string_free(string,FALSE);
+
+}
+
+
gchar * v3270_get_copy_as_html(v3270 * terminal)
{
- g_autofree char * text = get_as_div(terminal);
+ g_autofree char * text = NULL;
+
+ if(terminal->selection.format == V3270_SELECT_TABLE)
+ text = get_as_table(terminal);
+ else
+ text = get_as_div(terminal);
+
return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL);
}
diff --git a/src/selection/linux/copy.c b/src/selection/linux/copy.c
index 6d86938..d7d98c9 100644
--- a/src/selection/linux/copy.c
+++ b/src/selection/linux/copy.c
@@ -59,18 +59,15 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa
{
gchar *text;
+#ifdef DEBUG
+ text = v3270_get_copy_as_html(terminal);
+#else
if(terminal->selection.format == V3270_SELECT_TABLE)
- {
text = v3270_get_copy_as_table(terminal,"\t");
- }
else
- {
-#ifdef DEBUG
- text = v3270_get_copy_as_html(terminal);
-#else
text = v3270_get_copy_as_text(terminal);
#endif // DEBUG
- }
+
gtk_selection_data_set_text(selection,text,-1);
g_free(text);
}
diff --git a/src/selection/table.c b/src/selection/table.c
index d96db40..607c968 100644
--- a/src/selection/table.c
+++ b/src/selection/table.c
@@ -31,11 +31,6 @@
#include
#include
- struct ColumnDescription {
- unsigned int begin;
- unsigned int width;
- };
-
/*--[ Implement ]------------------------------------------------------------------------------------*/
/// @brief Check if column has data.
@@ -70,7 +65,7 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col)
}
/// @brief Get column list.
-GList * getColumns(v3270 * terminal)
+GList * v3270_getColumns_from_selection(v3270 * terminal)
{
unsigned int col = 0;
GList *rc = NULL;
@@ -108,7 +103,7 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter)
{
GString * string = g_string_new("");
- GList * columns = getColumns(terminal);
+ GList * columns = v3270_getColumns_from_selection(terminal);
debug("columns=%p",columns);
--
libgit2 0.21.2