File: csr_change.c

package info (click to toggle)
xview 3.2p1.4-28.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 26,680 kB
  • ctags: 34,403
  • sloc: ansic: 241,397; yacc: 1,435; sh: 1,086; makefile: 148; lex: 76; perl: 54; asm: 50; cpp: 15
file content (786 lines) | stat: -rw-r--r-- 20,616 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
#ifndef lint
#ifdef sccs
static char     sccsid[] = "@(#)csr_change.c 20.51 93/06/28";
#endif
#endif
/*
 *	(c) Copyright 1989 Sun Microsystems, Inc. Sun design patents 
 *	pending in the U.S. and foreign countries. See LEGAL NOTICE 
 *	file for terms of the license.
 */

/*
 * Character screen operations (except size change and init).
 */

#include <xview_private/tty_impl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#include <X11/Xlib.h>
#include <pixrect/pixrect.h>
#include <pixrect/pixfont.h>

#ifdef __STDC__ 
#ifndef CAT
#define CAT(a,b)        a ## b 
#endif 
#endif
#include <pixrect/memvar.h>

#include <xview/rect.h>
#include <xview/rectlist.h>
#include <xview/pixwin.h>
#include <xview/ttysw.h>
#include <xview/sel_svc.h>

#include <xview_private/charimage.h>
#include <xview_private/charscreen.h>
#undef CTRL
#include <xview_private/ttyansi.h>
#include <xview_private/term_impl.h>
#include <xview/window.h>
#include <xview/pkg.h>
#include <xview/attrol.h>
#include <xview/server.h>
#include <xview/font.h>
#ifndef __linux__
Xv_private_data char *xv_shell_prompt;
#else
/* Global already defined in server/server.c */
extern char *xv_shell_prompt;
#endif

#ifdef OW_I18N
#define NULL_CHARP      (CHAR *) 0
#endif

#define TTYSW_HOME_CHAR	'A'

extern Xv_Window csr_pixwin;
extern int      cursor;		/* NOCURSOR, UNDERCURSOR, BLOCKCURSOR */

/* static */ void ttysw_fixup_display_mode();

#ifdef OW_I18N
/* static */ void ttysw_convert_string();
#endif
static void ttysw_paintCursor();

static int      caretx, carety, lxhome;
static short    charcursx, charcursy;


#ifdef  OW_I18N
/*
 *      To save the width of cursor that has been most recently
 *      drawn , so that when deleting the cursor , we can construct
 *      the reversed image easily.
 */
static  int     curs_width;
#endif

static int      boldstyle, inverse_mode, underline_mode;

extern struct timeval ttysw_bell_tv;	/* initialized to 1/10 second */

static u_short  ttysw_gray17_data[16] = {	/* really 16-2/3	 */
    0x8208, 0x2082, 0x0410, 0x1041, 0x4104, 0x0820, 0x8208, 0x2082,
    0x0410, 0x1041, 0x4104, 0x0820, 0x8208, 0x2082, 0x0410, 0x1041
};

mpr_static(ttysw_gray17_pr, 12, 12, 1, ttysw_gray17_data);

Pkg_private int /* Note: change to void */
ttysw_setboldstyle(new_boldstyle)
    int             new_boldstyle;
{
    if (new_boldstyle > TTYSW_BOLD_MAX
	|| new_boldstyle < TTYSW_BOLD_NONE)
	boldstyle = TTYSW_BOLD_NONE;
    else
	boldstyle = new_boldstyle;
    return boldstyle;
}

Pkg_private void
ttysw_set_inverse_mode(new_inverse_mode)
    int             new_inverse_mode;
{
    inverse_mode = new_inverse_mode;
}

Pkg_private void
ttysw_set_underline_mode(new_underline_mode)
    int             new_underline_mode;
{
    underline_mode = new_underline_mode;
}

Pkg_private int
ttysw_getboldstyle()
{
    return boldstyle;
}

/* NOT USED */
ttysw_get_inverse_mode()
{
    return inverse_mode;
}

/* NOT USED */
ttysw_get_underline_mode()
{
    return underline_mode;
}


Pkg_private void
ttysw_setleftmargin(left_margin)
{
    chrleftmargin = left_margin > 0 ? left_margin : 0;
}

/* NOT USED */
ttysw_getleftmargin()
{
    return chrleftmargin;
}

/* static */ void
ttysw_fixup_display_mode(mode)
    char           *mode;
{

    if ((*mode & MODE_INVERT) && (inverse_mode != TTYSW_ENABLE)) {
	*mode &= ~MODE_INVERT;
	if (inverse_mode == TTYSW_SAME_AS_BOLD)
	    *mode |= MODE_BOLD;
    }
    if ((*mode & MODE_UNDERSCORE) && (underline_mode != TTYSW_ENABLE)) {
	*mode &= ~MODE_UNDERSCORE;
	if (underline_mode == TTYSW_SAME_AS_BOLD)
	    *mode |= MODE_BOLD;
    }
    if ((*mode & MODE_BOLD) && (boldstyle & TTYSW_BOLD_INVERT)) {
	*mode &= ~MODE_BOLD;
	*mode |= MODE_INVERT;
    }
}

/* Note: whole string will be diplayed with mode. */
Pkg_private void
ttysw_pstring(s, mode, col, row, op)
    register CHAR  *s;          /* must be null-terminated */
    char            mode;
    register int    col, row;
    int             op;		/* PIX_SRC | PIX_DST (faster), or PIX_SRC
				 * (safer) */
{
#ifdef OW_I18N
    register CHAR *cp;
#define BUFSIZE 1024
    /*
     *  ttysw_pstring() is called a line at a time
     */
    CHAR           buf[BUFSIZE];
#endif
    register int    x_home;
    register int    y_home;
    XFontStruct	*x_font_info = (XFontStruct *)xv_get((Xv_opaque)pixfont, FONT_INFO);

#ifdef OW_I18N
    x_home = x_font_info->min_bounds.lbearing;
    y_home = -chrbase;
#else
    x_home =  x_font_info->per_char ?
              x_font_info->per_char[TTYSW_HOME_CHAR -
                         x_font_info->min_char_or_byte2].lbearing
             : x_font_info->min_bounds.lbearing;
    y_home = -x_font_info->ascent;
#endif

    /* this is needed for correct caret rendering */
    lxhome = x_home;

    /* possibly use escape sequences ? */

    if (xv_get(XV_SERVER_FROM_WINDOW(csr_pixwin), SERVER_JOURNALLING))
        if (INDEX(s, xv_shell_prompt[0]))
	    xv_set(XV_SERVER_FROM_WINDOW(csr_pixwin), 
                         SERVER_JOURNAL_SYNC_EVENT, 1, 0);

    if (delaypainting) {
	if (row == ttysw_bottom)
	    /*
	     * Reached bottom of screen so end delaypainting.
	     */
	    (void) ttysw_pdisplayscreen(1);
	return;
    }
    if (s == 0)
	return;
    ttysw_fixup_display_mode(&mode);

#ifdef  OW_I18N
    ttysw_convert_string( buf , s );
    if (mode & MODE_BOLD) {
                /* Clean up first */
        (void) ttysw_pclearline(col, col + STRLEN(s), row);

        /* render the first one, the potential offset of the others */
        tty_newtext(csr_pixwin,
		   col_to_x(col) - x_home,
		   row_to_y(row) - y_home,
		   (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : op,
		   pixfont, buf, STRLEN(buf));

        if (boldstyle & TTYSW_BOLD_OFFSET_X)
            tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home + 1,
		       row_to_y(row) - y_home,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, buf, STRLEN(buf));
        if (boldstyle & TTYSW_BOLD_OFFSET_Y)
            tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home,
		       row_to_y(row) - y_home + 1,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, buf, STRLEN(buf));
        if (boldstyle & TTYSW_BOLD_OFFSET_XY)
            tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home + 1,
		       row_to_y(row) - y_home + 1,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, buf, STRLEN(buf));
    } else {
        tty_newtext(csr_pixwin,
		   col_to_x(col) - x_home,
		   row_to_y(row) - y_home,
(mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : op, pixfont, buf, STRLEN(buf));
    }
    if (mode & MODE_UNDERSCORE) {
        struct pr_size str_size;
        struct pr_size xv_pf_textwidth_wc();
        str_size = xv_pf_textwidth_wc(STRLEN(buf),pixfont,buf);
        tty_background(csr_pixwin,
                       col_to_x(col), row_to_y(row) + chrheight - 1,
                       str_size.x, 1,
                       (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : PIX_SRC);
    }
#else
    if (mode & MODE_BOLD) {
	    	/* Clean up first */
	(void) ttysw_pclearline(col, col + strlen(s), row);

	/* render the first one, the potential offset of the others */
	tty_newtext(csr_pixwin,
		   col_to_x(col) - x_home,
		   row_to_y(row) - y_home,
		   (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : op, 
		   pixfont, s, strlen(s));

	if (boldstyle & TTYSW_BOLD_OFFSET_X)
	    tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home + 1,
		       row_to_y(row) - y_home,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, s, strlen(s));
	if (boldstyle & TTYSW_BOLD_OFFSET_Y)
	    tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home,
		       row_to_y(row) - y_home + 1,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, s, strlen(s));
	if (boldstyle & TTYSW_BOLD_OFFSET_XY)
	    tty_newtext(csr_pixwin,
		       col_to_x(col) - x_home + 1,
		       row_to_y(row) - y_home + 1,
		 (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) & PIX_DST :
		       PIX_SRC | PIX_DST, pixfont, s, strlen(s));
    } else {
	tty_newtext(csr_pixwin,
		   col_to_x(col) - x_home,
		   row_to_y(row) - y_home,
(mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : op, pixfont, s, strlen(s));
    }
    if (mode & MODE_UNDERSCORE) {
	tty_background(csr_pixwin,
		       col_to_x(col), row_to_y(row) + chrheight - 1,
		       strlen(s) * chrwidth, 1,
                       (mode & MODE_INVERT) ? PIX_NOT(PIX_SRC) : PIX_SRC);
    }
#endif  /* OW_I18N */

#ifdef  OW_I18N
#undef  BUFSIZE
#endif
}

Pkg_private void
ttysw_pclearline(fromcol, tocol, row)
    int             fromcol, tocol, row;
{
    int	klu1284	= (fromcol == 0 ? 1 : 0 ); 

    if (delaypainting)
	return;
    (void) tty_background(csr_pixwin, 
			  col_to_x(fromcol)-klu1284, row_to_y(row),
			  col_to_x(tocol) - col_to_x(fromcol)+klu1284,
			  chrheight, PIX_CLR);
}

Pkg_private void
ttysw_pcopyline(tocol, fromcol, count, row)
    int             fromcol, tocol, count, row;
{
    int             pix_width = (count * chrwidth);
    if (delaypainting)
	return;
    (void) tty_copyarea(csr_pixwin,
		     col_to_x(fromcol)-1, row_to_y(row), pix_width+1, chrheight,
			col_to_x(tocol)-1, row_to_y(row));
    tty_synccopyarea(csr_pixwin);
}

Pkg_private void
ttysw_pclearscreen(fromrow, torow)
    int             fromrow, torow;
{
    if (delaypainting)
	return;
    (void) tty_background(csr_pixwin, col_to_x(ttysw_left)-1,
			  row_to_y(fromrow),
			  winwidthp+1, row_to_y(torow - fromrow), PIX_CLR);
}

Pkg_private void
ttysw_pcopyscreen(fromrow, torow, count)
    int             fromrow, torow, count;
{
    if (delaypainting)
	return;
    (void) tty_copyarea(csr_pixwin,
			col_to_x(ttysw_left)-1, row_to_y(fromrow), winwidthp+1, row_to_y(count),
			col_to_x(ttysw_left)-1, row_to_y(torow));
    tty_synccopyarea(csr_pixwin);
}

static void
ttysw_displayrow(row, leftcol)
	register int row, leftcol;
{
	register int	colstart, blanks, colfirst;
	register CHAR  *strstart, *strfirst;
	register char	modefirst;
	register char  *modestart;
	CHAR		csave;

	colfirst = 0;
	colstart = leftcol;

	if ((unsigned char)leftcol < LINE_LENGTH(image[row])) {
#ifdef OW_I18N
		strfirst = NULL_CHARP;
#else
		strfirst = (caddr_t) 0;
#endif
		modefirst = MODE_CLEAR;
		blanks = 1;
		for (strstart = image[row] + leftcol,
		     modestart = screenmode[row] + leftcol; *strstart;
		     strstart++, modestart++, colstart++) {
		    /*
		     * Find beginning of bold string
		     */
		    if (*modestart != modefirst) {
			goto Flush;
			/*
			 * Find first non-blank char
			 */
		    } else if (blanks && (*strstart != ' '))
			goto Flush;
		    else
			continue;
	    Flush:
#ifdef OW_I18N
                    if (strfirst != NULL_CHARP) {
#else
		    if (strfirst != (caddr_t) 0) {
#endif
			csave = *strstart;
			*strstart = '\0';
			(void) ttysw_pstring(strfirst, modefirst,
				       colfirst, row,
				       PIX_SRC /* | PIX_DST - jcb */ );
			*strstart = csave;
		    }
		    colfirst = colstart;
		    strfirst = strstart;
		    modefirst = *modestart;
		    blanks = 0;
		}
#ifdef OW_I18N
                if (strfirst != NULL_CHARP)
#else
		if (strfirst != (caddr_t) 0)
#endif
		    (void) ttysw_pstring(strfirst, modefirst, colfirst,
				   row, PIX_SRC /* | PIX_DST -- jcb */ );
	}
}

Pkg_private void
ttysw_pdisplayscreen(dontrestorecursor)
    int             dontrestorecursor;
{
    struct rect *rect;
    int row;

    delaypainting = 0;
    /*
     * refresh the entire image.
     */
    rect = (struct rect *) xv_get(csr_pixwin, WIN_RECT);
    (void) tty_background(csr_pixwin, 0, 0,
			      rect->r_width+1, rect->r_height, PIX_CLR);

    for (row = ttysw_top; row < ttysw_bottom; row++)
		ttysw_displayrow(row, 0);

    if (!dontrestorecursor)
	/*
	 * The following has effect of restoring cursor.
	 */
	(void) ttysw_removeCursor();
}

/* ARGSUSED */
Pkg_private void
ttysw_prepair(eventp)
	XEvent		*eventp;
{
	Tty_exposed_lines *exposed;
	Ttysw_folio	ttysw = TTY_PRIVATE_FROM_ANY_VIEW(csr_pixwin);
	register int	row;
	int		leftcol;
	int		display_cursor = FALSE;

	/* 
	 * Handles expose and graphics expose events for the ttysw.   
	 */

	/* Get the expose events, ignore textsw caret checking with -10000 */
	exposed = tty_calc_exposed_lines(csr_pixwin, eventp, -10000);

	leftcol = x_to_col(exposed->leftmost);

	/* 
	 * Check damage on for cursor:
	 * When the cursor is light, it actually appears
	 * in the lines above and below the cursrow
	 * so these lines have to be checked too.
	 */
	if(leftcol <= curscol+1) {
	  /* 
	   * cheak and use one column to right and left of curscol because 
	   * unhilighted cursor actually overlaps into adjoining columns.
	   * Need to repaint these characters so they look right after 
	   * erasing with ttysw_paintCursor().
	   */
	  leftcol = MIN(leftcol, curscol-1);
	  leftcol = MAX(leftcol, 0);
	  if((exposed->line_exposed[cursrow]) ||
	     ((cursor & LIGHTCURSOR) && exposed->line_exposed[cursrow+1] ||
	      (cursrow > 0 && exposed->line_exposed[cursrow-1]))) {

			ttysw_paintCursor(PIX_CLR);
			exposed->line_exposed[cursrow] = TRUE;
			display_cursor = TRUE;
	  }
	}

	if(ttysw->ttysw_primary.sel_made && !ttysw->ttysw_primary.sel_null) {
		/* 
		 * In this case, there is a primary selection when
		 * an expose event happened.  To be most efficient and
		 * visually appealing, we might want to only repaint
		 * damaged areas.  But because the primary selection
		 * is highlighted with exclusive-or, this has to be
		 * done very cleverly.  
		 * 
		 * The secondary selection is painted over the text
		 * not using xor so it appears correctly regardless.
		 * This selection might be repainted here if it becomes an 
		 * issue, but the thinking is that simultaneous selections 
		 * and exposures are relatively rare.
		 */
		struct textselpos *begin, *end;
		int	selected_lines_damaged = FALSE;
		Xv_private void ttysortextents();

		ttysortextents(&ttysw->ttysw_primary, &begin, &end);

		for (row = begin->tsp_row; row <= end->tsp_row; row++)
			if(exposed->line_exposed[row]) {
				/* there was damage to the selected areas. */
				selected_lines_damaged = TRUE;
				break;
			}

		for (row = ttysw_top; row < ttysw_bottom; row++) {
			if((selected_lines_damaged &&
			   (row >= begin->tsp_row) && (row <= end->tsp_row)) ||
			   (row == cursrow)) {
				/* because of xor, the line is cleared */
				(void) ttysw_pclearline(0, STRLEN(image[row])+1, row);
				ttysw_displayrow(row, 0);
			} else
			if(exposed->line_exposed[row])
				ttysw_displayrow(row, leftcol);
		}

		if(selected_lines_damaged)
			ttyhiliteselection(&ttysw->ttysw_primary, SELN_PRIMARY);
		/* secondary selection is painted in caller */


	} else {

		/* The easy case: no selection, just repaint damaged lines. */

		for (row = ttysw_top; row < ttysw_bottom; row++) {
		    if(exposed->line_exposed[row])
				ttysw_displayrow(row, leftcol);
		}
	}

	if(display_cursor)
		(void) ttysw_removeCursor();

	tty_clear_clip_rectangles(csr_pixwin);

}

Pkg_private void
ttysw_drawCursor(yChar, xChar)
{
#ifdef  OW_I18N
    int         offset;
#ifdef FULL_R5
    Ttysw_folio		ttysw_folio = TTY_PRIVATE_FROM_ANY_VIEW(csr_pixwin);
    XPoint		loc;
    XVaNestedList	va_nested_list;
#endif /* FULL_R5 */	    

    /*
     *  OW_I18N needs to check whether the target character is
     *  ascii or not , so we cannot put cursor out of range.
     */

    if( xChar >= ttysw_right )
        xChar = ttysw_right-1;
    if( xChar < ttysw_left )
        xChar = ttysw_left;
    if( yChar >= ttysw_bottom )
        yChar = ttysw_bottom-1;
    if( yChar < ttysw_top )
        yChar = ttysw_top;
#endif
    charcursx = xChar;
    charcursy = yChar;
    caretx = col_to_x(xChar);
    carety = row_to_y(yChar);
    if (delaypainting || cursor == NOCURSOR)
	return;
#ifdef  OW_I18N
/*
 *    Setup appropriate Cursor-width and originated pixrect address
 *    according as the character size
 */
    tty_column_wchar_type( xChar , yChar , &curs_width , &offset );
    curs_width *= chrwidth;
    caretx     -= offset*chrwidth;
    (void) tty_background(csr_pixwin,
             caretx-lxhome, carety, curs_width, chrheight, PIX_NOT(PIX_DST));
#else
    (void) tty_background(csr_pixwin,
		     caretx-lxhome, carety, chrwidth, chrheight, PIX_NOT(PIX_DST));
#endif
    if (cursor & LIGHTCURSOR) {
#ifdef  OW_I18N
        (void) tty_background(csr_pixwin,
                              caretx - lxhome - 1, carety - 1, curs_width + 2,
                              chrheight + 2, PIX_NOT(PIX_DST));
#else
	(void) tty_background(csr_pixwin,
			      caretx - lxhome - 1, carety - 1, chrwidth + 2, 
			      chrheight + 2, PIX_NOT(PIX_DST));
#endif
	(void) ttysw_pos(xChar, yChar);
    }
#ifdef FULL_R5
#ifdef OW_I18N
    if (ttysw_folio->ic && (ttysw_folio->xim_style & XIMPreeditPosition)) {  
        /*loc.x = (short)caretx + (curs_width/2);*/
        loc.x = (short)caretx;
        loc.y = (short)(carety + chrbase);
        va_nested_list = XVaCreateNestedList(NULL, 
					     XNSpotLocation, &loc, 
					     NULL);
        XSetICValues(ttysw_folio->ic, XNPreeditAttributes, va_nested_list,
        	     NULL);
        XFree(va_nested_list);
    }
#endif /* OW_I18N */	
#endif /* FULL_R5 */	
    
}

static void
ttysw_paintCursor(op)
	int op;
{
	int y;
	int height;
	/*
	 * Erase or xor all bits used in light and normal cursor.
	 */

	y = carety-1;
	height = chrheight + 2;
	if(y<0) {
		/* work around xnews server bug. */
		y=0;
		height--;
	}
	
#ifdef  OW_I18N
        (void) tty_background(csr_pixwin,
                              caretx - lxhome - 1, y, curs_width + 2, height, 
			      op);
#else
	(void) tty_background(csr_pixwin,
			      caretx - lxhome - 1, y, chrwidth + 2, height, 
			      op);
#endif
}

Pkg_private void
ttysw_removeCursor()
{
    if (delaypainting || cursor == NOCURSOR)
	return;
#ifdef  OW_I18N
/*
 *      caretx and curs_width are stored in global and those values
 *      represent the location and width of the cursor.
 */
    (void) tty_background(csr_pixwin,
             caretx-lxhome, carety, curs_width, chrheight, PIX_NOT(PIX_DST));
#else
    (void) tty_background(csr_pixwin,
		     caretx-lxhome, carety, chrwidth, chrheight, PIX_NOT(PIX_DST));
#endif
    if (cursor & LIGHTCURSOR)
	ttysw_paintCursor(PIX_NOT(PIX_DST));
}

Pkg_private void
ttysw_restoreCursor()	/* BUG ALERT: unnecessary routine */
{
    (void) ttysw_removeCursor();
}

Pkg_private void
ttysw_screencomp()	/* BUG ALERT: unnecessary routine */
{
}

Pkg_private void
ttysw_blinkscreen()
{
    struct timeval  now;
    static struct timeval lastblink;

    (void) gettimeofday(&now, (struct timezone *) 0);
    if (now.tv_sec - lastblink.tv_sec > 1) {
	Xv_object       window = (Xv_object) csr_pixwin;
	(void) win_bell(window, ttysw_bell_tv, csr_pixwin);
	lastblink = now;
    }
}

Pkg_private void
ttysw_pselectionhilite(r, sel_rank)
    struct rect    *r;
    Seln_rank       sel_rank;
{
    struct rect     rectlock;

    rectlock = *r;
    rect_marginadjust(&rectlock, 1);
    if (sel_rank == SELN_PRIMARY)
	(void) tty_background(csr_pixwin, r->r_left, r->r_top,
			      r->r_width, r->r_height, PIX_NOT(PIX_DST));
    else
	(void) xv_replrop(csr_pixwin,
			  r->r_left, r->r_top,
			  r->r_width, r->r_height,
			  PIX_SRC | PIX_DST, &ttysw_gray17_pr, 0, 0);
}

#ifdef OW_I18N

/*
 *      Tty-subwindow stores screen image in a global CHAR **image.
 *      This array treats characters in a tricky way.
 *      For a character which has larger size than ascii characters,
 *      image data array is padded with TTY_NON_WCHAR so that
 *      image data array and the actual screen get coincident.
 *      This function converts image arrary to a normal wchar array
 *      by eliminating TTY_NON_WCHAR.
 */
/* static */ void
ttysw_convert_string( str , ttystr )
    CHAR        *str;
    CHAR        *ttystr;
{
    register    CHAR *strtmp = str;
    register    CHAR *ttystrtmp  = ttystr;

    while( *ttystrtmp ) {
        if( *ttystrtmp != TTY_NON_WCHAR )
                *strtmp++ = *ttystrtmp++;
        else
                ttystrtmp++;
    }
    *strtmp = (CHAR)'\0';
}


/*
 *      Get the size of a character.
 */
Pkg_private int
tty_character_size(c)
   CHAR         c;
{

    /*
     *  Warning!!
     *  To get the charcter-width , this function calls wscol()
     *  which may cause a problem in portability.
     */
    static wchar_t      str[2] = {(wchar_t)'\0',(wchar_t)'\0'};

    if( c == (wchar_t)'\0' )
        return 1;

    str[0] = c;
    return( wscol(str) );

}
#endif