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.7 by pcg, Tue Dec 16 23:04:13 2003 UTC vs.
Revision 1.19 by pcg, Thu Jan 29 23:26:01 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.c
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * $Id: screen.C,v 1.7 2003/12/16 23:04:13 pcg Exp $
5 * 4 *
6 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
7 * 6 *
8 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
31#include <X11/Xmd.h> /* get the typedef for CARD32 */ 30#include <X11/Xmd.h> /* get the typedef for CARD32 */
32 31
33#include <stdint.h> 32#include <stdint.h>
34#include <wchar.h> 33#include <wchar.h>
35 34
35#include "salloc.C" // HACK!!
36
36inline void fill_text (text_t *start, text_t value, int len) 37inline void fill_text (text_t *start, text_t value, int len)
37{ 38{
38 while (len--) 39 while (len--)
39 *start++ = value; 40 *start++ = value;
40} 41}
87/* 88/*
88 * CLEAR_ROWS : clear <num> rows starting from row <row> 89 * CLEAR_ROWS : clear <num> rows starting from row <row>
89 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 90 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
90 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour 91 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
91 */ 92 */
92#define drawBuffer (R->TermWin.vt) 93#define drawBuffer TermWin.vt
93 94
94#define CLEAR_ROWS(row, num) \ 95#define CLEAR_ROWS(row, num) \
95 if (R->TermWin.mapped) \ 96 if (TermWin.mapped) \
96 XClearArea(R->Xdisplay, drawBuffer, R->TermWin.int_bwidth, \ 97 XClearArea (Xdisplay, drawBuffer, TermWin.int_bwidth, \
97 Row2Pixel(row), (unsigned int)R->TermWin.width, \ 98 Row2Pixel(row), (unsigned int)TermWin.width, \
98 (unsigned int)Height2Pixel(num), False) 99 (unsigned int)Height2Pixel(num), False)
99 100
100#define CLEAR_CHARS(x, y, num) \ 101#define CLEAR_CHARS(x, y, num) \
101 if (R->TermWin.mapped) \ 102 if (TermWin.mapped) \
102 XClearArea(R->Xdisplay, drawBuffer, x, y, \ 103 XClearArea (Xdisplay, drawBuffer, x, y, \
103 (unsigned int)Width2Pixel(num), \ 104 (unsigned int)Width2Pixel(num), \
104 (unsigned int)Height2Pixel(1), False) 105 (unsigned int)Height2Pixel(1), False)
105 106
106#define ERASE_ROWS(row, num) \ 107#define ERASE_ROWS(row, num) \
107 XFillRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, \ 108 XFillRectangle (Xdisplay, drawBuffer, TermWin.gc, \
108 R->TermWin.int_bwidth, Row2Pixel(row), \ 109 TermWin.int_bwidth, Row2Pixel(row), \
109 (unsigned int)R->TermWin.width, \ 110 (unsigned int)TermWin.width, \
110 (unsigned int)Height2Pixel(num)) 111 (unsigned int)Height2Pixel(num))
111 112
112/* ------------------------------------------------------------------------- * 113/* ------------------------------------------------------------------------- *
113 * SCREEN `COMMON' ROUTINES * 114 * SCREEN `COMMON' ROUTINES *
114 * ------------------------------------------------------------------------- */ 115 * ------------------------------------------------------------------------- */
115/* Fill part/all of a line with blanks. */ 116/* Fill part/all of a line with blanks. */
116/* INTPROTO */
117void 117void
118rxvt_blank_line(pR_ text_t *et, rend_t *er, unsigned int width, rend_t efs) 118rxvt_term::scr_blank_line (text_t *et, rend_t *er, unsigned int width, rend_t efs)
119{ 119{
120 efs &= ~RS_baseattrMask; 120 efs &= ~RS_baseattrMask;
121 efs = SET_FONT (efs, R->TermWin.fontset->find_font (' ')); 121 efs = SET_FONT (efs, TermWin.fontset->find_font (' '));
122 122
123 while (width--) 123 while (width--)
124 { 124 {
125 *et++ = ' '; 125 *et++ = ' ';
126 *er++ = efs; 126 *er++ = efs;
127 } 127 }
128} 128}
129 129
130/* ------------------------------------------------------------------------- */ 130/* ------------------------------------------------------------------------- */
131/* Fill a full line with blanks - make sure it is allocated first */ 131/* Fill a full line with blanks - make sure it is allocated first */
132/* INTPROTO */
133void 132void
134rxvt_blank_screen_mem(pR_ text_t **tp, rend_t **rp, unsigned int row, rend_t efs) 133rxvt_term::scr_blank_screen_mem (text_t **tp, rend_t **rp, unsigned int row, rend_t efs)
135{ 134{
136 int width = R->TermWin.ncol;
137 rend_t *er;
138
139#ifdef DEBUG_STRICT 135#ifdef DEBUG_STRICT
140 assert((tp[row] && rp[row]) || (tp[row] == NULL && rp[row] == NULL)); 136 assert((tp[row] && rp[row]) || (tp[row] == NULL && rp[row] == NULL));
141#endif 137#endif
142 if (tp[row] == NULL) { 138 if (tp[row] == NULL)
143 tp[row] = (text_t *)rxvt_malloc(sizeof(text_t) * width);
144 rp[row] = (rend_t *)rxvt_malloc(sizeof(rend_t) * width);
145 } 139 {
140 tp[row] = (text_t *)talloc->alloc ();
141 rp[row] = (rend_t *)ralloc->alloc ();
142 }
143
146 rxvt_blank_line (aR_ tp[row], rp[row], width, efs); 144 scr_blank_line (tp[row], rp[row], TermWin.ncol, efs);
147} 145}
148 146
149/* ------------------------------------------------------------------------- * 147/* ------------------------------------------------------------------------- *
150 * SCREEN INITIALISATION * 148 * SCREEN INITIALISATION *
151 * ------------------------------------------------------------------------- */ 149 * ------------------------------------------------------------------------- */
152/* EXTPROTO */
153void 150void
154rxvt_scr_reset(pR) 151rxvt_term::scr_reset ()
155{ 152{
156 unsigned int ncol, nrow, prev_ncol, prev_nrow, 153 unsigned int ncol, nrow, total_rows, prev_total_rows;
157 total_rows, prev_total_rows;
158 unsigned int p, q; 154 unsigned int p, q;
159 int k; 155 int k;
160 rend_t setrstyle; 156 rend_t setrstyle;
161 157
162 D_SCREEN((stderr, "rxvt_scr_reset()")); 158 D_SCREEN((stderr, "rxvt_scr_reset()"));
163 159
164 R->TermWin.view_start = 0; 160 TermWin.view_start = 0;
165 R->num_scr = 0; 161 num_scr = 0;
166 162
167 prev_ncol = R->prev_ncol;
168 prev_nrow = R->prev_nrow;
169 if (R->TermWin.ncol == 0) 163 if (TermWin.ncol == 0)
170 R->TermWin.ncol = 80; 164 TermWin.ncol = 80;
165
171 if (R->TermWin.nrow == 0) 166 if (TermWin.nrow == 0)
172 R->TermWin.nrow = 24; 167 TermWin.nrow = 24;
168
173 ncol = R->TermWin.ncol; 169 ncol = TermWin.ncol;
174 nrow = R->TermWin.nrow; 170 nrow = TermWin.nrow;
171
175 if (ncol == prev_ncol && nrow == prev_nrow) 172 if (ncol == prev_ncol && nrow == prev_nrow)
176 return; 173 return;
177 174
178 R->want_refresh = 1; 175 want_refresh = 1;
179 176
180 total_rows = nrow + R->TermWin.saveLines; 177 total_rows = nrow + TermWin.saveLines;
181 prev_total_rows = prev_nrow + R->TermWin.saveLines; 178 prev_total_rows = prev_nrow + TermWin.saveLines;
182 179
183 R->screen.tscroll = 0; 180 screen.tscroll = 0;
184 R->screen.bscroll = nrow - 1; 181 screen.bscroll = nrow - 1;
185 182
183 if (!talloc)
184 {
185 talloc = new rxvt_salloc (ncol * sizeof (text_t));
186 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
187 }
188
186 if (prev_nrow == 0) { 189 if (prev_nrow == 0)
187/* 190 {
191 /*
188 * A: first time called so just malloc everything : don't rely on realloc 192 * first time called so just malloc everything : don't rely on realloc
189 * Note: this is still needed so that all the scrollback lines are NULL 193 * Note: this is still needed so that all the scrollback lines are NULL
190 */ 194 */
191 R->screen.text = (text_t **)rxvt_calloc(total_rows, sizeof(text_t *)); 195 screen.text = (text_t **)rxvt_calloc(total_rows, sizeof(text_t *));
192 R->buf_text = (text_t **)rxvt_calloc(total_rows, sizeof(text_t *)); 196 buf_text = (text_t **)rxvt_calloc(total_rows, sizeof(text_t *));
193 R->drawn_text = (text_t **)rxvt_calloc(nrow, sizeof(text_t *)); 197 drawn_text = (text_t **)rxvt_calloc(nrow, sizeof(text_t *));
194 R->swap.text = (text_t **)rxvt_calloc(nrow, sizeof(text_t *)); 198 swap.text = (text_t **)rxvt_calloc(nrow, sizeof(text_t *));
195 199
196 R->screen.tlen = (int16_t *)rxvt_calloc(total_rows, sizeof(int16_t)); 200 screen.tlen = (int16_t *)rxvt_calloc(total_rows, sizeof(int16_t));
197 R->swap.tlen = (int16_t *)rxvt_calloc(nrow, sizeof(int16_t)); 201 swap.tlen = (int16_t *)rxvt_calloc(nrow, sizeof(int16_t));
198 202
199 R->screen.rend = (rend_t **)rxvt_calloc(total_rows, sizeof(rend_t *)); 203 screen.rend = (rend_t **)rxvt_calloc(total_rows, sizeof(rend_t *));
200 R->buf_rend = (rend_t **)rxvt_calloc(total_rows, sizeof(rend_t *)); 204 buf_rend = (rend_t **)rxvt_calloc(total_rows, sizeof(rend_t *));
201 R->drawn_rend = (rend_t **)rxvt_calloc(nrow, sizeof(rend_t *)); 205 drawn_rend = (rend_t **)rxvt_calloc(nrow, sizeof(rend_t *));
202 R->swap.rend = (rend_t **)rxvt_calloc(nrow, sizeof(rend_t *)); 206 swap.rend = (rend_t **)rxvt_calloc(nrow, sizeof(rend_t *));
203 207
204 for (p = 0; p < nrow; p++) { 208 for (p = 0; p < nrow; p++)
209 {
205 q = p + R->TermWin.saveLines; 210 q = p + TermWin.saveLines;
206 rxvt_blank_screen_mem(aR_ R->screen.text, R->screen.rend, 211 scr_blank_screen_mem (screen.text, screen.rend, q, DEFAULT_RSTYLE);
207 q, DEFAULT_RSTYLE); 212 scr_blank_screen_mem (swap.text, swap.rend, p, DEFAULT_RSTYLE);
208 rxvt_blank_screen_mem(aR_ R->swap.text, R->swap.rend,
209 p, DEFAULT_RSTYLE);
210 R->screen.tlen[q] = R->swap.tlen[p] = 0; 213 screen.tlen[q] = swap.tlen[p] = 0;
211 rxvt_blank_screen_mem(aR_ R->drawn_text, R->drawn_rend, 214 scr_blank_screen_mem (drawn_text, drawn_rend, p, DEFAULT_RSTYLE);
212 p, DEFAULT_RSTYLE);
213 } 215 }
216
214 MEMSET(R->charsets, 'B', sizeof(R->charsets)); 217 MEMSET(charsets, 'B', sizeof(charsets));
215 R->TermWin.nscrolled = 0; /* no saved lines */ 218 TermWin.nscrolled = 0; /* no saved lines */
216 R->rstyle = DEFAULT_RSTYLE; 219 rstyle = DEFAULT_RSTYLE;
217 R->screen.flags = Screen_DefaultFlags; 220 screen.flags = Screen_DefaultFlags;
218 R->screen.cur.row = R->screen.cur.col = 0; 221 screen.cur.row = screen.cur.col = 0;
219 R->screen.charset = 0; 222 screen.charset = 0;
220 R->current_screen = PRIMARY; 223 current_screen = PRIMARY;
221 rxvt_scr_cursor(aR_ SAVE); 224 rxvt_scr_cursor (this, SAVE);
225
222#if NSCREENS 226#if NSCREENS
223 R->swap.flags = Screen_DefaultFlags; 227 swap.flags = Screen_DefaultFlags;
224 R->swap.cur.row = R->swap.cur.col = 0; 228 swap.cur.row = swap.cur.col = 0;
225 R->swap.charset = 0; 229 swap.charset = 0;
226 R->current_screen = SECONDARY; 230 current_screen = SECONDARY;
227 rxvt_scr_cursor(aR_ SAVE); 231 rxvt_scr_cursor (this, SAVE);
228 R->current_screen = PRIMARY; 232 current_screen = PRIMARY;
229#endif 233#endif
234
230 R->selection.text = NULL; 235 selection.text = NULL;
231 R->selection.len = 0; 236 selection.len = 0;
232 R->selection.op = SELECTION_CLEAR; 237 selection.op = SELECTION_CLEAR;
233 R->selection.screen = PRIMARY; 238 selection.screen = PRIMARY;
234 R->selection.clicks = 0; 239 selection.clicks = 0;
235 CLEAR_ALL_SELECTION(R); 240 CLEAR_ALL_SELECTION (this);
236 R->rvideo = 0; 241 rvideo = 0;
237 242 }
238 } else { 243 else
239/* 244 {
245 /*
240 * B1: add or delete rows as appropriate 246 * add or delete rows as appropriate
241 */ 247 */
242 setrstyle = DEFAULT_RSTYLE; 248 setrstyle = DEFAULT_RSTYLE;
243 249
244 if (nrow < prev_nrow) { 250 if (nrow < prev_nrow)
251 {
245 /* delete rows */ 252 /* delete rows */
246 k = min(R->TermWin.nscrolled, prev_nrow - nrow); 253 k = min (TermWin.nscrolled, prev_nrow - nrow);
247 rxvt_scroll_text(aR_ 0, (int)prev_nrow - 1, k, 1); 254 scr_scroll_text (0, (int)prev_nrow - 1, k, 1);
255
248 for (p = nrow; p < prev_nrow; p++) { 256 for (p = nrow; p < prev_nrow; p++)
257 {
249 q = p + R->TermWin.saveLines; 258 q = p + TermWin.saveLines;
250 if (R->screen.text[q]) { 259 if (screen.text[q])
260 {
251#ifdef DEBUG_STRICT 261#ifdef DEBUG_STRICT
252 assert(R->screen.rend[q]); 262 assert (screen.rend[q]);
253#endif 263#endif
254 free(R->screen.text[q]); 264 talloc->free (screen.text[q]);
255 free(R->screen.rend[q]); 265 ralloc->free (screen.rend[q]);
256 } 266 }
257 if (R->swap.text[p]) { 267 if (swap.text[p])
268 {
258#ifdef DEBUG_STRICT 269#ifdef DEBUG_STRICT
259 assert(R->swap.rend[p]); 270 assert (swap.rend[p]);
260#endif 271#endif
261 free(R->swap.text[p]); 272 talloc->free (swap.text[p]);
262 free(R->swap.rend[p]); 273 ralloc->free (swap.rend[p]);
263 } 274 }
264#ifdef DEBUG_STRICT 275#ifdef DEBUG_STRICT
265 assert(R->drawn_text[p] && R->drawn_rend[p]); 276 assert (drawn_text[p] && drawn_rend[p]);
266#endif 277#endif
267 free(R->drawn_text[p]); 278 talloc->free (drawn_text[p]);
268 free(R->drawn_rend[p]); 279 ralloc->free (drawn_rend[p]);
269 } 280 }
281
270 /* we have fewer rows so fix up cursor position */ 282 /* we have fewer rows so fix up cursor position */
271 MIN_IT(R->screen.cur.row, (int32_t)nrow - 1); 283 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
272 MIN_IT(R->swap.cur.row, (int32_t)nrow - 1); 284 MIN_IT (swap.cur.row, (int32_t)nrow - 1);
273 285
274 rxvt_scr_reset_realloc(aR); /* realloc _last_ */ 286 scr_reset_realloc (); /* realloc _last_ */
275 287 }
276 } else if (nrow > prev_nrow) { 288 else if (nrow > prev_nrow)
289 {
277 /* add rows */ 290 /* add rows */
278 rxvt_scr_reset_realloc(aR); /* realloc _first_ */ 291 scr_reset_realloc (); /* realloc _first_ */
279 292
293 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
294
280 k = min(R->TermWin.nscrolled, nrow - prev_nrow); 295 k = min (TermWin.nscrolled, nrow - prev_nrow);
296
281 for (p = prev_total_rows; p < total_rows; p++) { 297 for (p = prev_total_rows; p < total_rows; p++)
298 {
282 R->screen.tlen[p] = 0; 299 screen.tlen[p] = 0;
283 R->screen.text[p] = NULL; 300 screen.text[p] = NULL;
284 R->screen.rend[p] = NULL; 301 screen.rend[p] = NULL;
285 } 302 }
303
286 for (p = prev_total_rows; p < total_rows - k; p++) 304 for (p = prev_total_rows; p < total_rows - k; p++)
287 rxvt_blank_screen_mem(aR_ R->screen.text, R->screen.rend, 305 scr_blank_screen_mem (screen.text, screen.rend, p, setrstyle);
288 p, setrstyle); 306
289 for (p = prev_nrow; p < nrow; p++) { 307 for (p = prev_nrow; p < nrow; p++)
308 {
290 R->swap.tlen[p] = 0; 309 swap.tlen[p] = 0;
291 R->swap.text[p] = NULL; 310 swap.text[p] = NULL;
292 R->swap.rend[p] = NULL; 311 swap.rend[p] = NULL;
293 R->drawn_text[p] = NULL; 312 drawn_text[p] = NULL;
294 R->drawn_rend[p] = NULL; 313 drawn_rend[p] = NULL;
295 rxvt_blank_screen_mem(aR_ R->swap.text, R->swap.rend, 314 scr_blank_screen_mem (swap.text, swap.rend, p, setrstyle);
296 p, setrstyle);
297 rxvt_blank_screen_mem(aR_ R->drawn_text, R->drawn_rend, 315 scr_blank_screen_mem (drawn_text, drawn_rend, p, setrstyle);
298 p, setrstyle);
299 } 316 }
317
300 if (k > 0) { 318 if (k > 0)
319 {
301 rxvt_scroll_text(aR_ 0, (int)nrow - 1, -k, 1); 320 scr_scroll_text (0, (int)nrow - 1, -k, 1);
302 R->screen.cur.row += k; 321 screen.cur.row += k;
303 R->screen.s_cur.row += k; 322 screen.s_cur.row += k;
304 R->TermWin.nscrolled -= k; 323 TermWin.nscrolled -= k;
305 } 324 }
306#ifdef DEBUG_STRICT 325#ifdef DEBUG_STRICT
307 assert(R->screen.cur.row < R->TermWin.nrow); 326 assert(screen.cur.row < TermWin.nrow);
308 assert(R->swap.cur.row < R->TermWin.nrow); 327 assert(swap.cur.row < TermWin.nrow);
309#else /* drive with your eyes closed */ 328#else /* drive with your eyes closed */
329
310 MIN_IT(R->screen.cur.row, nrow - 1); 330 MIN_IT(screen.cur.row, nrow - 1);
311 MIN_IT(R->swap.cur.row, nrow - 1); 331 MIN_IT(swap.cur.row, nrow - 1);
312#endif 332#endif
333 TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this
313 } 334 }
335
314/* B2: resize columns */ 336 /* resize columns */
315 if (ncol != prev_ncol) { 337 if (ncol != prev_ncol)
338 {
339 int common = min (prev_ncol, ncol);
340 rxvt_salloc *ta = new rxvt_salloc (ncol * sizeof (text_t));
341 rxvt_salloc *ra = new rxvt_salloc (ncol * sizeof (rend_t));
342
316 for (p = 0; p < total_rows; p++) { 343 for (p = 0; p < total_rows; p++)
344 {
317 if (R->screen.text[p]) { 345 if (screen.text[p])
318 R->screen.text[p] = (text_t *)rxvt_realloc(R->screen.text[p], ncol * sizeof(text_t)); 346 {
319 R->screen.rend[p] = (rend_t *)rxvt_realloc(R->screen.rend[p], ncol * sizeof(rend_t)); 347 text_t *t = (text_t *)ta->alloc (); memcpy (t, screen.text[p], common * sizeof (text_t)); screen.text[p] = t;
348 rend_t *r = (rend_t *)ra->alloc (); memcpy (r, screen.rend[p], common * sizeof (rend_t)); screen.rend[p] = r;
349
320 MIN_IT(R->screen.tlen[p], (int16_t)ncol); 350 MIN_IT(screen.tlen[p], (int16_t)ncol);
351
321 if (ncol > prev_ncol) 352 if (ncol > prev_ncol)
322 rxvt_blank_line(aR_ 353 scr_blank_line (&(screen.text[p][prev_ncol]),
323 &(R->screen.text[p][prev_ncol]),
324 &(R->screen.rend[p][prev_ncol]), 354 &(screen.rend[p][prev_ncol]),
325 ncol - prev_ncol, 355 ncol - prev_ncol,
326 setrstyle); 356 setrstyle);
327 } 357 }
328 } 358 }
359
329 for (p = 0; p < nrow; p++) { 360 for (p = 0; p < nrow; p++)
330 R->drawn_text[p] = (text_t *)rxvt_realloc(R->drawn_text[p], ncol * sizeof(text_t)); 361 {
331 R->drawn_rend[p] = (rend_t *)rxvt_realloc(R->drawn_rend[p], ncol * sizeof(rend_t)); 362 text_t *t = (text_t *)ta->alloc (); memcpy (t, drawn_text[p], common * sizeof (text_t)); drawn_text[p] = t;
363 rend_t *r = (rend_t *)ra->alloc (); memcpy (r, drawn_rend[p], common * sizeof (rend_t)); drawn_rend[p] = r;
364
365 if (ncol > prev_ncol)
366 scr_blank_line (&(drawn_text[p][prev_ncol]),
367 &(drawn_rend[p][prev_ncol]),
368 ncol - prev_ncol, setrstyle);
369
332 if (R->swap.text[p]) { 370 if (swap.text[p])
333 R->swap.text[p] = (text_t *)rxvt_realloc(R->swap.text[p], ncol * sizeof(text_t)); 371 {
334 R->swap.rend[p] = (rend_t *)rxvt_realloc(R->swap.rend[p], ncol * sizeof(rend_t)); 372 text_t *t = (text_t *)ta->alloc (); memcpy (t, swap.text[p], common * sizeof (text_t)); swap.text[p] = t;
373 rend_t *r = (rend_t *)ra->alloc (); memcpy (r, swap.rend[p], common * sizeof (rend_t)); swap.rend[p] = r;
374
335 MIN_IT(R->swap.tlen[p], (int16_t)ncol); 375 MIN_IT(swap.tlen[p], (int16_t)ncol);
376
336 if (ncol > prev_ncol) 377 if (ncol > prev_ncol)
337 rxvt_blank_line(aR_ 378 scr_blank_line (&(swap.text[p][prev_ncol]),
338 &(R->swap.text[p][prev_ncol]),
339 &(R->swap.rend[p][prev_ncol]), 379 &(swap.rend[p][prev_ncol]),
340 ncol - prev_ncol, setrstyle); 380 ncol - prev_ncol, setrstyle);
341 } 381 }
342 if (ncol > prev_ncol) 382
343 rxvt_blank_line(aR_
344 &(R->drawn_text[p][prev_ncol]),
345 &(R->drawn_rend[p][prev_ncol]),
346 ncol - prev_ncol, setrstyle);
347 } 383 }
384
348 MIN_IT(R->screen.cur.col, (int16_t)ncol - 1); 385 MIN_IT (screen.cur.col, (int16_t)ncol - 1);
349 MIN_IT(R->swap.cur.col, (int16_t)ncol - 1); 386 MIN_IT (swap.cur.col, (int16_t)ncol - 1);
387
388 delete talloc; talloc = ta;
389 delete ralloc; ralloc = ra;
350 } 390 }
391
351 if (R->tabs) 392 if (tabs)
352 free(R->tabs); 393 free(tabs);
353 } 394 }
354 395
396 prev_nrow = nrow;
397 prev_ncol = ncol;
398
355 R->tabs = (char *)rxvt_malloc(ncol * sizeof(char)); 399 tabs = (char *)rxvt_malloc (ncol * sizeof(char));
356 400
357 for (p = 0; p < ncol; p++) 401 for (p = 0; p < ncol; p++)
358 R->tabs[p] = (p % TABSIZE == 0) ? 1 : 0; 402 tabs[p] = (p % TABSIZE == 0) ? 1 : 0;
359 403
360 R->prev_nrow = nrow;
361 R->prev_ncol = ncol;
362
363 R->tt_winch (); 404 tt_winch ();
364} 405}
365 406
366/* INTPROTO */
367void 407void
368rxvt_scr_reset_realloc(pR) 408rxvt_term::scr_reset_realloc()
369{ 409{
370 uint16_t total_rows, nrow; 410 uint16_t total_rows, nrow;
371 411
372 nrow = R->TermWin.nrow; 412 nrow = TermWin.nrow;
373 total_rows = nrow + R->TermWin.saveLines; 413 total_rows = nrow + TermWin.saveLines;
374/* *INDENT-OFF* */ 414 /* *INDENT-OFF* */
375 R->screen.text = (text_t **)rxvt_realloc(R->screen.text, total_rows * sizeof(text_t *)); 415 screen.text = (text_t **)rxvt_realloc(screen.text, total_rows * sizeof(text_t *));
376 R->buf_text = (text_t **)rxvt_realloc(R->buf_text , total_rows * sizeof(text_t *)); 416 buf_text = (text_t **)rxvt_realloc(buf_text , total_rows * sizeof(text_t *));
377 R->drawn_text = (text_t **)rxvt_realloc(R->drawn_text , nrow * sizeof(text_t *)); 417 drawn_text = (text_t **)rxvt_realloc(drawn_text , nrow * sizeof(text_t *));
378 R->swap.text = (text_t **)rxvt_realloc(R->swap.text , nrow * sizeof(text_t *)); 418 swap.text = (text_t **)rxvt_realloc(swap.text , nrow * sizeof(text_t *));
379 419
380 R->screen.tlen = (int16_t *)rxvt_realloc(R->screen.tlen, total_rows * sizeof(int16_t)); 420 screen.tlen = (int16_t *)rxvt_realloc(screen.tlen, total_rows * sizeof(int16_t));
381 R->swap.tlen = (int16_t *)rxvt_realloc(R->swap.tlen , total_rows * sizeof(int16_t)); 421 swap.tlen = (int16_t *)rxvt_realloc(swap.tlen , total_rows * sizeof(int16_t));
382 422
383 R->screen.rend = (rend_t **)rxvt_realloc(R->screen.rend, total_rows * sizeof(rend_t *)); 423 screen.rend = (rend_t **)rxvt_realloc(screen.rend, total_rows * sizeof(rend_t *));
384 R->buf_rend = (rend_t **)rxvt_realloc(R->buf_rend , total_rows * sizeof(rend_t *)); 424 buf_rend = (rend_t **)rxvt_realloc(buf_rend , total_rows * sizeof(rend_t *));
385 R->drawn_rend = (rend_t **)rxvt_realloc(R->drawn_rend , nrow * sizeof(rend_t *)); 425 drawn_rend = (rend_t **)rxvt_realloc(drawn_rend , nrow * sizeof(rend_t *));
386 R->swap.rend = (rend_t **)rxvt_realloc(R->swap.rend , nrow * sizeof(rend_t *)); 426 swap.rend = (rend_t **)rxvt_realloc(swap.rend , nrow * sizeof(rend_t *));
387/* *INDENT-ON* */ 427 /* *INDENT-ON* */
388} 428}
389 429
390/* ------------------------------------------------------------------------- */ 430/* ------------------------------------------------------------------------- */
391/* 431/*
392 * Free everything. That way malloc debugging can find leakage. 432 * Free everything. That way malloc debugging can find leakage.
393 */ 433 */
394/* EXTPROTO */
395void 434void
396rxvt_scr_release(pR) 435rxvt_term::scr_release()
397{ 436{
398 uint16_t total_rows; 437 uint16_t total_rows;
399 int i; 438 int i;
400 439
401 total_rows = R->TermWin.nrow + R->TermWin.saveLines; 440 total_rows = TermWin.nrow + TermWin.saveLines;
402 for (i = 0; i < total_rows; i++) { 441
403 if (R->screen.text[i]) { /* then so is R->screen.rend[i] */
404 free(R->screen.text[i]);
405#ifdef DEBUG_STRICT 442#ifdef DEBUG_STRICT
443 for (i = 0; i < total_rows; i++)
444 {
445 if (screen.text[i])
446 /* then so is screen.rend[i] */
406 assert(R->screen.rend[i]); 447 assert(screen.rend[i]);
407#endif
408 free(R->screen.rend[i]);
409 }
410 } 448 }
411 for (i = 0; i < R->TermWin.nrow; i++) { 449#endif
412 free(R->drawn_text[i]); 450
413 free(R->drawn_rend[i]); 451 delete talloc; talloc = 0;
414 free(R->swap.text[i]); 452 delete ralloc; ralloc = 0;
415 free(R->swap.rend[i]); 453
416 }
417 free(R->screen.text); 454 free (screen.text);
418 free(R->screen.tlen); 455 free (screen.tlen);
419 free(R->screen.rend); 456 free (screen.rend);
420 free(R->drawn_text); 457 free (drawn_text);
421 free(R->drawn_rend); 458 free (drawn_rend);
422 free(R->swap.text); 459 free (swap.text);
423 free(R->swap.tlen); 460 free (swap.tlen);
424 free(R->swap.rend); 461 free (swap.rend);
425 free(R->buf_text); 462 free (buf_text);
426 free(R->buf_rend); 463 free (buf_rend);
427 free(R->tabs); 464 free (tabs);
428 465
429/* NULL these so if anything tries to use them, we'll know about it */ 466 /* NULL these so if anything tries to use them, we'll know about it */
430 R->screen.text = R->drawn_text = R->swap.text = NULL; 467 screen.text = drawn_text = swap.text = NULL;
431 R->screen.rend = R->drawn_rend = R->swap.rend = NULL; 468 screen.rend = drawn_rend = swap.rend = NULL;
432 R->screen.tlen = R->swap.tlen = NULL; 469 screen.tlen = swap.tlen = NULL;
433 R->buf_text = NULL; 470 buf_text = NULL;
434 R->buf_rend = NULL; 471 buf_rend = NULL;
435 R->tabs = NULL; 472 tabs = NULL;
436} 473}
437 474
438/* ------------------------------------------------------------------------- */ 475/* ------------------------------------------------------------------------- */
439/* 476/*
440 * Hard reset 477 * Hard reset
441 */ 478 */
442/* EXTPROTO */ 479/* EXTPROTO */
443void 480void
444rxvt_scr_poweron(pR) 481rxvt_scr_poweron(pR)
445{ 482{
446 D_SCREEN((stderr, "rxvt_scr_poweron()")); 483 D_SCREEN((stderr, "rxvt_scr_poweron()"));
447 484
448 rxvt_scr_release(aR); 485 R->scr_release ();
449 R->prev_nrow = R->prev_ncol = 0; 486 R->prev_nrow = R->prev_ncol = 0;
450 rxvt_scr_reset(aR); 487 R->scr_reset ();
451 488
452 rxvt_scr_clear(aR); 489 R->scr_clear ();
453 rxvt_scr_refresh(aR_ SLOW_REFRESH); 490 R->scr_refresh (SLOW_REFRESH);
454#ifdef RXVT_GRAPHICS 491#ifdef RXVT_GRAPHICS
455 rxvt_Gr_reset(aR); 492 rxvt_Gr_reset (aR);
456#endif 493#endif
457} 494}
458 495
459/* ------------------------------------------------------------------------- * 496/* ------------------------------------------------------------------------- *
460 * PROCESS SCREEN COMMANDS * 497 * PROCESS SCREEN COMMANDS *
576 if (R->current_screen == PRIMARY 613 if (R->current_screen == PRIMARY
577# ifdef RXVT_GRAPHICS 614# ifdef RXVT_GRAPHICS
578 && !rxvt_Gr_Displayed(aR) 615 && !rxvt_Gr_Displayed(aR)
579# endif 616# endif
580 ) 617 )
581 rxvt_scroll_text(aR_ 0, (R->prev_nrow - 1), R->prev_nrow, 0); 618 R->scr_scroll_text(0, (R->prev_nrow - 1), R->prev_nrow, 0);
582# endif 619# endif
583#endif 620#endif
584 return scrn; 621 return scrn;
585} 622}
586 623
620 * Scroll text between <row1> and <row2> inclusive, by <count> lines 657 * Scroll text between <row1> and <row2> inclusive, by <count> lines
621 * count positive ==> scroll up 658 * count positive ==> scroll up
622 * count negative ==> scroll down 659 * count negative ==> scroll down
623 * spec == 0 for normal routines 660 * spec == 0 for normal routines
624 */ 661 */
625/* EXTPROTO */
626int 662int
627rxvt_scroll_text(pR_ int row1, int row2, int count, int spec) 663rxvt_term::scr_scroll_text (int row1, int row2, int count, int spec)
628{ 664{
629 int i, j; 665 int i, j;
630 long nscrolled; 666 long nscrolled;
631 667
632 if (count == 0 || (row1 > row2)) 668 if (count == 0 || (row1 > row2))
633 return 0; 669 return 0;
634 670
635 R->want_refresh = 1; 671 want_refresh = 1;
636 D_SCREEN((stderr, "rxvt_scroll_text(%d,%d,%d,%d): %s", row1, row2, count, spec, (R->current_screen == PRIMARY) ? "Primary" : "Secondary")); 672 D_SCREEN((stderr, "rxvt_scroll_text(%d,%d,%d,%d): %s", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary"));
637 673
638 if ((count > 0) && (row1 == 0) && (R->current_screen == PRIMARY)) { 674 if ((count > 0) && (row1 == 0) && (current_screen == PRIMARY))
675 {
639 nscrolled = (long)R->TermWin.nscrolled + (long)count;; 676 nscrolled = (long)TermWin.nscrolled + (long)count;
677
640 if (nscrolled > (long)R->TermWin.saveLines) 678 if (nscrolled > (long)TermWin.saveLines)
641 R->TermWin.nscrolled = R->TermWin.saveLines; 679 TermWin.nscrolled = TermWin.saveLines;
642 else 680 else
643 R->TermWin.nscrolled = (uint16_t)nscrolled; 681 TermWin.nscrolled = (uint16_t)nscrolled;
682
644 if ((R->Options & Opt_scrollWithBuffer) 683 if ((Options & Opt_scrollWithBuffer)
645 && R->TermWin.view_start != 0 684 && TermWin.view_start != 0
646 && R->TermWin.view_start != R->TermWin.saveLines) 685 && TermWin.view_start != TermWin.saveLines)
647 rxvt_scr_page(aR_ UP, count); 686 rxvt_scr_page (this, UP, count);
687 }
648 } else if (!spec) 688 else if (!spec)
649 row1 += R->TermWin.saveLines;
650 row2 += R->TermWin.saveLines; 689 row1 += TermWin.saveLines;
651 690
691 row2 += TermWin.saveLines;
692
652 if (R->selection.op && R->current_screen == R->selection.screen) { 693 if (selection.op && current_screen == selection.screen)
694 {
653 i = R->selection.beg.row + R->TermWin.saveLines; 695 i = selection.beg.row + TermWin.saveLines;
654 j = R->selection.end.row + R->TermWin.saveLines; 696 j = selection.end.row + TermWin.saveLines;
655 if ((i < row1 && j > row1) 697 if ((i < row1 && j > row1)
656 || (i < row2 && j > row2) 698 || (i < row2 && j > row2)
657 || (i - count < row1 && i >= row1) 699 || (i - count < row1 && i >= row1)
658 || (i - count > row2 && i <= row2) 700 || (i - count > row2 && i <= row2)
659 || (j - count < row1 && j >= row1) 701 || (j - count < row1 && j >= row1)
660 || (j - count > row2 && j <= row2)) { 702 || (j - count > row2 && j <= row2))
703 {
661 CLEAR_ALL_SELECTION(R); 704 CLEAR_ALL_SELECTION (this);
662 R->selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 705 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */
706 }
663 } else if (j >= row1 && j <= row2) { 707 else if (j >= row1 && j <= row2)
708 {
664 /* move selected region too */ 709 /* move selected region too */
665 R->selection.beg.row -= count; 710 selection.beg.row -= count;
666 R->selection.end.row -= count; 711 selection.end.row -= count;
667 R->selection.mark.row -= count; 712 selection.mark.row -= count;
668 } 713 }
669 } 714 }
715
670 rxvt_selection_check(aR_ 0); /* _after_ R->TermWin.nscrolled update */ 716 rxvt_selection_check (this, 0); /* _after_ TermWin.nscrolled update */
671 717
672 R->num_scr += count; 718 num_scr += count;
673 j = count; 719 j = count;
720
674 if (count < 0) 721 if (count < 0)
675 count = -count; 722 count = -count;
723
676 i = row2 - row1 + 1; 724 i = row2 - row1 + 1;
677 MIN_IT(count, i); 725 MIN_IT(count, i);
678 726
679 if (j > 0) { 727 if (j > 0)
728 {
680/* A: scroll up */ 729 /* A: scroll up */
681 730
682/* A1: Copy lines that will get clobbered by the rotation */ 731 /* A1: Copy lines that will get clobbered by the rotation */
683 for (i = 0, j = row1; i < count; i++, j++) { 732 for (i = 0, j = row1; i < count; i++, j++)
733 {
684 R->buf_text[i] = R->screen.text[j]; 734 buf_text[i] = screen.text[j];
685 R->buf_rend[i] = R->screen.rend[j]; 735 buf_rend[i] = screen.rend[j];
686 } 736 }
687/* A2: Rotate lines */ 737 /* A2: Rotate lines */
688 for (j = row1, i = j + count; i <= row2; i++, j++) { 738 for (j = row1, i = j + count; i <= row2; i++, j++)
739 {
689 R->screen.tlen[j] = R->screen.tlen[i]; 740 screen.tlen[j] = screen.tlen[i];
690 R->screen.text[j] = R->screen.text[i]; 741 screen.text[j] = screen.text[i];
691 R->screen.rend[j] = R->screen.rend[i]; 742 screen.rend[j] = screen.rend[i];
692 } 743 }
693 j = row2 - count + 1, i = count; 744 j = row2 - count + 1, i = count;
745 }
694 } else /* if (j < 0) */ { 746 else /* if (j < 0) */
747 {
695/* B: scroll down */ 748 /* B: scroll down */
696 749
697/* B1: Copy lines that will get clobbered by the rotation */ 750 /* B1: Copy lines that will get clobbered by the rotation */
698 for (i = 0, j = row2; i < count; i++, j--) { 751 for (i = 0, j = row2; i < count; i++, j--)
752 {
699 R->buf_text[i] = R->screen.text[j]; 753 buf_text[i] = screen.text[j];
700 R->buf_rend[i] = R->screen.rend[j]; 754 buf_rend[i] = screen.rend[j];
701 } 755 }
702/* B2: Rotate lines */ 756 /* B2: Rotate lines */
703 for (j = row2, i = j - count; i >= row1; i--, j--) { 757 for (j = row2, i = j - count; i >= row1; i--, j--)
758 {
704 R->screen.tlen[j] = R->screen.tlen[i]; 759 screen.tlen[j] = screen.tlen[i];
705 R->screen.text[j] = R->screen.text[i]; 760 screen.text[j] = screen.text[i];
706 R->screen.rend[j] = R->screen.rend[i]; 761 screen.rend[j] = screen.rend[i];
707 } 762 }
708 j = row1, i = count; 763 j = row1, i = count;
709 count = -count; 764 count = -count;
710 } 765 }
711 766
712/* C: Resurrect lines */ 767 /* C: Resurrect lines */
713 for (; i--; j++) { 768 for (; i--; j++)
769 {
714 R->screen.tlen[j] = 0; 770 screen.tlen[j] = 0;
715 R->screen.text[j] = R->buf_text[i]; 771 screen.text[j] = buf_text[i];
716 R->screen.rend[j] = R->buf_rend[i]; 772 screen.rend[j] = buf_rend[i];
773
717 if (!spec) /* line length may not equal TermWin.ncol */ 774 if (!spec) /* line length may not equal TermWin.ncol */
718 rxvt_blank_screen_mem(aR_ R->screen.text, R->screen.rend, 775 scr_blank_screen_mem (screen.text, screen.rend,
719 (unsigned int)j, R->rstyle); 776 (unsigned int)j, rstyle);
720 } 777 }
721 778
722#ifdef RXVT_GRAPHICS 779#ifdef RXVT_GRAPHICS
723 if (rxvt_Gr_Displayed(aR)) 780 if (rxvt_Gr_Displayed (this))
724 rxvt_Gr_scroll(aR_ count); 781 rxvt_Gr_scroll(this, count);
725#endif 782#endif
783
726 return count; 784 return count;
727} 785}
728 786
729/* ------------------------------------------------------------------------- */ 787/* ------------------------------------------------------------------------- */
730/* 788/*
731 * Add text given in <str> of length <len> to screen struct 789 * Add text given in <str> of length <len> to screen struct
752 nlines += (R->screen.cur.row - R->screen.bscroll); 810 nlines += (R->screen.cur.row - R->screen.bscroll);
753 if ((nlines > 0) 811 if ((nlines > 0)
754 && (R->screen.tscroll == 0) 812 && (R->screen.tscroll == 0)
755 && (R->screen.bscroll == (R->TermWin.nrow - 1))) { 813 && (R->screen.bscroll == (R->TermWin.nrow - 1))) {
756 /* _at least_ this many lines need to be scrolled */ 814 /* _at least_ this many lines need to be scrolled */
757 rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, nlines, 815 R->scr_scroll_text(R->screen.tscroll, R->screen.bscroll, nlines, 0);
758 0);
759 R->screen.cur.row -= nlines; 816 R->screen.cur.row -= nlines;
760 } 817 }
761 } 818 }
762#ifdef DEBUG_STRICT 819#ifdef DEBUG_STRICT
763 assert(R->screen.cur.col < last_col); 820 assert(R->screen.cur.col < last_col);
779 836
780 for (i = 0; i < len;) { 837 for (i = 0; i < len;) {
781 c = str[i++]; 838 c = str[i++];
782 switch (c) { 839 switch (c) {
783 case '\t': 840 case '\t':
784 rxvt_scr_tab(aR_ 1); 841 rxvt_scr_tab (aR_ 1);
785 continue; 842 continue;
786 case '\n': 843 case '\n':
787 if (R->screen.tlen[row] != -1) /* XXX: think about this */ 844 if (R->screen.tlen[row] != -1) /* XXX: think about this */
788 MAX_IT(R->screen.tlen[row], R->screen.cur.col); 845 MAX_IT(R->screen.tlen[row], R->screen.cur.col);
789 R->screen.flags &= ~Screen_WrapNext; 846 R->screen.flags &= ~Screen_WrapNext;
790 if (R->screen.cur.row == R->screen.bscroll) 847 if (R->screen.cur.row == R->screen.bscroll)
791 rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, 1, 0); 848 R->scr_scroll_text (R->screen.tscroll, R->screen.bscroll, 1, 0);
792 else if (R->screen.cur.row < (R->TermWin.nrow - 1)) 849 else if (R->screen.cur.row < (R->TermWin.nrow - 1))
793 row = (++R->screen.cur.row) + R->TermWin.saveLines; 850 row = (++R->screen.cur.row) + R->TermWin.saveLines;
794 stp = R->screen.text[row]; /* _must_ refresh */ 851 stp = R->screen.text[row]; /* _must_ refresh */
795 srp = R->screen.rend[row]; /* _must_ refresh */ 852 srp = R->screen.rend[row]; /* _must_ refresh */
796 continue; 853 continue;
813 clearsel = 1; 870 clearsel = 1;
814 } 871 }
815 if (R->screen.flags & Screen_WrapNext) { 872 if (R->screen.flags & Screen_WrapNext) {
816 R->screen.tlen[row] = -1; 873 R->screen.tlen[row] = -1;
817 if (R->screen.cur.row == R->screen.bscroll) 874 if (R->screen.cur.row == R->screen.bscroll)
818 rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, 1, 0); 875 R->scr_scroll_text(R->screen.tscroll, R->screen.bscroll, 1, 0);
819 else if (R->screen.cur.row < (R->TermWin.nrow - 1)) 876 else if (R->screen.cur.row < (R->TermWin.nrow - 1))
820 row = (++R->screen.cur.row) + R->TermWin.saveLines; 877 row = (++R->screen.cur.row) + R->TermWin.saveLines;
821 stp = R->screen.text[row]; /* _must_ refresh */ 878 stp = R->screen.text[row]; /* _must_ refresh */
822 srp = R->screen.rend[row]; /* _must_ refresh */ 879 srp = R->screen.rend[row]; /* _must_ refresh */
823 R->screen.cur.col = 0; 880 R->screen.cur.col = 0;
841 case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break; 898 case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break;
842 case '}': c = 0x00a3; break; case '~': c = 0x00b7; break; 899 case '}': c = 0x00a3; break; case '~': c = 0x00b7; break;
843 } 900 }
844 901
845 rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c)); 902 rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c));
846
847 stp[R->screen.cur.col] = c;
848 srp[R->screen.cur.col] = rend;
849
850 if (c > 255)
851 {
852 // rely on wcwidth to tell us the character width, at least for non iso-8859-1 903 // rely on wcwidth to tell us the character width, at least for non-ascii
853 int width = wcwidth (c); 904 int width = c <= 128 ? 1 : wcwidth (c);
905
906 // width -1 characters (e.g. combining chars) are ignored currently.
907 if (width > 0)
908 do
854 909 {
855 if (width > 1) 910 stp[R->screen.cur.col] = c;
856 {
857 while (--width > 0 && R->screen.cur.col < last_col - 1)
858 {
859
860 srp[R->screen.cur.col] |= RS_wide; 911 srp[R->screen.cur.col] = rend;
861 912
913 if (R->screen.cur.col < last_col - 1)
862 R->screen.cur.col++; 914 R->screen.cur.col++;
863 stp[R->screen.cur.col] = NOCHAR; 915 else
864 srp[R->screen.cur.col] = rend;
865 } 916 {
866 }
867 }
868
869 if (R->screen.cur.col < last_col - 1)
870 R->screen.cur.col++;
871 else {
872 R->screen.tlen[row] = last_col; 917 R->screen.tlen[row] = last_col;
873 if (R->screen.flags & Screen_Autowrap) 918 if (R->screen.flags & Screen_Autowrap)
874 R->screen.flags |= Screen_WrapNext; 919 R->screen.flags |= Screen_WrapNext;
920 break;
921 }
922
923 c = NOCHAR;
875 } 924 }
925 while (--width > 0);
926 else
927 1; /* handle combining character etc. here. */
876 } 928 }
929
877 if (R->screen.tlen[row] != -1) /* XXX: think about this */ 930 if (R->screen.tlen[row] != -1) /* XXX: think about this */
878 MAX_IT(R->screen.tlen[row], R->screen.cur.col); 931 MAX_IT(R->screen.tlen[row], R->screen.cur.col);
879 932
880/* 933/*
881 * If we wrote anywhere in the selected area, kill the selection 934 * If we wrote anywhere in the selected area, kill the selection
882 * XXX: should we kill the mark too? Possibly, but maybe that 935 * XXX: should we kill the mark too? Possibly, but maybe that
883 * should be a similar check. 936 * should be a similar check.
1075#endif 1128#endif
1076 1129
1077 R->screen.flags &= ~Screen_WrapNext; 1130 R->screen.flags &= ~Screen_WrapNext;
1078 if ((R->screen.cur.row == R->screen.bscroll && direction == UP) 1131 if ((R->screen.cur.row == R->screen.bscroll && direction == UP)
1079 || (R->screen.cur.row == R->screen.tscroll && direction == DN)) 1132 || (R->screen.cur.row == R->screen.tscroll && direction == DN))
1080 rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, dirn, 0); 1133 R->scr_scroll_text(R->screen.tscroll, R->screen.bscroll, dirn, 0);
1081 else 1134 else
1082 R->screen.cur.row += dirn; 1135 R->screen.cur.row += dirn;
1083 MAX_IT(R->screen.cur.row, 0); 1136 MAX_IT(R->screen.cur.row, 0);
1084 MIN_IT(R->screen.cur.row, (int32_t)R->TermWin.nrow - 1); 1137 MIN_IT(R->screen.cur.row, (int32_t)R->TermWin.nrow - 1);
1085 rxvt_selection_check(aR_ 0); 1138 rxvt_selection_check(aR_ 0);
1094 */ 1147 */
1095/* EXTPROTO */ 1148/* EXTPROTO */
1096void 1149void
1097rxvt_scr_erase_line(pR_ int mode) 1150rxvt_scr_erase_line(pR_ int mode)
1098{ 1151{
1099 unsigned int row, col, num; 1152 unsigned int row, col, num;
1100 1153
1101 R->want_refresh = 1; 1154 R->want_refresh = 1;
1102 D_SCREEN((stderr, "rxvt_scr_erase_line(%d) at screen row: %d", mode, R->screen.cur.row)); 1155 D_SCREEN((stderr, "rxvt_scr_erase_line(%d) at screen row: %d", mode, R->screen.cur.row));
1103 ZERO_SCROLLBACK(R); 1156 ZERO_SCROLLBACK (R);
1104 1157
1105#ifdef RXVT_GRAPHICS 1158#ifdef RXVT_GRAPHICS
1106 if (rxvt_Gr_Displayed(aR)) 1159 if (rxvt_Gr_Displayed (aR))
1107 rxvt_Gr_scroll(aR_ 0); 1160 rxvt_Gr_scroll (aR_ 0);
1108#endif 1161#endif
1109 1162
1110 rxvt_selection_check(aR_ 1); 1163 rxvt_selection_check (aR_ 1);
1111 1164
1112 R->screen.flags &= ~Screen_WrapNext; 1165 R->screen.flags &= ~Screen_WrapNext;
1113 1166
1114 row = R->TermWin.saveLines + R->screen.cur.row; 1167 row = R->TermWin.saveLines + R->screen.cur.row;
1115 switch (mode) { 1168 switch (mode)
1169 {
1116 case 0: /* erase to end of line */ 1170 case 0: /* erase to end of line */
1117 col = R->screen.cur.col; 1171 col = R->screen.cur.col;
1118 num = R->TermWin.ncol - col; 1172 num = R->TermWin.ncol - col;
1119 MIN_IT(R->screen.tlen[row], (int16_t)col); 1173 MIN_IT(R->screen.tlen[row], (int16_t)col);
1120 if (ROWCOL_IN_ROW_AT_OR_AFTER(R->selection.beg, R->screen.cur) 1174 if (ROWCOL_IN_ROW_AT_OR_AFTER(R->selection.beg, R->screen.cur)
1121 || ROWCOL_IN_ROW_AT_OR_AFTER(R->selection.end, R->screen.cur)) 1175 || ROWCOL_IN_ROW_AT_OR_AFTER(R->selection.end, R->screen.cur))
1122 CLEAR_SELECTION(R); 1176 CLEAR_SELECTION(R);
1123 break; 1177 break;
1124 case 1: /* erase to beginning of line */ 1178 case 1: /* erase to beginning of line */
1125 col = 0; 1179 col = 0;
1126 num = R->screen.cur.col + 1; 1180 num = R->screen.cur.col + 1;
1127 if (ROWCOL_IN_ROW_AT_OR_BEFORE(R->selection.beg, R->screen.cur) 1181 if (ROWCOL_IN_ROW_AT_OR_BEFORE(R->selection.beg, R->screen.cur)
1128 || ROWCOL_IN_ROW_AT_OR_BEFORE(R->selection.end, R->screen.cur)) 1182 || ROWCOL_IN_ROW_AT_OR_BEFORE(R->selection.end, R->screen.cur))
1129 CLEAR_SELECTION(R); 1183 CLEAR_SELECTION(R);
1130 break; 1184 break;
1131 case 2: /* erase whole line */ 1185 case 2: /* erase whole line */
1132 col = 0; 1186 col = 0;
1133 num = R->TermWin.ncol; 1187 num = R->TermWin.ncol;
1134 R->screen.tlen[row] = 0; 1188 R->screen.tlen[row] = 0;
1135 if (R->selection.beg.row <= R->screen.cur.row 1189 if (R->selection.beg.row <= R->screen.cur.row
1136 && R->selection.end.row >= R->screen.cur.row) 1190 && R->selection.end.row >= R->screen.cur.row)
1137 CLEAR_SELECTION(R); 1191 CLEAR_SELECTION(R);
1138 break; 1192 break;
1139 default: 1193 default:
1140 return; 1194 return;
1141 } 1195 }
1196
1142 if (R->screen.text[row]) 1197 if (R->screen.text[row])
1143 rxvt_blank_line(aR_ 1198 R->scr_blank_line (&(R->screen.text[row][col]),
1144 &(R->screen.text[row][col]),
1145 &(R->screen.rend[row][col]), num, R->rstyle); 1199 &(R->screen.rend[row][col]), num, R->rstyle);
1146 else 1200 else
1147 rxvt_blank_screen_mem(aR_ R->screen.text, R->screen.rend, row, 1201 R->scr_blank_screen_mem (R->screen.text, R->screen.rend, row, R->rstyle);
1148 R->rstyle);
1149} 1202}
1150 1203
1151/* ------------------------------------------------------------------------- */ 1204/* ------------------------------------------------------------------------- */
1152/* 1205/*
1153 * Erase part of whole of the screen 1206 * Erase part of whole of the screen
1154 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1207 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1155 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1208 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1156 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1209 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1157 */ 1210 */
1158/* EXTPROTO */
1159void 1211void
1160rxvt_scr_erase_screen(pR_ int mode) 1212rxvt_term::scr_erase_screen (int mode)
1161{ 1213{
1162 int num; 1214 int num;
1163 int32_t row, row_offset; 1215 int32_t row, row_offset;
1164 rend_t ren; 1216 rend_t ren;
1165 XGCValues gcvalue; 1217 XGCValues gcvalue;
1166 1218
1167 R->want_refresh = 1; 1219 want_refresh = 1;
1168 D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, R->screen.cur.row)); 1220 D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, screen.cur.row));
1169 ZERO_SCROLLBACK(R); 1221 ZERO_SCROLLBACK(this);
1170 row_offset = (int32_t)R->TermWin.saveLines; 1222 row_offset = (int32_t)TermWin.saveLines;
1171 1223
1172 switch (mode) { 1224 switch (mode) {
1173 case 0: /* erase to end of screen */ 1225 case 0: /* erase to end of screen */
1174 rxvt_selection_check(aR_ 1); 1226 rxvt_selection_check(this,1);
1175 rxvt_scr_erase_line(aR_ 0); 1227 rxvt_scr_erase_line(this,0);
1176 row = R->screen.cur.row + 1; /* possible OOB */ 1228 row = screen.cur.row + 1; /* possible OOB */
1177 num = R->TermWin.nrow - row; 1229 num = TermWin.nrow - row;
1178 break; 1230 break;
1179 case 1: /* erase to beginning of screen */ 1231 case 1: /* erase to beginning of screen */
1180 rxvt_selection_check(aR_ 3); 1232 rxvt_selection_check(this,3);
1181 rxvt_scr_erase_line(aR_ 1); 1233 rxvt_scr_erase_line(this,1);
1182 row = 0; 1234 row = 0;
1183 num = R->screen.cur.row; 1235 num = screen.cur.row;
1184 break; 1236 break;
1185 case 2: /* erase whole screen */ 1237 case 2: /* erase whole screen */
1186 rxvt_selection_check(aR_ 3); 1238 rxvt_selection_check (this, 3);
1187#ifdef RXVT_GRAPHICS 1239#ifdef RXVT_GRAPHICS
1188 rxvt_Gr_ClearScreen(aR); 1240 rxvt_Gr_ClearScreen (this);
1189#endif 1241#endif
1190 row = 0; 1242 row = 0;
1191 num = R->TermWin.nrow; 1243 num = TermWin.nrow;
1192 break; 1244 break;
1193 default: 1245 default:
1194 return; 1246 return;
1195 } 1247 }
1196 R->refresh_type |= REFRESH_BOUNDS; 1248 refresh_type |= REFRESH_BOUNDS;
1197 if (R->selection.op && R->current_screen == R->selection.screen 1249 if (selection.op && current_screen == selection.screen
1198 && ((R->selection.beg.row >= row && R->selection.beg.row <= row + num) 1250 && ((selection.beg.row >= row && selection.beg.row <= row + num)
1199 || (R->selection.end.row >= row 1251 || (selection.end.row >= row
1200 && R->selection.end.row <= row + num))) 1252 && selection.end.row <= row + num)))
1201 CLEAR_SELECTION(R); 1253 CLEAR_SELECTION (this);
1202 if (row >= R->TermWin.nrow) /* Out Of Bounds */ 1254 if (row >= TermWin.nrow) /* Out Of Bounds */
1203 return; 1255 return;
1204 MIN_IT(num, (R->TermWin.nrow - row)); 1256 MIN_IT(num, (TermWin.nrow - row));
1205 if (R->rstyle & (RS_RVid | RS_Uline)) 1257 if (rstyle & (RS_RVid | RS_Uline))
1206 ren = (rend_t) ~RS_None; 1258 ren = (rend_t) ~RS_None;
1207 else if (GET_BASEBG(R->rstyle) == Color_bg) { 1259 else if (GET_BASEBG(rstyle) == Color_bg) {
1208 ren = DEFAULT_RSTYLE; 1260 ren = DEFAULT_RSTYLE;
1209 CLEAR_ROWS(row, num); 1261 CLEAR_ROWS(row, num);
1210 } else { 1262 } else {
1211 ren = (R->rstyle & (RS_fgMask | RS_bgMask)); 1263 ren = (rstyle & (RS_fgMask | RS_bgMask));
1212 gcvalue.foreground = R->PixColors[GET_BGCOLOR(R->rstyle)]; 1264 gcvalue.foreground = PixColors[GET_BGCOLOR(rstyle)];
1213 XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); 1265 XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue);
1214 ERASE_ROWS(row, num); 1266 ERASE_ROWS(row, num);
1215 gcvalue.foreground = R->PixColors[Color_fg]; 1267 gcvalue.foreground = PixColors[Color_fg];
1216 XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); 1268 XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue);
1217 } 1269 }
1218 for (; num--; row++) { 1270 for (; num--; row++) {
1219 rxvt_blank_screen_mem(aR_ R->screen.text, R->screen.rend, 1271 scr_blank_screen_mem (screen.text, screen.rend,
1220 (unsigned int)(row + row_offset), R->rstyle); 1272 (unsigned int)(row + row_offset), rstyle);
1221 R->screen.tlen[row + row_offset] = 0; 1273 screen.tlen[row + row_offset] = 0;
1222 rxvt_blank_line(aR_ 1274 scr_blank_line (drawn_text[row], drawn_rend[row],
1223 R->drawn_text[row], R->drawn_rend[row],
1224 (unsigned int)R->TermWin.ncol, ren); 1275 (unsigned int)TermWin.ncol, ren);
1225 } 1276 }
1226} 1277}
1227 1278
1228/* ------------------------------------------------------------------------- */ 1279/* ------------------------------------------------------------------------- */
1229/* 1280/*
1280 else if (insdel == INSERT) 1331 else if (insdel == INSERT)
1281 count = end; 1332 count = end;
1282 } 1333 }
1283 R->screen.flags &= ~Screen_WrapNext; 1334 R->screen.flags &= ~Screen_WrapNext;
1284 1335
1285 rxvt_scroll_text(aR_ R->screen.cur.row, R->screen.bscroll, insdel * count, 1336 R->scr_scroll_text(R->screen.cur.row, R->screen.bscroll, insdel * count, 0);
1286 0);
1287} 1337}
1288 1338
1289/* ------------------------------------------------------------------------- */ 1339/* ------------------------------------------------------------------------- */
1290/* 1340/*
1291 * Insert/Delete <count> characters from the current position 1341 * Insert/Delete <count> characters from the current position
1340 R->selection.beg.col += count; 1390 R->selection.beg.col += count;
1341 R->selection.mark.col += count; /* XXX: yes? */ 1391 R->selection.mark.col += count; /* XXX: yes? */
1342 R->selection.end.col += count; 1392 R->selection.end.col += count;
1343 } 1393 }
1344 } 1394 }
1345 rxvt_blank_line(aR_ &(stp[R->screen.cur.col]), &(srp[R->screen.cur.col]), 1395 R->scr_blank_line (&(stp[R->screen.cur.col]), &(srp[R->screen.cur.col]),
1346 (unsigned int)count, R->rstyle); 1396 (unsigned int)count, R->rstyle);
1347 break; 1397 break;
1348 case ERASE: 1398 case ERASE:
1349 R->screen.cur.col += count; /* don't worry if > R->TermWin.ncol */ 1399 R->screen.cur.col += count; /* don't worry if > R->TermWin.ncol */
1350 rxvt_selection_check(aR_ 1); 1400 rxvt_selection_check(aR_ 1);
1351 R->screen.cur.col -= count; 1401 R->screen.cur.col -= count;
1352 rxvt_blank_line(aR_ &(stp[R->screen.cur.col]), &(srp[R->screen.cur.col]), 1402 R->scr_blank_line (&(stp[R->screen.cur.col]), &(srp[R->screen.cur.col]),
1353 (unsigned int)count, R->rstyle); 1403 (unsigned int)count, R->rstyle);
1354 break; 1404 break;
1355 case DELETE: 1405 case DELETE:
1356 tr = srp[R->TermWin.ncol - 1] 1406 tr = srp[R->TermWin.ncol - 1]
1357 & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1407 & (RS_fgMask | RS_bgMask | RS_baseattrMask);
1358 for (col = R->screen.cur.col; (col + count) < R->TermWin.ncol; col++) { 1408 for (col = R->screen.cur.col; (col + count) < R->TermWin.ncol; col++) {
1359 stp[col] = stp[col + count]; 1409 stp[col] = stp[col + count];
1360 srp[col] = srp[col + count]; 1410 srp[col] = srp[col + count];
1361 } 1411 }
1362 rxvt_blank_line(aR_ 1412 R->scr_blank_line (&(stp[R->TermWin.ncol - count]),
1363 &(stp[R->TermWin.ncol - count]),
1364 &(srp[R->TermWin.ncol - count]), 1413 &(srp[R->TermWin.ncol - count]),
1365 (unsigned int)count, tr); 1414 (unsigned int)count, tr);
1366 if (*slp == -1) /* break line continuation */ 1415 if (*slp == -1) /* break line continuation */
1367 *slp = R->TermWin.ncol; 1416 *slp = R->TermWin.ncol;
1368 *slp -= count; 1417 *slp -= count;
1369 MAX_IT(*slp, 0); 1418 MAX_IT(*slp, 0);
1370 if (R->selection.op && R->current_screen == R->selection.screen 1419 if (R->selection.op && R->current_screen == R->selection.screen
1515 1564
1516 gcvalue.foreground = R->PixColors[Color_fg]; 1565 gcvalue.foreground = R->PixColors[Color_fg];
1517 gcvalue.background = R->PixColors[Color_bg]; 1566 gcvalue.background = R->PixColors[Color_bg];
1518 XChangeGC(R->Xdisplay, R->TermWin.gc, GCBackground | GCForeground, 1567 XChangeGC(R->Xdisplay, R->TermWin.gc, GCBackground | GCForeground,
1519 &gcvalue); 1568 &gcvalue);
1520 rxvt_scr_clear(aR); 1569 R->scr_clear ();
1521 rxvt_scr_touch(aR_ True); 1570 R->scr_touch (true);
1522 } 1571 }
1523} 1572}
1524 1573
1525/* ------------------------------------------------------------------------- */ 1574/* ------------------------------------------------------------------------- */
1526/* 1575/*
1596 rxvt_set_font_style(aR); 1645 rxvt_set_font_style(aR);
1597} 1646}
1598 1647
1599 1648
1600/* ------------------------------------------------------------------------- * 1649/* ------------------------------------------------------------------------- *
1601 * GRAPHICS COLOURS *
1602 * ------------------------------------------------------------------------- */
1603
1604#ifdef RXVT_GRAPHICS
1605/* EXTPROTO */
1606int
1607rxvt_scr_get_fgcolor(pR)
1608{
1609 return GET_FGCOLOR(R->rstyle);
1610}
1611
1612/* ------------------------------------------------------------------------- */
1613/* EXTPROTO */
1614int
1615rxvt_scr_get_bgcolor(pR)
1616{
1617 return GET_BGCOLOR(R->rstyle);
1618}
1619#endif
1620
1621/* ------------------------------------------------------------------------- *
1622 * MAJOR SCREEN MANIPULATION * 1650 * MAJOR SCREEN MANIPULATION *
1623 * ------------------------------------------------------------------------- */ 1651 * ------------------------------------------------------------------------- */
1652
1653/*
1654 * refresh matching text.
1655 */
1656bool
1657rxvt_term::scr_refresh_rend (rend_t mask, rend_t value)
1658{
1659 bool found = false;
1660
1661 for (int i = 0; i < TermWin.nrow; i++)
1662 {
1663 int col = 0;
1664 rend_t *drp = drawn_rend [i];
1665
1666 for (; col < TermWin.ncol; col++, drp++)
1667 if ((*drp & mask) == value)
1668 {
1669 found = true;
1670 *drp = ~value;
1671 }
1672 }
1673
1674 return found;
1675}
1624 1676
1625/* 1677/*
1626 * Refresh an area 1678 * Refresh an area
1627 */ 1679 */
1628enum { 1680enum {
1629 PART_BEG = 0, 1681 PART_BEG = 0,
1630 PART_END, 1682 PART_END,
1631 RC_COUNT 1683 RC_COUNT
1632}; 1684};
1633 1685
1634/* EXTPROTO */
1635void 1686void
1636rxvt_scr_expose(pR_ int x, int y, int width, int height, Bool refresh) 1687rxvt_term::scr_expose (int x, int y, int width, int height, bool refresh)
1637{ 1688{
1638 int i; 1689 int i;
1639 row_col_t rc[RC_COUNT]; 1690 row_col_t rc[RC_COUNT];
1640 1691
1641 if (R->drawn_text == NULL) /* sanity check */ 1692 if (drawn_text == NULL) /* sanity check */
1642 return; 1693 return;
1643 1694
1644#ifdef DEBUG_STRICT 1695#ifdef DEBUG_STRICT
1645 x = max(x, (int)R->TermWin.int_bwidth); 1696 x = max(x, (int)TermWin.int_bwidth);
1646 x = min(x, (int)R->TermWin.width); 1697 x = min(x, (int)TermWin.width);
1647 y = max(y, (int)R->TermWin.int_bwidth); 1698 y = max(y, (int)TermWin.int_bwidth);
1648 y = min(y, (int)R->TermWin.height); 1699 y = min(y, (int)TermWin.height);
1649#endif 1700#endif
1650 1701
1651/* round down */ 1702/* round down */
1652 rc[PART_BEG].col = Pixel2Col(x); 1703 rc[PART_BEG].col = Pixel2Col(x);
1653 rc[PART_BEG].row = Pixel2Row(y); 1704 rc[PART_BEG].row = Pixel2Row(y);
1654/* round up */ 1705/* round up */
1655 rc[PART_END].col = Pixel2Width(x + width + R->TermWin.fwidth - 1); 1706 rc[PART_END].col = Pixel2Width(x + width + TermWin.fwidth - 1);
1656 rc[PART_END].row = Pixel2Row(y + height + R->TermWin.fheight - 1); 1707 rc[PART_END].row = Pixel2Row(y + height + TermWin.fheight - 1);
1657 1708
1658/* sanity checks */ 1709/* sanity checks */
1659 for (i = PART_BEG; i < RC_COUNT; i++) { 1710 for (i = PART_BEG; i < RC_COUNT; i++)
1711 {
1660 MIN_IT(rc[i].col, R->TermWin.ncol - 1); 1712 MIN_IT(rc[i].col, TermWin.ncol - 1);
1661 MIN_IT(rc[i].row, R->TermWin.nrow - 1); 1713 MIN_IT(rc[i].row, TermWin.nrow - 1);
1662 } 1714 }
1663 1715
1664 D_SCREEN((stderr, "rxvt_scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)", x, y, width, height, rc[PART_BEG].col, rc[PART_BEG].row, rc[PART_END].col, rc[PART_END].row)); 1716 D_SCREEN((stderr, "rxvt_scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)", x, y, width, height, rc[PART_BEG].col, rc[PART_BEG].row, rc[PART_END].col, rc[PART_END].row));
1665 1717
1666 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1718 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1667 fill_text (&(R->drawn_text[i][rc[PART_BEG].col]), 0, 1719 fill_text (&(drawn_text[i][rc[PART_BEG].col]), 0,
1668 (rc[PART_END].col - rc[PART_BEG].col + 1)); 1720 (rc[PART_END].col - rc[PART_BEG].col + 1));
1669 1721
1670 if (refresh) 1722 if (refresh)
1671 rxvt_scr_refresh(aR_ SLOW_REFRESH | REFRESH_BOUNDS); 1723 scr_refresh (SLOW_REFRESH | REFRESH_BOUNDS);
1672} 1724}
1673 1725
1674/* ------------------------------------------------------------------------- */ 1726/* ------------------------------------------------------------------------- */
1675/* 1727/*
1676 * Refresh the entire screen 1728 * Refresh the entire screen
1677 */ 1729 */
1678/* EXTPROTO */
1679void 1730void
1680rxvt_scr_touch(pR_ Bool refresh) 1731rxvt_term::scr_touch (bool refresh)
1681{ 1732{
1682 rxvt_scr_expose(aR_ 0, 0, R->TermWin.width, R->TermWin.height, refresh); 1733 scr_expose (0, 0, TermWin.width, TermWin.height, refresh);
1683} 1734}
1684 1735
1685/* ------------------------------------------------------------------------- */ 1736/* ------------------------------------------------------------------------- */
1686/* 1737/*
1687 * Move the display so that the line represented by scrollbar value Y is at 1738 * Move the display so that the line represented by scrollbar value Y is at
1806 * Refresh the screen 1857 * Refresh the screen
1807 * R->drawn_text/R->drawn_rend contain the screen information before the update. 1858 * R->drawn_text/R->drawn_rend contain the screen information before the update.
1808 * R->screen.text/R->screen.rend contain what the screen will change to. 1859 * R->screen.text/R->screen.rend contain what the screen will change to.
1809 */ 1860 */
1810 1861
1811#if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD)
1812# define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink))
1813# define MONO_BOLD_FG(x, fg) MONO_BOLD(x)
1814#else
1815# define MONO_BOLD(x) \
1816 (((x) & (RS_Bold | RS_fgMask)) == (RS_Bold | Color_fg))
1817# define MONO_BOLD_FG(x, fg) (((x) & RS_Bold) && (fg) == Color_fg)
1818#endif
1819
1820#define FONT_WIDTH(X, Y) \ 1862#define FONT_WIDTH(X, Y) \
1821 (X)->per_char[(Y) - (X)->min_char_or_byte2].width 1863 (X)->per_char[(Y) - (X)->min_char_or_byte2].width
1822#define FONT_RBEAR(X, Y) \ 1864#define FONT_RBEAR(X, Y) \
1823 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing 1865 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing
1824#define FONT_LBEAR(X, Y) \ 1866#define FONT_LBEAR(X, Y) \
1825 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing 1867 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing
1826#define IS_FONT_CHAR(X, Y) \ 1868#define IS_FONT_CHAR(X, Y) \
1827 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) 1869 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2)
1828 1870
1829/* EXTPROTO */
1830void 1871void
1831rxvt_scr_refresh(pR_ unsigned char refresh_type) 1872rxvt_term::scr_refresh (unsigned char refresh_type)
1832{ 1873{
1833 unsigned char clearfirst, /* first character writes before cell */ 1874 unsigned char clearfirst, /* first character writes before cell */
1834 clearlast, /* last character writes beyond cell */ 1875 clearlast, /* last character writes beyond cell */
1835 must_clear, /* use draw_string not draw_image_string */ 1876 must_clear, /* use draw_string not draw_image_string */
1836#ifndef NO_BOLDFONT
1837 bfont, /* we've changed font to bold font */
1838#endif
1839 rvid, /* reverse video this position */ 1877 rvid, /* reverse video this position */
1840 wbyte, /* we're in multibyte */
1841 showcursor; /* show the cursor */ 1878 showcursor; /* show the cursor */
1842 int fore, back; /* desired foreground/background */
1843 int16_t col, row, /* column/row we're processing */ 1879 int16_t col, row, /* column/row we're processing */
1844 ocrow; /* old cursor row */ 1880 ocrow; /* old cursor row */
1845 int cursorwidth; 1881 int cursorwidth;
1846 int i, /* tmp */ 1882 int i, /* tmp */
1847 row_offset; /* basic offset in screen structure */ 1883 row_offset; /* basic offset in screen structure */
1849 rend_t cc1; /* store colours at cursor position(s) */ 1885 rend_t cc1; /* store colours at cursor position(s) */
1850 rend_t cc2; /* store colours at cursor position(s) */ 1886 rend_t cc2; /* store colours at cursor position(s) */
1851#endif 1887#endif
1852 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ 1888 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */
1853 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ 1889 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */
1854 char *buffer; /* local copy of R->buffer */
1855 1890
1856 if (refresh_type == NO_REFRESH || !R->TermWin.mapped) 1891 if (refresh_type == NO_REFRESH || !TermWin.mapped)
1857 return; 1892 return;
1858 1893
1859 /* 1894 /*
1860 * A: set up vars 1895 * A: set up vars
1861 */ 1896 */
1862 clearfirst = clearlast = must_clear = wbyte = 0; 1897 clearfirst = clearlast = must_clear = 0;
1863#ifndef NO_BOLDFONT
1864 bfont = 0;
1865#endif
1866 1898
1867 if (R->currmaxcol < R->TermWin.ncol) 1899 if (currmaxcol < TermWin.ncol)
1868 { 1900 {
1869 R->currmaxcol = R->TermWin.ncol; 1901 currmaxcol = TermWin.ncol;
1870 R->buffer = (char *)rxvt_realloc (R->buffer, 1902 buffer = (char *)rxvt_realloc (buffer,
1871 sizeof(char) * (R->currmaxcol + 1) * MB_CUR_MAX); 1903 sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX);
1872 } 1904 }
1873 1905
1874 buffer = R->buffer;
1875 R->refresh_count = 0; 1906 refresh_count = 0;
1876 1907
1877 row_offset = R->TermWin.saveLines - R->TermWin.view_start; 1908 row_offset = TermWin.saveLines - TermWin.view_start;
1878 1909
1879 if ((refresh_type & REFRESH_BOUNDS)) 1910 if ((refresh_type & REFRESH_BOUNDS))
1880 { 1911 {
1881 clearfirst = clearlast = 1; 1912 clearfirst = clearlast = 1;
1882 R->refresh_type &= ~REFRESH_BOUNDS; 1913 refresh_type &= ~REFRESH_BOUNDS;
1883 } 1914 }
1884 1915
1885#if defined(XPM_BACKGROUND) 1916#if defined(XPM_BACKGROUND)
1886 must_clear |= (R->bgPixmap.pixmap != None); 1917 must_clear |= (bgPixmap.pixmap != None);
1887#endif 1918#endif
1888#if defined(TRANSPARENT) 1919#if defined(TRANSPARENT)
1889 must_clear |= ((R->Options & Opt_transparent) && R->am_transparent); 1920 must_clear |= ((Options & Opt_transparent) && am_transparent);
1890#endif 1921#endif
1891 ocrow = R->oldcursor.row; /* is there an old outline cursor on screen? */ 1922 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1892 1923
1893/* 1924 /*
1894 * B: reverse any characters which are selected 1925 * B: reverse any characters which are selected
1895 */ 1926 */
1896 rxvt_scr_reverse_selection(aR); 1927 rxvt_scr_reverse_selection (this);
1897 1928
1898/* 1929 /*
1899 * C: set the cursor character(s) 1930 * C: set the cursor character(s)
1900 */ 1931 */
1901 { 1932 {
1902 unsigned char setoldcursor; 1933 unsigned char setoldcursor;
1903 rend_t ccol1, /* Cursor colour */ 1934 rend_t ccol1, /* Cursor colour */
1904 ccol2; /* Cursor colour2 */ 1935 ccol2; /* Cursor colour2 */
1905 1936
1906 showcursor = (R->screen.flags & Screen_VisibleCursor); 1937 showcursor = (screen.flags & Screen_VisibleCursor);
1907 cursorwidth = 0; 1938 cursorwidth = 0;
1908#ifdef CURSOR_BLINK 1939#ifdef CURSOR_BLINK
1909 if (R->hidden_cursor) 1940 if (hidden_cursor)
1910 showcursor = 0; 1941 showcursor = 0;
1911#endif 1942#endif
1912 1943
1913 cursorwidth = 0; 1944 cursorwidth = 0;
1914 1945
1915 if (showcursor) 1946 if (showcursor)
1916 { 1947 {
1917 cursorwidth++; 1948 cursorwidth++;
1918 1949
1919 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 1950 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
1920 [R->screen.cur.col]); 1951 [screen.cur.col]);
1921 1952
1922 if (showcursor && R->TermWin.focus) 1953 if (showcursor && TermWin.focus)
1923 { 1954 {
1924 *srp ^= RS_RVid; 1955 *srp ^= RS_RVid;
1925#ifndef NO_CURSORCOLOR 1956#ifndef NO_CURSORCOLOR
1926 cc1 = *srp & (RS_fgMask | RS_bgMask); 1957 cc1 = *srp & (RS_fgMask | RS_bgMask);
1927 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) 1958 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor))
1928 ccol1 = Color_cursor; 1959 ccol1 = Color_cursor;
1929 else 1960 else
1930#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1961#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1931 ccol1 = GET_FGCOLOR(R->rstyle); 1962 ccol1 = GET_FGCOLOR(rstyle);
1932#else 1963#else
1933 ccol1 = Color_fg; 1964 ccol1 = Color_fg;
1934#endif 1965#endif
1935 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor2)) 1966 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor2))
1936 ccol2 = Color_cursor2; 1967 ccol2 = Color_cursor2;
1937 else 1968 else
1938#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1969#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1939 ccol2 = GET_BGCOLOR(R->rstyle); 1970 ccol2 = GET_BGCOLOR(rstyle);
1940#else 1971#else
1941 ccol2 = Color_bg; 1972 ccol2 = Color_bg;
1942#endif 1973#endif
1943 *srp = SET_FGCOLOR(*srp, ccol1); 1974 *srp = SET_FGCOLOR(*srp, ccol1);
1944 *srp = SET_BGCOLOR(*srp, ccol2); 1975 *srp = SET_BGCOLOR(*srp, ccol2);
1945#endif 1976#endif
1946 } 1977 }
1947
1948 while (IS_WIDE (*srp))
1949 cursorwidth++, srp++;
1950 } 1978 }
1951 1979
1952 /* make sure no outline cursor is left around */ 1980 /* make sure no outline cursor is left around */
1953 setoldcursor = 0; 1981 setoldcursor = 0;
1954 if (ocrow != -1) { 1982 if (ocrow != -1) {
1955 if (R->screen.cur.row + R->TermWin.view_start != ocrow 1983 if (screen.cur.row + TermWin.view_start != ocrow
1956 || R->screen.cur.col != R->oldcursor.col) { 1984 || screen.cur.col != oldcursor.col) {
1957 if (ocrow < R->TermWin.nrow 1985 if (ocrow < TermWin.nrow
1958 && R->oldcursor.col < R->TermWin.ncol) { 1986 && oldcursor.col < TermWin.ncol) {
1959 R->drawn_rend[ocrow][R->oldcursor.col] ^= (RS_RVid | RS_Uline); 1987 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline);
1960 } 1988 }
1961 if (R->TermWin.focus || !showcursor) 1989 if (TermWin.focus || !showcursor)
1962 R->oldcursor.row = -1; 1990 oldcursor.row = -1;
1963 else 1991 else
1964 setoldcursor = 1; 1992 setoldcursor = 1;
1965 } 1993 }
1966 } else if (!R->TermWin.focus) 1994 } else if (!TermWin.focus)
1967 setoldcursor = 1; 1995 setoldcursor = 1;
1968 if (setoldcursor) { 1996 if (setoldcursor) {
1969 if (R->screen.cur.row + R->TermWin.view_start >= R->TermWin.nrow) 1997 if (screen.cur.row + TermWin.view_start >= TermWin.nrow)
1970 R->oldcursor.row = -1; 1998 oldcursor.row = -1;
1971 else { 1999 else {
1972 R->oldcursor.row = R->screen.cur.row + R->TermWin.view_start; 2000 oldcursor.row = screen.cur.row + TermWin.view_start;
1973 R->oldcursor.col = R->screen.cur.col; 2001 oldcursor.col = screen.cur.col;
1974 } 2002 }
1975 } 2003 }
1976 } 2004 }
1977 2005
1978#ifndef NO_SLOW_LINK_SUPPORT 2006#ifndef NO_SLOW_LINK_SUPPORT
1979/* 2007 /*
1980 * D: CopyArea pass - very useful for slower links 2008 * D: CopyArea pass - very useful for slower links
1981 * This has been deliberately kept simple. 2009 * This has been deliberately kept simple.
1982 */ 2010 */
1983 i = R->num_scr; 2011 i = num_scr;
1984 if (refresh_type == FAST_REFRESH && R->num_scr_allow && i 2012 if (refresh_type == FAST_REFRESH && num_scr_allow && i
1985 && abs(i) < R->TermWin.nrow && !must_clear) 2013 && abs(i) < TermWin.nrow && !must_clear)
1986 { 2014 {
1987 int16_t nits; 2015 int16_t nits;
1988 int j; 2016 int j;
1989 rend_t *drp2; 2017 rend_t *drp2;
1990 text_t *dtp2; 2018 text_t *dtp2;
1991 int len, wlen; 2019 int len, wlen;
1992 2020
1993 j = R->TermWin.nrow; 2021 j = TermWin.nrow;
1994 wlen = len = -1; 2022 wlen = len = -1;
1995 row = i > 0 ? 0 : j - 1; 2023 row = i > 0 ? 0 : j - 1;
1996 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2024 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
1997 { 2025 {
1998 if (row + i >= 0 && row + i < R->TermWin.nrow && row + i != ocrow) 2026 if (row + i >= 0 && row + i < TermWin.nrow && row + i != ocrow)
1999 { 2027 {
2000 stp = R->screen.text[row + row_offset]; 2028 stp = screen.text[row + row_offset];
2001 srp = R->screen.rend[row + row_offset]; 2029 srp = screen.rend[row + row_offset];
2002 dtp = R->drawn_text[row]; 2030 dtp = drawn_text[row];
2003 dtp2 = R->drawn_text[row + i]; 2031 dtp2 = drawn_text[row + i];
2004 drp = R->drawn_rend[row]; 2032 drp = drawn_rend[row];
2005 drp2 = R->drawn_rend[row + i]; 2033 drp2 = drawn_rend[row + i];
2006 2034
2007 for (nits = 0, col = R->TermWin.ncol; col--; ) 2035 for (nits = 0, col = TermWin.ncol; col--; )
2008 if (stp[col] != dtp2[col] || srp[col] != drp2[col]) 2036 if (stp[col] != dtp2[col] || srp[col] != drp2[col])
2009 nits--; 2037 nits--;
2010 else if (stp[col] != dtp[col] || srp[col] != drp[col]) 2038 else if (stp[col] != dtp[col] || srp[col] != drp[col])
2011 nits++; 2039 nits++;
2012 2040
2013 if (nits > 8) /* XXX: arbitrary choice */ 2041 if (nits > 8) /* XXX: arbitrary choice */
2014 { 2042 {
2015 for (col = R->TermWin.ncol; col--; ) 2043 for (col = TermWin.ncol; col--; )
2016 { 2044 {
2017 *dtp++ = *dtp2++; 2045 *dtp++ = *dtp2++;
2018 *drp++ = *drp2++; 2046 *drp++ = *drp2++;
2019 } 2047 }
2020 2048
2029 if (len != -1) 2057 if (len != -1)
2030 { 2058 {
2031 /* also comes here at end if needed because of >= above */ 2059 /* also comes here at end if needed because of >= above */
2032 if (wlen < len) 2060 if (wlen < len)
2033 SWAP_IT(wlen, len, int); 2061 SWAP_IT(wlen, len, int);
2062
2034 D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1)); 2063 D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1));
2035 XCopyArea(R->Xdisplay, R->TermWin.vt, R->TermWin.vt, 2064 XCopyArea (Xdisplay, TermWin.vt, TermWin.vt,
2036 R->TermWin.gc, 0, Row2Pixel(len + i), 2065 TermWin.gc, 0, Row2Pixel (len + i),
2037 (unsigned int)TermWin_TotalWidth(), 2066 (unsigned int)TermWin_TotalWidth (),
2038 (unsigned int)Height2Pixel(wlen - len + 1), 2067 (unsigned int)Height2Pixel (wlen - len + 1),
2039 0, Row2Pixel(len)); 2068 0, Row2Pixel (len));
2040 len = -1; 2069 len = -1;
2041 } 2070 }
2042 } 2071 }
2043 } 2072 }
2044#endif 2073#endif
2045 2074
2046/* 2075 /*
2047 * E: main pass across every character 2076 * E: main pass across every character
2048 */ 2077 */
2049 for (row = 0; row < R->TermWin.nrow; row++) 2078 for (row = 0; row < TermWin.nrow; row++)
2050 { 2079 {
2051 stp = R->screen.text[row + row_offset]; 2080 stp = screen.text[row + row_offset];
2052 srp = R->screen.rend[row + row_offset]; 2081 srp = screen.rend[row + row_offset];
2053 dtp = R->drawn_text[row]; 2082 dtp = drawn_text[row];
2054 drp = R->drawn_rend[row]; 2083 drp = drawn_rend[row];
2055 2084
2056/* 2085 /*
2057 * E2: OK, now the real pass 2086 * E2: OK, now the real pass
2058 */ 2087 */
2059 int ypixel = (int)Row2Pixel(row); 2088 int ypixel = (int)Row2Pixel(row);
2060 2089
2061 for (col = 0; col < R->TermWin.ncol; col++) 2090 for (col = 0; col < TermWin.ncol; col++)
2062 { 2091 {
2063 /* compare new text with old - if exactly the same then continue */ 2092 /* compare new text with old - if exactly the same then continue */
2064 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2093 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2065 2094
2066 if (stp[col] == dtp[col] /* Must match characters to skip. */ 2095 if (stp[col] == dtp[col] /* Must match characters to skip. */
2082 2111
2083 int xpixel = Col2Pixel(col); 2112 int xpixel = Col2Pixel(col);
2084 2113
2085 // this loop looks very messy, it can probably be optimized 2114 // this loop looks very messy, it can probably be optimized
2086 // and cleaned a bit by you? 2115 // and cleaned a bit by you?
2087 for (i = 0; ++col < R->TermWin.ncol; ) 2116 for (i = 0; ++col < TermWin.ncol; )
2088 { 2117 {
2089 if (stp[col] == NOCHAR) 2118 if (stp[col] == NOCHAR)
2090 { 2119 {
2091 dtp[col] = stp[col]; 2120 dtp[col] = stp[col];
2092 drp[col] = rend; 2121 drp[col] = rend;
2096 i++; 2125 i++;
2097 2126
2098 continue; 2127 continue;
2099 } 2128 }
2100 2129
2101 if (((rend ^ srp[col]) & ~RS_wide) != 0) 2130 if (rend != srp[col])
2102 break; 2131 break;
2103 2132
2104 count++; 2133 count++;
2105 2134
2106 if (stp[col] != dtp[col] 2135 if (stp[col] != dtp[col]
2118 } 2147 }
2119 2148
2120 col--; /* went one too far. move back */ 2149 col--; /* went one too far. move back */
2121 count -= i; /* dump any matching trailing chars */ 2150 count -= i; /* dump any matching trailing chars */
2122 2151
2123/* 2152 /*
2124 * Determine the attributes for the string 2153 * Determine the attributes for the string
2125 */ 2154 */
2126 int fid = GET_FONT(rend); 2155 int fid = GET_FONT (rend);
2127 fore = GET_FGCOLOR(rend); 2156 int fore = GET_FGCOLOR (rend); // desired foreground
2128 back = GET_BGCOLOR(rend); 2157 int back = GET_BGCOLOR (rend); // desired background
2158
2129 rend = GET_ATTR(rend); 2159 rend = GET_ATTR (rend);
2130 2160
2131 rvid = (rend & RS_RVid) ? 1 : 0; 2161 rvid = !!(rend & RS_RVid);
2162#ifdef TEXT_BLINK
2163 if (rend & RS_Blink)
2164 {
2165 if (!text_blink_ev.active)
2166 {
2167 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2168 hidden_text = 0;
2169 }
2170 else if (hidden_text)
2171 fore = back;
2172 }
2132#ifdef OPTION_HC 2173#elif OPTION_HC
2133 if (!rvid && (rend & RS_Blink)) 2174 if (!rvid && (rend & RS_Blink))
2134 { 2175 {
2135 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_HC)) 2176 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC))
2136 back = Color_HC; 2177 back = Color_HC;
2137 else 2178 else
2138 rvid = !rvid; /* fall back */ 2179 rvid = !rvid; /* fall back */
2139 } 2180 }
2140#endif 2181#endif
2141 if (rvid) 2182 if (rvid)
2142 { 2183 {
2143 SWAP_IT(fore, back, int); 2184 SWAP_IT(fore, back, int);
2144 2185
2145#ifndef NO_BOLD_UNDERLINE_REVERSE 2186#ifndef NO_BOLD_UNDERLINE_REVERSE
2146 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_RV) 2187 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_RV)
2147# ifndef NO_CURSORCOLOR 2188# ifndef NO_CURSORCOLOR
2148 && !ISSET_PIXCOLOR(R, Color_cursor) 2189 && !ISSET_PIXCOLOR (this, Color_cursor)
2149# endif 2190# endif
2150 ) 2191 )
2151 back = Color_RV; 2192 back = Color_RV;
2152#endif 2193#endif
2153 } 2194 }
2154#ifndef NO_BOLD_UNDERLINE_REVERSE 2195#ifndef NO_BOLD_UNDERLINE_REVERSE
2155 else if (rend & RS_Bold) 2196 else if (rend & RS_Bold)
2156 { 2197 {
2198 if (Xdepth > 2)
2157 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_BD)) 2199 if (ISSET_PIXCOLOR (this, Color_BD))
2158 {
2159 fore = Color_BD; 2200 fore = Color_BD;
2160# ifndef VERYBOLD
2161 rend &= ~RS_Bold; /* we've taken care of it */
2162# endif
2163 } 2201 else
2202 fore = Color_White;
2164 } 2203 }
2165 else if (rend & RS_Uline) 2204 else if (rend & RS_Uline)
2166 { 2205 {
2167 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_UL)) 2206 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL))
2168 {
2169 fore = Color_UL; 2207 fore = Color_UL;
2170 rend &= ~RS_Uline; /* we've taken care of it */
2171 }
2172 } 2208 }
2173#endif 2209#endif
2174 2210
2175/* 2211 /*
2176 * Actually do the drawing of the string here 2212 * Actually do the drawing of the string here
2177 */ 2213 */
2178 rxvt_font *font = (*R->TermWin.fontset)[fid]; 2214 rxvt_font *font = (*TermWin.fontset)[fid];
2179 2215
2180 if (back == Color_bg) 2216 if (back == Color_bg)
2181 { 2217 {
2182 if (must_clear) 2218 if (must_clear)
2183 { 2219 {
2186 { 2222 {
2187 font->draw (xpixel, ypixel, text, count, fore, -1); 2223 font->draw (xpixel, ypixel, text, count, fore, -1);
2188 goto nodraw; 2224 goto nodraw;
2189 } 2225 }
2190 2226
2191 CLEAR_CHARS(xpixel, ypixel, count); 2227 CLEAR_CHARS (xpixel, ypixel, count);
2192nodraw: ; 2228nodraw: ;
2193 } 2229 }
2194 else 2230 else
2195 font->draw (xpixel, ypixel, text, count, fore, Color_bg); 2231 font->draw (xpixel, ypixel, text, count, fore, Color_bg);
2196 } 2232 }
2197 else 2233 else
2198 font->draw (xpixel, ypixel, text, count, fore, back); 2234 font->draw (xpixel, ypixel, text, count, fore, back);
2199 2235
2200 if ((rend & RS_Uline) && (font->descent > 1)) 2236 if ((rend & RS_Uline) && (font->descent > 1))
2201 XDrawLine(R->Xdisplay, drawBuffer, R->TermWin.gc, 2237 XDrawLine(Xdisplay, drawBuffer, TermWin.gc,
2202 xpixel, ypixel + font->ascent + 1, 2238 xpixel, ypixel + font->ascent + 1,
2203 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); 2239 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1);
2204 } /* for (col....) */ 2240 } /* for (col....) */
2205 } /* for (row....) */ 2241 } /* for (row....) */
2206 2242
2207/* 2243 /*
2208 * G: cleanup cursor and display outline cursor if necessary 2244 * G: cleanup cursor and display outline cursor if necessary
2209 */ 2245 */
2210 if (showcursor) { 2246 if (showcursor) {
2211 if (R->TermWin.focus) { 2247 if (TermWin.focus) {
2212 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 2248 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
2213 [R->screen.cur.col]); 2249 [screen.cur.col]);
2214 *srp ^= RS_RVid; 2250 *srp ^= RS_RVid;
2215#ifndef NO_CURSORCOLOR 2251#ifndef NO_CURSORCOLOR
2216 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1; 2252 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1;
2217#endif 2253#endif
2218 } else if (R->oldcursor.row >= 0) { 2254 } else if (oldcursor.row >= 0) {
2219#ifndef NO_CURSORCOLOR 2255#ifndef NO_CURSORCOLOR
2220 unsigned long gcmask; /* Graphics Context mask */ 2256 unsigned long gcmask; /* Graphics Context mask */
2221 2257
2222 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) { 2258 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor))
2223 XSetForeground (R->Xdisplay, R->TermWin.gc, R->PixColors[Color_cursor]); 2259 XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]);
2224 }
2225#endif 2260#endif
2226 XDrawRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, 2261 XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc,
2227 Col2Pixel(R->oldcursor.col), 2262 Col2Pixel(oldcursor.col),
2228 Row2Pixel(R->oldcursor.row), 2263 Row2Pixel(oldcursor.row),
2229 (unsigned int)(Width2Pixel(cursorwidth) - 1), 2264 (unsigned int)(Width2Pixel(cursorwidth) - 1),
2230 (unsigned int)(Height2Pixel(1) - R->TermWin.lineSpace - 1)); 2265 (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1));
2231 } 2266 }
2232 } 2267 }
2233/* 2268
2269 /*
2234 * H: cleanup selection 2270 * H: cleanup selection
2235 */ 2271 */
2236 rxvt_scr_reverse_selection(aR); 2272 rxvt_scr_reverse_selection (this);
2237 2273
2238/* 2274 /*
2239 * I: other general cleanup 2275 * I: other general cleanup
2240 */ 2276 */
2241 if (clearfirst && R->TermWin.int_bwidth) 2277 if (clearfirst && TermWin.int_bwidth)
2242 /* 2278 /*
2243 * clear the whole screen height, note that width == 0 is treated 2279 * clear the whole screen height, note that width == 0 is treated
2244 * specially by XClearArea 2280 * specially by XClearArea
2245 */ 2281 */
2246 XClearArea(R->Xdisplay, R->TermWin.vt, 0, 0, 2282 XClearArea(Xdisplay, TermWin.vt, 0, 0,
2247 (unsigned int)R->TermWin.int_bwidth, 2283 (unsigned int)TermWin.int_bwidth,
2248 (unsigned int)TermWin_TotalHeight(), False); 2284 (unsigned int)TermWin_TotalHeight(), False);
2249 if (clearlast && R->TermWin.int_bwidth) 2285 if (clearlast && TermWin.int_bwidth)
2250 /* 2286 /*
2251 * clear the whole screen height, note that width == 0 is treated 2287 * clear the whole screen height, note that width == 0 is treated
2252 * specially by XClearArea 2288 * specially by XClearArea
2253 */ 2289 */
2254 XClearArea(R->Xdisplay, R->TermWin.vt, 2290 XClearArea(Xdisplay, TermWin.vt,
2255 R->TermWin.width + R->TermWin.int_bwidth, 0, 2291 TermWin.width + TermWin.int_bwidth, 0,
2256 (unsigned int)R->TermWin.int_bwidth, 2292 (unsigned int)TermWin.int_bwidth,
2257 (unsigned int)TermWin_TotalHeight(), False); 2293 (unsigned int)TermWin_TotalHeight(), False);
2258 if (refresh_type & SMOOTH_REFRESH) 2294 if (refresh_type & SMOOTH_REFRESH)
2259 XSync(R->Xdisplay, False); 2295 XSync(Xdisplay, False);
2260 2296
2261 R->num_scr = 0; 2297 num_scr = 0;
2262 R->num_scr_allow = 1; 2298 num_scr_allow = 1;
2263 R->want_refresh = 0; /* screen is current */ 2299 want_refresh = 0; /* screen is current */
2264} 2300}
2265/* ------------------------------------------------------------------------- */
2266 2301
2267/* EXTPROTO */ 2302/* ------------------------------------------------------------------------- */
2268void 2303void
2269rxvt_scr_clear(pR) 2304rxvt_term::scr_clear()
2270{ 2305{
2271 if (!R->TermWin.mapped) 2306 if (!TermWin.mapped)
2272 return; 2307 return;
2308
2273 R->num_scr_allow = 0; 2309 num_scr_allow = 0;
2274 R->want_refresh = 1; 2310 want_refresh = 1;
2275#ifdef TRANSPARENT 2311#ifdef TRANSPARENT
2276 if ((R->Options & Opt_transparent) && (R->am_pixmap_trans == 0)) { 2312 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2277 int i; 2313 {
2314 int i;
2278 2315
2279 if (!(R->Options & Opt_transparent_all)) 2316 if (!(Options & Opt_transparent_all))
2280 i = 0; 2317 i = 0;
2281 else 2318 else
2282 i = (int)(sizeof(R->TermWin.parent) / sizeof(Window)); 2319 i = (int)(sizeof(TermWin.parent) / sizeof(Window));
2283 for (; i--;) 2320
2321 while (i--)
2284 if (R->TermWin.parent[i] != None) 2322 if (TermWin.parent[i] != None)
2285 XClearWindow(R->Xdisplay, R->TermWin.parent[i]); 2323 XClearWindow(Xdisplay, TermWin.parent[i]);
2286 } 2324 }
2287#endif 2325#endif
2326
2288 XClearWindow(R->Xdisplay, R->TermWin.vt); 2327 XClearWindow (Xdisplay, TermWin.vt);
2289} 2328}
2290 2329
2291/* ------------------------------------------------------------------------- */ 2330/* ------------------------------------------------------------------------- */
2292/* INTPROTO */ 2331/* INTPROTO */
2293void 2332void
2401rxvt_term::paste (const unsigned char *data, unsigned int len) 2440rxvt_term::paste (const unsigned char *data, unsigned int len)
2402{ 2441{
2403 unsigned int i, j, n; 2442 unsigned int i, j, n;
2404 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE); 2443 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE);
2405 2444
2445#if 0
2446 /* a paste should act like the user is typing, so check scrollTtyKeypress */
2447 ZERO_SCROLLBACK (r);
2448#endif
2449
2406 /* convert normal newline chars into common keyboard Return key sequence */ 2450 /* convert normal newline chars into common keyboard Return key sequence */
2407 for (i = 0; i < len; i += PROP_SIZE) 2451 for (i = 0; i < len; i += PROP_SIZE)
2408 { 2452 {
2409 n = min (len - i, PROP_SIZE); 2453 n = min (len - i, PROP_SIZE);
2410 MEMCPY (ds, data + i, n); 2454 MEMCPY (ds, data + i, n);
2429rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) 2473rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop)
2430{ 2474{
2431 long nread = 0; 2475 long nread = 0;
2432 unsigned long bytes_after; 2476 unsigned long bytes_after;
2433 XTextProperty ct; 2477 XTextProperty ct;
2434 int dummy_count;
2435 char **cl;
2436 2478
2437 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); 2479 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait));
2438 2480
2439 if (prop == None) /* check for failed XConvertSelection */ 2481 if (prop == None) /* check for failed XConvertSelection */
2440 { 2482 {
2443 int selnum = R->selection_type & Sel_whereMask; 2485 int selnum = R->selection_type & Sel_whereMask;
2444 2486
2445 R->selection_type = 0; 2487 R->selection_type = 0;
2446 if (selnum != Sel_direct) 2488 if (selnum != Sel_direct)
2447 rxvt_selection_request_other(aR_ XA_STRING, selnum); 2489 rxvt_selection_request_other(aR_ XA_STRING, selnum);
2490 }
2491
2492 if ((R->selection_type & Sel_UTF8String))
2493 {
2494 int selnum = R->selection_type & Sel_whereMask;
2495
2496 R->selection_type = Sel_CompoundText;
2497 if (selnum != Sel_direct)
2498 rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum);
2499 else
2500 R->selection_type = 0;
2448 } 2501 }
2449 2502
2450 return 0; 2503 return 0;
2451 } 2504 }
2452 2505
2487 nread = -1; /* discount any previous stuff */ 2540 nread = -1; /* discount any previous stuff */
2488 break; 2541 break;
2489 } 2542 }
2490 2543
2491 nread += ct.nitems; 2544 nread += ct.nitems;
2545
2546 char **cl;
2547 int cr;
2492 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, 2548 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl,
2493 &dummy_count) == Success && cl) 2549 &cr) >= 0 && cl)
2494 { 2550 {
2551 for (int i = 0; i < cr; i++)
2495 R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); 2552 R->paste ((unsigned char *)cl[i], STRLEN (cl[i]));
2553
2496 XFreeStringList (cl); 2554 XFreeStringList (cl);
2497 } 2555 }
2498 else 2556 else
2499 R->paste (ct.value, ct.nitems); 2557 R->paste (ct.value, ct.nitems);
2500 2558
2515} 2573}
2516 2574
2517void 2575void
2518rxvt_term::incr_cb (time_watcher &w) 2576rxvt_term::incr_cb (time_watcher &w)
2519{ 2577{
2520 w.stop ();
2521 selection_wait = Sel_none; 2578 selection_wait = Sel_none;
2522 2579
2523 rxvt_print_error("data loss: timeout on INCR selection paste"); 2580 rxvt_print_error ("data loss: timeout on INCR selection paste");
2524} 2581}
2525 2582
2526/* 2583/*
2527 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> 2584 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2528 */ 2585 */
2594 int i; 2651 int i;
2595 2652
2596 R->selection_request_time = tm; 2653 R->selection_request_time = tm;
2597 R->selection_wait = Sel_normal; 2654 R->selection_wait = Sel_normal;
2598 for (i = Sel_Primary; i <= Sel_Clipboard; i++) { 2655 for (i = Sel_Primary; i <= Sel_Clipboard; i++) {
2656#if X_HAVE_UTF8_STRING
2657 R->selection_type = Sel_UTF8String;
2658 if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i))
2659 return;
2660#else
2599 R->selection_type = Sel_CompoundText; 2661 R->selection_type = Sel_CompoundText;
2600 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) 2662 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i))
2601 return; 2663 return;
2664#endif
2602 } 2665 }
2603 } 2666 }
2604 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ 2667 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */
2605 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); 2668 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0"));
2606 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); 2669 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False);
2738 { 2801 {
2739 free (new_selection_text); 2802 free (new_selection_text);
2740 return; 2803 return;
2741 } 2804 }
2742 2805
2743 // due to MB_MAX_CUR, selection wastage is usually high 2806 // due to MB_MAX_CUR, selection wastage is usually high, so realloc
2744 if (str - (char *)new_selection_text > 1024) 2807 if (str - (char *)new_selection_text > 1024)
2745 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); 2808 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1);
2746 2809
2747 R->selection.len = i; 2810 R->selection.len = i;
2811
2748 if (R->selection.text) 2812 if (R->selection.text)
2749 free (R->selection.text); 2813 free (R->selection.text);
2750 2814
2751 R->selection.text = new_selection_text; 2815 R->selection.text = new_selection_text;
2752 2816
2753 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); 2817 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm);
2754 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) 2818 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt)
2755 rxvt_print_error("can't get primary selection"); 2819 rxvt_print_error("can't get primary selection");
2820
2821
2822 {
2823 XTextProperty ct;
2824 char *cl = (char *)R->selection.text;
2825
2826 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0)
2827 {
2828 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2829 PropModeReplace, ct.value, ct.nitems);
2830 XFree (ct.value);
2831 }
2832 else
2756 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, 2833 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2757 PropModeReplace, R->selection.text, (int)R->selection.len); 2834 PropModeReplace, R->selection.text, (int)R->selection.len);
2835 }
2836
2758 R->selection_time = tm; 2837 R->selection_time = tm;
2759 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); 2838 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len));
2760} 2839}
2761 2840
2762/* ------------------------------------------------------------------------- */ 2841/* ------------------------------------------------------------------------- */
2763/* 2842/*
2764 * Mark or select text based upon number of clicks: 1, 2, or 3 2843 * Mark or select text based upon number of clicks: 1, 2, or 3
2765 * EXT: button 1 press 2844 * EXT: button 1 press
2766 */ 2845 */
2767/* EXTPROTO */
2768void 2846void
2769rxvt_selection_click(pR_ int clicks, int x, int y) 2847rxvt_term::selection_click (int clicks, int x, int y)
2770{ 2848{
2771 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y)); 2849 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y));
2772 2850
2773 clicks = ((clicks - 1) % 3) + 1; 2851 clicks = ((clicks - 1) % 3) + 1;
2774 R->selection.clicks = clicks; /* save clicks so extend will work */ 2852 selection.clicks = clicks; /* save clicks so extend will work */
2775 2853
2776 rxvt_selection_start_colrow(aR_ Pixel2Col(x), Pixel2Row(y)); 2854 rxvt_selection_start_colrow (this, Pixel2Col(x), Pixel2Row(y));
2855
2777 if (clicks == 2 || clicks == 3) 2856 if (clicks == 2 || clicks == 3)
2778 rxvt_selection_extend_colrow(aR_ R->selection.mark.col, 2857 rxvt_selection_extend_colrow (this, selection.mark.col,
2779 R->selection.mark.row
2780 + R->TermWin.view_start, 2858 selection.mark.row + TermWin.view_start,
2781 0, /* button 3 */ 2859 0, /* button 3 */
2782 1, /* button press */ 2860 1, /* button press */
2783 0); /* click change */ 2861 0); /* click change */
2784} 2862}
2785 2863
2786/* ------------------------------------------------------------------------- */ 2864/* ------------------------------------------------------------------------- */
2787/* 2865/*
2788 * Mark a selection at the specified col/row 2866 * Mark a selection at the specified col/row
2898 * EXT: button 3 press; button 1 or 3 drag 2976 * EXT: button 3 press; button 1 or 3 drag
2899 * flag == 0 ==> button 1 2977 * flag == 0 ==> button 1
2900 * flag == 1 ==> button 3 press 2978 * flag == 1 ==> button 3 press
2901 * flag == 2 ==> button 3 motion 2979 * flag == 2 ==> button 3 motion
2902 */ 2980 */
2903/* EXTPROTO */
2904void 2981void
2905rxvt_selection_extend(pR_ int x, int y, int flag) 2982rxvt_term::selection_extend (int x, int y, int flag)
2906{ 2983{
2907 int col, row; 2984 int col, row;
2908 2985
2909 col = Pixel2Col(x); 2986 col = Pixel2Col(x);
2910 row = Pixel2Row(y); 2987 row = Pixel2Row(y);
2911 MAX_IT(row, 0); 2988 MAX_IT(row, 0);
2912 MIN_IT(row, (int)R->TermWin.nrow - 1); 2989 MIN_IT(row, (int)TermWin.nrow - 1);
2913 MAX_IT(col, 0); 2990 MAX_IT(col, 0);
2914 MIN_IT(col, (int)R->TermWin.ncol); 2991 MIN_IT(col, (int)TermWin.ncol);
2992
2915#ifndef NO_NEW_SELECTION 2993#ifndef NO_NEW_SELECTION
2916/* 2994 /*
2917 * If we're selecting characters (single click) then we must check first 2995 * If we're selecting characters (single click) then we must check first
2918 * if we are at the same place as the original mark. If we are then 2996 * if we are at the same place as the original mark. If we are then
2919 * select nothing. Otherwise, if we're to the right of the mark, you have to 2997 * select nothing. Otherwise, if we're to the right of the mark, you have to
2920 * be _past_ a character for it to be selected. 2998 * be _past_ a character for it to be selected.
2921 */ 2999 */
2922 if (R->selection_style != OLD_SELECT) { 3000 if (selection_style != OLD_SELECT)
3001 {
2923 if (((R->selection.clicks % 3) == 1) && !flag 3002 if (((selection.clicks % 3) == 1) && !flag
2924 && (col == R->selection.mark.col 3003 && (col == selection.mark.col
2925 && (row == R->selection.mark.row + R->TermWin.view_start))) { 3004 && (row == selection.mark.row + TermWin.view_start)))
3005 {
2926 /* select nothing */ 3006 /* select nothing */
2927 R->selection.beg.row = R->selection.end.row = 0; 3007 selection.beg.row = selection.end.row = 0;
2928 R->selection.beg.col = R->selection.end.col = 0; 3008 selection.beg.col = selection.end.col = 0;
2929 R->selection.clicks = 4; 3009 selection.clicks = 4;
2930 R->want_refresh = 1; 3010 want_refresh = 1;
2931 D_SELECT((stderr, "rxvt_selection_extend() R->selection.clicks = 4")); 3011 D_SELECT((stderr, "rxvt_selection_extend() selection.clicks = 4"));
2932 return; 3012 return;
2933 } 3013 }
2934 } 3014 }
2935#endif 3015#endif
2936 if (R->selection.clicks == 4) 3016 if (selection.clicks == 4)
2937 R->selection.clicks = 1; 3017 selection.clicks = 1;
3018
2938 rxvt_selection_extend_colrow(aR_ col, row, !!flag, /* ? button 3 */ 3019 rxvt_selection_extend_colrow (this, col, row, !!flag, /* ? button 3 */
2939 flag == 1 ? 1 : 0, /* ? button press */ 3020 flag == 1 ? 1 : 0, /* ? button press */
2940 0); /* no click change */ 3021 0); /* no click change */
2941} 3022}
2942 3023
2943/* ------------------------------------------------------------------------- */ 3024/* ------------------------------------------------------------------------- */
2944/* 3025/*
2945 * Extend the selection to the specified col/row 3026 * Extend the selection to the specified col/row
3199/* ------------------------------------------------------------------------- */ 3280/* ------------------------------------------------------------------------- */
3200/* 3281/*
3201 * Double click on button 3 when already selected 3282 * Double click on button 3 when already selected
3202 * EXT: button 3 double click 3283 * EXT: button 3 double click
3203 */ 3284 */
3204/* EXTPROTO */
3205void 3285void
3206rxvt_selection_rotate(pR_ int x, int y) 3286rxvt_term::selection_rotate (int x, int y)
3207{ 3287{
3208 R->selection.clicks = R->selection.clicks % 3 + 1; 3288 selection.clicks = selection.clicks % 3 + 1;
3209 rxvt_selection_extend_colrow(aR_ Pixel2Col(x), Pixel2Row(y), 1, 0, 1); 3289 rxvt_selection_extend_colrow (this, Pixel2Col(x), Pixel2Row(y), 1, 0, 1);
3210} 3290}
3211 3291
3212/* ------------------------------------------------------------------------- */ 3292/* ------------------------------------------------------------------------- */
3213/* 3293/*
3214 * On some systems, the Atom typedef is 64 bits wide. We need to have a type 3294 * On some systems, the Atom typedef is 64 bits wide. We need to have a type
3215 * that is exactly 32 bits wide, because a format of 64 is not allowed by 3295 * that is exactly 32 bits wide, because a format of 64 is not allowed by
3216 * the X11 protocol. 3296 * the X11 protocol.
3217 */ 3297 */
3218typedef CARD32 Atom32; 3298typedef CARD32 Atom32;
3219 3299
3220/* ------------------------------------------------------------------------- */ 3300/* ------------------------------------------------------------------------- */
3221/* 3301/*
3222 * Respond to a request for our current selection 3302 * Respond to a request for our current selection
3223 * EXT: SelectionRequest 3303 * EXT: SelectionRequest
3225/* EXTPROTO */ 3305/* EXTPROTO */
3226void 3306void
3227rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) 3307rxvt_selection_send(pR_ const XSelectionRequestEvent *rq)
3228{ 3308{
3229 XSelectionEvent ev; 3309 XSelectionEvent ev;
3230#ifdef USE_XIM
3231 Atom32 target_list[4];
3232#else
3233 Atom32 target_list[3];
3234#endif
3235 Atom target;
3236 XTextProperty ct; 3310 XTextProperty ct;
3237 XICCEncodingStyle style; 3311 XICCEncodingStyle style;
3238 char *cl[2], dummy[1]; 3312 Atom target;
3239 3313
3240 ev.type = SelectionNotify; 3314 ev.type = SelectionNotify;
3241 ev.property = None; 3315 ev.property = None;
3242 ev.display = rq->display; 3316 ev.display = rq->display;
3243 ev.requestor = rq->requestor; 3317 ev.requestor = rq->requestor;
3244 ev.selection = rq->selection; 3318 ev.selection = rq->selection;
3245 ev.target = rq->target; 3319 ev.target = rq->target;
3246 ev.time = rq->time; 3320 ev.time = rq->time;
3247 3321
3248 if (rq->target == R->xa[XA_TARGETS]) { 3322 if (rq->target == R->xa[XA_TARGETS]) {
3323 Atom32 target_list[5];
3324 Atom32 *target = target_list;
3325
3249 target_list[0] = (Atom32) R->xa[XA_TARGETS]; 3326 *target++ = (Atom32) R->xa[XA_TARGETS];
3250 target_list[1] = (Atom32) XA_STRING; 3327 *target++ = (Atom32) XA_STRING;
3251 target_list[2] = (Atom32) R->xa[XA_TEXT]; 3328 *target++ = (Atom32) R->xa[XA_TEXT];
3252#ifdef USE_XIM
3253 target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; 3329 *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT];
3330#if X_HAVE_UTF8_STRING
3331 *target++ = (Atom32) R->xa[XA_UTF8_STRING];
3254#endif 3332#endif
3255 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, 3333 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM,
3256 (8 * sizeof(target_list[0])), PropModeReplace, 3334 (8 * sizeof(target_list[0])), PropModeReplace,
3257 (unsigned char *)target_list, 3335 (unsigned char *)target_list,
3258 (sizeof(target_list) / sizeof(target_list[0]))); 3336 target - target_list);
3259 ev.property = rq->property; 3337 ev.property = rq->property;
3260 } else if (rq->target == R->xa[XA_MULTIPLE]) { 3338 } else if (rq->target == R->xa[XA_MULTIPLE]) {
3261 /* TODO: Handle MULTIPLE */ 3339 /* TODO: Handle MULTIPLE */
3262 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { 3340 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) {
3263 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, 3341 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER,
3264 (8 * sizeof(Time)), PropModeReplace, 3342 (8 * sizeof(Time)), PropModeReplace,
3265 (unsigned char *)&R->selection_time, 1); 3343 (unsigned char *)&R->selection_time, 1);
3266 ev.property = rq->property; 3344 ev.property = rq->property;
3267 } else if (rq->target == XA_STRING 3345 } else if (rq->target == XA_STRING
3346 || rq->target == R->xa[XA_TEXT]
3268 || rq->target == R->xa[XA_COMPOUND_TEXT] 3347 || rq->target == R->xa[XA_COMPOUND_TEXT]
3269 || rq->target == R->xa[XA_TEXT]) { 3348 || rq->target == R->xa[XA_UTF8_STRING]
3270#ifdef USE_XIM 3349 ) {
3271 short freect = 0; 3350 short freect = 0;
3272#endif
3273 int selectlen; 3351 int selectlen;
3352 char *cl;
3274 3353
3275#ifdef USE_XIM 3354 target = rq->target;
3355
3276 if (rq->target != XA_STRING) { 3356 if (target == XA_STRING)
3357 // we actually don't do XA_STRING, but who cares, as i18n clients
3358 // will ask for another format anyways.
3359 style = XStringStyle;
3360 else if (target == R->xa[XA_TEXT])
3361 style = XTextStyle;
3362 else if (target == R->xa[XA_COMPOUND_TEXT])
3363 style = XCompoundTextStyle;
3364#if X_HAVE_UTF8_STRING
3365 else if (target == R->xa[XA_UTF8_STRING])
3366 style = XUTF8StringStyle;
3367#endif
3368 else
3369 {
3277 target = R->xa[XA_COMPOUND_TEXT]; 3370 target = R->xa[XA_COMPOUND_TEXT];
3278 style = (rq->target == R->xa[XA_COMPOUND_TEXT])
3279 ? XCompoundTextStyle : XStdICCTextStyle;
3280 } else
3281#endif
3282 {
3283 target = XA_STRING;
3284 style = XStringStyle; 3371 style = XCompoundTextStyle;
3285 } 3372 }
3373
3286 if (R->selection.text) { 3374 if (R->selection.text) {
3287 cl[0] = (char *)R->selection.text; 3375 cl = (char *)R->selection.text;
3288 selectlen = R->selection.len; 3376 selectlen = R->selection.len;
3289 } else { 3377 } else {
3290 cl[0] = dummy; 3378 cl = "";
3291 *dummy = '\0';
3292 selectlen = 0; 3379 selectlen = 0;
3293 } 3380 }
3294#ifdef USE_XIM 3381
3295 if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) 3382 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0)
3296 == Success) /* if we failed to convert then send it raw */
3297 freect = 1; 3383 freect = 1;
3298 else 3384 else
3299#endif
3300 { 3385 {
3386 /* if we failed to convert then send it raw */
3301 ct.value = (unsigned char *)cl[0]; 3387 ct.value = (unsigned char *)cl;
3302 ct.nitems = selectlen; 3388 ct.nitems = selectlen;
3303 } 3389 }
3390
3304 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, 3391 XChangeProperty(R->Xdisplay, rq->requestor, rq->property,
3305 target, 8, PropModeReplace, 3392 target, 8, PropModeReplace,
3306 ct.value, (int)ct.nitems); 3393 ct.value, (int)ct.nitems);
3307 ev.property = rq->property; 3394 ev.property = rq->property;
3308#ifdef USE_XIM 3395
3309 if (freect) 3396 if (freect)
3310 XFree(ct.value); 3397 XFree (ct.value);
3311#endif
3312 } 3398 }
3313 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); 3399 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev);
3314} 3400}
3315 3401
3316/* ------------------------------------------------------------------------- * 3402/* ------------------------------------------------------------------------- *
3318 * ------------------------------------------------------------------------- */ 3404 * ------------------------------------------------------------------------- */
3319 3405
3320/* 3406/*
3321 * return col/row values corresponding to x/y pixel values 3407 * return col/row values corresponding to x/y pixel values
3322 */ 3408 */
3323/* EXTPROTO */
3324void 3409void
3325rxvt_pixel_position(pR_ int *x, int *y) 3410rxvt_term::pixel_position (int *x, int *y)
3326{ 3411{
3327 *x = Pixel2Col(*x); 3412 *x = Pixel2Col(*x);
3328/* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */ 3413 /* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */
3329 *y = Pixel2Row(*y); 3414 *y = Pixel2Row(*y);
3330/* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */ 3415 /* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */
3331} 3416}
3417
3332/* ------------------------------------------------------------------------- */ 3418/* ------------------------------------------------------------------------- */
3333#ifdef USE_XIM 3419#ifdef USE_XIM
3334/* EXTPROTO */
3335void 3420void
3336rxvt_setPosition(pR_ XPoint *pos) 3421rxvt_term::set_position (XPoint *pos)
3337{ 3422{
3338 XWindowAttributes xwa; 3423 XWindowAttributes xwa;
3339 3424
3340 XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &xwa); 3425 XGetWindowAttributes (Xdisplay, TermWin.vt, &xwa);
3341 pos->x = Col2Pixel(R->screen.cur.col) + xwa.x; 3426 pos->x = Col2Pixel (screen.cur.col) + xwa.x;
3342 pos->y = Height2Pixel((R->screen.cur.row + 1)) + xwa.y 3427 pos->y = Height2Pixel ((screen.cur.row + 1)) + xwa.y - TermWin.lineSpace;
3343 - R->TermWin.lineSpace;
3344} 3428}
3429
3345#endif 3430#endif
3346/* ------------------------------------------------------------------------- */ 3431/* ------------------------------------------------------------------------- */
3347 3432
3348/* ------------------------------------------------------------------------- * 3433/* ------------------------------------------------------------------------- *
3349 * DEBUG ROUTINES * 3434 * DEBUG ROUTINES *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines