~ubuntu-branches/ubuntu/hoary/kterm/hoary

« back to all changes in this revision

Viewing changes to util.c

  • Committer: Bazaar Package Importer
  • Author(s): ISHIKAWA Mutsumi
  • Date: 2002-02-15 00:30:40 UTC
  • Revision ID: james.westby@ubuntu.com-20020215003040-alhq02sirfiir6qy
Tags: upstream-6.2.0
ImportĀ upstreamĀ versionĀ 6.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      $XConsortium: util.c,v 1.31 91/06/20 18:34:47 gildea Exp $
 
3
 *      $Id: util.c,v 6.3 1996/07/02 05:01:31 kagotani Rel $
 
4
 */
 
5
 
 
6
/*
 
7
 * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 
8
 *
 
9
 *                         All Rights Reserved
 
10
 *
 
11
 * Permission to use, copy, modify, and distribute this software and its
 
12
 * documentation for any purpose and without fee is hereby granted,
 
13
 * provided that the above copyright notice appear in all copies and that
 
14
 * both that copyright notice and this permission notice appear in
 
15
 * supporting documentation, and that the name of Digital Equipment
 
16
 * Corporation not be used in advertising or publicity pertaining to
 
17
 * distribution of the software without specific, written prior permission.
 
18
 *
 
19
 *
 
20
 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
21
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
22
 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
23
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
24
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
25
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
/* util.c */
 
30
 
 
31
#include "ptyx.h"
 
32
#include "data.h"
 
33
#include "error.h"
 
34
#include "menu.h"
 
35
 
 
36
#include <stdio.h>
 
37
 
 
38
static void horizontal_copy_area();
 
39
static void vertical_copy_area();
 
40
 
 
41
#ifdef KTERM
 
42
static int fnum = F_ISO8859_1; /* refered by *GC in many functions */
 
43
#endif /* KTERM */
 
44
 
 
45
/*
 
46
 * These routines are used for the jump scroll feature
 
47
 */
 
48
FlushScroll(screen)
 
49
register TScreen *screen;
 
50
{
 
51
        register int i;
 
52
        register int shift = -screen->topline;
 
53
        register int bot = screen->max_row - shift;
 
54
        register int refreshtop;
 
55
        register int refreshheight;
 
56
        register int scrolltop;
 
57
        register int scrollheight;
 
58
 
 
59
        if(screen->cursor_state)
 
60
                HideCursor();
 
61
        if(screen->scroll_amt > 0) {
 
62
                refreshheight = screen->refresh_amt;
 
63
                scrollheight = screen->bot_marg - screen->top_marg -
 
64
                 refreshheight + 1;
 
65
                if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
 
66
                 (i = screen->max_row - screen->scroll_amt + 1))
 
67
                        refreshtop = i;
 
68
                if(screen->scrollWidget && !screen->alternate
 
69
                 && screen->top_marg == 0) {
 
70
                        scrolltop = 0;
 
71
                        if((scrollheight += shift) > i)
 
72
                                scrollheight = i;
 
73
                        if((i = screen->bot_marg - bot) > 0 &&
 
74
                         (refreshheight -= i) < screen->scroll_amt)
 
75
                                refreshheight = screen->scroll_amt;
 
76
                        if((i = screen->savedlines) < screen->savelines) {
 
77
                                if((i += screen->scroll_amt) >
 
78
                                  screen->savelines)
 
79
                                        i = screen->savelines;
 
80
                                screen->savedlines = i;
 
81
                                ScrollBarDrawThumb(screen->scrollWidget);
 
82
                        }
 
83
                } else {
 
84
                        scrolltop = screen->top_marg + shift;
 
85
                        if((i = bot - (screen->bot_marg - screen->refresh_amt +
 
86
                         screen->scroll_amt)) > 0) {
 
87
                                if(bot < screen->bot_marg)
 
88
                                        refreshheight = screen->scroll_amt + i;
 
89
                        } else {
 
90
                                scrollheight += i;
 
91
                                refreshheight = screen->scroll_amt;
 
92
                                if((i = screen->top_marg + screen->scroll_amt -
 
93
                                 1 - bot) > 0) {
 
94
                                        refreshtop += i;
 
95
                                        refreshheight -= i;
 
96
                                }
 
97
                        }
 
98
                }
 
99
        } else {
 
100
                refreshheight = -screen->refresh_amt;
 
101
                scrollheight = screen->bot_marg - screen->top_marg -
 
102
                 refreshheight + 1;
 
103
                refreshtop = screen->top_marg + shift;
 
104
                scrolltop = refreshtop + refreshheight;
 
105
                if((i = screen->bot_marg - bot) > 0)
 
106
                        scrollheight -= i;
 
107
                if((i = screen->top_marg + refreshheight - 1 - bot) > 0)
 
108
                        refreshheight -= i;
 
109
        }
 
110
        scrolling_copy_area(screen, scrolltop+screen->scroll_amt,
 
111
                            scrollheight, screen->scroll_amt);
 
112
        ScrollSelection(screen, -(screen->scroll_amt));
 
113
        screen->scroll_amt = 0;
 
114
        screen->refresh_amt = 0;
 
115
        if(refreshheight > 0) {
 
116
                XClearArea (
 
117
                    screen->display,
 
118
                    TextWindow(screen),
 
119
                    (int) screen->border + screen->scrollbar,
 
120
                    (int) refreshtop * FontHeight(screen) + screen->border,
 
121
                    (unsigned) Width(screen),
 
122
                    (unsigned) refreshheight * FontHeight(screen),
 
123
                    FALSE);
 
124
                ScrnRefresh(screen, refreshtop, 0, refreshheight,
 
125
                 screen->max_col + 1, False);
 
126
        }
 
127
}
 
128
 
 
129
AddToRefresh(screen)
 
130
register TScreen *screen;
 
131
{
 
132
        register int amount = screen->refresh_amt;
 
133
        register int row = screen->cur_row;
 
134
 
 
135
#ifdef STATUSLINE
 
136
        if(amount == 0 || screen->instatus)
 
137
#else /* !STATUSLINE */
 
138
        if(amount == 0)
 
139
#endif /* !STATUSLINE */
 
140
                return(0);
 
141
        if(amount > 0) {
 
142
                register int bottom;
 
143
 
 
144
                if(row == (bottom = screen->bot_marg) - amount) {
 
145
                        screen->refresh_amt++;
 
146
                        return(1);
 
147
                }
 
148
                return(row >= bottom - amount + 1 && row <= bottom);
 
149
        } else {
 
150
                register int top;
 
151
 
 
152
                amount = -amount;
 
153
                if(row == (top = screen->top_marg) + amount) {
 
154
                        screen->refresh_amt--;
 
155
                        return(1);
 
156
                }
 
157
                return(row <= top + amount - 1 && row >= top);
 
158
        }
 
159
}
 
160
 
 
161
/* 
 
162
 * scrolls the screen by amount lines, erases bottom, doesn't alter 
 
163
 * cursor position (i.e. cursor moves down amount relative to text).
 
164
 * All done within the scrolling region, of course. 
 
165
 * requires: amount > 0
 
166
 */
 
167
Scroll(screen, amount)
 
168
register TScreen *screen;
 
169
register int amount;
 
170
{
 
171
        register int i = screen->bot_marg - screen->top_marg + 1;
 
172
        register int shift;
 
173
        register int bot;
 
174
        register int refreshtop = 0;
 
175
        register int refreshheight;
 
176
        register int scrolltop;
 
177
        register int scrollheight;
 
178
 
 
179
        if(screen->cursor_state)
 
180
                HideCursor();
 
181
        if (amount > i)
 
182
                amount = i;
 
183
    if(screen->jumpscroll) {
 
184
        if(screen->scroll_amt > 0) {
 
185
                if(screen->refresh_amt + amount > i)
 
186
                        FlushScroll(screen);
 
187
                screen->scroll_amt += amount;
 
188
                screen->refresh_amt += amount;
 
189
        } else {
 
190
                if(screen->scroll_amt < 0)
 
191
                        FlushScroll(screen);
 
192
                screen->scroll_amt = amount;
 
193
                screen->refresh_amt = amount;
 
194
        }
 
195
        refreshheight = 0;
 
196
    } else {
 
197
        ScrollSelection(screen, -(amount));
 
198
        if (amount == i) {
 
199
                ClearScreen(screen);
 
200
                return;
 
201
        }
 
202
        shift = -screen->topline;
 
203
        bot = screen->max_row - shift;
 
204
        scrollheight = i - amount;
 
205
        refreshheight = amount;
 
206
        if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
 
207
         (i = screen->max_row - refreshheight + 1))
 
208
                refreshtop = i;
 
209
        if(screen->scrollWidget && !screen->alternate
 
210
         && screen->top_marg == 0) {
 
211
                scrolltop = 0;
 
212
                if((scrollheight += shift) > i)
 
213
                        scrollheight = i;
 
214
                if((i = screen->savedlines) < screen->savelines) {
 
215
                        if((i += amount) > screen->savelines)
 
216
                                i = screen->savelines;
 
217
                        screen->savedlines = i;
 
218
                        ScrollBarDrawThumb(screen->scrollWidget);
 
219
                }
 
220
        } else {
 
221
                scrolltop = screen->top_marg + shift;
 
222
                if((i = screen->bot_marg - bot) > 0) {
 
223
                        scrollheight -= i;
 
224
                        if((i = screen->top_marg + amount - 1 - bot) >= 0) {
 
225
                                refreshtop += i;
 
226
                                refreshheight -= i;
 
227
                        }
 
228
                }
 
229
        }
 
230
 
 
231
        if (screen->multiscroll && amount == 1 &&
 
232
            screen->topline == 0 && screen->top_marg == 0 &&
 
233
            screen->bot_marg == screen->max_row) {
 
234
            if (screen->incopy < 0 && screen->scrolls == 0)
 
235
                CopyWait(screen);
 
236
            screen->scrolls++;
 
237
        }
 
238
        scrolling_copy_area(screen, scrolltop+amount, scrollheight, amount);
 
239
        if(refreshheight > 0) {
 
240
                XClearArea (
 
241
                   screen->display,
 
242
                   TextWindow(screen),
 
243
                   (int) screen->border + screen->scrollbar,
 
244
                   (int) refreshtop * FontHeight(screen) + screen->border,
 
245
                   (unsigned) Width(screen),
 
246
                   (unsigned) refreshheight * FontHeight(screen),
 
247
                   FALSE);
 
248
                if(refreshheight > shift)
 
249
                        refreshheight = shift;
 
250
        }
 
251
    }
 
252
        if(screen->scrollWidget && !screen->alternate && screen->top_marg == 0)
 
253
                ScrnDeleteLine(screen->allbuf, screen->bot_marg +
 
254
                 screen->savelines, 0, amount, screen->max_col + 1);
 
255
        else
 
256
                ScrnDeleteLine(screen->buf, screen->bot_marg, screen->top_marg,
 
257
                 amount, screen->max_col + 1);
 
258
        if(refreshheight > 0)
 
259
                ScrnRefresh(screen, refreshtop, 0, refreshheight,
 
260
                 screen->max_col + 1, False);
 
261
}
 
262
 
 
263
 
 
264
/*
 
265
 * Reverse scrolls the screen by amount lines, erases top, doesn't alter
 
266
 * cursor position (i.e. cursor moves up amount relative to text).
 
267
 * All done within the scrolling region, of course.
 
268
 * Requires: amount > 0
 
269
 */
 
270
RevScroll(screen, amount)
 
271
register TScreen *screen;
 
272
register int amount;
 
273
{
 
274
        register int i = screen->bot_marg - screen->top_marg + 1;
 
275
        register int shift;
 
276
        register int bot;
 
277
        register int refreshtop;
 
278
        register int refreshheight;
 
279
        register int scrolltop;
 
280
        register int scrollheight;
 
281
 
 
282
        if(screen->cursor_state)
 
283
                HideCursor();
 
284
        if (amount > i)
 
285
                amount = i;
 
286
    if(screen->jumpscroll) {
 
287
        if(screen->scroll_amt < 0) {
 
288
                if(-screen->refresh_amt + amount > i)
 
289
                        FlushScroll(screen);
 
290
                screen->scroll_amt -= amount;
 
291
                screen->refresh_amt -= amount;
 
292
        } else {
 
293
                if(screen->scroll_amt > 0)
 
294
                        FlushScroll(screen);
 
295
                screen->scroll_amt = -amount;
 
296
                screen->refresh_amt = -amount;
 
297
        }
 
298
    } else {
 
299
        shift = -screen->topline;
 
300
        bot = screen->max_row - shift;
 
301
        refreshheight = amount;
 
302
        scrollheight = screen->bot_marg - screen->top_marg -
 
303
         refreshheight + 1;
 
304
        refreshtop = screen->top_marg + shift;
 
305
        scrolltop = refreshtop + refreshheight;
 
306
        if((i = screen->bot_marg - bot) > 0)
 
307
                scrollheight -= i;
 
308
        if((i = screen->top_marg + refreshheight - 1 - bot) > 0)
 
309
                refreshheight -= i;
 
310
 
 
311
        if (screen->multiscroll && amount == 1 &&
 
312
            screen->topline == 0 && screen->top_marg == 0 &&
 
313
            screen->bot_marg == screen->max_row) {
 
314
            if (screen->incopy < 0 && screen->scrolls == 0)
 
315
                CopyWait(screen);
 
316
            screen->scrolls++;
 
317
        }
 
318
        scrolling_copy_area(screen, scrolltop-amount, scrollheight, -amount);
 
319
        if(refreshheight > 0)
 
320
                XClearArea (
 
321
                    screen->display,
 
322
                    TextWindow(screen),
 
323
                    (int) screen->border + screen->scrollbar,
 
324
                    (int) refreshtop * FontHeight(screen) + screen->border,
 
325
                    (unsigned) Width(screen),
 
326
                    (unsigned) refreshheight * FontHeight(screen),
 
327
                    FALSE);
 
328
    }
 
329
        ScrnInsertLine (screen->buf, screen->bot_marg, screen->top_marg,
 
330
                        amount, screen->max_col + 1);
 
331
}
 
332
 
 
333
/*
 
334
 * If cursor not in scrolling region, returns.  Else,
 
335
 * inserts n blank lines at the cursor's position.  Lines above the
 
336
 * bottom margin are lost.
 
337
 */
 
338
InsertLine (screen, n)
 
339
register TScreen *screen;
 
340
register int n;
 
341
{
 
342
        register int i;
 
343
        register int shift;
 
344
        register int bot;
 
345
        register int refreshtop;
 
346
        register int refreshheight;
 
347
        register int scrolltop;
 
348
        register int scrollheight;
 
349
 
 
350
        if (screen->cur_row < screen->top_marg ||
 
351
         screen->cur_row > screen->bot_marg)
 
352
                return;
 
353
        if(screen->cursor_state)
 
354
                HideCursor();
 
355
        screen->do_wrap = 0;
 
356
        if (n > (i = screen->bot_marg - screen->cur_row + 1))
 
357
                n = i;
 
358
    if(screen->jumpscroll) {
 
359
        if(screen->scroll_amt <= 0 &&
 
360
         screen->cur_row <= -screen->refresh_amt) {
 
361
                if(-screen->refresh_amt + n > screen->max_row + 1)
 
362
                        FlushScroll(screen);
 
363
                screen->scroll_amt -= n;
 
364
                screen->refresh_amt -= n;
 
365
        } else if(screen->scroll_amt)
 
366
                FlushScroll(screen);
 
367
    }
 
368
    if(!screen->scroll_amt) {
 
369
        shift = -screen->topline;
 
370
        bot = screen->max_row - shift;
 
371
        refreshheight = n;
 
372
        scrollheight = screen->bot_marg - screen->cur_row - refreshheight + 1;
 
373
        refreshtop = screen->cur_row + shift;
 
374
        scrolltop = refreshtop + refreshheight;
 
375
        if((i = screen->bot_marg - bot) > 0)
 
376
                scrollheight -= i;
 
377
        if((i = screen->cur_row + refreshheight - 1 - bot) > 0)
 
378
                refreshheight -= i;
 
379
        vertical_copy_area(screen, scrolltop-n, scrollheight, -n);
 
380
        if(refreshheight > 0)
 
381
                XClearArea (
 
382
                    screen->display,
 
383
                    TextWindow(screen),
 
384
                    (int) screen->border + screen->scrollbar,
 
385
                    (int) refreshtop * FontHeight(screen) + screen->border,
 
386
                    (unsigned) Width(screen),
 
387
                    (unsigned) refreshheight * FontHeight(screen),
 
388
                    FALSE);
 
389
    }
 
390
        /* adjust screen->buf */
 
391
        ScrnInsertLine(screen->buf, screen->bot_marg, screen->cur_row, n,
 
392
                        screen->max_col + 1);
 
393
}
 
394
 
 
395
/*
 
396
 * If cursor not in scrolling region, returns.  Else, deletes n lines
 
397
 * at the cursor's position, lines added at bottom margin are blank.
 
398
 */
 
399
DeleteLine(screen, n)
 
400
register TScreen *screen;
 
401
register int n;
 
402
{
 
403
        register int i;
 
404
        register int shift;
 
405
        register int bot;
 
406
        register int refreshtop;
 
407
        register int refreshheight;
 
408
        register int scrolltop;
 
409
        register int scrollheight;
 
410
 
 
411
        if (screen->cur_row < screen->top_marg ||
 
412
         screen->cur_row > screen->bot_marg)
 
413
                return;
 
414
        if(screen->cursor_state)
 
415
                HideCursor();
 
416
        screen->do_wrap = 0;
 
417
        if (n > (i = screen->bot_marg - screen->cur_row + 1))
 
418
                n = i;
 
419
    if(screen->jumpscroll) {
 
420
        if(screen->scroll_amt >= 0 && screen->cur_row == screen->top_marg) {
 
421
                if(screen->refresh_amt + n > screen->max_row + 1)
 
422
                        FlushScroll(screen);
 
423
                screen->scroll_amt += n;
 
424
                screen->refresh_amt += n;
 
425
        } else if(screen->scroll_amt)
 
426
                FlushScroll(screen);
 
427
    }
 
428
    if(!screen->scroll_amt) {
 
429
 
 
430
        shift = -screen->topline;
 
431
        bot = screen->max_row - shift;
 
432
        scrollheight = i - n;
 
433
        refreshheight = n;
 
434
        if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
 
435
         (i = screen->max_row - refreshheight + 1))
 
436
                refreshtop = i;
 
437
        if(screen->scrollWidget && !screen->alternate && screen->cur_row == 0) {
 
438
                scrolltop = 0;
 
439
                if((scrollheight += shift) > i)
 
440
                        scrollheight = i;
 
441
                if((i = screen->savedlines) < screen->savelines) {
 
442
                        if((i += n) > screen->savelines)
 
443
                                i = screen->savelines;
 
444
                        screen->savedlines = i;
 
445
                        ScrollBarDrawThumb(screen->scrollWidget);
 
446
                }
 
447
        } else {
 
448
                scrolltop = screen->cur_row + shift;
 
449
                if((i = screen->bot_marg - bot) > 0) {
 
450
                        scrollheight -= i;
 
451
                        if((i = screen->cur_row + n - 1 - bot) >= 0) {
 
452
                                refreshheight -= i;
 
453
                        }
 
454
                }
 
455
        }
 
456
        vertical_copy_area(screen, scrolltop+n, scrollheight, n);
 
457
        if(refreshheight > 0)
 
458
                XClearArea (
 
459
                    screen->display,
 
460
                    TextWindow(screen),
 
461
                    (int) screen->border + screen->scrollbar,
 
462
                    (int) refreshtop * FontHeight(screen) + screen->border,
 
463
                    (unsigned) Width(screen),
 
464
                    (unsigned) refreshheight * FontHeight(screen),
 
465
                    FALSE);
 
466
    }
 
467
        /* adjust screen->buf */
 
468
        if(screen->scrollWidget && !screen->alternate && screen->cur_row == 0)
 
469
                ScrnDeleteLine(screen->allbuf, screen->bot_marg +
 
470
                 screen->savelines, 0, n, screen->max_col + 1);
 
471
        else
 
472
                ScrnDeleteLine(screen->buf, screen->bot_marg, screen->cur_row,
 
473
                 n, screen->max_col + 1);
 
474
}
 
475
 
 
476
/*
 
477
 * Insert n blanks at the cursor's position, no wraparound
 
478
 */
 
479
InsertChar (screen, n)
 
480
    register TScreen *screen;
 
481
    register int n;
 
482
{
 
483
        register int cx, cy;
 
484
 
 
485
        if(screen->cursor_state)
 
486
                HideCursor();
 
487
        screen->do_wrap = 0;
 
488
#ifdef KTERM_MBCS
 
489
        BreakMBchar(screen);
 
490
#endif /* KTERM_MBCS */
 
491
#ifdef STATUSLINE
 
492
        if(screen->cur_row - screen->topline <= screen->max_row ||
 
493
           screen->instatus) {
 
494
#else /* !STATUSLINE */
 
495
        if(screen->cur_row - screen->topline <= screen->max_row) {
 
496
#endif /* !STATUSLINE */
 
497
            if(!AddToRefresh(screen)) {
 
498
                if(screen->scroll_amt)
 
499
                        FlushScroll(screen);
 
500
 
 
501
                /*
 
502
                 * prevent InsertChar from shifting the end of a line over
 
503
                 * if it is being appended to
 
504
                 */
 
505
                if (non_blank_line (screen->buf, screen->cur_row, 
 
506
                                    screen->cur_col, screen->max_col + 1))
 
507
                    horizontal_copy_area(screen, screen->cur_col,
 
508
                                         screen->max_col+1 - (screen->cur_col+n),
 
509
                                         n);
 
510
        
 
511
                cx = CursorX (screen, screen->cur_col);
 
512
                cy = CursorY (screen, screen->cur_row);
 
513
 
 
514
                XFillRectangle(
 
515
                    screen->display,
 
516
                    TextWindow(screen), 
 
517
#ifdef STATUSLINE
 
518
                    screen->instatus && screen->reversestatus ?
 
519
                    screen->normalGC :
 
520
#endif /* STATUSLINE */
 
521
                    screen->reverseGC,
 
522
                    cx, cy,
 
523
                    (unsigned) n * FontWidth(screen), (unsigned) FontHeight(screen));
 
524
            }
 
525
        }
 
526
        /* adjust screen->buf */
 
527
        ScrnInsertChar(screen->buf, screen->cur_row, screen->cur_col, n,
 
528
                        screen->max_col + 1);
 
529
}
 
530
 
 
531
/*
 
532
 * Deletes n chars at the cursor's position, no wraparound.
 
533
 */
 
534
DeleteChar (screen, n)
 
535
    register TScreen *screen;
 
536
    register int        n;
 
537
{
 
538
        register int width;
 
539
 
 
540
        if(screen->cursor_state)
 
541
                HideCursor();
 
542
        screen->do_wrap = 0;
 
543
        if (n > (width = screen->max_col + 1 - screen->cur_col))
 
544
                n = width;
 
545
                
 
546
#ifdef KTERM_MBCS
 
547
        BreakMBchar(screen);
 
548
        screen->cur_col += n;
 
549
        BreakMBchar(screen);
 
550
        screen->cur_col -= n;
 
551
#endif /* KTERM_MBCS */
 
552
#ifdef STATUSLINE
 
553
        if(screen->cur_row - screen->topline <= screen->max_row ||
 
554
           screen->instatus) {
 
555
#else /* !STATUSLINE */
 
556
        if(screen->cur_row - screen->topline <= screen->max_row) {
 
557
#endif /* !STATUSLINE */
 
558
            if(!AddToRefresh(screen)) {
 
559
                if(screen->scroll_amt)
 
560
                        FlushScroll(screen);
 
561
        
 
562
                horizontal_copy_area(screen, screen->cur_col+n,
 
563
                                     screen->max_col+1 - (screen->cur_col+n),
 
564
                                     -n);
 
565
        
 
566
                XFillRectangle
 
567
                    (screen->display, TextWindow(screen),
 
568
#ifdef STATUSLINE
 
569
                     screen->instatus && screen->reversestatus ?
 
570
                     screen->normalGC :
 
571
#endif /* STATUSLINE */
 
572
                     screen->reverseGC,
 
573
                     screen->border + screen->scrollbar
 
574
                       + Width(screen) - n*FontWidth(screen),
 
575
                     CursorY (screen, screen->cur_row), n * FontWidth(screen),
 
576
                     FontHeight(screen));
 
577
            }
 
578
        }
 
579
        /* adjust screen->buf */
 
580
        ScrnDeleteChar (screen->buf, screen->cur_row, screen->cur_col, n,
 
581
                        screen->max_col + 1);
 
582
 
 
583
}
 
584
 
 
585
/*
 
586
 * Clear from cursor position to beginning of display, inclusive.
 
587
 */
 
588
ClearAbove (screen)
 
589
register TScreen *screen;
 
590
{
 
591
        register top, height;
 
592
 
 
593
        if(screen->cursor_state)
 
594
                HideCursor();
 
595
        if((top = -screen->topline) <= screen->max_row) {
 
596
                if(screen->scroll_amt)
 
597
                        FlushScroll(screen);
 
598
                if((height = screen->cur_row + top) > screen->max_row)
 
599
                        height = screen->max_row;
 
600
                if((height -= top) > 0)
 
601
                        XClearArea(screen->display, TextWindow(screen),
 
602
                         screen->border + screen->scrollbar, top *
 
603
                         FontHeight(screen) + screen->border,
 
604
                         Width(screen), height * FontHeight(screen), FALSE);
 
605
 
 
606
                if(screen->cur_row - screen->topline <= screen->max_row)
 
607
                        ClearLeft(screen);
 
608
        }
 
609
        ClearBufRows(screen, 0, screen->cur_row - 1);
 
610
}
 
611
 
 
612
/*
 
613
 * Clear from cursor position to end of display, inclusive.
 
614
 */
 
615
ClearBelow (screen)
 
616
register TScreen *screen;
 
617
{
 
618
        register top;
 
619
 
 
620
        ClearRight(screen);
 
621
        if((top = screen->cur_row - screen->topline) <= screen->max_row) {
 
622
                if(screen->scroll_amt)
 
623
                        FlushScroll(screen);
 
624
                if(++top <= screen->max_row)
 
625
                        XClearArea(screen->display, TextWindow(screen),
 
626
                         screen->border + screen->scrollbar, top *
 
627
                         FontHeight(screen) + screen->border,
 
628
                         Width(screen), (screen->max_row - top + 1) *
 
629
                         FontHeight(screen), FALSE);
 
630
        }
 
631
        ClearBufRows(screen, screen->cur_row + 1, screen->max_row);
 
632
}
 
633
 
 
634
/* 
 
635
 * Clear last part of cursor's line, inclusive.
 
636
 */
 
637
ClearRight (screen)
 
638
register TScreen *screen;
 
639
{
 
640
        if(screen->cursor_state)
 
641
                HideCursor();
 
642
        screen->do_wrap = 0;
 
643
#ifdef KTERM_MBCS
 
644
        BreakMBchar(screen);
 
645
#endif /* KTERM_MBCS */
 
646
#ifdef STATUSLINE
 
647
        if(screen->cur_row - screen->topline <= screen->max_row ||
 
648
           screen->instatus) {
 
649
#else /* !STATUSLINE */
 
650
        if(screen->cur_row - screen->topline <= screen->max_row) {
 
651
#endif /* !STATUSLINE */
 
652
            if(!AddToRefresh(screen)) {
 
653
        if(screen->scroll_amt)
 
654
                FlushScroll(screen);
 
655
                XFillRectangle(screen->display, TextWindow(screen),
 
656
#ifdef STATUSLINE
 
657
                  screen->instatus && screen->reversestatus ?
 
658
                  screen->normalGC :
 
659
#endif /* STATUSLINE */
 
660
                  screen->reverseGC,
 
661
                 CursorX(screen, screen->cur_col),
 
662
                 CursorY(screen, screen->cur_row),
 
663
                 Width(screen) - screen->cur_col * FontWidth(screen),
 
664
                 FontHeight(screen));
 
665
            }
 
666
        }
 
667
#ifdef KTERM
 
668
        bzero(screen->buf[screen->cur_row] + screen->cur_col,
 
669
               (screen->max_col - screen->cur_col + 1) * sizeof(Bchr));
 
670
        /* with the right part cleared, we can't be wrapping */
 
671
        screen->buf [screen->cur_row] [0].attr &= ~LINEWRAPPED;
 
672
#else /* !KTERM */
 
673
        bzero(screen->buf [2 * screen->cur_row] + screen->cur_col,
 
674
               (screen->max_col - screen->cur_col + 1));
 
675
        bzero(screen->buf [2 * screen->cur_row + 1] + screen->cur_col,
 
676
               (screen->max_col - screen->cur_col + 1));
 
677
        /* with the right part cleared, we can't be wrapping */
 
678
        screen->buf [2 * screen->cur_row + 1] [0] &= ~LINEWRAPPED;
 
679
#endif /* !KTERM */
 
680
}
 
681
 
 
682
/*
 
683
 * Clear first part of cursor's line, inclusive.
 
684
 */
 
685
ClearLeft (screen)
 
686
    register TScreen *screen;
 
687
{
 
688
        int i;
 
689
#ifdef KTERM
 
690
        Bchr *cp;
 
691
#else /* !TERM */
 
692
        Char *cp;
 
693
#endif /* !TERM */
 
694
 
 
695
        if(screen->cursor_state)
 
696
                HideCursor();
 
697
        screen->do_wrap = 0;
 
698
#ifdef KTERM_MBCS
 
699
        BreakMBchar(screen);
 
700
#endif /* KTERM_MBCS */
 
701
#ifdef STATUSLINE
 
702
        if(screen->cur_row - screen->topline <= screen->max_row ||
 
703
           screen->instatus) {
 
704
#else /* !STATUSLINE */
 
705
        if(screen->cur_row - screen->topline <= screen->max_row) {
 
706
#endif /* !STATUSLINE */
 
707
            if(!AddToRefresh(screen)) {
 
708
                if(screen->scroll_amt)
 
709
                        FlushScroll(screen);
 
710
                XFillRectangle (screen->display, TextWindow(screen),
 
711
#ifdef STATUSLINE
 
712
                     screen->instatus && screen->reversestatus ?
 
713
                     screen->normalGC :
 
714
#endif /* STATUSLINE */
 
715
                     screen->reverseGC,
 
716
                     screen->border + screen->scrollbar,
 
717
                      CursorY (screen, screen->cur_row),
 
718
                     (screen->cur_col + 1) * FontWidth(screen),
 
719
                     FontHeight(screen));
 
720
            }
 
721
        }
 
722
        
 
723
#ifdef KTERM
 
724
        for ( i=0, cp=screen->buf[screen->cur_row];
 
725
              i < screen->cur_col + 1;
 
726
              i++, cp++) {
 
727
            cp->gset = GSET_ASCII;
 
728
            cp->code = ' ';
 
729
            cp->attr = CHARDRAWN;
 
730
        }
 
731
#else /* !KTERM */
 
732
        for ( i=0, cp=screen->buf[2 * screen->cur_row];
 
733
              i < screen->cur_col + 1;
 
734
              i++, cp++)
 
735
            *cp = ' ';
 
736
        for ( i=0, cp=screen->buf[2 * screen->cur_row + 1];
 
737
              i < screen->cur_col + 1;
 
738
              i++, cp++)
 
739
            *cp = CHARDRAWN;
 
740
#endif /* !KTERM */
 
741
}
 
742
 
 
743
/* 
 
744
 * Erase the cursor's line.
 
745
 */
 
746
ClearLine(screen)
 
747
register TScreen *screen;
 
748
{
 
749
        if(screen->cursor_state)
 
750
                HideCursor();
 
751
        screen->do_wrap = 0;
 
752
#ifdef STATUSLINE
 
753
        if(screen->cur_row - screen->topline <= screen->max_row ||
 
754
           screen->instatus) {
 
755
#else /* !STATUSLINE */
 
756
        if(screen->cur_row - screen->topline <= screen->max_row) {
 
757
#endif /* !STATUSLINE */
 
758
            if(!AddToRefresh(screen)) {
 
759
                if(screen->scroll_amt)
 
760
                        FlushScroll(screen);
 
761
                XFillRectangle (screen->display, TextWindow(screen), 
 
762
#ifdef STATUSLINE
 
763
                     screen->instatus && screen->reversestatus ?
 
764
                     screen->normalGC :
 
765
#endif /* STATUSLINE */
 
766
                     screen->reverseGC,
 
767
                     screen->border + screen->scrollbar,
 
768
                      CursorY (screen, screen->cur_row),
 
769
                     Width(screen), FontHeight(screen));
 
770
            }
 
771
        }
 
772
#ifdef KTERM
 
773
        bzero (screen->buf[screen->cur_row], (screen->max_col + 1) * sizeof(Bchr));
 
774
#else /* !KTERM */
 
775
        bzero (screen->buf [2 * screen->cur_row], (screen->max_col + 1));
 
776
        bzero (screen->buf [2 * screen->cur_row + 1], (screen->max_col + 1));
 
777
#endif /* !KTERM */
 
778
}
 
779
 
 
780
ClearScreen(screen)
 
781
register TScreen *screen;
 
782
{
 
783
        register int top;
 
784
 
 
785
        if(screen->cursor_state)
 
786
                HideCursor();
 
787
        screen->do_wrap = 0;
 
788
        if((top = -screen->topline) <= screen->max_row) {
 
789
                if(screen->scroll_amt)
 
790
                        FlushScroll(screen);
 
791
#ifdef STATUSLINE
 
792
                if(top == 0 && !screen->statusheight)
 
793
#else /* !STATUSLINE */
 
794
                if(top == 0)
 
795
#endif /* !STATUSLINE */
 
796
                        XClearWindow(screen->display, TextWindow(screen));
 
797
                else
 
798
                        XClearArea(screen->display, TextWindow(screen),
 
799
                         screen->border + screen->scrollbar, 
 
800
                         top * FontHeight(screen) + screen->border,     
 
801
                         Width(screen), (screen->max_row - top + 1) *
 
802
                         FontHeight(screen), FALSE);
 
803
        }
 
804
        ClearBufRows (screen, 0, screen->max_row);
 
805
}
 
806
 
 
807
CopyWait(screen)
 
808
register TScreen *screen;
 
809
{
 
810
        XEvent reply;
 
811
        XEvent *rep = &reply;
 
812
 
 
813
        while (1) {
 
814
                XWindowEvent (screen->display, VWindow(screen), 
 
815
                  ExposureMask, &reply);
 
816
                switch (reply.type) {
 
817
                case Expose:
 
818
                        HandleExposure (screen, &reply);
 
819
                        break;
 
820
                case NoExpose:
 
821
                case GraphicsExpose:
 
822
                        if (screen->incopy <= 0) {
 
823
                                screen->incopy = 1;
 
824
                                if (screen->scrolls > 0)
 
825
                                        screen->scrolls--;
 
826
                        }
 
827
                        if (reply.type == GraphicsExpose)
 
828
                            HandleExposure (screen, &reply);
 
829
 
 
830
                        if ((reply.type == NoExpose) ||
 
831
                            ((XExposeEvent *)rep)->count == 0) {
 
832
                            if (screen->incopy <= 0 && screen->scrolls > 0)
 
833
                                screen->scrolls--;
 
834
                            if (screen->scrolls == 0) {
 
835
                                screen->incopy = 0;
 
836
                                return;
 
837
                            }
 
838
                            screen->incopy = -1;
 
839
                        }
 
840
                        break;
 
841
                }
 
842
        }
 
843
}
 
844
 
 
845
/*
 
846
 * used by vertical_copy_area and and horizontal_copy_area
 
847
 */
 
848
static void
 
849
copy_area(screen, src_x, src_y, width, height, dest_x, dest_y)
 
850
    TScreen *screen;
 
851
    int src_x, src_y;
 
852
    unsigned int width, height;
 
853
    int dest_x, dest_y;
 
854
{
 
855
#ifdef KTERM
 
856
    static GC copygc;
 
857
#endif /* KTERM */
 
858
    /* wait for previous CopyArea to complete unless
 
859
       multiscroll is enabled and active */
 
860
    if (screen->incopy  &&  screen->scrolls == 0)
 
861
        CopyWait(screen);
 
862
    screen->incopy = -1;
 
863
 
 
864
    /* save for translating Expose events */
 
865
    screen->copy_src_x = src_x;
 
866
    screen->copy_src_y = src_y;
 
867
    screen->copy_width = width;
 
868
    screen->copy_height = height;
 
869
    screen->copy_dest_x = dest_x;
 
870
    screen->copy_dest_y = dest_y;
 
871
 
 
872
#ifdef KTERM
 
873
    if (!copygc)
 
874
        copygc = XtGetGC((Widget)term, 0, NULL); /* graphics_exposures = TRUE */
 
875
    XCopyArea(screen->display, 
 
876
              TextWindow(screen), TextWindow(screen),
 
877
              copygc,
 
878
              src_x, src_y, width, height, dest_x, dest_y);
 
879
#else /* !KTERM */
 
880
    XCopyArea(screen->display, 
 
881
              TextWindow(screen), TextWindow(screen),
 
882
              screen->normalGC,
 
883
              src_x, src_y, width, height, dest_x, dest_y);
 
884
#endif /* !KTERM */
 
885
}
 
886
 
 
887
/*
 
888
 * use when inserting or deleting characters on the current line
 
889
 */
 
890
static void
 
891
horizontal_copy_area(screen, firstchar, nchars, amount)
 
892
    TScreen *screen;
 
893
    int firstchar;              /* char pos on screen to start copying at */
 
894
    int nchars;
 
895
    int amount;                 /* number of characters to move right */
 
896
{
 
897
    int src_x = CursorX(screen, firstchar);
 
898
    int src_y = CursorY(screen, screen->cur_row);
 
899
 
 
900
    copy_area(screen, src_x, src_y,
 
901
              (unsigned)nchars*FontWidth(screen), FontHeight(screen),
 
902
              src_x + amount*FontWidth(screen), src_y);
 
903
}
 
904
 
 
905
/*
 
906
 * use when inserting or deleting lines from the screen
 
907
 */
 
908
static void
 
909
vertical_copy_area(screen, firstline, nlines, amount)
 
910
    TScreen *screen;
 
911
    int firstline;              /* line on screen to start copying at */
 
912
    int nlines;
 
913
    int amount;                 /* number of lines to move up (neg=down) */
 
914
{
 
915
    if(nlines > 0) {
 
916
        int src_x = screen->border + screen->scrollbar;
 
917
        int src_y = firstline * FontHeight(screen) + screen->border;
 
918
 
 
919
        copy_area(screen, src_x, src_y,
 
920
                  (unsigned)Width(screen), nlines*FontHeight(screen),
 
921
                  src_x, src_y - amount*FontHeight(screen));
 
922
    }
 
923
}
 
924
 
 
925
/*
 
926
 * use when scrolling the entire screen
 
927
 */
 
928
scrolling_copy_area(screen, firstline, nlines, amount)
 
929
    TScreen *screen;
 
930
    int firstline;              /* line on screen to start copying at */
 
931
    int nlines;
 
932
    int amount;                 /* number of lines to move up (neg=down) */
 
933
{
 
934
 
 
935
    if(nlines > 0) {
 
936
        vertical_copy_area(screen, firstline, nlines, amount);
 
937
    }
 
938
}
 
939
 
 
940
/*
 
941
 * Handler for Expose events on the VT widget.
 
942
 * Returns 1 iff the area where the cursor was got refreshed.
 
943
 */
 
944
HandleExposure (screen, event)
 
945
    register TScreen *screen;
 
946
    register XEvent *event;
 
947
{
 
948
    register XExposeEvent *reply = (XExposeEvent *)event;
 
949
 
 
950
    /* if not doing CopyArea or if this is a GraphicsExpose, don't translate */
 
951
    if(!screen->incopy  ||  event->type != Expose)
 
952
        return handle_translated_exposure (screen, reply->x, reply->y,
 
953
                                           reply->width, reply->height);
 
954
    else {
 
955
        /* compute intersection of area being copied with
 
956
           area being exposed. */
 
957
        int both_x1 = Max(screen->copy_src_x, reply->x);
 
958
        int both_y1 = Max(screen->copy_src_y, reply->y);
 
959
        int both_x2 = Min(screen->copy_src_x+screen->copy_width,
 
960
                          reply->x+reply->width);
 
961
        int both_y2 = Min(screen->copy_src_y+screen->copy_height,
 
962
                          reply->y+reply->height);
 
963
        int value = 0;
 
964
 
 
965
        /* was anything copied affected? */
 
966
        if(both_x2 > both_x1  && both_y2 > both_y1) {
 
967
            /* do the copied area */
 
968
            value = handle_translated_exposure
 
969
                (screen, reply->x + screen->copy_dest_x - screen->copy_src_x,
 
970
                 reply->y + screen->copy_dest_y - screen->copy_src_y,
 
971
                 reply->width, reply->height);
 
972
        }
 
973
        /* was anything not copied affected? */
 
974
        if(reply->x < both_x1 || reply->y < both_y1
 
975
           || reply->x+reply->width > both_x2
 
976
           || reply->y+reply->height > both_y2)
 
977
            value = handle_translated_exposure (screen, reply->x, reply->y,
 
978
                                                reply->width, reply->height);
 
979
 
 
980
        return value;
 
981
    }
 
982
}
 
983
 
 
984
/*
 
985
 * Called by the ExposeHandler to do the actual repaint after the coordinates
 
986
 * have been translated to allow for any CopyArea in progress.
 
987
 * The rectangle passed in is pixel coordinates.
 
988
 */
 
989
handle_translated_exposure (screen, rect_x, rect_y, rect_width, rect_height)
 
990
    register TScreen *screen;
 
991
    register int rect_x, rect_y;
 
992
    register unsigned int rect_width, rect_height;
 
993
{
 
994
        register int toprow, leftcol, nrows, ncols;
 
995
        extern Bool waiting_for_initial_map;
 
996
 
 
997
        toprow = (rect_y - screen->border) / FontHeight(screen);
 
998
        if(toprow < 0)
 
999
                toprow = 0;
 
1000
#ifdef STATUSLINE
 
1001
        if(toprow > screen->max_row + 1)
 
1002
                toprow = screen->max_row + 1;
 
1003
#endif /* STATUSLINE */
 
1004
        leftcol = (rect_x - screen->border - screen->scrollbar)
 
1005
            / FontWidth(screen);
 
1006
        if(leftcol < 0)
 
1007
                leftcol = 0;
 
1008
        nrows = (rect_y + rect_height - 1 - screen->border) / 
 
1009
                FontHeight(screen) - toprow + 1;
 
1010
        ncols =
 
1011
         (rect_x + rect_width - 1 - screen->border - screen->scrollbar) /
 
1012
                        FontWidth(screen) - leftcol + 1;
 
1013
        toprow -= screen->scrolls;
 
1014
        if (toprow < 0) {
 
1015
                nrows += toprow;
 
1016
                toprow = 0;
 
1017
        }
 
1018
        if (toprow + nrows - 1 > screen->max_row)
 
1019
#ifdef STATUSLINE
 
1020
                nrows = screen->max_row - toprow + 1 + !!screen->statusheight;
 
1021
                                /* !!statusheight == (statusheight ? 1 : 0) */
 
1022
#else /* !STATUSLINE */
 
1023
                nrows = screen->max_row - toprow + 1;
 
1024
#endif /* !STATUSLINE */
 
1025
        if (leftcol + ncols - 1 > screen->max_col)
 
1026
                ncols = screen->max_col - leftcol + 1;
 
1027
 
 
1028
        if (nrows > 0 && ncols > 0) {
 
1029
                ScrnRefresh (screen, toprow, leftcol, nrows, ncols, False);
 
1030
                if (waiting_for_initial_map) {
 
1031
                    first_map_occurred ();
 
1032
                }
 
1033
                if (screen->cur_row >= toprow &&
 
1034
                    screen->cur_row < toprow + nrows &&
 
1035
                    screen->cur_col >= leftcol &&
 
1036
                    screen->cur_col < leftcol + ncols)
 
1037
                        return (1);
 
1038
 
 
1039
        }
 
1040
        return (0);
 
1041
}
 
1042
 
 
1043
ReverseVideo (termw)
 
1044
        XtermWidget termw;
 
1045
{
 
1046
        register TScreen *screen = &termw->screen;
 
1047
        GC tmpGC;
 
1048
#ifndef KTERM_NOTEK
 
1049
        Window tek = TWindow(screen);
 
1050
#endif /* !KTERM_NOTEK */
 
1051
        unsigned long tmp;
 
1052
#ifdef KTERM
 
1053
        int fnum;
 
1054
#endif /* KTERM */
 
1055
 
 
1056
        tmp = termw->core.background_pixel;
 
1057
        if(screen->cursorcolor == screen->foreground)
 
1058
                screen->cursorcolor = tmp;
 
1059
        termw->core.background_pixel = screen->foreground;
 
1060
        screen->foreground = tmp;
 
1061
 
 
1062
        tmp = screen->mousecolorback;
 
1063
        screen->mousecolorback = screen->mousecolor;
 
1064
        screen->mousecolor = tmp;
 
1065
 
 
1066
#ifdef KTERM
 
1067
        for (fnum=F_ISO8859_1; fnum<FCNT; fnum++) {
 
1068
            tmpGC = screen->normalGC;
 
1069
            screen->normalGC = screen->reverseGC;
 
1070
            screen->reverseGC = tmpGC;
 
1071
 
 
1072
            tmpGC = screen->normalboldGC;
 
1073
            screen->normalboldGC = screen->reverseboldGC;
 
1074
            screen->reverseboldGC = tmpGC;
 
1075
 
 
1076
            tmpGC = screen->cursorGC;
 
1077
            screen->cursorGC = screen->reversecursorGC;
 
1078
            screen->reversecursorGC = tmpGC;
 
1079
        }
 
1080
#else /* !KTERM */
 
1081
        tmpGC = screen->normalGC;
 
1082
        screen->normalGC = screen->reverseGC;
 
1083
        screen->reverseGC = tmpGC;
 
1084
 
 
1085
        tmpGC = screen->normalboldGC;
 
1086
        screen->normalboldGC = screen->reverseboldGC;
 
1087
        screen->reverseboldGC = tmpGC;
 
1088
# ifndef ENBUG
 
1089
/*
 
1090
 * Bug fix by michael
 
1091
 * 3 non null lines are inserted.
 
1092
 */
 
1093
        tmpGC = screen->cursorGC;
 
1094
        screen->cursorGC = screen->reversecursorGC;
 
1095
        screen->reversecursorGC = tmpGC;
 
1096
# endif /* !ENBUG */
 
1097
#endif /* !KTERM */
 
1098
 
 
1099
        recolor_cursor (screen->pointer_cursor, 
 
1100
                        screen->mousecolor, screen->mousecolorback);
 
1101
        recolor_cursor (screen->arrow,
 
1102
                        screen->mousecolor, screen->mousecolorback);
 
1103
 
 
1104
        termw->misc.re_verse = !termw->misc.re_verse;
 
1105
 
 
1106
        XDefineCursor(screen->display, TextWindow(screen), screen->pointer_cursor);
 
1107
#ifndef KTERM_NOTEK
 
1108
        if(tek)
 
1109
                XDefineCursor(screen->display, tek, screen->arrow);
 
1110
#endif /* !KTERM_NOTEK */
 
1111
 
 
1112
        
 
1113
        if(screen->scrollWidget)
 
1114
                ScrollBarReverseVideo(screen->scrollWidget);
 
1115
 
 
1116
        XSetWindowBackground(screen->display, TextWindow(screen), termw->core.background_pixel);
 
1117
#ifndef KTERM_NOTEK
 
1118
        if(tek) {
 
1119
            TekReverseVideo(screen);
 
1120
        }
 
1121
#endif /* !KTERM_NOTEK */
 
1122
        XClearWindow(screen->display, TextWindow(screen));
 
1123
#ifdef STATUSLINE
 
1124
        ScrnRefresh (screen, 0, 0, screen->max_row + 1 + !!screen->statusheight,
 
1125
                                /* !!statusheight == (statusheight ? 1 : 0) */
 
1126
#else /* !STATUSLINE */
 
1127
        ScrnRefresh (screen, 0, 0, screen->max_row + 1,
 
1128
#endif /* !STATUSLINE */
 
1129
         screen->max_col + 1, False);
 
1130
#ifndef KTERM_NOTEK
 
1131
        if(screen->Tshow) {
 
1132
            XClearWindow(screen->display, tek);
 
1133
            TekExpose((Widget)NULL, (XEvent *)NULL, (Region)NULL);
 
1134
        }
 
1135
#endif /* !KTERM_NOTEK */
 
1136
        update_reversevideo();
 
1137
#ifdef KTERM_XIM
 
1138
        IMSendColor(screen);
 
1139
#endif /* KTERM_XIM */
 
1140
#ifdef KTERM_KINPUT2
 
1141
        Kinput2SendColor();
 
1142
#endif /* KTERM_KINPUT2 */
 
1143
}
 
1144
 
 
1145
 
 
1146
recolor_cursor (cursor, fg, bg)
 
1147
    Cursor cursor;                      /* X cursor ID to set */
 
1148
    unsigned long fg, bg;               /* pixel indexes to look up */
 
1149
{
 
1150
    register TScreen *screen = &term->screen;
 
1151
    register Display *dpy = screen->display;
 
1152
    XColor colordefs[2];                /* 0 is foreground, 1 is background */
 
1153
 
 
1154
    colordefs[0].pixel = fg;
 
1155
    colordefs[1].pixel = bg;
 
1156
    XQueryColors (dpy, DefaultColormap (dpy, DefaultScreen (dpy)),
 
1157
                  colordefs, 2);
 
1158
    XRecolorCursor (dpy, cursor, colordefs, colordefs+1);
 
1159
    return;
 
1160
}
 
1161
 
 
1162
#ifdef KTERM_MBCS
 
1163
/*
 
1164
 * If the cursor points the second byte of a multi byte character,
 
1165
 * replace this character with two blanks.
 
1166
 */
 
1167
BreakMBchar(screen)
 
1168
register TScreen *screen;
 
1169
{
 
1170
        register Bchr *ptr;
 
1171
        if (screen->cur_col >= 1 && screen->cur_col <= screen->max_col
 
1172
         && screen->buf[screen->cur_row][screen->cur_col].gset == MBC2) {
 
1173
 
 
1174
#ifdef STATUSLINE
 
1175
                if(screen->cur_row - screen->topline <= screen->max_row ||
 
1176
                   screen->instatus) {
 
1177
#else /* !STATUSLINE */
 
1178
                if(screen->cur_row - screen->topline <= screen->max_row) {
 
1179
#endif /* !STATUSLINE */
 
1180
                    if(!AddToRefresh(screen)) {
 
1181
                        if(screen->scroll_amt)
 
1182
                                FlushScroll(screen);
 
1183
                        XFillRectangle(screen->display, TextWindow(screen),
 
1184
#ifdef STATUSLINE
 
1185
                                screen->instatus && screen->reversestatus ?
 
1186
                                screen->normalGC :
 
1187
#endif /* STATUSLINE */
 
1188
                                screen->reverseGC,
 
1189
                                CursorX(screen, screen->cur_col - 1),
 
1190
                                CursorY(screen, screen->cur_row),
 
1191
                                2 * FontWidth(screen), FontHeight(screen));
 
1192
                    }
 
1193
                }
 
1194
                ptr = screen->buf[screen->cur_row] + screen->cur_col - 1;
 
1195
                bzero((char*)ptr, 2 * sizeof(Bchr));
 
1196
        }
 
1197
}
 
1198
 
 
1199
#endif /* KTERM_MBCS */