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.174 by root, Mon Dec 19 02:40:14 2005 UTC vs.
Revision 1.175 by root, Tue Dec 20 19:30:59 2005 UTC

83#define ROWCOL_IN_ROW_AT_OR_AFTER(X, Y) \ 83#define ROWCOL_IN_ROW_AT_OR_AFTER(X, Y) \
84 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 84 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
85#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 85#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
86 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 86 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
87 87
88#define LINENO(n) (((n) + term_start + total_rows) % total_rows)
89#define ROW(n) (save [LINENO (n)])
90
88/* 91/*
89 * CLEAR_ROWS : clear <num> rows starting from row <row> 92 * CLEAR_ROWS : clear <num> rows starting from row <row>
90 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 93 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
91 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour 94 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
92 */ 95 */
116 119
117/* Fill part/all of a line with blanks. */ 120/* Fill part/all of a line with blanks. */
118void 121void
119rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) 122rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs)
120{ 123{
124 if (!l.t)
125 {
126 lalloc (l);
127 col = 0;
128 width = ncol;
129 }
130
121 efs &= ~RS_baseattrMask; 131 efs &= ~RS_baseattrMask;
122 efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); 132 efs = SET_FONT (efs, FONTSET (efs)->find_font (' '));
123 133
124 text_t *et = l.t + col; 134 text_t *et = l.t + col;
125 rend_t *er = l.r + col; 135 rend_t *er = l.r + col;
134/* ------------------------------------------------------------------------- */ 144/* ------------------------------------------------------------------------- */
135/* Fill a full line with blanks - make sure it is allocated first */ 145/* Fill a full line with blanks - make sure it is allocated first */
136void 146void
137rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) 147rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs)
138{ 148{
139 if (!l.t)
140 lalloc (l);
141
142 scr_blank_line (l, 0, ncol, efs); 149 scr_blank_line (l, 0, ncol, efs);
143} 150}
144 151
145/* ------------------------------------------------------------------------- * 152/* ------------------------------------------------------------------------- *
146 * SCREEN INITIALISATION * 153 * SCREEN INITIALISATION *
170 // we need at least two lines for wrapping to work correctly 177 // we need at least two lines for wrapping to work correctly
171 if (nrow + saveLines < 2) 178 if (nrow + saveLines < 2)
172 { 179 {
173 saveLines++; 180 saveLines++;
174 prev_nrow--; 181 prev_nrow--;
175 nscrolled++; 182 nsaved++;
176 } 183 }
177 184
178 want_refresh = 1; 185 want_refresh = 1;
179 186
180 int prev_total_rows = prev_nrow + saveLines; 187 int prev_total_rows = prev_nrow + saveLines;
181 int total_rows = nrow + saveLines; 188 total_rows = nrow + saveLines;
182 189
183 screen.tscroll = 0; 190 screen.tscroll = 0;
184 screen.bscroll = nrow - 1; 191 screen.bscroll = nrow - 1;
185 192
186 if (!save) 193 if (!save)
187 { 194 {
188 /* 195 /*
189 * first time called so just malloc everything: don't rely on realloc 196 * first time called so just malloc everything: don't rely on realloc
190 * Note: this is still needed so that all the scrollback lines are NULL 197 * Note: this is still needed so that all the scrollback lines are NULL
191 */ 198 */
192 nscrolled = 0; /* no saved lines */ 199 nsaved = 0; /* no saved lines */
193 term_start = 0; 200 term_start = 0;
194 nsaved = 0;
195 201
196 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 202 talloc = new rxvt_salloc (ncol * sizeof (text_t));
197 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 203 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
198 204
199 save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 205 save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
200 buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 206 buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
201 drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 207 drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t));
202 swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 208 swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t));
203 209
204 screen.line = (line_t **)rxvt_calloc (nrow, sizeof (line_t *));
205
206 scr_update_term ();
207
208 for (p = nrow; p--; ) 210 for (p = nrow; p--; )
209 { 211 {
210 scr_blank_screen_mem (*screen.line[p], DEFAULT_RSTYLE); 212 scr_blank_screen_mem (ROW(p), DEFAULT_RSTYLE);
211 scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 213 scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE);
212 scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); 214 scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE);
213 } 215 }
214 216
215 memset (charsets, 'B', sizeof (charsets)); 217 memset (charsets, 'B', sizeof (charsets));
247 rxvt_salloc *old_ra; 249 rxvt_salloc *old_ra;
248 250
249 if (nrow < prev_nrow) 251 if (nrow < prev_nrow)
250 { 252 {
251 /* delete rows */ 253 /* delete rows */
252 k = min (nscrolled, prev_nrow - nrow); 254 k = min (nsaved, prev_nrow - nrow);
253 // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO 255 // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO
254 scr_scroll_text (0, (int)prev_nrow - 1, k, 1); 256 scr_scroll_text (0, (int)prev_nrow - 1, k, 1);
255 257
256 for (p = nrow; p < prev_nrow; p++) 258 for (p = nrow; p < prev_nrow; p++)
257 { 259 {
258 lfree (save[p + saveLines]); 260 lfree (ROW(p));
259 lfree (swap_save[p]); 261 lfree (swap_save[p]);
260 lfree (drawn[p]); 262 lfree (drawn[p]);
261 } 263 }
262 264
263 /* we have fewer rows so fix up cursor position */ 265 /* we have fewer rows so fix up cursor position */
271 scr_reset_realloc (); /* realloc _first_ */ 273 scr_reset_realloc (); /* realloc _first_ */
272 274
273 int ocol = ncol; 275 int ocol = ncol;
274 ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this 276 ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
275 277
276 k = min (nscrolled, nrow - prev_nrow); 278 k = min (nsaved, nrow - prev_nrow);
277 279
278 for (p = prev_total_rows; p < total_rows; p++) 280 for (p = prev_total_rows; p < total_rows; p++)
279 save[p].clear (); 281 save[p].clear ();
280 282
281 for (p = prev_total_rows; p < total_rows - k; p++) 283 for (p = prev_total_rows; p < total_rows - k; p++)
282 scr_blank_screen_mem (save[p], DEFAULT_RSTYLE); 284 scr_blank_screen_mem (save[p], DEFAULT_RSTYLE);
283
284 scr_update_term ();
285 285
286 for (p = prev_nrow; p < nrow; p++) 286 for (p = prev_nrow; p < nrow; p++)
287 { 287 {
288 swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 288 swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE);
289 drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); 289 drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE);
292 if (k > 0) 292 if (k > 0)
293 { 293 {
294 scr_scroll_text (0, (int)nrow - 1, -k, 1); 294 scr_scroll_text (0, (int)nrow - 1, -k, 1);
295 screen.cur.row += k; 295 screen.cur.row += k;
296 screen.s_cur.row += k; 296 screen.s_cur.row += k;
297 nscrolled -= k; 297 nsaved -= k;
298 } 298 }
299 299
300#ifdef DEBUG_STRICT 300#ifdef DEBUG_STRICT
301 assert (screen.cur.row < nrow); 301 assert (screen.cur.row < nrow);
302#else /* drive with your eyes closed */ 302#else /* drive with your eyes closed */
437} 437}
438 438
439void 439void
440rxvt_term::scr_reset_realloc () 440rxvt_term::scr_reset_realloc ()
441{ 441{
442 unsigned int total_rows = nrow + saveLines;
443
444 screen.line = (line_t **)rxvt_realloc (screen.line, nrow * sizeof (line_t *));
445 swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t)); 442 swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t));
446 drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t)); 443 drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t));
444 buf = (line_t *) rxvt_realloc (buf , nrow * sizeof (line_t));
447 save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t)); 445 save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t));
448 buf = (line_t *) rxvt_realloc (buf , total_rows * sizeof (line_t));
449} 446}
450 447
451/* ------------------------------------------------------------------------- */ 448/* ------------------------------------------------------------------------- */
452/* 449/*
453 * Free everything. That way malloc debugging can find leakage. 450 * Free everything. That way malloc debugging can find leakage.
454 */ 451 */
455void 452void
456rxvt_term::scr_release () 453rxvt_term::scr_release ()
457{ 454{
458 unsigned int total_rows;
459
460 total_rows = nrow + saveLines;
461
462 delete talloc; talloc = 0; 455 delete talloc; talloc = 0;
463 delete ralloc; ralloc = 0; 456 delete ralloc; ralloc = 0;
464 457
465 free (screen.line);
466 free (save); 458 free (save);
467 free (swap_save); 459 free (swap_save);
468 free (drawn); 460 free (drawn);
469 free (buf); 461 free (buf);
470 free (tabs); 462 free (tabs);
576 { 568 {
577 num_scr = 0; 569 num_scr = 0;
578 offset = saveLines; 570 offset = saveLines;
579 571
580 for (i = prev_nrow; i--;) 572 for (i = prev_nrow; i--;)
581 SWAP_IT (*(screen.line[i]), swap_save[i], line_t); 573 SWAP_IT (ROW(i), swap_save[i], line_t);
582 574
583 SWAP_IT (screen.charset, swap.charset, int16_t); 575 SWAP_IT (screen.charset, swap.charset, int16_t);
584 SWAP_IT (screen.flags, swap.flags, int); 576 SWAP_IT (screen.flags, swap.flags, int);
585 screen.flags |= Screen_VisibleCursor; 577 screen.flags |= Screen_VisibleCursor;
586 swap.flags |= Screen_VisibleCursor; 578 swap.flags |= Screen_VisibleCursor;
639 rstyle = DEFAULT_RSTYLE; 631 rstyle = DEFAULT_RSTYLE;
640 else 632 else
641 rstyle &= ~style; 633 rstyle &= ~style;
642 } 634 }
643 635
644// set screen.line pointers to the actual lines in the save buffer
645void
646rxvt_term::scr_update_term ()
647{
648 for (int i = nrow; i--; )
649 screen.line[i] = save + saveLines + i;
650}
651
652/* ------------------------------------------------------------------------- */ 636/* ------------------------------------------------------------------------- */
653/* 637/*
654 * Scroll text between <row1> and <row2> inclusive, by <count> lines 638 * Scroll text between <row1> and <row2> inclusive, by <count> lines
655 * count positive ==> scroll up 639 * count positive ==> scroll up
656 * count negative ==> scroll down 640 * count negative ==> scroll down
667 want_refresh = 1; 651 want_refresh = 1;
668 652
669 if (row1 == 0 && count > 0 653 if (row1 == 0 && count > 0
670 && (current_screen == PRIMARY || options & Opt_secondaryScroll)) 654 && (current_screen == PRIMARY || options & Opt_secondaryScroll))
671 { 655 {
672 nscrolled += count; 656 nsaved = min (nsaved + count, saveLines);
657 term_start = (term_start + count) % total_rows;
673 658
674 if (nscrolled > saveLines) 659 if (selection.op && current_screen == selection.screen)
675 nscrolled = saveLines; 660 {
661 selection.beg.row -= count;
662 selection.end.row -= count;
663 selection.mark.row -= count;
664 }
676 665
666 for (int i = count; i--; )
667 scr_blank_screen_mem (ROW(row2 - i), rstyle);
668
677 if ((options & Opt_scrollWithBuffer) 669 if ((options & Opt_scrollWithBuffer)
678 && view_start != 0 670 && view_start != 0
679 && view_start != saveLines) 671 && view_start != saveLines)
680 scr_page (UP, count); 672 scr_page (UP, count);
681 } 673 }
674 else
675 {
682 else if (!spec) 676 if (!spec)
683 row1 += saveLines; 677 row1 += saveLines;
684 678
685 row2 += saveLines; 679 row2 += saveLines;
686 680
687 if (selection.op && current_screen == selection.screen) 681 if (selection.op && current_screen == selection.screen)
688 { 682 {
689 i = selection.beg.row + saveLines; 683 i = selection.beg.row + saveLines;
690 j = selection.end.row + saveLines; 684 j = selection.end.row + saveLines;
691 685
692 if ((i < row1 && j > row1) 686 if ((i < row1 && j > row1)
693 || (i < row2 && j > row2) 687 || (i < row2 && j > row2)
694 || (i - count < row1 && i >= row1) 688 || (i - count < row1 && i >= row1)
695 || (i - count > row2 && i <= row2) 689 || (i - count > row2 && i <= row2)
696 || (j - count < row1 && j >= row1) 690 || (j - count < row1 && j >= row1)
697 || (j - count > row2 && j <= row2)) 691 || (j - count > row2 && j <= row2))
698 { 692 {
699 CLEAR_ALL_SELECTION (); 693 CLEAR_ALL_SELECTION ();
700 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 694 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */
701 } 695 }
702 else if (j >= row1 && j <= row2) 696 else if (j >= row1 && j <= row2)
703 { 697 {
704 /* move selected region too */ 698 /* move selected region too */
705 selection.beg.row -= count; 699 selection.beg.row -= count;
706 selection.end.row -= count; 700 selection.end.row -= count;
707 selection.mark.row -= count; 701 selection.mark.row -= count;
708 } 702 }
709 } 703 }
710 704
711 selection_check (0); /* _after_ nscrolled update */ 705 selection_check (0); /* _after_ nsaved update */
712 706
713 num_scr += count; 707 num_scr += count;
714 j = count; 708 j = count;
715 709
716 if (count < 0) 710 if (count < 0)
717 count = -count; 711 count = -count;
718 712
719 i = row2 - row1 + 1; 713 i = row2 - row1 + 1;
720 MIN_IT (count, i); 714 MIN_IT (count, i);
721 715
722 if (j > 0) 716 if (j > 0)
723 { 717 {
724 /* scroll up */ 718 /* scroll up */
725 719
726 /* Copy lines that will get clobbered by the rotation */ 720 /* Copy lines that will get clobbered by the rotation */
727 memcpy (buf, save + row1, count * sizeof (line_t)); 721 memcpy (buf, save + row1, count * sizeof (line_t));
728 722
729 /* Rotate lines */ 723 /* Rotate lines */
730 i = row2 - row1 - count + 1; 724 i = row2 - row1 - count + 1;
731 memmove (save + row1, save + row1 + count, i * sizeof (line_t)); 725 memmove (save + row1, save + row1 + count, i * sizeof (line_t));
732 726
733 j = row2 - count + 1, i = count; 727 j = row2 - count + 1, i = count;
734 } 728 }
735 else /* if (j < 0) */ 729 else /* if (j < 0) */
736 { 730 {
737 /* scroll down */ 731 /* scroll down */
738 732
739 /* Copy lines that will get clobbered by the rotation */ 733 /* Copy lines that will get clobbered by the rotation */
740 for (i = 0, j = row2; i < count; i++, j--) 734 for (i = 0, j = row2; i < count; i++, j--)
741 buf[i] = save[j]; 735 buf[i] = save[j];
742 736
743 /* Rotate lines */ 737 /* Rotate lines */
744 for (j = row2, i = j - count; i >= row1; i--, j--) 738 for (j = row2, i = j - count; i >= row1; i--, j--)
745 save[j] = save[i]; 739 save[j] = save[i];
746 740
747 j = row1, i = count; 741 j = row1, i = count;
748 count = -count; 742 count = -count;
749 } 743 }
750 744
751 /* Resurrect lines */ 745 /* Resurrect lines */
752 memcpy (save + j, buf, i * sizeof (line_t)); 746 memcpy (save + j, buf, i * sizeof (line_t));
753 747
754 scr_update_term ();
755
756 if (!spec) /* line length may not equal ncol */ 748 if (!spec) /* line length may not equal ncol */
757 for (; i--; j++) 749 for (; i--; j++)
758 scr_blank_screen_mem (save[j], rstyle); 750 scr_blank_screen_mem (save[j], rstyle);
751 }
759 752
760 return count; 753 return count;
761} 754}
762 755
763/* ------------------------------------------------------------------------- */ 756/* ------------------------------------------------------------------------- */
793 } 786 }
794 787
795#ifdef DEBUG_STRICT 788#ifdef DEBUG_STRICT
796 assert (screen.cur.col < last_col); 789 assert (screen.cur.col < last_col);
797 assert ((screen.cur.row < nrow) 790 assert ((screen.cur.row < nrow)
798 && (screen.cur.row >= - (int32_t)nscrolled)); 791 && (screen.cur.row >= - (int32_t)nsaved));
799#else /* drive with your eyes closed */ 792#else /* drive with your eyes closed */
800 MIN_IT (screen.cur.col, last_col - 1); 793 MIN_IT (screen.cur.col, last_col - 1);
801 MIN_IT (screen.cur.row, (int32_t)nrow - 1); 794 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
802 MAX_IT (screen.cur.row, - (int32_t)nscrolled); 795 MAX_IT (screen.cur.row, - (int32_t)nsaved);
803#endif 796#endif
804 row = screen.cur.row + saveLines; 797 row = screen.cur.row;
805 798
806 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 799 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
807 800
808 line_t *line = save + row; 801 line_t *line = &ROW(row);
809 802
810 while (str < strend) 803 while (str < strend)
811 { 804 {
812 c = *str++; 805 c = *str++;
813 806
820 screen.flags &= ~Screen_WrapNext; 813 screen.flags &= ~Screen_WrapNext;
821 814
822 if (screen.cur.row == screen.bscroll) 815 if (screen.cur.row == screen.bscroll)
823 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); 816 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0);
824 else if (screen.cur.row < (nrow - 1)) 817 else if (screen.cur.row < (nrow - 1))
825 row = (++screen.cur.row) + saveLines; 818 row = ++screen.cur.row;
826 819
827 line = save + row; /* _must_ refresh */ 820 line = &ROW(row); /* _must_ refresh */
828 continue; 821 continue;
829 } 822 }
830 else if (c == C0_CR) 823 else if (c == C0_CR)
831 { 824 {
832 if (!line->is_longer ()) /* XXX: think about this */ 825 if (!line->is_longer ()) /* XXX: think about this */
859 { 852 {
860 line->set_is_longer (); 853 line->set_is_longer ();
861 854
862 scr_do_wrap (); 855 scr_do_wrap ();
863 856
864 row = screen.cur.row + saveLines; 857 row = screen.cur.row;
865 line = save + row; /* _must_ refresh */ 858 line = &ROW(row); /* _must_ refresh */
866 } 859 }
867 860
868 // some utf-8 decoders "decode" surrogate characters: let's fix this. 861 // some utf-8 decoders "decode" surrogate characters: let's fix this.
869 if (IN_RANGE (c, 0xd800, 0xdfff)) 862 if (IN_RANGE_INC (c, 0xd800, 0xdfff))
870 c = 0xfffd; 863 c = 0xfffd;
871 864
872 // rely on wcwidth to tell us the character width, at least for non-latin1 865 // rely on wcwidth to tell us the character width, at least for non-latin1
873 // do wcwidth before further replacements, as wcwidth might return -1 866 // do wcwidth before further replacements, as wcwidth might return -1
874 // for the line drawing characters below as they might be invalid in the current 867 // for the line drawing characters below as they might be invalid in the current
989 982
990 while (*tp == NOCHAR && tp > line->t) 983 while (*tp == NOCHAR && tp > line->t)
991 tp--, rp--; 984 tp--, rp--;
992 } 985 }
993 else if (screen.cur.row > 0 986 else if (screen.cur.row > 0
994 && save [screen.cur.row - 1 + saveLines].is_longer ()) 987 && ROW(screen.cur.row - 1).is_longer ())
995 { 988 {
996 line_t *line = save + (screen.cur.row - 1 + saveLines); 989 line_t *line = &ROW(screen.cur.row - 1);
997 990
998 tp = line->t + last_col - 1; 991 tp = line->t + last_col - 1;
999 rp = line->r + last_col - 1; 992 rp = line->r + last_col - 1;
1000 993
1001 while (*tp == NOCHAR && tp > line->t) 994 while (*tp == NOCHAR && tp > line->t)
1068 1061
1069 if (count == 0) 1062 if (count == 0)
1070 return; 1063 return;
1071 else if (count > 0) 1064 else if (count > 0)
1072 { 1065 {
1073 int row = saveLines + screen.cur.row; 1066 int row = screen.cur.row;
1074 1067
1075 line_t &l = save[row]; 1068 line_t &l = ROW(row);
1076 rend_t base_rend = l.r[i]; 1069 rend_t base_rend = l.r[i];
1077 ht &= l.t[i] == ' '; 1070 ht &= l.t[i] == ' ';
1078 1071
1079 for (; ++i < ncol; ) 1072 for (; ++i < ncol; )
1080 if (tabs[i]) 1073 if (tabs[i])
1141rxvt_term::scr_backindex () 1134rxvt_term::scr_backindex ()
1142{ 1135{
1143 if (screen.cur.col > 0) 1136 if (screen.cur.col > 0)
1144 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1137 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1145 else 1138 else
1146 {
1147 if (!save[screen.cur.row + saveLines].l)
1148 return; /* um, yeah? */
1149
1150 scr_insdel_chars (1, INSERT); 1139 scr_insdel_chars (1, INSERT);
1151 }
1152} 1140}
1153#endif 1141#endif
1154/* ------------------------------------------------------------------------- */ 1142/* ------------------------------------------------------------------------- */
1155/* 1143/*
1156 * Process DEC Forward Index 1144 * Process DEC Forward Index
1166 1154
1167 if (screen.cur.col < ncol - 1) 1155 if (screen.cur.col < ncol - 1)
1168 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1156 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1169 else 1157 else
1170 { 1158 {
1171 row = screen.cur.row + saveLines; 1159 row = screen.cur.row;
1172 1160
1173 if (!save[row].l)
1174 return; /* um, yeah? */
1175
1176 if (save[row].is_longer ()) //TODO//FIXME//LEN 1161 if (ROW(row).is_longer ()) //TODO//FIXME//LEN
1177 save[row].l = ncol; 1162 ROW(row).l = ncol;
1178 1163
1179 scr_gotorc (0, 0, R_RELATIVE); 1164 scr_gotorc (0, 0, R_RELATIVE);
1180 scr_insdel_chars (1, DELETE); 1165 scr_insdel_chars (1, DELETE);
1181 scr_gotorc (0, ncol - 1, R_RELATIVE); 1166 scr_gotorc (0, ncol - 1, R_RELATIVE);
1182 } 1167 }
1275 want_refresh = 1; 1260 want_refresh = 1;
1276 ZERO_SCROLLBACK (); 1261 ZERO_SCROLLBACK ();
1277 1262
1278 selection_check (1); 1263 selection_check (1);
1279 1264
1280 row = saveLines + screen.cur.row; 1265 row = screen.cur.row;
1281 1266
1282 switch (mode) 1267 switch (mode)
1283 { 1268 {
1284 case 0: /* erase to end of line */ 1269 case 0: /* erase to end of line */
1285 col = screen.cur.col; 1270 col = screen.cur.col;
1286 num = ncol - col; 1271 num = ncol - col;
1287 MIN_IT (save[row].l, (int16_t)col); 1272 MIN_IT (ROW(row).l, (int16_t)col);
1288 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1273 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1289 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1274 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1290 CLEAR_SELECTION (); 1275 CLEAR_SELECTION ();
1291 break; 1276 break;
1292 case 1: /* erase to beginning of line */ 1277 case 1: /* erase to beginning of line */
1297 CLEAR_SELECTION (); 1282 CLEAR_SELECTION ();
1298 break; 1283 break;
1299 case 2: /* erase whole line */ 1284 case 2: /* erase whole line */
1300 col = 0; 1285 col = 0;
1301 num = ncol; 1286 num = ncol;
1302 save[row].l = 0; 1287 ROW(row).l = 0;
1303 if (selection.beg.row <= screen.cur.row 1288 if (selection.beg.row <= screen.cur.row
1304 && selection.end.row >= screen.cur.row) 1289 && selection.end.row >= screen.cur.row)
1305 CLEAR_SELECTION (); 1290 CLEAR_SELECTION ();
1306 break; 1291 break;
1307 default: 1292 default:
1308 return; 1293 return;
1309 } 1294 }
1310 1295
1311 if (save[row].t)
1312 scr_blank_line (save[row], col, num, rstyle); 1296 scr_blank_line (ROW(row), col, num, rstyle);
1313 else
1314 scr_blank_screen_mem (save[row], rstyle);
1315} 1297}
1316 1298
1317/* ------------------------------------------------------------------------- */ 1299/* ------------------------------------------------------------------------- */
1318/* 1300/*
1319 * Erase part of whole of the screen 1301 * Erase part of whole of the screen
1398rxvt_term::scr_erase_savelines () 1380rxvt_term::scr_erase_savelines ()
1399{ 1381{
1400 want_refresh = 1; 1382 want_refresh = 1;
1401 ZERO_SCROLLBACK (); 1383 ZERO_SCROLLBACK ();
1402 1384
1403 nscrolled = 0; 1385 nsaved = 0;
1404} 1386}
1405#endif 1387#endif
1406 1388
1407/* ------------------------------------------------------------------------- */ 1389/* ------------------------------------------------------------------------- */
1408/* 1390/*
1879 1861
1880 oldviewstart = view_start; 1862 oldviewstart = view_start;
1881 1863
1882 if (y < len) 1864 if (y < len)
1883 { 1865 {
1884 p = (nrow + nscrolled) * (len - y) / len; 1866 p = (nrow + nsaved) * (len - y) / len;
1885 p -= (long) (nrow - 1); 1867 p -= (long) (nrow - 1);
1886 p = max (p, 0); 1868 p = max (p, 0);
1887 } 1869 }
1888 1870
1889 view_start = (unsigned int)min (p, nscrolled); 1871 view_start = (unsigned int)min (p, nsaved);
1890 1872
1891 return scr_changeview (oldviewstart); 1873 return scr_changeview (oldviewstart);
1892} 1874}
1893 1875
1894/* ------------------------------------------------------------------------- */ 1876/* ------------------------------------------------------------------------- */
1905 oldviewstart = view_start; 1887 oldviewstart = view_start;
1906 1888
1907 if (direction == UP) 1889 if (direction == UP)
1908 { 1890 {
1909 n = view_start + nlines; 1891 n = view_start + nlines;
1910 view_start = min (n, nscrolled); 1892 view_start = min (n, nsaved);
1911 } 1893 }
1912 else 1894 else
1913 { 1895 {
1914 n = view_start - nlines; 1896 n = view_start - nlines;
1915 view_start = max (n, 0); 1897 view_start = max (n, 0);
1972 1954
1973 if (!fullhist) 1955 if (!fullhist)
1974 row_offset -= view_start; 1956 row_offset -= view_start;
1975 else 1957 else
1976 { 1958 {
1977 nrows += nscrolled; 1959 nrows += nsaved;
1978 row_offset -= nscrolled; 1960 row_offset -= nsaved;
1979 } 1961 }
1980 1962
1981 wctomb (0, 0); 1963 wctomb (0, 0);
1982 1964
1983 for (r1 = 0; r1 < nrows; r1++) 1965 for (r1 = 0; r1 < nrows; r1++)
2039 * A: set up vars 2021 * A: set up vars
2040 */ 2022 */
2041 must_clear = 0; 2023 must_clear = 0;
2042 refresh_count = 0; 2024 refresh_count = 0;
2043 2025
2044 row_offset = saveLines - view_start; 2026 row_offset = term_start - view_start;
2045 2027
2046#if XPM_BACKGROUND 2028#if XPM_BACKGROUND
2047 must_clear |= bgPixmap.pixmap != None; 2029 must_clear |= bgPixmap.pixmap != None;
2048#endif 2030#endif
2049#if TRANSPARENT 2031#if TRANSPARENT
2072 2054
2073 if (showcursor) 2055 if (showcursor)
2074 { 2056 {
2075 int col = screen.cur.col; 2057 int col = screen.cur.col;
2076 2058
2077 while (col && screen.line[screen.cur.row]->t[col] == NOCHAR) 2059 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2078 col--; 2060 col--;
2079 2061
2080 crp = &screen.line[screen.cur.row]->r[col]; 2062 crp = &ROW(screen.cur.row).r[col];
2081 2063
2082 if (showcursor && focus) 2064 if (showcursor && focus)
2083 { 2065 {
2084 if (options & Opt_cursorUnderline) 2066 if (options & Opt_cursorUnderline)
2085 *crp ^= RS_Uline; 2067 *crp ^= RS_Uline;
2167 row = i > 0 ? 0 : j - 1; 2149 row = i > 0 ? 0 : j - 1;
2168 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2150 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2169 { 2151 {
2170 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2152 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2171 { 2153 {
2172 line_t s = save[row + row_offset]; 2154 line_t s = save[(row + row_offset) % nlines];
2173 line_t d = drawn[row]; 2155 line_t d = drawn[row];
2174 line_t d2 = drawn[row + i]; 2156 line_t d2 = drawn[row + i];
2175 2157
2176 for (nits = 0, col = ncol; col--; ) 2158 for (nits = 0, col = ncol; col--; )
2177 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) 2159 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col])
2215 /* 2197 /*
2216 * E: main pass across every character 2198 * E: main pass across every character
2217 */ 2199 */
2218 for (row = 0; row < nrow; row++) 2200 for (row = 0; row < nrow; row++)
2219 { 2201 {
2220 text_t *stp = save[row + row_offset].t; 2202 text_t *stp = save[(row + row_offset) % total_rows].t;
2221 rend_t *srp = save[row + row_offset].r; 2203 rend_t *srp = save[(row + row_offset) % total_rows].r;
2222 text_t *dtp = drawn[row].t; 2204 text_t *dtp = drawn[row].t;
2223 rend_t *drp = drawn[row].r; 2205 rend_t *drp = drawn[row].r;
2224 2206
2225 /* 2207 /*
2226 * E2: OK, now the real pass 2208 * E2: OK, now the real pass
2437 else if (oldcursor.row >= 0) 2419 else if (oldcursor.row >= 0)
2438 { 2420 {
2439 int cursorwidth = 1; 2421 int cursorwidth = 1;
2440 int col = oldcursor.col; 2422 int col = oldcursor.col;
2441 2423
2442 while (col && save[screen.cur.row + saveLines].t[col] == NOCHAR) 2424 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2443 col--; 2425 col--;
2444 2426
2445 while (col + cursorwidth < ncol 2427 while (col + cursorwidth < ncol
2446 && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2428 && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2447 cursorwidth++; 2429 cursorwidth++;
2482} 2464}
2483 2465
2484void 2466void
2485rxvt_term::scr_remap_chars () 2467rxvt_term::scr_remap_chars ()
2486{ 2468{
2487 for (int i = nrow + saveLines; i--; ) 2469 for (int i = total_rows; i--; )
2488 scr_remap_chars (save[i]); 2470 scr_remap_chars (save[i]);
2489 2471
2490 for (int i = nrow; i--; ) 2472 for (int i = nrow; i--; )
2491 { 2473 {
2492 scr_remap_chars (drawn[i]); 2474 scr_remap_chars (drawn[i]);
2540 2522
2541/* ------------------------------------------------------------------------- */ 2523/* ------------------------------------------------------------------------- */
2542void 2524void
2543rxvt_term::scr_reverse_selection () 2525rxvt_term::scr_reverse_selection ()
2544{ 2526{
2527 if (selection.op
2545 if (selection.op && current_screen == selection.screen) 2528 && current_screen == selection.screen
2529 && selection.end.row >= -view_start)
2546 { 2530 {
2547 int end_row = saveLines - view_start; 2531 int view_end = -view_start + nrow;
2548 int i = selection.beg.row + saveLines; 2532 int row, col;
2549 int col, row = selection.end.row + saveLines;
2550 rend_t *srp;
2551 2533
2552#if ENABLE_FRILLS 2534#if ENABLE_FRILLS
2553 if (selection.rect) 2535 if (selection.rect)
2554 { 2536 {
2555 end_row += nrow; 2537 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++)
2556
2557 for (; i <= row && i <= end_row; i++)
2558 for (srp = save[i].r, col = selection.beg.col; col < selection.end.col; col++) 2538 for (rend_t *srp = ROW(row).r, col = selection.beg.col; col < selection.end.col; col++)
2559 srp[col] ^= RS_RVid; 2539 srp[col] ^= RS_RVid;
2560 } 2540 }
2561 else 2541 else
2562#endif 2542#endif
2563 { 2543 {
2564 if (i >= end_row) 2544 if (selection.beg.row >= -view_start)
2545 {
2565 col = selection.beg.col; 2546 col = selection.beg.col;
2547 row = selection.beg.row;
2548 }
2566 else 2549 else
2567 { 2550 {
2568 col = 0; 2551 col = 0;
2569 i = end_row; 2552 row = view_start;
2570 } 2553 }
2571 2554
2572 end_row += nrow; 2555 for (; row < min (selection.end.row, view_end); row++, col = 0)
2573
2574 for (; i < row && i < end_row; i++, col = 0)
2575 for (srp = save[i].r; col < ncol; col++) 2556 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2576 srp[col] ^= RS_RVid; 2557 srp[col] ^= RS_RVid;
2577 2558
2578 if (i == row && i < end_row) 2559 if (row == selection.end.row)
2579 for (srp = save[i].r; col < selection.end.col; col++) 2560 for (rend_t *srp = ROW(row).r; col < selection.end.col; col++)
2580 srp[col] ^= RS_RVid; 2561 srp[col] ^= RS_RVid;
2581 } 2562 }
2582 } 2563 }
2583} 2564}
2584 2565
2593{ 2574{
2594 int row, wrote; 2575 int row, wrote;
2595 unsigned int width, towrite; 2576 unsigned int width, towrite;
2596 char r1[] = "\n"; 2577 char r1[] = "\n";
2597 2578
2598 for (row = saveLines - nscrolled; 2579 for (row = saveLines - nsaved;
2599 row < saveLines + nrow - 1; row++) 2580 row < saveLines + nrow - 1; row++)
2600 { 2581 {
2601 width = save[row].l >= 0 ? save[row].l 2582 width = save[row].l >= 0 ? save[row].l
2602 : ncol; 2583 : ncol;
2603 for (towrite = width; towrite; towrite -= wrote) 2584 for (towrite = width; towrite; towrite -= wrote)
2615#endif 2596#endif
2616 2597
2617/* ------------------------------------------------------------------------- * 2598/* ------------------------------------------------------------------------- *
2618 * CHARACTER SELECTION * 2599 * CHARACTER SELECTION *
2619 * ------------------------------------------------------------------------- */ 2600 * ------------------------------------------------------------------------- */
2620
2621/*
2622 * -nscrolled <= (selection row) <= nrow - 1
2623 */
2624void 2601void
2625rxvt_term::selection_check (int check_more) 2602rxvt_term::selection_check (int check_more)
2626{ 2603{
2627 row_col_t pos; 2604 row_col_t pos;
2628 2605
2629 if (!selection.op) 2606 if (!selection.op)
2630 return; 2607 return;
2631 2608
2632 pos.row = pos.col = 0; 2609 pos.row = pos.col = 0;
2633 if ((selection.beg.row < - (int32_t)nscrolled) 2610 if (!IN_RANGE_EXC (selection.beg.row, -nsaved, nrow)
2634 || (selection.beg.row >= nrow) 2611 || !IN_RANGE_EXC (selection.mark.row, -nsaved, nrow)
2635 || (selection.mark.row < - (int32_t)nscrolled) 2612 || !IN_RANGE_EXC (selection.end.row, -nsaved, nrow)
2636 || (selection.mark.row >= nrow)
2637 || (selection.end.row < - (int32_t)nscrolled)
2638 || (selection.end.row >= nrow)
2639 || (check_more == 1 2613 || (check_more == 1
2640 && current_screen == selection.screen 2614 && current_screen == selection.screen
2641 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 2615 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
2642 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 2616 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
2643 || (check_more == 2 2617 || (check_more == 2
2949 * EXT: button 1 or 3 release 2923 * EXT: button 1 or 3 release
2950 */ 2924 */
2951void 2925void
2952rxvt_term::selection_make (Time tm) 2926rxvt_term::selection_make (Time tm)
2953{ 2927{
2954 int i, col, end_col, row, end_row; 2928 int i;
2955 wchar_t *new_selection_text; 2929 wchar_t *new_selection_text;
2956 text_t *t; 2930 text_t *t;
2957 2931
2958 switch (selection.op) 2932 switch (selection.op)
2959 { 2933 {
2975 return; /* nothing selected, go away */ 2949 return; /* nothing selected, go away */
2976 2950
2977 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2951 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
2978 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); 2952 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t));
2979 2953
2980 col = selection.beg.col;
2981 row = selection.beg.row + saveLines;
2982 end_row = selection.end.row + saveLines;
2983 int ofs = 0; 2954 int ofs = 0;
2984 int extra = 0; 2955 int extra = 0;
2985 2956
2957 int col = selection.beg.col;
2958 int row = selection.beg.row;
2959
2960 int end_col;
2961
2986 for (; row <= end_row; row++, col = 0) 2962 for (; row <= selection.end.row; row++, col = 0)
2987 { 2963 {
2988#if ENABLE_FRILLS 2964#if ENABLE_FRILLS
2989 if (selection.rect) 2965 if (selection.rect)
2990 { 2966 {
2991 col = selection.beg.col; 2967 col = selection.beg.col;
2992 end_col = ncol + 1; 2968 end_col = ncol + 1;
2993 } 2969 }
2994 else 2970 else
2995#endif 2971#endif
2996 end_col = save[row].is_longer () ? ncol : save[row].l; //TODO//FIXME//LEN 2972 end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN
2997 2973
2998 MAX_IT (col, 0); 2974 col = max (col, 0);
2999 2975
3000 if (row == end_row || selection.rect) 2976 if (row == selection.end.row || selection.rect)
3001 MIN_IT (end_col, selection.end.col); 2977 end_col = min (end_col, selection.end.col);
3002 2978
3003 t = save[row].t + col; 2979 t = ROW(row).t + col;
3004 for (; col < end_col; col++) 2980 for (; col < end_col; col++)
3005 { 2981 {
3006 if (*t == NOCHAR) 2982 if (*t == NOCHAR)
3007 t++; 2983 t++;
3008#if ENABLE_COMBINING 2984#if ENABLE_COMBINING
3024#endif 3000#endif
3025 else 3001 else
3026 new_selection_text[ofs++] = *t++; 3002 new_selection_text[ofs++] = *t++;
3027 } 3003 }
3028 3004
3029 if (!save[row].is_longer () && row != end_row) 3005 if (!ROW(row).is_longer () && row != selection.end.row)
3030 new_selection_text[ofs++] = C0_LF; 3006 new_selection_text[ofs++] = C0_LF;
3031 } 3007 }
3032 3008
3033 if (end_col != selection.end.col) 3009 if (end_col != selection.end.col)
3034 new_selection_text[ofs++] = C0_LF; 3010 new_selection_text[ofs++] = C0_LF;
3093 */ 3069 */
3094void 3070void
3095rxvt_term::selection_start_colrow (int col, int row) 3071rxvt_term::selection_start_colrow (int col, int row)
3096{ 3072{
3097 want_refresh = 1; 3073 want_refresh = 1;
3074
3075 selection.mark.row = row - view_start;
3098 selection.mark.col = col; 3076 selection.mark.col = col;
3099 selection.mark.row = row - view_start;
3100 3077
3101 MAX_IT (selection.mark.row, - (int32_t)nscrolled); 3078 selection.mark.row = min (max (selection.mark.row, -nsaved), nrow - 1);
3102 MIN_IT (selection.mark.row, (int32_t)nrow - 1); 3079 selection.mark.col = min (max (selection.mark.col, 0), ncol - 1);
3103 MAX_IT (selection.mark.col, 0);
3104 MIN_IT (selection.mark.col, (int32_t)ncol - 1);
3105 3080
3106 while (selection.mark.col > 0 3081 while (selection.mark.col > 0
3107 && save[selection.mark.row + saveLines].t[selection.mark.col] == NOCHAR) 3082 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3108 --selection.mark.col; 3083 --selection.mark.col;
3109 3084
3110 if (selection.op) 3085 if (selection.op)
3111 { /* clear the old selection */ 3086 { /* clear the old selection */
3112 selection.beg.row = selection.end.row = selection.mark.row; 3087 selection.beg.row = selection.end.row = selection.mark.row;
3136 text_t *stp; 3111 text_t *stp;
3137 rend_t *srp; 3112 rend_t *srp;
3138 3113
3139 if (dirn == UP) 3114 if (dirn == UP)
3140 { 3115 {
3141 bound.row = saveLines - nscrolled - 1; 3116 bound.row = - nsaved - 1;
3142 bound.col = 0; 3117 bound.col = 0;
3143 dirnadd = -1; 3118 dirnadd = -1;
3144 } 3119 }
3145 else 3120 else
3146 { 3121 {
3147 bound.row = saveLines + nrow; 3122 bound.row = nrow;
3148 bound.col = ncol - 1; 3123 bound.col = ncol - 1;
3149 dirnadd = 1; 3124 dirnadd = 1;
3150 } 3125 }
3151 3126
3152 row = mark->row + saveLines; 3127 row = mark->row;
3153 col = mark->col; 3128 col = max (mark->col, 0);
3154 MAX_IT (col, 0); 3129
3155 /* find the edge of a word */ 3130 /* find the edge of a word */
3156 stp = save[row].t + col; w1 = DELIMIT_TEXT (*stp); 3131 stp = ROW(row).t + col; w1 = DELIMIT_TEXT (*stp);
3157 srp = save[row].r + col; w2 = DELIMIT_REND (*srp); 3132 srp = ROW(row).r + col; w2 = DELIMIT_REND (*srp);
3158 3133
3159 for (;;) 3134 for (;;)
3160 { 3135 {
3161 for (; col != bound.col; col += dirnadd) 3136 for (; col != bound.col; col += dirnadd)
3162 { 3137 {
3172 break; 3147 break;
3173 } 3148 }
3174 3149
3175 if ((col == bound.col) && (row != bound.row)) 3150 if ((col == bound.col) && (row != bound.row))
3176 { 3151 {
3177 if (save[ (row - (dirn == UP ? 1 : 0))].is_longer ()) 3152 if (ROW(row - (dirn == UP ? 1 : 0)).is_longer ())
3178 { 3153 {
3179 trow = row + dirnadd; 3154 trow = row + dirnadd;
3180 tcol = dirn == UP ? ncol - 1 : 0; 3155 tcol = dirn == UP ? ncol - 1 : 0;
3181 3156
3182 if (!save[trow].t) 3157 if (!ROW(trow).t)
3183 break; 3158 break;
3184 3159
3185 stp = save[trow].t + tcol; 3160 stp = ROW(trow).t + tcol;
3186 srp = save[trow].r + tcol; 3161 srp = ROW(trow).r + tcol;
3187 3162
3188 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2) 3163 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2)
3189 break; 3164 break;
3190 3165
3191 row = trow; 3166 row = trow;
3199Old_Word_Selection_You_Die: 3174Old_Word_Selection_You_Die:
3200 if (dirn == DN) 3175 if (dirn == DN)
3201 col++; /* put us on one past the end */ 3176 col++; /* put us on one past the end */
3202 3177
3203 /* Poke the values back in */ 3178 /* Poke the values back in */
3204 ret->row = row - saveLines; 3179 ret->row = row;
3205 ret->col = col; 3180 ret->col = col;
3206} 3181}
3207 3182
3208/* ------------------------------------------------------------------------- */ 3183/* ------------------------------------------------------------------------- */
3209/* 3184/*
3214 * flag == 2 ==> button 3 motion 3189 * flag == 2 ==> button 3 motion
3215 */ 3190 */
3216void 3191void
3217rxvt_term::selection_extend (int x, int y, int flag) 3192rxvt_term::selection_extend (int x, int y, int flag)
3218{ 3193{
3219 int col, row; 3194 int col = min (max (Pixel2Col (x), 0), nrow - 1);
3220 3195 int row = min (max (Pixel2Row (y), 0), ncol);
3221 col = Pixel2Col (x);
3222 row = Pixel2Row (y);
3223 MAX_IT (row, 0);
3224 MIN_IT (row, (int)nrow - 1);
3225 MAX_IT (col, 0);
3226 MIN_IT (col, (int)ncol);
3227 3196
3228 /* 3197 /*
3229 * If we're selecting characters (single click) then we must check first 3198 * If we're selecting characters (single click) then we must check first
3230 * if we are at the same place as the original mark. If we are then 3199 * if we are at the same place as the original mark. If we are then
3231 * select nothing. Otherwise, if we're to the right of the mark, you have to 3200 * select nothing. Otherwise, if we're to the right of the mark, you have to
3296 selection.beg.col = selection.end.col = selection.mark.col; 3265 selection.beg.col = selection.end.col = selection.mark.col;
3297 selection.beg.row = selection.end.row = selection.mark.row; 3266 selection.beg.row = selection.end.row = selection.mark.row;
3298 } 3267 }
3299 3268
3300 pos.col = col; 3269 pos.col = col;
3301 pos.row = row; 3270 pos.row = row - view_start;
3302
3303 pos.row -= view_start; /* adjust for scroll */
3304 3271
3305 /* 3272 /*
3306 * This is mainly xterm style selection with a couple of differences, mainly 3273 * This is mainly xterm style selection with a couple of differences, mainly
3307 * in the way button3 drag extension works. 3274 * in the way button3 drag extension works.
3308 * We're either doing: button1 drag; button3 press; or button3 drag 3275 * We're either doing: button1 drag; button3 press; or button3 drag
3367 } 3334 }
3368 } 3335 }
3369 3336
3370 if (selection.clicks == 1) 3337 if (selection.clicks == 1)
3371 { 3338 {
3372 if (selection.beg.col > save[selection.beg.row + saveLines].l //TODO//FIXME//LEN 3339 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN
3373 && !save[selection.beg.row + saveLines].is_longer () 3340 && !ROW(selection.beg.row).is_longer ()
3374#if ENABLE_FRILLS 3341#if ENABLE_FRILLS
3375 && !selection.rect 3342 && !selection.rect
3376#endif 3343#endif
3377 ) 3344 )
3378 selection.beg.col = ncol; 3345 selection.beg.col = ncol;
3379 3346
3380 if ( 3347 if (
3381 selection.end.col > save[selection.end.row + saveLines].l //TODO//FIXME//LEN 3348 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN
3382 && !save[selection.end.row + saveLines].is_longer () 3349 && !ROW(selection.end.row).is_longer ()
3383#if ENABLE_FRILLS 3350#if ENABLE_FRILLS
3384 && !selection.rect 3351 && !selection.rect
3385#endif 3352#endif
3386 ) 3353 )
3387 selection.end.col = ncol; 3354 selection.end.col = ncol;
3401 { 3368 {
3402 selection_delimit_word (UP, &selection.beg, &selection.beg); 3369 selection_delimit_word (UP, &selection.beg, &selection.beg);
3403 3370
3404 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3371 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3405 { 3372 {
3406 if (!save[end_row + saveLines].is_longer ()) 3373 if (!ROW(end_row).is_longer ())
3407 { 3374 {
3408 selection.end.row = end_row; 3375 selection.end.row = end_row;
3409 selection.end.col = save[end_row + saveLines].l; 3376 selection.end.col = save[end_row + saveLines].l;
3410 selection_remove_trailing_spaces (); 3377 selection_remove_trailing_spaces ();
3411 break; 3378 break;
3421 selection.beg.col = 0; 3388 selection.beg.col = 0;
3422 selection.end.col = ncol; 3389 selection.end.col = ncol;
3423 3390
3424 // select a complete logical line 3391 // select a complete logical line
3425 while (selection.beg.row > -saveLines 3392 while (selection.beg.row > -saveLines
3426 && save[selection.beg.row - 1 + saveLines].is_longer ()) 3393 && ROW(selection.beg.row - 1).is_longer ())
3427 selection.beg.row--; 3394 selection.beg.row--;
3428 3395
3429 while (selection.end.row < nrow 3396 while (selection.end.row < nrow
3430 && save[selection.end.row + saveLines].is_longer ()) 3397 && ROW(selection.end.row).is_longer ())
3431 selection.end.row++; 3398 selection.end.row++;
3432 } 3399 }
3433 } 3400 }
3434 3401
3435 if (button3 && buttonpress) 3402 if (button3 && buttonpress)
3460 text_t *stp; 3427 text_t *stp;
3461 3428
3462 end_col = selection.end.col; 3429 end_col = selection.end.col;
3463 end_row = selection.end.row; 3430 end_row = selection.end.row;
3464 3431
3465 for ( ; end_row >= selection.beg.row; ) 3432 for (; end_row >= selection.beg.row; )
3466 { 3433 {
3467 stp = save[end_row + saveLines].t; 3434 stp = ROW(end_row).t;
3468 3435
3469 while (--end_col >= 0) 3436 while (--end_col >= 0)
3470 { 3437 {
3471 if (stp[end_col] != ' ' 3438 if (stp[end_col] != ' '
3472 && stp[end_col] != '\t' 3439 && stp[end_col] != '\t'
3473 && stp[end_col] != NOCHAR) 3440 && stp[end_col] != NOCHAR)
3474 break; 3441 break;
3475 } 3442 }
3476 3443
3477 if (end_col >= 0 3444 if (end_col >= 0
3478 || !save[end_row - 1 + saveLines].is_longer ()) 3445 || !ROW(end_row - 1).is_longer ())
3479 { 3446 {
3480 selection.end.col = end_col + 1; 3447 selection.end.col = end_col + 1;
3481 selection.end.row = end_row; 3448 selection.end.row = end_row;
3482 break; 3449 break;
3483 } 3450 }
3791rxvt_term::scr_swap_overlay () 3758rxvt_term::scr_swap_overlay ()
3792{ 3759{
3793 if (!ov_text) 3760 if (!ov_text)
3794 return; 3761 return;
3795 3762
3796 int row_offset = ov_y + saveLines - view_start;
3797
3798 // swap screen mem with overlay 3763 // swap screen mem with overlay
3799 for (int y = ov_h; y--; ) 3764 for (int y = ov_h; y--; )
3800 { 3765 {
3801 text_t *t1 = ov_text[y]; 3766 text_t *t1 = ov_text[y];
3802 rend_t *r1 = ov_rend[y]; 3767 rend_t *r1 = ov_rend[y];
3803 3768
3804 text_t *t2 = save[y + row_offset].t + ov_x; 3769 text_t *t2 = ROW(y - view_start).t + ov_x;
3805 rend_t *r2 = save[y + row_offset].r + ov_x; 3770 rend_t *r2 = ROW(y - view_start).r + ov_x;
3806 3771
3807 for (int x = ov_w; x--; ) 3772 for (int x = ov_w; x--; )
3808 { 3773 {
3809 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3774 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3810 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3775 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));
3812 } 3777 }
3813} 3778}
3814 3779
3815#endif 3780#endif
3816/* ------------------------------------------------------------------------- */ 3781/* ------------------------------------------------------------------------- */
3782

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines