2 * $XConsortium: util.c,v 1.31 91/06/20 18:34:47 gildea Exp $
6 * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and that
13 * both that copyright notice and this permission notice appear in
14 * supporting documentation, and that the name of Digital Equipment
15 * Corporation not be used in advertising or publicity pertaining to
16 * distribution of the software without specific, written prior permission.
19 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
20 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
21 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
22 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
35 #include "../machine.h"
36 #include "All-extern-x.h"
40 static void horizontal_copy_area();
41 static void vertical_copy_area();
44 * These routines are used for the jump scroll feature
47 void FlushScroll(screen)
48 register TScreen *screen;
51 register int shift = -screen->topline;
52 register int bot = screen->max_row - shift;
53 register int refreshtop;
54 register int refreshheight;
55 register int scrolltop;
56 register int scrollheight;
58 if(screen->cursor_state)
60 if(screen->scroll_amt > 0) {
61 refreshheight = screen->refresh_amt;
62 scrollheight = screen->bot_marg - screen->top_marg -
64 if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
65 (i = screen->max_row - screen->scroll_amt + 1))
67 if(screen->scrollWidget && !screen->alternate
68 && screen->top_marg == 0) {
70 if((scrollheight += shift) > i)
72 if((i = screen->bot_marg - bot) > 0 &&
73 (refreshheight -= i) < screen->scroll_amt)
74 refreshheight = screen->scroll_amt;
75 if((i = screen->savedlines) < screen->savelines) {
76 if((i += screen->scroll_amt) >
78 i = screen->savelines;
79 screen->savedlines = i;
80 ScrollBarDrawThumb(screen->scrollWidget);
83 scrolltop = screen->top_marg + shift;
84 if((i = bot - (screen->bot_marg - screen->refresh_amt +
85 screen->scroll_amt)) > 0) {
86 if(bot < screen->bot_marg)
87 refreshheight = screen->scroll_amt + i;
90 refreshheight = screen->scroll_amt;
91 if((i = screen->top_marg + screen->scroll_amt -
99 refreshheight = -screen->refresh_amt;
100 scrollheight = screen->bot_marg - screen->top_marg -
102 refreshtop = screen->top_marg + shift;
103 scrolltop = refreshtop + refreshheight;
104 if((i = screen->bot_marg - bot) > 0)
106 if((i = screen->top_marg + refreshheight - 1 - bot) > 0)
109 scrolling_copy_area(screen, scrolltop+screen->scroll_amt,
110 scrollheight, screen->scroll_amt);
111 ScrollSelection(screen, -(screen->scroll_amt));
112 screen->scroll_amt = 0;
113 screen->refresh_amt = 0;
114 if(refreshheight > 0) {
118 (int) screen->border + screen->scrollbar,
119 (int) refreshtop * FontHeight(screen) + screen->border,
120 (unsigned) Width(screen),
121 (unsigned) refreshheight * FontHeight(screen),
123 ScrnRefresh(screen, refreshtop, 0, refreshheight,
124 screen->max_col + 1, False);
129 int AddToRefresh(screen)
130 register TScreen *screen;
132 register int amount = screen->refresh_amt;
133 register int row = screen->cur_row;
140 if(row == (bottom = screen->bot_marg) - amount) {
141 screen->refresh_amt++;
144 return(row >= bottom - amount + 1 && row <= bottom);
149 if(row == (top = screen->top_marg) + amount) {
150 screen->refresh_amt--;
153 return(row <= top + amount - 1 && row >= top);
158 * scrolls the screen by amount lines, erases bottom, doesn't alter
159 * cursor position (i.e. cursor moves down amount relative to text).
160 * All done within the scrolling region, of course.
161 * requires: amount > 0
163 void Scroll(screen, amount)
164 register TScreen *screen;
167 register int i = screen->bot_marg - screen->top_marg + 1;
170 register int refreshtop = 0;
171 register int refreshheight;
172 register int scrolltop;
173 register int scrollheight;
175 if(screen->cursor_state)
179 if(screen->jumpscroll) {
180 if(screen->scroll_amt > 0) {
181 if(screen->refresh_amt + amount > i)
183 screen->scroll_amt += amount;
184 screen->refresh_amt += amount;
186 if(screen->scroll_amt < 0)
188 screen->scroll_amt = amount;
189 screen->refresh_amt = amount;
193 ScrollSelection(screen, -(amount));
198 shift = -screen->topline;
199 bot = screen->max_row - shift;
200 scrollheight = i - amount;
201 refreshheight = amount;
202 if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
203 (i = screen->max_row - refreshheight + 1))
205 if(screen->scrollWidget && !screen->alternate
206 && screen->top_marg == 0) {
208 if((scrollheight += shift) > i)
210 if((i = screen->savedlines) < screen->savelines) {
211 if((i += amount) > screen->savelines)
212 i = screen->savelines;
213 screen->savedlines = i;
214 ScrollBarDrawThumb(screen->scrollWidget);
217 scrolltop = screen->top_marg + shift;
218 if((i = screen->bot_marg - bot) > 0) {
220 if((i = screen->top_marg + amount - 1 - bot) >= 0) {
227 if (screen->multiscroll && amount == 1 &&
228 screen->topline == 0 && screen->top_marg == 0 &&
229 screen->bot_marg == screen->max_row) {
230 if (screen->incopy < 0 && screen->scrolls == 0)
234 scrolling_copy_area(screen, scrolltop+amount, scrollheight, amount);
235 if(refreshheight > 0) {
239 (int) screen->border + screen->scrollbar,
240 (int) refreshtop * FontHeight(screen) + screen->border,
241 (unsigned) Width(screen),
242 (unsigned) refreshheight * FontHeight(screen),
244 if(refreshheight > shift)
245 refreshheight = shift;
248 if(screen->scrollWidget && !screen->alternate && screen->top_marg == 0)
249 ScrnDeleteLine(screen->allbuf, screen->bot_marg +
250 screen->savelines, 0, amount, screen->max_col + 1);
252 ScrnDeleteLine(screen->buf, screen->bot_marg, screen->top_marg,
253 amount, screen->max_col + 1);
254 if(refreshheight > 0)
255 ScrnRefresh(screen, refreshtop, 0, refreshheight,
256 screen->max_col + 1, False);
261 * Reverse scrolls the screen by amount lines, erases top, doesn't alter
262 * cursor position (i.e. cursor moves up amount relative to text).
263 * All done within the scrolling region, of course.
264 * Requires: amount > 0
266 void RevScroll(screen, amount)
267 register TScreen *screen;
270 register int i = screen->bot_marg - screen->top_marg + 1;
273 register int refreshtop;
274 register int refreshheight;
275 register int scrolltop;
276 register int scrollheight;
278 if(screen->cursor_state)
282 if(screen->jumpscroll) {
283 if(screen->scroll_amt < 0) {
284 if(-screen->refresh_amt + amount > i)
286 screen->scroll_amt -= amount;
287 screen->refresh_amt -= amount;
289 if(screen->scroll_amt > 0)
291 screen->scroll_amt = -amount;
292 screen->refresh_amt = -amount;
295 shift = -screen->topline;
296 bot = screen->max_row - shift;
297 refreshheight = amount;
298 scrollheight = screen->bot_marg - screen->top_marg -
300 refreshtop = screen->top_marg + shift;
301 scrolltop = refreshtop + refreshheight;
302 if((i = screen->bot_marg - bot) > 0)
304 if((i = screen->top_marg + refreshheight - 1 - bot) > 0)
307 if (screen->multiscroll && amount == 1 &&
308 screen->topline == 0 && screen->top_marg == 0 &&
309 screen->bot_marg == screen->max_row) {
310 if (screen->incopy < 0 && screen->scrolls == 0)
314 scrolling_copy_area(screen, scrolltop-amount, scrollheight, -amount);
315 if(refreshheight > 0)
319 (int) screen->border + screen->scrollbar,
320 (int) refreshtop * FontHeight(screen) + screen->border,
321 (unsigned) Width(screen),
322 (unsigned) refreshheight * FontHeight(screen),
325 ScrnInsertLine (screen->buf, screen->bot_marg, screen->top_marg,
326 amount, screen->max_col + 1);
330 * If cursor not in scrolling region, returns. Else,
331 * inserts n blank lines at the cursor's position. Lines above the
332 * bottom margin are lost.
334 void InsertLine (screen, n)
335 register TScreen *screen;
341 register int refreshtop;
342 register int refreshheight;
343 register int scrolltop;
344 register int scrollheight;
346 if (screen->cur_row < screen->top_marg ||
347 screen->cur_row > screen->bot_marg)
349 if(screen->cursor_state)
352 if (n > (i = screen->bot_marg - screen->cur_row + 1))
354 if(screen->jumpscroll) {
355 if(screen->scroll_amt <= 0 &&
356 screen->cur_row <= -screen->refresh_amt) {
357 if(-screen->refresh_amt + n > screen->max_row + 1)
359 screen->scroll_amt -= n;
360 screen->refresh_amt -= n;
361 } else if(screen->scroll_amt)
364 if(!screen->scroll_amt) {
365 shift = -screen->topline;
366 bot = screen->max_row - shift;
368 scrollheight = screen->bot_marg - screen->cur_row - refreshheight + 1;
369 refreshtop = screen->cur_row + shift;
370 scrolltop = refreshtop + refreshheight;
371 if((i = screen->bot_marg - bot) > 0)
373 if((i = screen->cur_row + refreshheight - 1 - bot) > 0)
375 vertical_copy_area(screen, scrolltop-n, scrollheight, -n);
376 if(refreshheight > 0)
380 (int) screen->border + screen->scrollbar,
381 (int) refreshtop * FontHeight(screen) + screen->border,
382 (unsigned) Width(screen),
383 (unsigned) refreshheight * FontHeight(screen),
386 /* adjust screen->buf */
387 ScrnInsertLine(screen->buf, screen->bot_marg, screen->cur_row, n,
388 screen->max_col + 1);
392 * If cursor not in scrolling region, returns. Else, deletes n lines
393 * at the cursor's position, lines added at bottom margin are blank.
396 void DeleteLine(screen, n)
397 register TScreen *screen;
403 register int refreshtop;
404 register int refreshheight;
405 register int scrolltop;
406 register int scrollheight;
408 if (screen->cur_row < screen->top_marg ||
409 screen->cur_row > screen->bot_marg)
411 if(screen->cursor_state)
414 if (n > (i = screen->bot_marg - screen->cur_row + 1))
416 if(screen->jumpscroll) {
417 if(screen->scroll_amt >= 0 && screen->cur_row == screen->top_marg) {
418 if(screen->refresh_amt + n > screen->max_row + 1)
420 screen->scroll_amt += n;
421 screen->refresh_amt += n;
422 } else if(screen->scroll_amt)
425 if(!screen->scroll_amt) {
427 shift = -screen->topline;
428 bot = screen->max_row - shift;
429 scrollheight = i - n;
431 if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >
432 (i = screen->max_row - refreshheight + 1))
434 if(screen->scrollWidget && !screen->alternate && screen->cur_row == 0) {
436 if((scrollheight += shift) > i)
438 if((i = screen->savedlines) < screen->savelines) {
439 if((i += n) > screen->savelines)
440 i = screen->savelines;
441 screen->savedlines = i;
442 ScrollBarDrawThumb(screen->scrollWidget);
445 scrolltop = screen->cur_row + shift;
446 if((i = screen->bot_marg - bot) > 0) {
448 if((i = screen->cur_row + n - 1 - bot) >= 0) {
453 vertical_copy_area(screen, scrolltop+n, scrollheight, n);
454 if(refreshheight > 0)
458 (int) screen->border + screen->scrollbar,
459 (int) refreshtop * FontHeight(screen) + screen->border,
460 (unsigned) Width(screen),
461 (unsigned) refreshheight * FontHeight(screen),
464 /* adjust screen->buf */
465 if(screen->scrollWidget && !screen->alternate && screen->cur_row == 0)
466 ScrnDeleteLine(screen->allbuf, screen->bot_marg +
467 screen->savelines, 0, n, screen->max_col + 1);
469 ScrnDeleteLine(screen->buf, screen->bot_marg, screen->cur_row,
470 n, screen->max_col + 1);
474 * Insert n blanks at the cursor's position, no wraparound
477 void InsertChar (screen, n)
478 register TScreen *screen;
483 if(screen->cursor_state)
486 if(screen->cur_row - screen->topline <= screen->max_row) {
487 if(!AddToRefresh(screen)) {
488 if(screen->scroll_amt)
492 * prevent InsertChar from shifting the end of a line over
493 * if it is being appended to
495 if (non_blank_line (screen->buf, screen->cur_row,
496 screen->cur_col, screen->max_col + 1))
497 horizontal_copy_area(screen, screen->cur_col,
498 screen->max_col+1 - (screen->cur_col+n),
501 cx = CursorX (screen, screen->cur_col);
502 cy = CursorY (screen, screen->cur_row);
509 (unsigned) n * FontWidth(screen), (unsigned) FontHeight(screen));
512 /* adjust screen->buf */
513 ScrnInsertChar(screen->buf, screen->cur_row, screen->cur_col, n,
514 screen->max_col + 1);
518 * Deletes n chars at the cursor's position, no wraparound.
520 void DeleteChar (screen, n)
521 register TScreen *screen;
526 if(screen->cursor_state)
529 if (n > (width = screen->max_col + 1 - screen->cur_col))
532 if(screen->cur_row - screen->topline <= screen->max_row) {
533 if(!AddToRefresh(screen)) {
534 if(screen->scroll_amt)
537 horizontal_copy_area(screen, screen->cur_col+n,
538 screen->max_col+1 - (screen->cur_col+n),
542 (screen->display, TextWindow(screen),
544 screen->border + screen->scrollbar
545 + Width(screen) - n*FontWidth(screen),
546 CursorY (screen, screen->cur_row),(unsigned) n * FontWidth(screen),
547 (unsigned) FontHeight(screen));
550 /* adjust screen->buf */
551 ScrnDeleteChar (screen->buf, screen->cur_row, screen->cur_col, n,
552 screen->max_col + 1);
557 * Clear from cursor position to beginning of display, inclusive.
560 void ClearAbove (screen)
561 register TScreen *screen;
563 register top, height;
565 if(screen->cursor_state)
567 if((top = -screen->topline) <= screen->max_row) {
568 if(screen->scroll_amt)
570 if((height = screen->cur_row + top) > screen->max_row)
571 height = screen->max_row;
572 if((height -= top) > 0)
573 XClearArea(screen->display, TextWindow(screen),
574 screen->border + screen->scrollbar, top *
575 FontHeight(screen) + screen->border,
576 (unsigned)Width(screen), (unsigned)height * FontHeight(screen), FALSE);
578 if(screen->cur_row - screen->topline <= screen->max_row)
581 ClearBufRows(screen, 0, screen->cur_row - 1);
585 * Clear from cursor position to end of display, inclusive.
588 void ClearBelow (screen)
589 register TScreen *screen;
594 if((top = screen->cur_row - screen->topline) <= screen->max_row) {
595 if(screen->scroll_amt)
597 if(++top <= screen->max_row)
598 XClearArea(screen->display, TextWindow(screen),
599 screen->border + screen->scrollbar, top *
600 FontHeight(screen) + screen->border,
601 (unsigned) Width(screen),(unsigned) (screen->max_row - top + 1) *
602 FontHeight(screen), FALSE);
604 ClearBufRows(screen, screen->cur_row + 1, screen->max_row);
608 * Clear last part of cursor's line, inclusive.
611 void ClearRight (screen)
612 register TScreen *screen;
614 if(screen->cursor_state)
617 if(screen->cur_row - screen->topline <= screen->max_row) {
618 if(!AddToRefresh(screen)) {
619 if(screen->scroll_amt)
621 XFillRectangle(screen->display, TextWindow(screen),
623 CursorX(screen, screen->cur_col),
624 CursorY(screen, screen->cur_row),
625 (unsigned) Width(screen) - screen->cur_col * FontWidth(screen),
626 (unsigned)FontHeight(screen));
629 bzero((char*) ( screen->buf [2 * screen->cur_row] + screen->cur_col),
630 (screen->max_col - screen->cur_col + 1));
631 bzero((char *) (screen->buf [2 * screen->cur_row + 1] + screen->cur_col),
632 (screen->max_col - screen->cur_col + 1));
633 /* with the right part cleared, we can't be wrapping */
634 screen->buf [2 * screen->cur_row + 1] [0] &= ~LINEWRAPPED;
638 * Clear first part of cursor's line, inclusive.
641 void ClearLeft (screen)
642 register TScreen *screen;
647 if(screen->cursor_state)
650 if(screen->cur_row - screen->topline <= screen->max_row) {
651 if(!AddToRefresh(screen)) {
652 if(screen->scroll_amt)
654 XFillRectangle (screen->display, TextWindow(screen),
656 screen->border + screen->scrollbar,
657 CursorY (screen, screen->cur_row),
658 (unsigned)(screen->cur_col + 1) * FontWidth(screen),
659 (unsigned)FontHeight(screen));
663 for ( i=0, cp=screen->buf[2 * screen->cur_row];
664 i < screen->cur_col + 1;
667 for ( i=0, cp=screen->buf[2 * screen->cur_row + 1];
668 i < screen->cur_col + 1;
674 * Erase the cursor's line.
677 void ClearLine(screen)
678 register TScreen *screen;
680 if(screen->cursor_state)
683 if(screen->cur_row - screen->topline <= screen->max_row) {
684 if(!AddToRefresh(screen)) {
685 if(screen->scroll_amt)
687 XFillRectangle (screen->display, TextWindow(screen),
689 screen->border + screen->scrollbar,
690 CursorY (screen, screen->cur_row),
691 (unsigned) Width(screen), (unsigned) FontHeight(screen));
694 bzero ((char *) (screen->buf [2 * screen->cur_row]), (screen->max_col + 1));
695 bzero ((char *) (screen->buf [2 * screen->cur_row + 1]), (screen->max_col + 1));
698 void ClearScreen(screen)
699 register TScreen *screen;
703 if(screen->cursor_state)
706 if((top = -screen->topline) <= screen->max_row) {
707 if(screen->scroll_amt)
710 XClearWindow(screen->display, TextWindow(screen));
712 XClearArea(screen->display, TextWindow(screen),
713 screen->border + screen->scrollbar,
714 top * FontHeight(screen) + screen->border,
715 (unsigned) Width(screen), (unsigned)(screen->max_row - top + 1) *
716 FontHeight(screen), FALSE);
718 ClearBufRows (screen, 0, screen->max_row);
721 void CopyWait(screen)
722 register TScreen *screen;
725 XEvent *rep = &reply;
728 XWindowEvent (screen->display, VWindow(screen),
729 ExposureMask, &reply);
730 switch (reply.type) {
732 HandleExposure (screen, &reply);
736 if (screen->incopy <= 0) {
738 if (screen->scrolls > 0)
741 if (reply.type == GraphicsExpose)
742 HandleExposure (screen, &reply);
744 if ((reply.type == NoExpose) ||
745 ((XExposeEvent *)rep)->count == 0) {
746 if (screen->incopy <= 0 && screen->scrolls > 0)
748 if (screen->scrolls == 0) {
760 * used by vertical_copy_area and and horizontal_copy_area
763 copy_area(screen, src_x, src_y, width, height, dest_x, dest_y)
766 unsigned int width, height;
769 /* wait for previous CopyArea to complete unless
770 multiscroll is enabled and active */
771 if (screen->incopy && screen->scrolls == 0)
775 /* save for translating Expose events */
776 screen->copy_src_x = src_x;
777 screen->copy_src_y = src_y;
778 screen->copy_width = width;
779 screen->copy_height = height;
780 screen->copy_dest_x = dest_x;
781 screen->copy_dest_y = dest_y;
783 XCopyArea(screen->display,
784 TextWindow(screen), TextWindow(screen),
786 src_x, src_y, width, height, dest_x, dest_y);
790 * use when inserting or deleting characters on the current line
793 horizontal_copy_area(screen, firstchar, nchars, amount)
795 int firstchar; /* char pos on screen to start copying at */
797 int amount; /* number of characters to move right */
799 int src_x = CursorX(screen, firstchar);
800 int src_y = CursorY(screen, screen->cur_row);
802 copy_area(screen, src_x, src_y,
803 (unsigned)nchars*FontWidth(screen),(unsigned) FontHeight(screen),
804 src_x + amount*FontWidth(screen), src_y);
808 * use when inserting or deleting lines from the screen
811 vertical_copy_area(screen, firstline, nlines, amount)
813 int firstline; /* line on screen to start copying at */
815 int amount; /* number of lines to move up (neg=down) */
818 int src_x = screen->border + screen->scrollbar;
819 int src_y = firstline * FontHeight(screen) + screen->border;
821 copy_area(screen, src_x, src_y,
822 (unsigned)Width(screen),(unsigned) nlines*FontHeight(screen),
823 src_x, src_y - amount*FontHeight(screen));
828 * use when scrolling the entire screen
831 void scrolling_copy_area(screen, firstline, nlines, amount)
833 int firstline; /* line on screen to start copying at */
835 int amount; /* number of lines to move up (neg=down) */
839 vertical_copy_area(screen, firstline, nlines, amount);
844 * Handler for Expose events on the VT widget.
845 * Returns 1 iff the area where the cursor was got refreshed.
848 int HandleExposure (screen, event)
849 register TScreen *screen;
850 register XEvent *event;
852 register XExposeEvent *reply = (XExposeEvent *)event;
854 /* if not doing CopyArea or if this is a GraphicsExpose, don't translate */
855 if(!screen->incopy || event->type != Expose)
856 return handle_translated_exposure (screen, reply->x, reply->y,
857 reply->width, reply->height);
859 /* compute intersection of area being copied with
860 area being exposed. */
861 int both_x1 = Max(screen->copy_src_x, reply->x);
862 int both_y1 = Max(screen->copy_src_y, reply->y);
863 int both_x2 = Min(screen->copy_src_x+screen->copy_width,
864 reply->x+reply->width);
865 int both_y2 = Min(screen->copy_src_y+screen->copy_height,
866 reply->y+reply->height);
869 /* was anything copied affected? */
870 if(both_x2 > both_x1 && both_y2 > both_y1) {
871 /* do the copied area */
872 value = handle_translated_exposure
873 (screen, reply->x + screen->copy_dest_x - screen->copy_src_x,
874 reply->y + screen->copy_dest_y - screen->copy_src_y,
875 reply->width, reply->height);
877 /* was anything not copied affected? */
878 if(reply->x < both_x1 || reply->y < both_y1
879 || reply->x+reply->width > both_x2
880 || reply->y+reply->height > both_y2)
881 value = handle_translated_exposure (screen, reply->x, reply->y,
882 reply->width, reply->height);
889 * Called by the ExposeHandler to do the actual repaint after the coordinates
890 * have been translated to allow for any CopyArea in progress.
891 * The rectangle passed in is pixel coordinates.
893 int handle_translated_exposure (screen, rect_x, rect_y, rect_width, rect_height)
894 register TScreen *screen;
895 register int rect_x, rect_y;
896 register int rect_width, rect_height;
898 register int toprow, leftcol, nrows, ncols;
900 toprow = (rect_y - screen->border) / FontHeight(screen);
903 leftcol = (rect_x - screen->border - screen->scrollbar)
907 nrows = (rect_y + rect_height - 1 - screen->border) /
908 FontHeight(screen) - toprow + 1;
910 (rect_x + rect_width - 1 - screen->border - screen->scrollbar) /
911 FontWidth(screen) - leftcol + 1;
912 toprow -= screen->scrolls;
917 if (toprow + nrows - 1 > screen->max_row)
918 nrows = screen->max_row - toprow + 1;
919 if (leftcol + ncols - 1 > screen->max_col)
920 ncols = screen->max_col - leftcol + 1;
922 if (nrows > 0 && ncols > 0) {
923 ScrnRefresh (screen, toprow, leftcol, nrows, ncols, False);
924 if (screen->cur_row >= toprow &&
925 screen->cur_row < toprow + nrows &&
926 screen->cur_col >= leftcol &&
927 screen->cur_col < leftcol + ncols)
934 void ReverseVideo (termw)
937 register TScreen *screen = &termw->screen;
941 tmp = termw->core.background_pixel;
942 if(screen->cursorcolor == screen->foreground)
943 screen->cursorcolor = tmp;
944 termw->core.background_pixel = screen->foreground;
945 screen->foreground = tmp;
947 tmp = screen->mousecolorback;
948 screen->mousecolorback = screen->mousecolor;
949 screen->mousecolor = tmp;
951 tmpGC = screen->normalGC;
952 screen->normalGC = screen->reverseGC;
953 screen->reverseGC = tmpGC;
955 tmpGC = screen->normalboldGC;
956 screen->normalboldGC = screen->reverseboldGC;
957 screen->reverseboldGC = tmpGC;
959 recolor_cursor (screen->pointer_cursor,
960 screen->mousecolor, screen->mousecolorback);
961 recolor_cursor (screen->arrow,
962 screen->mousecolor, screen->mousecolorback);
964 termw->misc.re_verse = !termw->misc.re_verse;
966 XDefineCursor(screen->display, TextWindow(screen), screen->pointer_cursor);
967 if(screen->scrollWidget)
968 ScrollBarReverseVideo(screen->scrollWidget);
970 XSetWindowBackground(screen->display, TextWindow(screen), termw->core.background_pixel);
971 XClearWindow(screen->display, TextWindow(screen));
972 ScrnRefresh (screen, 0, 0, screen->max_row + 1,
973 screen->max_col + 1, False);
974 update_reversevideo();
978 void recolor_cursor (cursor, fg, bg)
979 Cursor cursor; /* X cursor ID to set */
980 unsigned long fg, bg; /* pixel indexes to look up */
982 register TScreen *screen = &term->screen;
983 register Display *dpy = screen->display;
984 XColor colordefs[2]; /* 0 is foreground, 1 is background */
986 colordefs[0].pixel = fg;
987 colordefs[1].pixel = bg;
988 XQueryColors (dpy, DefaultColormap (dpy, DefaultScreen (dpy)),
990 XRecolorCursor (dpy, cursor, colordefs, colordefs+1);