From f146758200b3446c953617eed6aea7050ac7578c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 22 Jul 2019 09:46:13 -0300 Subject: [PATCH] Working on the new smart-paste feature. --- src/include/clipboard.h | 2 ++ src/selection/datablock.c | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/include/clipboard.h b/src/include/clipboard.h index e1eed0a..e720a9f 100644 --- a/src/include/clipboard.h +++ b/src/include/clipboard.h @@ -60,6 +60,8 @@ { unsigned int length; ///< @brief Length of the data block. unsigned int build; ///< @brief V3270 build id. + unsigned int rows; ///< @brief Terminal rows. + unsigned int cols; ///< @brief Terminal cols. }; /// @brief Header of a list of fields. diff --git a/src/selection/datablock.c b/src/selection/datablock.c index d6623b2..5f02750 100644 --- a/src/selection/datablock.c +++ b/src/selection/datablock.c @@ -35,7 +35,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ /// @brief Get a list of all selected and unprotected contents. -static GList * getUnprotected(const lib3270_selection *selection) +static GList * getUnprotected(H3270 *hSession, const lib3270_selection *selection) { GList * list = NULL; unsigned int row; @@ -48,14 +48,14 @@ static GList * getUnprotected(const lib3270_selection *selection) // Find selected and unprotected entries. while(col < selection->bounds.width) { - if((element[col].attribute.visual & LIB3270_ATTR_SELECTED) && !(element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT)) + if((element[col].attribute.visual & LIB3270_ATTR_SELECTED) && !((element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT) || (element[col].attribute.visual & LIB3270_ATTR_MARKER))) { // Element is selected and not protected, get the length. unsigned short start = col; unsigned short length = 0; while(col < selection->bounds.width) { - if( !(element[col].attribute.visual & LIB3270_ATTR_SELECTED) || (element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT)) + if( !(element[col].attribute.visual & (LIB3270_ATTR_SELECTED|LIB3270_ATTR_MARKER)) || (element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT)) break; col++; @@ -69,6 +69,22 @@ static GList * getUnprotected(const lib3270_selection *selection) (unsigned int) length ); + struct SelectionFieldHeader * field = (struct SelectionFieldHeader *) g_malloc0(sizeof(struct SelectionFieldHeader) + length); + + field->baddr = lib3270_translate_to_address(hSession,row + selection->bounds.row,start + selection->bounds.col); + field->length = length; + + // Copy string + unsigned char *ptr = (unsigned char *) (field+1); + unsigned short ix; + for(ix=0;ix < field->length; ix++) + { + ptr[ix] = element[start+ix].chr; + } + + // Add allocated block in the list + list = g_list_append(list, (gpointer) field); + } else { @@ -94,6 +110,7 @@ gchar * v3270_get_copy_as_data_block(v3270 * terminal) // Initialize header. header->build = BUILD_DATE; header->length = sizeof(struct SelectionHeader); + lib3270_get_screen_size(terminal->host, &header->rows, &header->cols); // Insert elements. for(element = terminal->selection.blocks; element; element = element->next) @@ -115,8 +132,25 @@ gchar * v3270_get_copy_as_data_block(v3270 * terminal) blockheader->records = 0; // Get values. - GList * values = getUnprotected((const lib3270_selection *) element->data); + GList * values = getUnprotected(terminal->host, (const lib3270_selection *) element->data); + GList * value; + + for(value = values; value; value = value->next) + { + size_t length = (sizeof(struct SelectionFieldHeader) + ((struct SelectionFieldHeader *) value->data)->length); + + if( (header->length+length) >= szBlock ) + { + szBlock += ALLOCATION_BLOCK_LENGTH + header->length + length; + header = (struct SelectionHeader *) g_realloc(header,szBlock+1); + } + unsigned char *ptr = ((unsigned char *) header); + + memcpy((ptr+header->length), value->data, length); + header->length += length; + + } g_list_free_full(values,g_free); -- libgit2 0.21.2