ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.57 by pcg, Sun Mar 14 17:33:08 2004 UTC vs.
Revision 1.71 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.C
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
7 * 7 *
439 uint16_t total_rows; 439 uint16_t total_rows;
440 int i; 440 int i;
441 441
442 total_rows = TermWin.nrow + TermWin.saveLines; 442 total_rows = TermWin.nrow + TermWin.saveLines;
443 443
444#ifdef DEBUG_STRICT
445 for (i = 0; i < total_rows; i++)
446 {
447 if (screen.text[i])
448 /* then so is screen.rend[i] */
449 assert (screen.rend[i]);
450 }
451#endif
452
453 delete talloc; talloc = 0; 444 delete talloc; talloc = 0;
454 delete ralloc; ralloc = 0; 445 delete ralloc; ralloc = 0;
455 446
456 free (screen.text); 447 free (screen.text);
457 free (screen.tlen); 448 free (screen.tlen);
500 * XTERM_SEQ: Restore cursor: ESC 8 491 * XTERM_SEQ: Restore cursor: ESC 8
501 */ 492 */
502void 493void
503rxvt_term::scr_cursor (int mode) 494rxvt_term::scr_cursor (int mode)
504{ 495{
505 screen_t *s; 496 screen_t *s;
506 497
507 D_SCREEN ((stderr, "rxvt_scr_cursor (%c)", mode)); 498 D_SCREEN ((stderr, "rxvt_scr_cursor (%c)", mode));
508 499
509#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 500#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
510 if (current_screen == SECONDARY) 501 if (current_screen == SECONDARY)
511 s = & (swap); 502 s = &swap;
512 else 503 else
513#endif 504#endif
514 s = & (screen); 505 s = &screen;
506
515 switch (mode) 507 switch (mode)
516 { 508 {
517 case SAVE: 509 case SAVE:
518 s->s_cur.row = s->cur.row; 510 s->s_cur.row = s->cur.row;
519 s->s_cur.col = s->cur.col; 511 s->s_cur.col = s->cur.col;
520 s->s_rstyle = rstyle; 512 s->s_rstyle = rstyle;
521 s->s_charset = s->charset; 513 s->s_charset = s->charset;
522 s->s_charset_char = charsets[s->charset]; 514 s->s_charset_char = charsets[s->charset];
523 break; 515 break;
516
524 case RESTORE: 517 case RESTORE:
525 want_refresh = 1; 518 want_refresh = 1;
526 s->cur.row = s->s_cur.row; 519 s->cur.row = s->s_cur.row;
527 s->cur.col = s->s_cur.col; 520 s->cur.col = s->s_cur.col;
528 s->flags &= ~Screen_WrapNext; 521 s->flags &= ~Screen_WrapNext;
530 s->charset = s->s_charset; 523 s->charset = s->s_charset;
531 charsets[s->charset] = s->s_charset_char; 524 charsets[s->charset] = s->s_charset_char;
532 set_font_style (); 525 set_font_style ();
533 break; 526 break;
534 } 527 }
528
535 /* boundary check in case screen size changed between SAVE and RESTORE */ 529 /* boundary check in case screen size changed between SAVE and RESTORE */
536 MIN_IT (s->cur.row, TermWin.nrow - 1); 530 MIN_IT (s->cur.row, TermWin.nrow - 1);
537 MIN_IT (s->cur.col, TermWin.ncol - 1); 531 MIN_IT (s->cur.col, TermWin.ncol - 1);
538#ifdef DEBUG_STRICT 532#ifdef DEBUG_STRICT
539 assert (s->cur.row >= 0); 533 assert (s->cur.row >= 0);
551 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 545 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
552 */ 546 */
553int 547int
554rxvt_term::scr_change_screen (int scrn) 548rxvt_term::scr_change_screen (int scrn)
555{ 549{
556 int i; 550 int i;
557#if NSCREENS 551#if NSCREENS
558 int offset; 552 int offset;
559#endif 553#endif
560 554
561 want_refresh = 1; 555 want_refresh = 1;
562 556
563 D_SCREEN ((stderr, "rxvt_scr_change_screen (%d)", scrn)); 557 D_SCREEN ((stderr, "rxvt_scr_change_screen (%d)", scrn));
564 558
565 TermWin.view_start = 0; 559 TermWin.view_start = 0;
566 560
567 if (current_screen == scrn) 561 if (current_screen == scrn)
568 return current_screen; 562 return scrn;
569 563
570 selection_check (2); /* check for boundary cross */ 564 selection_check (2); /* check for boundary cross */
571 565
572 SWAP_IT (current_screen, scrn, int); 566 SWAP_IT (current_screen, scrn, int);
573#if NSCREENS 567#if NSCREENS
568 if (Options & Opt_secondaryScreen)
569 {
574 num_scr = 0; 570 num_scr = 0;
575 offset = TermWin.saveLines; 571 offset = TermWin.saveLines;
576 for (i = prev_nrow; i--;) 572 for (i = prev_nrow; i--;)
577 { 573 {
578 SWAP_IT (screen.text[i + offset], swap.text[i], text_t *); 574 SWAP_IT (screen.text[i + offset], swap.text[i], text_t *);
579 SWAP_IT (screen.tlen[i + offset], swap.tlen[i], int16_t); 575 SWAP_IT (screen.tlen[i + offset], swap.tlen[i], int16_t);
580 SWAP_IT (screen.rend[i + offset], swap.rend[i], rend_t *); 576 SWAP_IT (screen.rend[i + offset], swap.rend[i], rend_t *);
581 } 577 }
582 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 578 SWAP_IT (screen.cur.row, swap.cur.row, int16_t);
583 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 579 SWAP_IT (screen.cur.col, swap.cur.col, int16_t);
584# ifdef DEBUG_STRICT 580# ifdef DEBUG_STRICT
585 assert ((screen.cur.row >= 0) && (screen.cur.row < prev_nrow)); 581 assert ((screen.cur.row >= 0) && (screen.cur.row < prev_nrow));
586 assert ((screen.cur.col >= 0) && (screen.cur.col < prev_ncol)); 582 assert ((screen.cur.col >= 0) && (screen.cur.col < prev_ncol));
587# else /* drive with your eyes closed */ 583# else /* drive with your eyes closed */
588 MAX_IT (screen.cur.row, 0); 584 MAX_IT (screen.cur.row, 0);
589 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 585 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1);
590 MAX_IT (screen.cur.col, 0); 586 MAX_IT (screen.cur.col, 0);
591 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); 587 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
592# endif 588# endif
593 SWAP_IT (screen.charset, swap.charset, int16_t); 589 SWAP_IT (screen.charset, swap.charset, int16_t);
594 SWAP_IT (screen.flags, swap.flags, int); 590 SWAP_IT (screen.flags, swap.flags, int);
595 screen.flags |= Screen_VisibleCursor; 591 screen.flags |= Screen_VisibleCursor;
596 swap.flags |= Screen_VisibleCursor; 592 swap.flags |= Screen_VisibleCursor;
597#else 593 }
598# ifdef SCROLL_ON_NO_SECONDARY 594 else
595#endif
596 if (Options & Opt_secondaryScroll)
599 if (current_screen == PRIMARY) 597 //if (current_screen == PRIMARY)
600 scr_scroll_text (0, (prev_nrow - 1), prev_nrow, 0); 598 scr_scroll_text (0, (prev_nrow - 1), prev_nrow, 0);
601# endif
602#endif
603 return scrn; 599 return scrn;
604} 600}
605 601
606/* ------------------------------------------------------------------------- */ 602/* ------------------------------------------------------------------------- */
607/* 603/*
649 return 0; 645 return 0;
650 646
651 want_refresh = 1; 647 want_refresh = 1;
652 D_SCREEN ((stderr, "rxvt_scroll_text (%d,%d,%d,%d): %s", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary")); 648 D_SCREEN ((stderr, "rxvt_scroll_text (%d,%d,%d,%d): %s", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary"));
653 649
654 if ((count > 0) && (row1 == 0) && (current_screen == PRIMARY)) 650 if (row1 == 0 && count > 0
651 && (current_screen == PRIMARY || Options & Opt_secondaryScroll))
655 { 652 {
656 nscrolled = (long)TermWin.nscrolled + (long)count; 653 nscrolled = (long)TermWin.nscrolled + (long)count;
657 654
658 if (nscrolled > (long)TermWin.saveLines) 655 if (nscrolled > (long)TermWin.saveLines)
659 TermWin.nscrolled = TermWin.saveLines; 656 TermWin.nscrolled = TermWin.saveLines;
762/* ------------------------------------------------------------------------- */ 759/* ------------------------------------------------------------------------- */
763/* 760/*
764 * Add text given in <str> of length <len> to screen struct 761 * Add text given in <str> of length <len> to screen struct
765 */ 762 */
766void 763void
767rxvt_term::scr_add_lines (const uint32_t *str, int nlines, int len) 764rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len)
768{ 765{
769 unsigned char checksel, clearsel; 766 unsigned char checksel, clearsel;
770 uint32_t c; 767 unicode_t c;
771 int i, row, last_col; 768 int i, row, last_col;
772 text_t *stp; 769 text_t *stp;
773 rend_t *srp; 770 rend_t *srp;
774 771
775 if (len <= 0) /* sanity */ 772 if (len <= 0) /* sanity */
801 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1); 798 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1);
802 MAX_IT (screen.cur.row, - (int32_t)TermWin.nscrolled); 799 MAX_IT (screen.cur.row, - (int32_t)TermWin.nscrolled);
803#endif 800#endif
804 row = screen.cur.row + TermWin.saveLines; 801 row = screen.cur.row + TermWin.saveLines;
805 802
806 checksel = (selection.op 803 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
807 && current_screen == selection.screen) ? 1 : 0;
808 clearsel = 0; 804 clearsel = 0;
809 805
810 stp = screen.text[row]; 806 stp = screen.text[row];
811 srp = screen.rend[row]; 807 srp = screen.rend[row];
812 808
813 for (i = 0; i < len;) 809 while (len--)
814 { 810 {
815 c = str[i++]; 811 c = *str++;
812
813 if (c < 0x20)
816 switch (c) 814 switch (c)
817 { 815 {
818 case '\t': 816 case C0_HT:
819 scr_tab (1); 817 scr_tab (1);
820 continue; 818 continue;
821 case '\n': 819
820 case C0_LF:
822 if (screen.tlen[row] != -1) /* XXX: think about this */ 821 if (screen.tlen[row] != -1) /* XXX: think about this */
823 MAX_IT (screen.tlen[row], screen.cur.col); 822 MAX_IT (screen.tlen[row], screen.cur.col);
823
824 screen.flags &= ~Screen_WrapNext; 824 screen.flags &= ~Screen_WrapNext;
825
825 if (screen.cur.row == screen.bscroll) 826 if (screen.cur.row == screen.bscroll)
826 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); 827 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0);
827 else if (screen.cur.row < (TermWin.nrow - 1)) 828 else if (screen.cur.row < (TermWin.nrow - 1))
828 row = (++screen.cur.row) + TermWin.saveLines; 829 row = (++screen.cur.row) + TermWin.saveLines;
830
829 stp = screen.text[row]; /* _must_ refresh */ 831 stp = screen.text[row]; /* _must_ refresh */
830 srp = screen.rend[row]; /* _must_ refresh */ 832 srp = screen.rend[row]; /* _must_ refresh */
831 continue; 833 continue;
832 case '\r': 834
835 case C0_CR:
833 if (screen.tlen[row] != -1) /* XXX: think about this */ 836 if (screen.tlen[row] != -1) /* XXX: think about this */
834 MAX_IT (screen.tlen[row], screen.cur.col); 837 MAX_IT (screen.tlen[row], screen.cur.col);
838
835 screen.flags &= ~Screen_WrapNext; 839 screen.flags &= ~Screen_WrapNext;
836 screen.cur.col = 0; 840 screen.cur.col = 0;
837 continue; 841 continue;
838 default:
839 if (c == 127)
840 continue; /* yummmm..... */
841 break;
842 } 842 }
843 843
844 if (checksel /* see if we're writing within selection */ 844 if (checksel /* see if we're writing within selection */
845 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 845 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
846 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 846 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
847 { 847 {
866 if (screen.flags & Screen_Insert) 866 if (screen.flags & Screen_Insert)
867 scr_insdel_chars (1, INSERT); 867 scr_insdel_chars (1, INSERT);
868 868
869 // rely on wcwidth to tell us the character width, at least for non-latin1 869 // rely on wcwidth to tell us the character width, at least for non-latin1
870 // do wcwidth before further replacements, as wcwidth says that line-drawing 870 // do wcwidth before further replacements, as wcwidth says that line-drawing
871 // characters have width -1 (DOH!) on gnu/linux sometimes. 871 // characters have width -1 (DOH!) on GNU/Linux sometimes.
872 int width = c < 256 ? 1 : wcwidth (c); 872 int width = c < 256 ? 1 : wcwidth (c);
873 873
874 if (charsets[screen.charset] == '0') // DEC SPECIAL 874 if (charsets[screen.charset] == '0') // DEC SPECIAL
875 switch (c)
876 { 875 {
877 // vt100 special graphics and line drawing 876 // vt100 special graphics and line drawing
878 case '`': c = 0x25c6; break; case '_': c = 0x0020; break; 877 static uint16_t vt100_0[32] = { // 5f .. 7e
879 case 'a': c = 0x2592; break; case 'b': c = 0x2409; break; case 'c': c = 0x240c; break; 878 0x0020, 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
880 case 'd': c = 0x240d; break; case 'e': c = 0x240a; break; case 'f': c = 0x00b0; break; 879 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
881 case 'g': c = 0x00b1; break; case 'h': c = 0x2424; break; case 'i': c = 0x240b; break; 880 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534,
882 case 'j': c = 0x2518; break; case 'k': c = 0x2510; break; case 'l': c = 0x250c; break; 881 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7,
883 case 'm': c = 0x2514; break; case 'n': c = 0x253c; break; case 'o': c = 0x23ba; break;
884 case 'p': c = 0x23bb; break; case 'q': c = 0x2500; break; case 'r': c = 0x23bc; break;
885 case 's': c = 0x23bd; break; case 't': c = 0x251c; break; case 'u': c = 0x2524; break;
886 case 'v': c = 0x2534; break; case 'w': c = 0x252c; break; case 'x': c = 0x2502; break;
887 case 'y': c = 0x2264; break; case 'z': c = 0x2265; break; case '{': c = 0x03c0; break;
888 case '|': c = 0x2260; break; case '}': c = 0x00a3; break; case '~': c = 0x00b7; break;
889 } 882 };
883
884 if (c >= 0x5f && c <= 0x7e)
885 {
886 c = vt100_0[c - 0x5f];
887 width = 1;
888 }
889 }
890 890
891 if (width > 0) 891 if (width > 0)
892 { 892 {
893#if !UNICODE_3 && ENABLE_COMBINING 893#if !UNICODE_3 && ENABLE_COMBINING
894 // trim characters we can't store directly :( 894 // trim characters we can't store directly :(
951 // handle double-width-chars by making them look extremely ugly 951 // handle double-width-chars by making them look extremely ugly
952 if (*tp == NOCHAR) 952 if (*tp == NOCHAR)
953 *tp = ' '; // hack //D //TODO //--tp, --rp; 953 *tp = ' '; // hack //D //TODO //--tp, --rp;
954 954
955 // first try to find a precomposed character 955 // first try to find a precomposed character
956 uint32_t n = rxvt_compose (*tp, c); 956 unicode_t n = rxvt_compose (*tp, c);
957 if (n == NOCHAR) 957 if (n == NOCHAR)
958 n = rxvt_composite.compose (*tp, c); 958 n = rxvt_composite.compose (*tp, c);
959 959
960 *tp = n; 960 *tp = n;
961 *rp = SET_FONT (*rp, TermWin.fontset->find_font (*tp)); 961 *rp = SET_FONT (*rp, TermWin.fontset->find_font (*tp));
988 */ 988 */
989void 989void
990rxvt_term::scr_backspace () 990rxvt_term::scr_backspace ()
991{ 991{
992 want_refresh = 1; 992 want_refresh = 1;
993
993 if (screen.cur.col == 0) 994 if (screen.cur.col == 0)
994 { 995 {
995 if (screen.cur.row > 0) 996 if (screen.cur.row > 0)
996 { 997 {
997#ifdef TERMCAP_HAS_BW 998#ifdef TERMCAP_HAS_BW
1002 1003
1003 } 1004 }
1004 } 1005 }
1005 else if ((screen.flags & Screen_WrapNext) == 0) 1006 else if ((screen.flags & Screen_WrapNext) == 0)
1006 scr_gotorc (0, -1, RELATIVE); 1007 scr_gotorc (0, -1, RELATIVE);
1008
1007 screen.flags &= ~Screen_WrapNext; 1009 screen.flags &= ~Screen_WrapNext;
1008} 1010}
1009 1011
1010/* ------------------------------------------------------------------------- */ 1012/* ------------------------------------------------------------------------- */
1011/* 1013/*
1014 * XTERM_SEQ: CTRL-I 1016 * XTERM_SEQ: CTRL-I
1015 */ 1017 */
1016void 1018void
1017rxvt_term::scr_tab (int count) 1019rxvt_term::scr_tab (int count)
1018{ 1020{
1019 int i, x; 1021 int i, x;
1020 1022
1021 D_SCREEN ((stderr, "rxvt_scr_tab (%d)", count)); 1023 D_SCREEN ((stderr, "rxvt_scr_tab (%d)", count));
1022 want_refresh = 1; 1024 want_refresh = 1;
1023 i = x = screen.cur.col; 1025 i = x = screen.cur.col;
1026
1024 if (count == 0) 1027 if (count == 0)
1025 return; 1028 return;
1026 else if (count > 0) 1029 else if (count > 0)
1027 { 1030 {
1028 for (; ++i < TermWin.ncol; ) 1031 for (; ++i < TermWin.ncol; )
1030 { 1033 {
1031 x = i; 1034 x = i;
1032 if (!--count) 1035 if (!--count)
1033 break; 1036 break;
1034 } 1037 }
1038
1035 if (count) 1039 if (count)
1036 x = TermWin.ncol - 1; 1040 x = TermWin.ncol - 1;
1037 } 1041 }
1038 else /* if (count < 0) */ 1042 else /* if (count < 0) */
1039 { 1043 {
1042 { 1046 {
1043 x = i; 1047 x = i;
1044 if (!++count) 1048 if (!++count)
1045 break; 1049 break;
1046 } 1050 }
1051
1047 if (count) 1052 if (count)
1048 x = 0; 1053 x = 0;
1049 } 1054 }
1055
1050 if (x != screen.cur.col) 1056 if (x != screen.cur.col)
1051 scr_gotorc (0, x, R_RELATIVE); 1057 scr_gotorc (0, x, R_RELATIVE);
1052} 1058}
1053 1059
1054/* ------------------------------------------------------------------------- */ 1060/* ------------------------------------------------------------------------- */
1111 want_refresh = 1; 1117 want_refresh = 1;
1112 ZERO_SCROLLBACK (); 1118 ZERO_SCROLLBACK ();
1113 1119
1114 D_SCREEN ((stderr, "rxvt_scr_gotorc (r:%s%d,c:%s%d): from (r:%d,c:%d)", (relative & R_RELATIVE ? "+" : ""), row, (relative & C_RELATIVE ? "+" : ""), col, screen.cur.row, screen.cur.col)); 1120 D_SCREEN ((stderr, "rxvt_scr_gotorc (r:%s%d,c:%s%d): from (r:%d,c:%d)", (relative & R_RELATIVE ? "+" : ""), row, (relative & C_RELATIVE ? "+" : ""), col, screen.cur.row, screen.cur.col));
1115 1121
1116 screen.cur.col = ((relative & C_RELATIVE) ? (screen.cur.col + col) 1122 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1117 : col);
1118 MAX_IT (screen.cur.col, 0); 1123 MAX_IT (screen.cur.col, 0);
1119 MIN_IT (screen.cur.col, (int32_t)TermWin.ncol - 1); 1124 MIN_IT (screen.cur.col, (int32_t)TermWin.ncol - 1);
1120 1125
1121 screen.flags &= ~Screen_WrapNext; 1126 screen.flags &= ~Screen_WrapNext;
1122 if (relative & R_RELATIVE) 1127 if (relative & R_RELATIVE)
1161 * direction should be UP or DN 1166 * direction should be UP or DN
1162 */ 1167 */
1163void 1168void
1164rxvt_term::scr_index (enum page_dirn direction) 1169rxvt_term::scr_index (enum page_dirn direction)
1165{ 1170{
1166 int dirn; 1171 int dirn;
1167 1172
1168 want_refresh = 1; 1173 want_refresh = 1;
1169 dirn = ((direction == UP) ? 1 : -1); 1174 dirn = ((direction == UP) ? 1 : -1);
1170 D_SCREEN ((stderr, "rxvt_scr_index (%d)", dirn)); 1175 D_SCREEN ((stderr, "rxvt_scr_index (%d)", dirn));
1171 1176
1247 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1252 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1248 */ 1253 */
1249void 1254void
1250rxvt_term::scr_erase_screen (int mode) 1255rxvt_term::scr_erase_screen (int mode)
1251{ 1256{
1252 int num; 1257 int num;
1253 int32_t row, row_offset; 1258 int32_t row, row_offset;
1254 rend_t ren; 1259 rend_t ren;
1255 XGCValues gcvalue; 1260 XGCValues gcvalue;
1256 1261
1257 want_refresh = 1; 1262 want_refresh = 1;
1258 D_SCREEN ((stderr, "rxvt_scr_erase_screen (%d) at screen row: %d", mode, screen.cur.row)); 1263 D_SCREEN ((stderr, "rxvt_scr_erase_screen (%d) at screen row: %d", mode, screen.cur.row));
1259 ZERO_SCROLLBACK (); 1264 ZERO_SCROLLBACK ();
1260 row_offset = (int32_t)TermWin.saveLines; 1265 row_offset = (int32_t)TermWin.saveLines;
1279 num = TermWin.nrow; 1284 num = TermWin.nrow;
1280 break; 1285 break;
1281 default: 1286 default:
1282 return; 1287 return;
1283 } 1288 }
1289
1284 refresh_type |= REFRESH_BOUNDS; 1290 refresh_type |= REFRESH_BOUNDS;
1291
1285 if (selection.op && current_screen == selection.screen 1292 if (selection.op && current_screen == selection.screen
1286 && ((selection.beg.row >= row && selection.beg.row <= row + num) 1293 && ((selection.beg.row >= row && selection.beg.row <= row + num)
1287 || (selection.end.row >= row 1294 || (selection.end.row >= row
1288 && selection.end.row <= row + num))) 1295 && selection.end.row <= row + num)))
1289 CLEAR_SELECTION (); 1296 CLEAR_SELECTION ();
1297
1290 if (row >= TermWin.nrow) /* Out Of Bounds */ 1298 if (row >= TermWin.nrow) /* Out Of Bounds */
1291 return; 1299 return;
1300
1292 MIN_IT (num, (TermWin.nrow - row)); 1301 MIN_IT (num, (TermWin.nrow - row));
1302
1293 if (rstyle & (RS_RVid | RS_Uline)) 1303 if (rstyle & (RS_RVid | RS_Uline))
1294 ren = (rend_t) ~RS_None; 1304 ren = (rend_t) ~RS_None;
1295 else if (GET_BASEBG (rstyle) == Color_bg) 1305 else if (GET_BASEBG (rstyle) == Color_bg)
1296 { 1306 {
1297 ren = DEFAULT_RSTYLE; 1307 ren = DEFAULT_RSTYLE;
1304 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue); 1314 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue);
1305 ERASE_ROWS (row, num); 1315 ERASE_ROWS (row, num);
1306 gcvalue.foreground = PixColors[Color_fg]; 1316 gcvalue.foreground = PixColors[Color_fg];
1307 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue); 1317 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue);
1308 } 1318 }
1319
1309 for (; num--; row++) 1320 for (; num--; row++)
1310 { 1321 {
1311 scr_blank_screen_mem (screen.text, screen.rend, 1322 scr_blank_screen_mem (screen.text, screen.rend,
1312 (unsigned int) (row + row_offset), rstyle); 1323 (unsigned int) (row + row_offset), rstyle);
1313 screen.tlen[row + row_offset] = 0; 1324 screen.tlen[row + row_offset] = 0;
1347 * Insert/Delete <count> lines 1358 * Insert/Delete <count> lines
1348 */ 1359 */
1349void 1360void
1350rxvt_term::scr_insdel_lines (int count, int insdel) 1361rxvt_term::scr_insdel_lines (int count, int insdel)
1351{ 1362{
1352 int end; 1363 int end;
1353 1364
1354 ZERO_SCROLLBACK (); 1365 ZERO_SCROLLBACK ();
1355 1366
1356 selection_check (1); 1367 selection_check (1);
1357 1368
1376 * Insert/Delete <count> characters from the current position 1387 * Insert/Delete <count> characters from the current position
1377 */ 1388 */
1378void 1389void
1379rxvt_term::scr_insdel_chars (int count, int insdel) 1390rxvt_term::scr_insdel_chars (int count, int insdel)
1380{ 1391{
1381 int col, row; 1392 int col, row;
1382 rend_t tr; 1393 rend_t tr;
1383 text_t *stp; 1394 text_t *stp;
1384 rend_t *srp; 1395 rend_t *srp;
1385 int16_t *slp; 1396 int16_t *slp;
1386 1397
1387 want_refresh = 1; 1398 want_refresh = 1;
1388 ZERO_SCROLLBACK (); 1399 ZERO_SCROLLBACK ();
1389 1400
1390 if (count <= 0) 1401 if (count <= 0)
1397 screen.flags &= ~Screen_WrapNext; 1408 screen.flags &= ~Screen_WrapNext;
1398 1409
1399 stp = screen.text[row]; 1410 stp = screen.text[row];
1400 srp = screen.rend[row]; 1411 srp = screen.rend[row];
1401 slp = & (screen.tlen[row]); 1412 slp = & (screen.tlen[row]);
1413
1402 switch (insdel) 1414 switch (insdel)
1403 { 1415 {
1404 case INSERT: 1416 case INSERT:
1405 for (col = TermWin.ncol - 1; (col - count) >= screen.cur.col; 1417 for (col = TermWin.ncol - 1; (col - count) >= screen.cur.col;
1406 col--) 1418 col--)
1407 { 1419 {
1408 stp[col] = stp[col - count]; 1420 stp[col] = stp[col - count];
1409 srp[col] = srp[col - count]; 1421 srp[col] = srp[col - count];
1410 } 1422 }
1423
1411 if (*slp != -1) 1424 if (*slp != -1)
1412 { 1425 {
1413 *slp += count; 1426 *slp += count;
1414 MIN_IT (*slp, TermWin.ncol); 1427 MIN_IT (*slp, TermWin.ncol);
1415 } 1428 }
1429
1416 if (selection.op && current_screen == selection.screen 1430 if (selection.op && current_screen == selection.screen
1417 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1431 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1418 { 1432 {
1419 if (selection.end.row != screen.cur.row 1433 if (selection.end.row != screen.cur.row
1420 || (selection.end.col + count >= TermWin.ncol)) 1434 || (selection.end.col + count >= TermWin.ncol))
1424 selection.beg.col += count; 1438 selection.beg.col += count;
1425 selection.mark.col += count; /* XXX: yes? */ 1439 selection.mark.col += count; /* XXX: yes? */
1426 selection.end.col += count; 1440 selection.end.col += count;
1427 } 1441 }
1428 } 1442 }
1443
1429 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]), 1444 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]),
1430 (unsigned int)count, rstyle); 1445 (unsigned int)count, rstyle);
1431 break; 1446 break;
1447
1432 case ERASE: 1448 case ERASE:
1433 screen.cur.col += count; /* don't worry if > TermWin.ncol */ 1449 screen.cur.col += count; /* don't worry if > TermWin.ncol */
1434 selection_check (1); 1450 selection_check (1);
1435 screen.cur.col -= count; 1451 screen.cur.col -= count;
1436 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]), 1452 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]),
1437 (unsigned int)count, rstyle); 1453 (unsigned int)count, rstyle);
1438 break; 1454 break;
1455
1439 case DELETE: 1456 case DELETE:
1440 tr = srp[TermWin.ncol - 1]
1441 & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1457 tr = srp[TermWin.ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask);
1458
1442 for (col = screen.cur.col; (col + count) < TermWin.ncol; col++) 1459 for (col = screen.cur.col; (col + count) < TermWin.ncol; col++)
1443 { 1460 {
1444 stp[col] = stp[col + count]; 1461 stp[col] = stp[col + count];
1445 srp[col] = srp[col + count]; 1462 srp[col] = srp[col + count];
1446 } 1463 }
1464
1447 scr_blank_line (& (stp[TermWin.ncol - count]), 1465 scr_blank_line (& (stp[TermWin.ncol - count]),
1448 & (srp[TermWin.ncol - count]), 1466 & (srp[TermWin.ncol - count]),
1449 (unsigned int)count, tr); 1467 (unsigned int)count, tr);
1468
1450 if (*slp == -1) /* break line continuation */ 1469 if (*slp == -1) /* break line continuation */
1451 *slp = TermWin.ncol; 1470 *slp = TermWin.ncol;
1471
1452 *slp -= count; 1472 *slp -= count;
1453 MAX_IT (*slp, 0); 1473 MAX_IT (*slp, 0);
1474
1454 if (selection.op && current_screen == selection.screen 1475 if (selection.op && current_screen == selection.screen
1455 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1476 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1456 { 1477 {
1457 if (selection.end.row != screen.cur.row 1478 if (selection.end.row != screen.cur.row
1458 || (screen.cur.col >= selection.beg.col - count) 1479 || (screen.cur.col >= selection.beg.col - count)
1464 selection.beg.col -= count; 1485 selection.beg.col -= count;
1465 selection.mark.col -= count; /* XXX: yes? */ 1486 selection.mark.col -= count; /* XXX: yes? */
1466 selection.end.col -= count; 1487 selection.end.col -= count;
1467 } 1488 }
1468 } 1489 }
1490
1469 break; 1491 break;
1470 } 1492 }
1471} 1493}
1472 1494
1473/* ------------------------------------------------------------------------- */ 1495/* ------------------------------------------------------------------------- */
1478void 1500void
1479rxvt_term::scr_scroll_region (int top, int bot) 1501rxvt_term::scr_scroll_region (int top, int bot)
1480{ 1502{
1481 MAX_IT (top, 0); 1503 MAX_IT (top, 0);
1482 MIN_IT (bot, (int)TermWin.nrow - 1); 1504 MIN_IT (bot, (int)TermWin.nrow - 1);
1505
1483 if (top > bot) 1506 if (top > bot)
1484 return; 1507 return;
1508
1485 screen.tscroll = top; 1509 screen.tscroll = top;
1486 screen.bscroll = bot; 1510 screen.bscroll = bot;
1487 scr_gotorc (0, 0, 0); 1511 scr_gotorc (0, 0, 0);
1488} 1512}
1489 1513
1495 */ 1519 */
1496void 1520void
1497rxvt_term::scr_cursor_visible (int mode) 1521rxvt_term::scr_cursor_visible (int mode)
1498{ 1522{
1499 want_refresh = 1; 1523 want_refresh = 1;
1524
1500 if (mode) 1525 if (mode)
1501 screen.flags |= Screen_VisibleCursor; 1526 screen.flags |= Screen_VisibleCursor;
1502 else 1527 else
1503 screen.flags &= ~Screen_VisibleCursor; 1528 screen.flags &= ~Screen_VisibleCursor;
1504} 1529}
1820 if (TermWin.view_start != oldviewstart) 1845 if (TermWin.view_start != oldviewstart)
1821 { 1846 {
1822 want_refresh = 1; 1847 want_refresh = 1;
1823 num_scr -= (TermWin.view_start - oldviewstart); 1848 num_scr -= (TermWin.view_start - oldviewstart);
1824 } 1849 }
1850
1825 return (int) (TermWin.view_start - oldviewstart); 1851 return (int) (TermWin.view_start - oldviewstart);
1826} 1852}
1827 1853
1828/* ------------------------------------------------------------------------- */ 1854/* ------------------------------------------------------------------------- */
1829void 1855void
1947 1973
1948 /* 1974 /*
1949 * C: set the cursor character (s) 1975 * C: set the cursor character (s)
1950 */ 1976 */
1951 { 1977 {
1952 unsigned char setoldcursor; 1978 unsigned char setoldcursor;
1953 rend_t ccol1, /* Cursor colour */ 1979 rend_t ccol1, /* Cursor colour */
1954 ccol2; /* Cursor colour2 */ 1980 ccol2; /* Cursor colour2 */
1955 1981
1956 showcursor = (screen.flags & Screen_VisibleCursor); 1982 showcursor = (screen.flags & Screen_VisibleCursor);
1957#ifdef CURSOR_BLINK 1983#ifdef CURSOR_BLINK
1958 if (hidden_cursor) 1984 if (hidden_cursor)
1959 showcursor = 0; 1985 showcursor = 0;
1960#endif 1986#endif
1961 1987
1962 if (showcursor) 1988 if (showcursor)
1963 { 1989 {
1964 srp = & (screen.rend[screen.cur.row + TermWin.saveLines] 1990 srp = &(screen.rend[screen.cur.row + TermWin.saveLines][screen.cur.col]);
1965 [screen.cur.col]);
1966 1991
1967 if (showcursor && TermWin.focus) 1992 if (showcursor && TermWin.focus)
1968 { 1993 {
1969 *srp ^= RS_RVid; 1994 *srp ^= RS_RVid;
1970#ifndef NO_CURSORCOLOR 1995#ifndef NO_CURSORCOLOR
1998 if (screen.cur.row + TermWin.view_start != ocrow 2023 if (screen.cur.row + TermWin.view_start != ocrow
1999 || screen.cur.col != oldcursor.col) 2024 || screen.cur.col != oldcursor.col)
2000 { 2025 {
2001 if (ocrow < TermWin.nrow 2026 if (ocrow < TermWin.nrow
2002 && oldcursor.col < TermWin.ncol) 2027 && oldcursor.col < TermWin.ncol)
2003 {
2004 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline); 2028 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline);
2005 } 2029
2006 if (TermWin.focus || !showcursor) 2030 if (TermWin.focus || !showcursor)
2007 oldcursor.row = -1; 2031 oldcursor.row = -1;
2008 else 2032 else
2009 setoldcursor = 1; 2033 setoldcursor = 1;
2010 } 2034 }
2011 } 2035 }
2012 else if (!TermWin.focus) 2036 else if (!TermWin.focus)
2013 setoldcursor = 1; 2037 setoldcursor = 1;
2038
2014 if (setoldcursor) 2039 if (setoldcursor)
2015 { 2040 {
2016 if (screen.cur.row + TermWin.view_start >= TermWin.nrow) 2041 if (screen.cur.row + TermWin.view_start >= TermWin.nrow)
2017 oldcursor.row = -1; 2042 oldcursor.row = -1;
2018 else 2043 else
2030 */ 2055 */
2031 i = num_scr; 2056 i = num_scr;
2032 if (refresh_type == FAST_REFRESH && num_scr_allow && i 2057 if (refresh_type == FAST_REFRESH && num_scr_allow && i
2033 && abs (i) < TermWin.nrow && !must_clear) 2058 && abs (i) < TermWin.nrow && !must_clear)
2034 { 2059 {
2035 int16_t nits; 2060 int16_t nits;
2036 int j; 2061 int j;
2037 rend_t *drp2; 2062 rend_t *drp2;
2038 text_t *dtp2; 2063 text_t *dtp2;
2039 int len, wlen; 2064 int len, wlen;
2040 2065
2041 j = TermWin.nrow; 2066 j = TermWin.nrow;
2042 wlen = len = -1; 2067 wlen = len = -1;
2043 row = i > 0 ? 0 : j - 1; 2068 row = i > 0 ? 0 : j - 1;
2044 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2069 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2496 { 2521 {
2497 n = min (len - i, PROP_SIZE); 2522 n = min (len - i, PROP_SIZE);
2498 MEMCPY (ds, data + i, n); 2523 MEMCPY (ds, data + i, n);
2499 2524
2500 for (j = 0; j < n; j++) 2525 for (j = 0; j < n; j++)
2501 if (ds[j] == '\n') 2526 if (ds[j] == C0_LF)
2502 ds[j] = '\r'; 2527 ds[j] = C0_CR;
2503 2528
2504 tt_write (ds, (int)n); 2529 tt_write (ds, (int)n);
2505 } 2530 }
2506 2531
2507 free (ds); 2532 free (ds);
2620void 2645void
2621rxvt_term::incr_cb (time_watcher &w) 2646rxvt_term::incr_cb (time_watcher &w)
2622{ 2647{
2623 selection_wait = Sel_none; 2648 selection_wait = Sel_none;
2624 2649
2625 rxvt_print_error ("data loss: timeout on INCR selection paste"); 2650 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2626} 2651}
2627 2652
2628/* 2653/*
2629 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> 2654 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2630 */ 2655 */
2709 { 2734 {
2710 int i; 2735 int i;
2711 2736
2712 selection_request_time = tm; 2737 selection_request_time = tm;
2713 selection_wait = Sel_normal; 2738 selection_wait = Sel_normal;
2739
2714 for (i = Sel_Primary; i <= Sel_Clipboard; i++) 2740 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2715 { 2741 {
2716#if X_HAVE_UTF8_STRING 2742#if X_HAVE_UTF8_STRING
2717 selection_type = Sel_UTF8String; 2743 selection_type = Sel_UTF8String;
2718 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2744 if (selection_request_other (xa[XA_UTF8_STRING], i))
2772 want_refresh = 1; 2798 want_refresh = 1;
2773 free (selection.text); 2799 free (selection.text);
2774 selection.text = NULL; 2800 selection.text = NULL;
2775 selection.len = 0; 2801 selection.len = 0;
2776 CLEAR_SELECTION (); 2802 CLEAR_SELECTION ();
2803
2804 if (display->selection_owner == this)
2805 display->selection_owner = 0;
2777} 2806}
2778 2807
2779/* ------------------------------------------------------------------------- */ 2808/* ------------------------------------------------------------------------- */
2780/* 2809/*
2781 * Copy a selection into the cut buffer 2810 * Copy a selection into the cut buffer
2854 else 2883 else
2855 new_selection_text[ofs++] = *t++; 2884 new_selection_text[ofs++] = *t++;
2856 } 2885 }
2857 2886
2858 if (screen.tlen[row] != -1 && row != end_row) 2887 if (screen.tlen[row] != -1 && row != end_row)
2859 new_selection_text[ofs++] = L'\n'; 2888 new_selection_text[ofs++] = C0_LF;
2860 } 2889 }
2861 2890
2862#ifndef NO_OLD_SELECTION
2863 if (selection_style == OLD_SELECT)
2864 if (end_col == TermWin.ncol)
2865 new_selection_text[ofs++] = L'\n';
2866#endif
2867#ifndef NO_NEW_SELECTION
2868 if (selection_style != OLD_SELECT)
2869 if (end_col != selection.end.col) 2891 if (end_col != selection.end.col)
2870 new_selection_text[ofs++] = L'\n'; 2892 new_selection_text[ofs++] = C0_LF;
2871#endif 2893
2872 new_selection_text[ofs] = 0; 2894 new_selection_text[ofs] = 0;
2873 2895
2874 if (ofs == 0) 2896 if (ofs == 0)
2875 { 2897 {
2876 free (new_selection_text); 2898 free (new_selection_text);
2885 2907
2886 XSetSelectionOwner (display->display, XA_PRIMARY, TermWin.vt, tm); 2908 XSetSelectionOwner (display->display, XA_PRIMARY, TermWin.vt, tm);
2887 if (XGetSelectionOwner (display->display, XA_PRIMARY) == TermWin.vt) 2909 if (XGetSelectionOwner (display->display, XA_PRIMARY) == TermWin.vt)
2888 display->set_selection_owner (this); 2910 display->set_selection_owner (this);
2889 else 2911 else
2890 rxvt_print_error ("can't get primary selection"); 2912 rxvt_warn ("can't get primary selection, ignoring.\n");
2891 2913
2892#if 0 2914#if 0
2893 XTextProperty ct; 2915 XTextProperty ct;
2894 2916
2895 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 2917 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
2935rxvt_term::selection_start_colrow (int col, int row) 2957rxvt_term::selection_start_colrow (int col, int row)
2936{ 2958{
2937 want_refresh = 1; 2959 want_refresh = 1;
2938 selection.mark.col = col; 2960 selection.mark.col = col;
2939 selection.mark.row = row - TermWin.view_start; 2961 selection.mark.row = row - TermWin.view_start;
2962
2940 MAX_IT (selection.mark.row, - (int32_t)TermWin.nscrolled); 2963 MAX_IT (selection.mark.row, - (int32_t)TermWin.nscrolled);
2941 MIN_IT (selection.mark.row, (int32_t)TermWin.nrow - 1); 2964 MIN_IT (selection.mark.row, (int32_t)TermWin.nrow - 1);
2942 MAX_IT (selection.mark.col, 0); 2965 MAX_IT (selection.mark.col, 0);
2943 MIN_IT (selection.mark.col, (int32_t)TermWin.ncol - 1); 2966 MIN_IT (selection.mark.col, (int32_t)TermWin.ncol - 1);
2944 2967
2968 while (selection.mark.col > 0
2969 && screen.text[selection.mark.row + TermWin.saveLines][selection.mark.col] == NOCHAR)
2970 --selection.mark.col;
2971
2945 if (selection.op) 2972 if (selection.op)
2946 { /* clear the old selection */ 2973 { /* clear the old selection */
2947 selection.beg.row = selection.end.row = selection.mark.row; 2974 selection.beg.row = selection.end.row = selection.mark.row;
2948 selection.beg.col = selection.end.col = selection.mark.col; 2975 selection.beg.col = selection.end.col = selection.mark.col;
2949 } 2976 }
2977
2950 selection.op = SELECTION_INIT; 2978 selection.op = SELECTION_INIT;
2951 selection.screen = current_screen; 2979 selection.screen = current_screen;
2952} 2980}
2953 2981
2954/* ------------------------------------------------------------------------- */ 2982/* ------------------------------------------------------------------------- */
2956 * Word select: select text for 2 clicks 2984 * Word select: select text for 2 clicks
2957 * We now only find out the boundary in one direction 2985 * We now only find out the boundary in one direction
2958 */ 2986 */
2959 2987
2960/* what do we want: spaces/tabs are delimiters or cutchars or non-cutchars */ 2988/* what do we want: spaces/tabs are delimiters or cutchars or non-cutchars */
2961#define DELIMIT_TEXT(x) \ 2989#define DELIMIT_TEXT(x) \
2962 (((x) == ' ' || (x) == '\t') ? 2 : (STRCHR (rs[Rs_cutchars], (x)) != NULL)) 2990 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!STRCHR (rs[Rs_cutchars], (x)))
2963#define DELIMIT_REND(x) 1 2991#define DELIMIT_REND(x) 1
2964 2992
2965void 2993void
2966rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 2994rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret)
2967{ 2995{
2968 int col, row, dirnadd, tcol, trow, w1, w2; 2996 int col, row, dirnadd, tcol, trow, w1, w2;
2969 row_col_t bound; 2997 row_col_t bound;
2970 text_t *stp; 2998 text_t *stp;
2971 rend_t *srp; 2999 rend_t *srp;
2972 3000
2973 if (dirn == UP) 3001 if (dirn == UP)
2974 { 3002 {
2975 bound.row = TermWin.saveLines - TermWin.nscrolled - 1; 3003 bound.row = TermWin.saveLines - TermWin.nscrolled - 1;
2976 bound.col = 0; 3004 bound.col = 0;
2980 { 3008 {
2981 bound.row = TermWin.saveLines + TermWin.nrow; 3009 bound.row = TermWin.saveLines + TermWin.nrow;
2982 bound.col = TermWin.ncol - 1; 3010 bound.col = TermWin.ncol - 1;
2983 dirnadd = 1; 3011 dirnadd = 1;
2984 } 3012 }
3013
2985 row = mark->row + TermWin.saveLines; 3014 row = mark->row + TermWin.saveLines;
2986 col = mark->col; 3015 col = mark->col;
2987 MAX_IT (col, 0); 3016 MAX_IT (col, 0);
2988 /* find the edge of a word */ 3017 /* find the edge of a word */
2989 stp = & (screen.text[row][col]); 3018 stp = & (screen.text[row][col]);
2990 w1 = DELIMIT_TEXT (*stp); 3019 w1 = DELIMIT_TEXT (*stp);
2991 3020
2992 if (selection_style != NEW_SELECT)
2993 {
2994 if (w1 == 1)
2995 {
2996 stp += dirnadd;
2997 if (DELIMIT_TEXT (*stp) == 1)
2998 goto Old_Word_Selection_You_Die;
2999 col += dirnadd;
3000 }
3001 w1 = 0;
3002 }
3003 srp = (&screen.rend[row][col]); 3021 srp = (&screen.rend[row][col]);
3004 w2 = DELIMIT_REND (*srp); 3022 w2 = DELIMIT_REND (*srp);
3005 3023
3006 for (;;) 3024 for (;;)
3007 { 3025 {
3008 for (; col != bound.col; col += dirnadd) 3026 for (; col != bound.col; col += dirnadd)
3009 { 3027 {
3010 stp += dirnadd; 3028 stp += dirnadd;
3029 srp += dirnadd;
3030
3031 if (*stp == NOCHAR)
3032 continue;
3033
3011 if (DELIMIT_TEXT (*stp) != w1) 3034 if (DELIMIT_TEXT (*stp) != w1)
3012 break; 3035 break;
3013 srp += dirnadd;
3014 if (DELIMIT_REND (*srp) != w2) 3036 if (DELIMIT_REND (*srp) != w2)
3015 break; 3037 break;
3016 } 3038 }
3039
3017 if ((col == bound.col) && (row != bound.row)) 3040 if ((col == bound.col) && (row != bound.row))
3018 { 3041 {
3019 if (screen.tlen[ (row - (dirn == UP ? 1 : 0))] == -1) 3042 if (screen.tlen[ (row - (dirn == UP ? 1 : 0))] == -1)
3020 { 3043 {
3021 trow = row + dirnadd; 3044 trow = row + dirnadd;
3022 tcol = dirn == UP ? TermWin.ncol - 1 : 0; 3045 tcol = dirn == UP ? TermWin.ncol - 1 : 0;
3046
3023 if (screen.text[trow] == NULL) 3047 if (screen.text[trow] == NULL)
3024 break; 3048 break;
3049
3025 stp = & (screen.text[trow][tcol]); 3050 stp = & (screen.text[trow][tcol]);
3026 srp = & (screen.rend[trow][tcol]); 3051 srp = & (screen.rend[trow][tcol]);
3052
3027 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2) 3053 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2)
3028 break; 3054 break;
3055
3029 row = trow; 3056 row = trow;
3030 col = tcol; 3057 col = tcol;
3031 continue; 3058 continue;
3032 } 3059 }
3033 } 3060 }
3034 break; 3061 break;
3035 } 3062 }
3063
3036Old_Word_Selection_You_Die: 3064Old_Word_Selection_You_Die:
3037 D_SELECT ((stderr, "rxvt_selection_delimit_word (%s,...) @ (r:%3d, c:%3d) has boundary (r:%3d, c:%3d)", (dirn == UP ? "up " : "down"), mark->row, mark->col, row - TermWin.saveLines, col)); 3065 D_SELECT ((stderr, "rxvt_selection_delimit_word (%s,...) @ (r:%3d, c:%3d) has boundary (r:%3d, c:%3d)", (dirn == UP ? "up " : "down"), mark->row, mark->col, row - TermWin.saveLines, col));
3038 3066
3039 if (dirn == DN) 3067 if (dirn == DN)
3040 col++; /* put us on one past the end */ 3068 col++; /* put us on one past the end */
3062 MAX_IT (row, 0); 3090 MAX_IT (row, 0);
3063 MIN_IT (row, (int)TermWin.nrow - 1); 3091 MIN_IT (row, (int)TermWin.nrow - 1);
3064 MAX_IT (col, 0); 3092 MAX_IT (col, 0);
3065 MIN_IT (col, (int)TermWin.ncol); 3093 MIN_IT (col, (int)TermWin.ncol);
3066 3094
3067#ifndef NO_NEW_SELECTION
3068 /* 3095 /*
3069 * If we're selecting characters (single click) then we must check first 3096 * If we're selecting characters (single click) then we must check first
3070 * if we are at the same place as the original mark. If we are then 3097 * if we are at the same place as the original mark. If we are then
3071 * select nothing. Otherwise, if we're to the right of the mark, you have to 3098 * select nothing. Otherwise, if we're to the right of the mark, you have to
3072 * be _past_ a character for it to be selected. 3099 * be _past_ a character for it to be selected.
3073 */ 3100 */
3074 if (selection_style != OLD_SELECT)
3075 {
3076 if (((selection.clicks % 3) == 1) && !flag 3101 if (((selection.clicks % 3) == 1) && !flag
3077 && (col == selection.mark.col 3102 && (col == selection.mark.col
3078 && (row == selection.mark.row + TermWin.view_start))) 3103 && (row == selection.mark.row + TermWin.view_start)))
3079 { 3104 {
3080 /* select nothing */ 3105 /* select nothing */
3081 selection.beg.row = selection.end.row = 0; 3106 selection.beg.row = selection.end.row = 0;
3082 selection.beg.col = selection.end.col = 0; 3107 selection.beg.col = selection.end.col = 0;
3083 selection.clicks = 4; 3108 selection.clicks = 4;
3084 want_refresh = 1; 3109 want_refresh = 1;
3085 D_SELECT ((stderr, "rxvt_selection_extend () selection.clicks = 4")); 3110 D_SELECT ((stderr, "rxvt_selection_extend () selection.clicks = 4"));
3086 return; 3111 return;
3087 }
3088 } 3112 }
3089#endif 3113
3090 if (selection.clicks == 4) 3114 if (selection.clicks == 4)
3091 selection.clicks = 1; 3115 selection.clicks = 1;
3092 3116
3093 selection_extend_colrow (col, row, !!flag, /* ? button 3 */ 3117 selection_extend_colrow (col, row, !!flag, /* ? button 3 */
3094 flag == 1 ? 1 : 0, /* ? button press */ 3118 flag == 1 ? 1 : 0, /* ? button press */
3100 * Extend the selection to the specified col/row 3124 * Extend the selection to the specified col/row
3101 */ 3125 */
3102void 3126void
3103rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3127rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange)
3104{ 3128{
3105 int16_t ncol = TermWin.ncol; 3129 int16_t ncol = TermWin.ncol;
3106 int end_col; 3130 int end_col;
3107 row_col_t pos; 3131 row_col_t pos;
3108 enum { 3132 enum {
3109 LEFT, RIGHT 3133 LEFT, RIGHT
3110 } closeto = RIGHT; 3134 } closeto = RIGHT;
3111 3135
3112 D_SELECT ((stderr, "rxvt_selection_extend_colrow (c:%d, r:%d, %d, %d) clicks:%d, op:%d", col, row, button3, buttonpress, selection.clicks, selection.op)); 3136 D_SELECT ((stderr, "rxvt_selection_extend_colrow (c:%d, r:%d, %d, %d) clicks:%d, op:%d", col, row, button3, buttonpress, selection.clicks, selection.op));
3148 pos.col = col; 3172 pos.col = col;
3149 pos.row = row; 3173 pos.row = row;
3150 3174
3151 pos.row -= TermWin.view_start; /* adjust for scroll */ 3175 pos.row -= TermWin.view_start; /* adjust for scroll */
3152 3176
3153#ifndef NO_OLD_SELECTION
3154 /*
3155 * This mimics some of the selection behaviour of version 2.20 and before.
3156 * There are no ``selection modes'', button3 is always character extension.
3157 * Note: button3 drag is always available, c.f. v2.20
3158 * Selection always terminates (left or right as appropriate) at the mark.
3159 */
3160 if (selection_style == OLD_SELECT)
3161 {
3162 if (selection.clicks == 1 || button3)
3163 {
3164 if (hate_those_clicks)
3165 {
3166 hate_those_clicks = 0;
3167 if (selection.clicks == 1)
3168 {
3169 selection.beg.row = selection.mark.row;
3170 selection.beg.col = selection.mark.col;
3171 }
3172 else
3173 {
3174 selection.mark.row = selection.beg.row;
3175 selection.mark.col = selection.beg.col;
3176 }
3177 }
3178 if (ROWCOL_IS_BEFORE (pos, selection.mark))
3179 {
3180 selection.end.row = selection.mark.row;
3181 selection.end.col = selection.mark.col + 1;
3182 selection.beg.row = pos.row;
3183 selection.beg.col = pos.col;
3184 }
3185 else
3186 {
3187 selection.beg.row = selection.mark.row;
3188 selection.beg.col = selection.mark.col;
3189 selection.end.row = pos.row;
3190 selection.end.col = pos.col + 1;
3191 }
3192 }
3193 else if (selection.clicks == 2)
3194 {
3195 selection_delimit_word (UP, & (selection.mark),
3196 & (selection.beg));
3197 selection_delimit_word (DN, & (selection.mark),
3198 & (selection.end));
3199 hate_those_clicks = 1;
3200 }
3201 else if (selection.clicks == 3)
3202 {
3203 selection.beg.row = selection.end.row = selection.mark.row;
3204 selection.beg.col = 0;
3205 selection.end.col = ncol;
3206 hate_those_clicks = 1;
3207 }
3208 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col));
3209 return;
3210 }
3211#endif /* ! NO_OLD_SELECTION */
3212#ifndef NO_NEW_SELECTION
3213 /* selection_style must not be OLD_SELECT to get here */
3214 /* 3177 /*
3215 * This is mainly xterm style selection with a couple of differences, mainly 3178 * This is mainly xterm style selection with a couple of differences, mainly
3216 * in the way button3 drag extension works. 3179 * in the way button3 drag extension works.
3217 * We're either doing: button1 drag; button3 press; or button3 drag 3180 * We're either doing: button1 drag; button3 press; or button3 drag
3218 * a) button1 drag : select around a midpoint/word/line - that point/word/line 3181 * a) button1 drag : select around a midpoint/word/line - that point/word/line
3223 * a point/word/line which is either the start or end of the selection 3186 * a point/word/line which is either the start or end of the selection
3224 * and it was decided by whichever point/word/line was `fixed' at the 3187 * and it was decided by whichever point/word/line was `fixed' at the
3225 * time of the most recent button3 press 3188 * time of the most recent button3 press
3226 */ 3189 */
3227 if (button3 && buttonpress) 3190 if (button3 && buttonpress)
3228 { /* button3 press */ 3191 { /* button3 press */
3229 /* 3192 /*
3230 * first determine which edge of the selection we are closest to 3193 * first determine which edge of the selection we are closest to
3231 */ 3194 */
3232 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3195 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3233 || (!ROWCOL_IS_AFTER (pos, selection.end) 3196 || (!ROWCOL_IS_AFTER (pos, selection.end)
3234 && (((pos.col - selection.beg.col) 3197 && (((pos.col - selection.beg.col)
3235 + ((pos.row - selection.beg.row) * ncol)) 3198 + ((pos.row - selection.beg.row) * ncol))
3236 < ((selection.end.col - pos.col) 3199 < ((selection.end.col - pos.col)
3237 + ((selection.end.row - pos.row) * ncol))))) 3200 + ((selection.end.row - pos.row) * ncol)))))
3238 closeto = LEFT; 3201 closeto = LEFT;
3202
3239 if (closeto == LEFT) 3203 if (closeto == LEFT)
3240 { 3204 {
3241 selection.beg.row = pos.row; 3205 selection.beg.row = pos.row;
3242 selection.beg.col = pos.col; 3206 selection.beg.col = pos.col;
3243 selection.mark.row = selection.end.row; 3207 selection.mark.row = selection.end.row;
3244 selection.mark.col = selection.end.col 3208 selection.mark.col = selection.end.col - (selection.clicks == 2);
3245 - (selection.clicks == 2);
3246 } 3209 }
3247 else 3210 else
3248 { 3211 {
3249 selection.end.row = pos.row; 3212 selection.end.row = pos.row;
3250 selection.end.col = pos.col; 3213 selection.end.col = pos.col;
3251 selection.mark.row = selection.beg.row; 3214 selection.mark.row = selection.beg.row;
3252 selection.mark.col = selection.beg.col; 3215 selection.mark.col = selection.beg.col;
3253 } 3216 }
3254 } 3217 }
3255 else 3218 else
3256 { /* button1 drag or button3 drag */ 3219 { /* button1 drag or button3 drag */
3257 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3220 if (ROWCOL_IS_AFTER (selection.mark, pos))
3258 { 3221 {
3259 if ((selection.mark.row == selection.end.row) 3222 if ((selection.mark.row == selection.end.row)
3260 && (selection.mark.col == selection.end.col) 3223 && (selection.mark.col == selection.end.col)
3261 && clickchange && selection.clicks == 2) 3224 && clickchange && selection.clicks == 2)
3262 selection.mark.col--; 3225 selection.mark.col--;
3226
3263 selection.beg.row = pos.row; 3227 selection.beg.row = pos.row;
3264 selection.beg.col = pos.col; 3228 selection.beg.col = pos.col;
3265 selection.end.row = selection.mark.row; 3229 selection.end.row = selection.mark.row;
3266 selection.end.col = selection.mark.col 3230 selection.end.col = selection.mark.col + (selection.clicks == 2);
3267 + (selection.clicks == 2);
3268 } 3231 }
3269 else 3232 else
3270 { 3233 {
3271 selection.beg.row = selection.mark.row; 3234 selection.beg.row = selection.mark.row;
3272 selection.beg.col = selection.mark.col; 3235 selection.beg.col = selection.mark.col;
3276 } 3239 }
3277 3240
3278 if (selection.clicks == 1) 3241 if (selection.clicks == 1)
3279 { 3242 {
3280 end_col = screen.tlen[selection.beg.row + TermWin.saveLines]; 3243 end_col = screen.tlen[selection.beg.row + TermWin.saveLines];
3244
3281 if (end_col != -1 && selection.beg.col > end_col) 3245 if (end_col != -1 && selection.beg.col > end_col)
3282 { 3246 {
3283#if 1 3247#if 1
3284 selection.beg.col = ncol; 3248 selection.beg.col = ncol;
3285#else 3249#else
3286 if (selection.beg.row != selection.end.row) 3250 if (selection.beg.row != selection.end.row)
3287 selection.beg.col = ncol; 3251 selection.beg.col = ncol;
3288 else 3252 else
3289 selection.beg.col = selection.mark.col; 3253 selection.beg.col = selection.mark.col;
3290#endif 3254#endif
3291
3292 } 3255 }
3256
3293 end_col = screen.tlen[selection.end.row + TermWin.saveLines]; 3257 end_col = screen.tlen[selection.end.row + TermWin.saveLines];
3258
3294 if (end_col != -1 && selection.end.col > end_col) 3259 if (end_col != -1 && selection.end.col > end_col)
3295 selection.end.col = ncol; 3260 selection.end.col = ncol;
3296
3297 } 3261 }
3298 else if (selection.clicks == 2) 3262 else if (selection.clicks == 2)
3299 { 3263 {
3300 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3264 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3301 selection.end.col--; 3265 selection.end.col--;
3266
3302 selection_delimit_word (UP, & (selection.beg), 3267 selection_delimit_word (UP, & (selection.beg), & (selection.beg));
3303 & (selection.beg));
3304 selection_delimit_word (DN, & (selection.end), 3268 selection_delimit_word (DN, & (selection.end), & (selection.end));
3305 & (selection.end));
3306 } 3269 }
3307 else if (selection.clicks == 3) 3270 else if (selection.clicks == 3)
3308 { 3271 {
3309#ifndef NO_FRILLS 3272#ifndef NO_FRILLS
3310 if ((Options & Opt_tripleclickwords)) 3273 if ((Options & Opt_tripleclickwords))
3311 { 3274 {
3312 int end_row; 3275 int end_row;
3313 3276
3314 selection_delimit_word (UP, & (selection.beg), 3277 selection_delimit_word (UP, & (selection.beg), & (selection.beg));
3315 & (selection.beg));
3316 end_row = screen.tlen[selection.mark.row 3278 end_row = screen.tlen[selection.mark.row + TermWin.saveLines];
3317 + TermWin.saveLines]; 3279
3318 for (end_row = selection.mark.row; end_row < TermWin.nrow; 3280 for (end_row = selection.mark.row; end_row < TermWin.nrow; end_row++)
3319 end_row++)
3320 { 3281 {
3321 end_col = screen.tlen[end_row + TermWin.saveLines]; 3282 end_col = screen.tlen[end_row + TermWin.saveLines];
3283
3322 if (end_col != -1) 3284 if (end_col != -1)
3323 { 3285 {
3324 selection.end.row = end_row; 3286 selection.end.row = end_row;
3325 selection.end.col = end_col; 3287 selection.end.col = end_col;
3326 selection_remove_trailing_spaces (); 3288 selection_remove_trailing_spaces ();
3328 } 3290 }
3329 } 3291 }
3330 } 3292 }
3331 else 3293 else
3332#endif 3294#endif
3333
3334 { 3295 {
3335 if (ROWCOL_IS_AFTER (selection.mark, selection.beg)) 3296 if (ROWCOL_IS_AFTER (selection.mark, selection.beg))
3336 selection.mark.col++; 3297 selection.mark.col++;
3337 selection.beg.col = 0; 3298 selection.beg.col = 0;
3338 selection.end.col = ncol; 3299 selection.end.col = ncol;
3339 } 3300 }
3340 } 3301 }
3302
3341 if (button3 && buttonpress) 3303 if (button3 && buttonpress)
3342 { /* mark may need to be changed */ 3304 { /* mark may need to be changed */
3343 if (closeto == LEFT) 3305 if (closeto == LEFT)
3344 { 3306 {
3345 selection.mark.row = selection.end.row; 3307 selection.mark.row = selection.end.row;
3346 selection.mark.col = selection.end.col 3308 selection.mark.col = selection.end.col
3347 - (selection.clicks == 2); 3309 - (selection.clicks == 2);
3351 selection.mark.row = selection.beg.row; 3313 selection.mark.row = selection.beg.row;
3352 selection.mark.col = selection.beg.col; 3314 selection.mark.col = selection.beg.col;
3353 } 3315 }
3354 } 3316 }
3355 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col)); 3317 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col));
3356#endif /* ! NO_NEW_SELECTION */
3357} 3318}
3358 3319
3359#ifndef NO_FRILLS 3320#ifndef NO_FRILLS
3360void 3321void
3361rxvt_term::selection_remove_trailing_spaces () 3322rxvt_term::selection_remove_trailing_spaces ()
3460 /* TODO: Handle MULTIPLE */ 3421 /* TODO: Handle MULTIPLE */
3461 } 3422 }
3462 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3423 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3463 { 3424 {
3464 XChangeProperty (display->display, rq.requestor, rq.property, XA_INTEGER, 3425 XChangeProperty (display->display, rq.requestor, rq.property, XA_INTEGER,
3465 (8 * sizeof (Time)), PropModeReplace, 3426 (8 * sizeof (Time)), PropModeReplace,
3466 (unsigned char *)&selection_time, 1); 3427 (unsigned char *)&selection_time, 1);
3467 ev.property = rq.property; 3428 ev.property = rq.property;
3468 } 3429 }
3469 else if (rq.target == XA_STRING 3430 else if (rq.target == XA_STRING
3470 || rq.target == xa[XA_TEXT] 3431 || rq.target == xa[XA_TEXT]
3471 || rq.target == xa[XA_COMPOUND_TEXT] 3432 || rq.target == xa[XA_COMPOUND_TEXT]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines