Commit 9ad7fc9633db7baf8ae86aab3e6b78a96e8de743

Authored by Perry Werneck
1 parent 0e277129

Updating selection mechanism.

Showing 1 changed file with 7 additions and 160 deletions   Show diff stats
src/lib3270/selection/selection.c
... ... @@ -58,7 +58,6 @@ static void update_selected_rectangle(H3270 *session)
58 58 int col;
59 59 } p[2];
60 60  
61   -
62 61 int begin, end, row, col, baddr;
63 62  
64 63 get_selected_addr(session,&begin,&end);
... ... @@ -263,11 +262,11 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok, Boo
263 262 size_t sz = 0;
264 263 unsigned short attr = 0xFFFF;
265 264  
266   - if(!(lib3270_connected(hSession) && hSession->text))
267   - {
268   - errno = ENOTCONN;
  265 + if(check_online_session(hSession))
  266 + return NULL;
  267 +
  268 + if(!hSession->selected || hSession->select.start == hSession->select.end)
269 269 return NULL;
270   - }
271 270  
272 271 ret = lib3270_malloc(buflen);
273 272  
... ... @@ -466,171 +465,19 @@ LIB3270_EXPORT char * lib3270_get_field_text_at(H3270 *session, int baddr)
466 465  
467 466 LIB3270_EXPORT int lib3270_has_selection(H3270 *hSession)
468 467 {
469   - CHECK_SESSION_HANDLE(hSession);
  468 + if(check_online_session(hSession))
  469 + return 0;
  470 +
470 471 return hSession->selected != 0;
471 472 }
472 473  
473 474 LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
474 475 {
475   - CHECK_SESSION_HANDLE(hSession);
476   -
477   - if(!hSession->selected || hSession->select.start == hSession->select.end)
478   - return NULL;
479   -
480   - if(!lib3270_connected(hSession))
481   - return NULL;
482   -
483 476 return get_text(hSession,0,0,0);
484 477 }
485 478  
486 479 LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession)
487 480 {
488   - CHECK_SESSION_HANDLE(hSession);
489   -
490   - if(!hSession->selected || hSession->select.start == hSession->select.end)
491   - return NULL;
492   -
493   - if(!lib3270_connected(hSession))
494   - return NULL;
495   -
496 481 return get_text(hSession,0,0,1);
497 482 }
498 483  
499   -/*
500   -
501   -LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession)
502   -{
503   - return cut_text(hSession,0);
504   -}
505   -
506   -static void copy_chr(H3270 *hSession, int from, int to)
507   -{
508   - if(hSession->text[from].chr == hSession->text[to].chr)
509   - return;
510   -
511   - hSession->text[to].chr = hSession->text[from].chr;
512   -
513   - memcpy(&hSession->ea_buf[to], &hSession->ea_buf[from],sizeof(struct lib3270_ea));
514   - hSession->ea_buf[from].fa = 0;
515   -
516   - hSession->cbk.update( hSession,
517   - to,
518   - hSession->text[to].chr,
519   - hSession->text[to].attr,
520   - to == hSession->cursor_addr );
521   -}
522   -
523   -int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr)
524   -{
525   - if(hSession->ea_buf[saddr].fa)
526   - *sattr = hSession->ea_buf[saddr++].fa;
527   -
528   - if(FA_IS_PROTECTED(*sattr) || saddr >= maxlen)
529   - clear_chr(hSession,daddr);
530   - else
531   - copy_chr(hSession,saddr++,daddr);
532   -
533   - return saddr;
534   -}
535   -
536   -char * cut_text(H3270 *hSession, char tok)
537   -{
538   - unsigned short attr = 0xFFFF;
539   -
540   - CHECK_SESSION_HANDLE(hSession);
541   -
542   - if(!hSession->selected || hSession->select.start == hSession->select.end)
543   - return NULL;
544   -
545   - if(!(lib3270_connected(hSession) && hSession->text))
546   - return NULL;
547   -
548   - trace("Rectangle select is %s",lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECTANGLE_SELECT) ? "Active" : "Inactive");
549   -
550   - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECTANGLE_SELECT))
551   - {
552   - // Rectangle cut is not implemented
553   - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_INFO, _( "Not available" ), _( "Invalid cut action" ), "%s", _( "Can't cut rectangular regions") );
554   - }
555   - else
556   - {
557   - int end;
558   - size_t szText;
559   - size_t buflen;
560   - size_t bufpos = 0;
561   - int daddr; // Destination addr
562   - int dattr; // Destination addr attribute
563   - int saddr; // Source addr (First field after the selected area)
564   - int sattr; // Source addr attribute
565   - char *text;
566   - size_t maxlen = hSession->rows * hSession->cols;
567   - size_t f;
568   -
569   - get_selected_addr(hSession,&daddr,&end);
570   -
571   - lib3270_set_cursor_address(hSession,daddr);
572   -
573   - if(daddr >= end)
574   - return NULL;
575   -
576   - dattr = lib3270_field_attribute(hSession,daddr); // Get first attribute
577   -
578   - szText = (end-daddr)+1;
579   - buflen = szText;
580   - bufpos = 0;
581   -
582   - text = lib3270_malloc(buflen+1);
583   -
584   - saddr = daddr+szText;
585   - sattr = lib3270_field_attribute(hSession,saddr);
586   -
587   - for(f=0;f<szText;f++)
588   - {
589   - if(hSession->ea_buf[daddr].fa)
590   - dattr = hSession->ea_buf[daddr].fa;
591   -
592   - if((bufpos+10) > buflen)
593   - {
594   - buflen += 100;
595   - text = lib3270_realloc(text,buflen);
596   - }
597   -
598   - if(tok && attr != hSession->text[daddr].attr)
599   - {
600   - attr = hSession->text[daddr].attr;
601   - text[bufpos++] = tok;
602   - text[bufpos++] = (attr & 0x0F);
603   - text[bufpos++] = ((attr & 0xF0) >> 4);
604   - }
605   -
606   - text[bufpos++] = hSession->text[daddr].chr;
607   -
608   - if(!FA_IS_PROTECTED(dattr))
609   - saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr);
610   -
611   - daddr++;
612   - }
613   -
614   - text[bufpos++] = 0;
615   - text = lib3270_realloc(text,bufpos);
616   -
617   - // Move contents of the current field
618   - while(daddr < (int) (maxlen-1) && !hSession->ea_buf[daddr].fa)
619   - {
620   - saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr);
621   - daddr++;
622   - }
623   -
624   - if(!hSession->ea_buf[daddr].fa)
625   - clear_chr(hSession,daddr);
626   -
627   - hSession->cbk.changed(hSession,0,maxlen);
628   -
629   - lib3270_unselect(hSession);
630   - return text;
631   - }
632   -
633   - return NULL;
634   -}
635   -
636   -*/
... ...