⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 源码,标准c++用力
💻 C
📖 第 1 页 / 共 3 页
字号:
		case GraphicsExpose:			if (screen->incopy <= 0) {				screen->incopy = 1;				if (screen->scrolls > 0)					screen->scrolls--;			}			if (reply.type == GraphicsExpose)			    HandleExposure (screen, &reply);			if ((reply.type == NoExpose) ||			    ((XExposeEvent *)rep)->count == 0) {			    if (screen->incopy <= 0 && screen->scrolls > 0)				screen->scrolls--;			    if (screen->scrolls == 0) {				screen->incopy = 0;				return;			    }			    screen->incopy = -1;			}			break;		}	}}/* * used by vertical_copy_area and and horizontal_copy_area */static voidcopy_area(screen, src_x, src_y, width, height, dest_x, dest_y)    TScreen *screen;    int src_x, src_y;    unsigned int width, height;    int dest_x, dest_y;{    /* wait for previous CopyArea to complete unless       multiscroll is enabled and active */    if (screen->incopy  &&  screen->scrolls == 0)	CopyWait(screen);    screen->incopy = -1;    /* save for translating Expose events */    screen->copy_src_x = src_x;    screen->copy_src_y = src_y;    screen->copy_width = width;    screen->copy_height = height;    screen->copy_dest_x = dest_x;    screen->copy_dest_y = dest_y;    XCopyArea(screen->display, 	      TextWindow(screen), TextWindow(screen),	      screen->normalGC,	      src_x, src_y, width, height, dest_x, dest_y);}/* * use when inserting or deleting characters on the current line */static voidhorizontal_copy_area(screen, firstchar, nchars, amount)    TScreen *screen;    int firstchar;		/* char pos on screen to start copying at */    int nchars;    int amount;			/* number of characters to move right */{    int src_x = CursorX(screen, firstchar);    int src_y = CursorY(screen, screen->cur_row);    copy_area(screen, src_x, src_y,	      (unsigned)nchars*FontWidth(screen), FontHeight(screen),	      src_x + amount*FontWidth(screen), src_y);}/* * use when inserting or deleting lines from the screen */static voidvertical_copy_area(screen, firstline, nlines, amount)    TScreen *screen;    int firstline;		/* line on screen to start copying at */    int nlines;    int amount;			/* number of lines to move up (neg=down) */{    if(nlines > 0) {	int src_x = screen->border + screen->scrollbar;	int src_y = firstline * FontHeight(screen) + screen->border;	copy_area(screen, src_x, src_y,		  (unsigned)Width(screen), nlines*FontHeight(screen),		  src_x, src_y - amount*FontHeight(screen));    }}/* * use when scrolling the entire screen */scrolling_copy_area(screen, firstline, nlines, amount)    TScreen *screen;    int firstline;		/* line on screen to start copying at */    int nlines;    int amount;			/* number of lines to move up (neg=down) */{    if(nlines > 0) {	vertical_copy_area(screen, firstline, nlines, amount);    }}/* * Handler for Expose events on the VT widget. * Returns 1 iff the area where the cursor was got refreshed. */HandleExposure (screen, event)    register TScreen *screen;    register XEvent *event;{    register XExposeEvent *reply = (XExposeEvent *)event;    /* if not doing CopyArea or if this is a GraphicsExpose, don't translate */    if(!screen->incopy  ||  event->type != Expose)	return handle_translated_exposure (screen, reply->x, reply->y,					   reply->width, reply->height);    else {	/* compute intersection of area being copied with	   area being exposed. */	int both_x1 = Max(screen->copy_src_x, reply->x);	int both_y1 = Max(screen->copy_src_y, reply->y);	int both_x2 = Min(screen->copy_src_x+screen->copy_width,			  reply->x+reply->width);	int both_y2 = Min(screen->copy_src_y+screen->copy_height,			  reply->y+reply->height);	int value = 0;	/* was anything copied affected? */	if(both_x2 > both_x1  && both_y2 > both_y1) {	    /* do the copied area */	    value = handle_translated_exposure		(screen, reply->x + screen->copy_dest_x - screen->copy_src_x,		 reply->y + screen->copy_dest_y - screen->copy_src_y,		 reply->width, reply->height);	}	/* was anything not copied affected? */	if(reply->x < both_x1 || reply->y < both_y1	   || reply->x+reply->width > both_x2	   || reply->y+reply->height > both_y2)	    value = handle_translated_exposure (screen, reply->x, reply->y,						reply->width, reply->height);	return value;    }}/* * Called by the ExposeHandler to do the actual repaint after the coordinates * have been translated to allow for any CopyArea in progress. * The rectangle passed in is pixel coordinates. */handle_translated_exposure (screen, rect_x, rect_y, rect_width, rect_height)    register TScreen *screen;    register int rect_x, rect_y;    register unsigned int rect_width, rect_height;{	register int toprow, leftcol, nrows, ncols;	extern Bool waiting_for_initial_map;	toprow = (rect_y - screen->border) / FontHeight(screen);	if(toprow < 0)		toprow = 0;	leftcol = (rect_x - screen->border - screen->scrollbar)	    / FontWidth(screen);	if(leftcol < 0)		leftcol = 0;	nrows = (rect_y + rect_height - 1 - screen->border) / 		FontHeight(screen) - toprow + 1;	ncols =	 (rect_x + rect_width - 1 - screen->border - screen->scrollbar) /			FontWidth(screen) - leftcol + 1;	toprow -= screen->scrolls;	if (toprow < 0) {		nrows += toprow;		toprow = 0;	}	if (toprow + nrows - 1 > screen->max_row)		nrows = screen->max_row - toprow + 1;	if (leftcol + ncols - 1 > screen->max_col)		ncols = screen->max_col - leftcol + 1;	if (nrows > 0 && ncols > 0) {		ScrnRefresh (screen, toprow, leftcol, nrows, ncols, False);		if (waiting_for_initial_map) {		    first_map_occurred ();		}		if (screen->cur_row >= toprow &&		    screen->cur_row < toprow + nrows &&		    screen->cur_col >= leftcol &&		    screen->cur_col < leftcol + ncols)			return (1);	}	return (0);}/***=================================================================***/voidGetColors(term,pColors)	XtermWidget term;	ScrnColors *pColors;{	register TScreen *screen = &term->screen;	GC tmpGC;	Window tek = TWindow(screen);	unsigned long tmp;	pColors->which= 0;	SET_COLOR_VALUE(pColors,TEXT_FG,		screen->foreground);	SET_COLOR_VALUE(pColors,TEXT_BG,		term->core.background_pixel);	SET_COLOR_VALUE(pColors,TEXT_CURSOR,		screen->cursorcolor);	SET_COLOR_VALUE(pColors,MOUSE_FG,	screen->mousecolor);	SET_COLOR_VALUE(pColors,MOUSE_BG, 	screen->mousecolorback);	SET_COLOR_VALUE(pColors,TEK_FG,		screen->Tforeground);	SET_COLOR_VALUE(pColors,TEK_BG,		screen->Tbackground);}ChangeColors(term,pNew)	XtermWidget term;	ScrnColors *pNew;{	register TScreen *screen = &term->screen;	GC tmpGC;	Window tek = TWindow(screen);	unsigned long tmp;	Bool	newCursor=	TRUE;	if (COLOR_DEFINED(pNew,TEXT_BG)) {		term->core.background_pixel=	COLOR_VALUE(pNew,TEXT_BG);	}	if (COLOR_DEFINED(pNew,TEXT_CURSOR)) {		screen->cursorcolor=	COLOR_VALUE(pNew,TEXT_CURSOR);	}	else if ((screen->cursorcolor == screen->foreground)&&		(COLOR_DEFINED(pNew,TEXT_FG))) {		screen->cursorcolor=	COLOR_VALUE(pNew,TEXT_FG);	}	else newCursor= FALSE;	if (COLOR_DEFINED(pNew,TEXT_FG)) {		Pixel	fg= COLOR_VALUE(pNew,TEXT_FG);		screen->foreground= fg;		XSetForeground(screen->display,screen->normalGC,fg);		XSetBackground(screen->display,screen->reverseGC,fg);		XSetForeground(screen->display,screen->normalboldGC,fg);		XSetBackground(screen->display,screen->reverseboldGC,fg);	}	if (COLOR_DEFINED(pNew,TEXT_BG)) {		Pixel	bg=	COLOR_VALUE(pNew,TEXT_BG);		term->core.background_pixel=	bg;		XSetBackground(screen->display,screen->normalGC,bg);		XSetForeground(screen->display,screen->reverseGC,bg);		XSetBackground(screen->display,screen->normalboldGC,bg);		XSetForeground(screen->display,screen->reverseboldGC,bg);		XSetWindowBackground(screen->display, TextWindow(screen),						term->core.background_pixel);	}	if (COLOR_DEFINED(pNew,MOUSE_FG)||(COLOR_DEFINED(pNew,MOUSE_BG))) {		if (COLOR_DEFINED(pNew,MOUSE_FG))		screen->mousecolor= COLOR_VALUE(pNew,MOUSE_FG);		if (COLOR_DEFINED(pNew,MOUSE_BG))		screen->mousecolorback= COLOR_VALUE(pNew,MOUSE_BG);		recolor_cursor (screen->pointer_cursor,		screen->mousecolor, screen->mousecolorback);		recolor_cursor (screen->arrow,		screen->mousecolor, screen->mousecolorback);		XDefineCursor(screen->display, TextWindow(screen),						screen->pointer_cursor);		if(tek)		XDefineCursor(screen->display, tek, screen->arrow);	}	if ((tek)&&(COLOR_DEFINED(pNew,TEK_FG)||COLOR_DEFINED(pNew,TEK_BG))) {		ChangeTekColors(screen,pNew);	}	set_cursor_gcs(screen);	XClearWindow(screen->display, TextWindow(screen));	ScrnRefresh (screen, 0, 0, screen->max_row + 1,		screen->max_col + 1, False);	if(screen->Tshow) {		XClearWindow(screen->display, tek);		TekExpose((XExposeEvent *) NULL);	}}/***===================================================================***/ReverseVideo (termw)	XtermWidget termw;{	register TScreen *screen = &termw->screen;	GC tmpGC;	Window tek = TWindow(screen);	unsigned long tmp;	tmp = termw->core.background_pixel;	if(screen->cursorcolor == screen->foreground)		screen->cursorcolor = tmp;	termw->core.background_pixel = screen->foreground;	screen->foreground = tmp;	tmp = screen->mousecolorback;	screen->mousecolorback = screen->mousecolor;	screen->mousecolor = tmp;	tmpGC = screen->normalGC;	screen->normalGC = screen->reverseGC;	screen->reverseGC = tmpGC;	tmpGC = screen->normalboldGC;	screen->normalboldGC = screen->reverseboldGC;	screen->reverseboldGC = tmpGC;	recolor_cursor (screen->pointer_cursor, 			screen->mousecolor, screen->mousecolorback);	recolor_cursor (screen->arrow,			screen->mousecolor, screen->mousecolorback);	termw->misc.re_verse = !termw->misc.re_verse;	XDefineCursor(screen->display, TextWindow(screen), screen->pointer_cursor);	if(tek)		XDefineCursor(screen->display, tek, screen->arrow);		if(screen->scrollWidget)		ScrollBarReverseVideo(screen->scrollWidget);	XSetWindowBackground(screen->display, TextWindow(screen), termw->core.background_pixel);	if(tek) {	    TekReverseVideo(screen);	}	XClearWindow(screen->display, TextWindow(screen));	ScrnRefresh (screen, 0, 0, screen->max_row + 1,	 screen->max_col + 1, False);	if(screen->Tshow) {	    XClearWindow(screen->display, tek);	    TekExpose((Widget)NULL, (XEvent *)NULL, (Region)NULL);	}	ReverseOldColors();	update_reversevideo();}recolor_cursor (cursor, fg, bg)    Cursor cursor;			/* X cursor ID to set */    unsigned long fg, bg;		/* pixel indexes to look up */{    register TScreen *screen = &term->screen;    register Display *dpy = screen->display;    XColor colordefs[2];		/* 0 is foreground, 1 is background */    colordefs[0].pixel = fg;    colordefs[1].pixel = bg;    XQueryColors (dpy, DefaultColormap (dpy, DefaultScreen (dpy)),		  colordefs, 2);    XRecolorCursor (dpy, cursor, colordefs, colordefs+1);    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -