Commit 4b7d100d892ebf07ec31e1dc9ac125158ac4874c
1 parent
207329f2
Exists in
master
and in
5 other branches
Iniciando implementação do recurso "copy" com atributos
Showing
4 changed files
with
44 additions
and
25 deletions
Show diff stats
src/lib3270/selection.c
... | ... | @@ -372,12 +372,13 @@ LIB3270_ACTION( reselect ) |
372 | 372 | return 0; |
373 | 373 | } |
374 | 374 | |
375 | -static char * get_text(H3270 *hSession,unsigned char all) | |
375 | +static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) | |
376 | 376 | { |
377 | - int row, col, baddr; | |
378 | - char *ret; | |
379 | - size_t buflen = (hSession->rows * (hSession->cols+1))+1; | |
380 | - size_t sz = 0; | |
377 | + int row, col, baddr; | |
378 | + char * ret; | |
379 | + size_t buflen = (hSession->rows * (hSession->cols+1))+1; | |
380 | + size_t sz = 0; | |
381 | + unsigned short attr = 0; | |
381 | 382 | |
382 | 383 | if(!(lib3270_connected(hSession) && hSession->text)) |
383 | 384 | { |
... | ... | @@ -388,6 +389,15 @@ static char * get_text(H3270 *hSession,unsigned char all) |
388 | 389 | ret = lib3270_malloc(buflen); |
389 | 390 | |
390 | 391 | baddr = 0; |
392 | + | |
393 | + if(tok) | |
394 | + { | |
395 | + attr = hSession->text[baddr].attr; | |
396 | + ret[sz++] = tok; | |
397 | + ret[sz++] = (attr & 0x0F); | |
398 | + ret[sz++] = ((attr & 0xF0) >> 4); | |
399 | + } | |
400 | + | |
391 | 401 | for(row=0;row < hSession->rows;row++) |
392 | 402 | { |
393 | 403 | int cr = 0; |
... | ... | @@ -396,6 +406,14 @@ static char * get_text(H3270 *hSession,unsigned char all) |
396 | 406 | { |
397 | 407 | if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) |
398 | 408 | { |
409 | + if(tok && attr != hSession->text[baddr].attr) | |
410 | + { | |
411 | + attr = hSession->text[baddr].attr; | |
412 | + ret[sz++] = tok; | |
413 | + ret[sz++] = (attr & 0x0F); | |
414 | + ret[sz++] = ((attr & 0xF0) >> 4); | |
415 | + } | |
416 | + | |
399 | 417 | cr++; |
400 | 418 | ret[sz++] = hSession->text[baddr].chr; |
401 | 419 | } |
... | ... | @@ -404,6 +422,12 @@ static char * get_text(H3270 *hSession,unsigned char all) |
404 | 422 | |
405 | 423 | if(cr) |
406 | 424 | ret[sz++] = '\n'; |
425 | + | |
426 | + if((sz+10) > buflen) | |
427 | + { | |
428 | + buflen += 100; | |
429 | + ret = lib3270_realloc(ret,buflen); | |
430 | + } | |
407 | 431 | } |
408 | 432 | |
409 | 433 | if(!sz) |
... | ... | @@ -563,7 +587,7 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) |
563 | 587 | return NULL; |
564 | 588 | |
565 | 589 | |
566 | - return get_text(hSession,0); | |
590 | + return get_text(hSession,0,0); | |
567 | 591 | } |
568 | 592 | |
569 | 593 | static void copy_chr(H3270 *hSession, int from, int to) |
... | ... | @@ -602,14 +626,6 @@ int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) |
602 | 626 | if(hSession->ea_buf[saddr].fa) |
603 | 627 | *sattr = hSession->ea_buf[saddr++].fa; |
604 | 628 | |
605 | -/* | |
606 | - if(FA_IS_PROTECTED(*sattr)) | |
607 | - { | |
608 | - saddr = lib3270_get_next_unprotected(hSession,saddr); | |
609 | - *sattr = lib3270_field_attribute(hSession,saddr); | |
610 | - } | |
611 | -*/ | |
612 | - | |
613 | 629 | if(FA_IS_PROTECTED(*sattr) || saddr >= maxlen) |
614 | 630 | clear_chr(hSession,daddr); |
615 | 631 | else | ... | ... |
src/pw3270/v3270/private.h
... | ... | @@ -244,6 +244,8 @@ void v3270_draw_shift_status(v3270 *terminal); |
244 | 244 | void v3270_draw_alt_status(v3270 *terminal); |
245 | 245 | void v3270_draw_ins_status(v3270 *terminal); |
246 | 246 | |
247 | +void v3270_clear_clipboard(v3270 *terminal); | |
248 | + | |
247 | 249 | void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr); |
248 | 250 | |
249 | 251 | void v3270_register_io_handlers(v3270Class *cls); | ... | ... |
src/pw3270/v3270/selection.c
... | ... | @@ -138,11 +138,7 @@ const gchar * v3270_get_selected_text(GtkWidget *widget, gboolean cut) |
138 | 138 | |
139 | 139 | terminal = GTK_V3270(widget); |
140 | 140 | |
141 | - if(terminal->clipboard) | |
142 | - { | |
143 | - g_free(terminal->clipboard); | |
144 | - terminal->clipboard = NULL; | |
145 | - } | |
141 | + v3270_clear_clipboard(terminal); | |
146 | 142 | |
147 | 143 | if(cut) |
148 | 144 | text = lib3270_cut_selected(terminal->host); |
... | ... | @@ -276,7 +272,7 @@ const gchar * v3270_copy_append(GtkWidget *widget) |
276 | 272 | clip = g_strconcat(terminal->clipboard,"\n",text,NULL); |
277 | 273 | |
278 | 274 | g_free(text); |
279 | - g_free(terminal->clipboard); | |
275 | + v3270_clear_clipboard(terminal); | |
280 | 276 | |
281 | 277 | terminal->clipboard = clip; |
282 | 278 | ... | ... |
src/pw3270/v3270/widget.c
... | ... | @@ -895,6 +895,15 @@ GtkWidget * v3270_new(void) |
895 | 895 | return g_object_new(GTK_TYPE_V3270, NULL); |
896 | 896 | } |
897 | 897 | |
898 | +void v3270_clear_clipboard(v3270 *terminal) | |
899 | +{ | |
900 | + if(terminal->clipboard) | |
901 | + { | |
902 | + g_free(terminal->clipboard); | |
903 | + terminal->clipboard = NULL; | |
904 | + } | |
905 | +} | |
906 | + | |
898 | 907 | #if GTK_CHECK_VERSION(3,0,0) |
899 | 908 | static void v3270_destroy(GtkWidget *widget) |
900 | 909 | #else |
... | ... | @@ -969,11 +978,7 @@ static void v3270_destroy(GtkObject *widget) |
969 | 978 | terminal->input_method = NULL; |
970 | 979 | } |
971 | 980 | |
972 | - if(terminal->clipboard) | |
973 | - { | |
974 | - g_free(terminal->clipboard); | |
975 | - terminal->clipboard = NULL; | |
976 | - } | |
981 | + v3270_clear_clipboard(terminal); | |
977 | 982 | |
978 | 983 | if(terminal->session_name) |
979 | 984 | { | ... | ... |