Commit f146758200b3446c953617eed6aea7050ac7578c

Authored by Perry Werneck
1 parent 0bbb8fbb
Exists in master and in 1 other branch develop

Working on the new smart-paste feature.

src/include/clipboard.h
... ... @@ -60,6 +60,8 @@
60 60 {
61 61 unsigned int length; ///< @brief Length of the data block.
62 62 unsigned int build; ///< @brief V3270 build id.
  63 + unsigned int rows; ///< @brief Terminal rows.
  64 + unsigned int cols; ///< @brief Terminal cols.
63 65 };
64 66  
65 67 /// @brief Header of a list of fields.
... ...
src/selection/datablock.c
... ... @@ -35,7 +35,7 @@
35 35 /*--[ Implement ]------------------------------------------------------------------------------------*/
36 36  
37 37 /// @brief Get a list of all selected and unprotected contents.
38   -static GList * getUnprotected(const lib3270_selection *selection)
  38 +static GList * getUnprotected(H3270 *hSession, const lib3270_selection *selection)
39 39 {
40 40 GList * list = NULL;
41 41 unsigned int row;
... ... @@ -48,14 +48,14 @@ static GList * getUnprotected(const lib3270_selection *selection)
48 48 // Find selected and unprotected entries.
49 49 while(col < selection->bounds.width)
50 50 {
51   - if((element[col].attribute.visual & LIB3270_ATTR_SELECTED) && !(element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT))
  51 + if((element[col].attribute.visual & LIB3270_ATTR_SELECTED) && !((element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT) || (element[col].attribute.visual & LIB3270_ATTR_MARKER)))
52 52 {
53 53 // Element is selected and not protected, get the length.
54 54 unsigned short start = col;
55 55 unsigned short length = 0;
56 56 while(col < selection->bounds.width)
57 57 {
58   - if( !(element[col].attribute.visual & LIB3270_ATTR_SELECTED) || (element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT))
  58 + if( !(element[col].attribute.visual & (LIB3270_ATTR_SELECTED|LIB3270_ATTR_MARKER)) || (element[col].attribute.field & LIB3270_FIELD_ATTRIBUTE_PROTECT))
59 59 break;
60 60  
61 61 col++;
... ... @@ -69,6 +69,22 @@ static GList * getUnprotected(const lib3270_selection *selection)
69 69 (unsigned int) length
70 70 );
71 71  
  72 + struct SelectionFieldHeader * field = (struct SelectionFieldHeader *) g_malloc0(sizeof(struct SelectionFieldHeader) + length);
  73 +
  74 + field->baddr = lib3270_translate_to_address(hSession,row + selection->bounds.row,start + selection->bounds.col);
  75 + field->length = length;
  76 +
  77 + // Copy string
  78 + unsigned char *ptr = (unsigned char *) (field+1);
  79 + unsigned short ix;
  80 + for(ix=0;ix < field->length; ix++)
  81 + {
  82 + ptr[ix] = element[start+ix].chr;
  83 + }
  84 +
  85 + // Add allocated block in the list
  86 + list = g_list_append(list, (gpointer) field);
  87 +
72 88 }
73 89 else
74 90 {
... ... @@ -94,6 +110,7 @@ gchar * v3270_get_copy_as_data_block(v3270 * terminal)
94 110 // Initialize header.
95 111 header->build = BUILD_DATE;
96 112 header->length = sizeof(struct SelectionHeader);
  113 + lib3270_get_screen_size(terminal->host, &header->rows, &header->cols);
97 114  
98 115 // Insert elements.
99 116 for(element = terminal->selection.blocks; element; element = element->next)
... ... @@ -115,8 +132,25 @@ gchar * v3270_get_copy_as_data_block(v3270 * terminal)
115 132 blockheader->records = 0;
116 133  
117 134 // Get values.
118   - GList * values = getUnprotected((const lib3270_selection *) element->data);
  135 + GList * values = getUnprotected(terminal->host, (const lib3270_selection *) element->data);
  136 + GList * value;
  137 +
  138 + for(value = values; value; value = value->next)
  139 + {
  140 + size_t length = (sizeof(struct SelectionFieldHeader) + ((struct SelectionFieldHeader *) value->data)->length);
  141 +
  142 + if( (header->length+length) >= szBlock )
  143 + {
  144 + szBlock += ALLOCATION_BLOCK_LENGTH + header->length + length;
  145 + header = (struct SelectionHeader *) g_realloc(header,szBlock+1);
  146 + }
119 147  
  148 + unsigned char *ptr = ((unsigned char *) header);
  149 +
  150 + memcpy((ptr+header->length), value->data, length);
  151 + header->length += length;
  152 +
  153 + }
120 154  
121 155 g_list_free_full(values,g_free);
122 156  
... ...