rxvtlib_screen.c

来自「具有IDE功能的编辑器」· C语言 代码 · 共 2,128 行 · 第 1/5 页

C
2,128 行
字号
	}    }}#endif				/* MULTICHAR_SET *//* ------------------------------------------------------------------------- * *                           GRAPHICS COLOURS                                *  * ------------------------------------------------------------------------- */#ifdef RXVT_GRAPHICS/* EXTPROTO */int             rxvtlib_scr_get_fgcolor (rxvtlib *o){    return GET_FGCOLOR (o->rstyle);}/* ------------------------------------------------------------------------- *//* EXTPROTO */int             rxvtlib_scr_get_bgcolor (rxvtlib *o){    return GET_BGCOLOR (o->rstyle);}#endif/* ------------------------------------------------------------------------- * *                        MAJOR SCREEN MANIPULATION                          *  * ------------------------------------------------------------------------- *//* * Refresh an area */enum {    PART_BEG = 0,    PART_END,#if defined(XPM_BACKGROUND) && defined(XPM_BUFFERING)    FULL_BEG,    FULL_END,#endif    RC_COUNT};/* EXTPROTO */void            rxvtlib_scr_expose (rxvtlib *o, int x, int y, int width, int height){    int             i;    row_col_t       rc[RC_COUNT];    if (o->drawn_text == NULL)	/* sanity check */	return;/* round down */    rc[PART_BEG].col = Pixel2Col(x);    rc[PART_BEG].row = Pixel2Row(y);/* round up */    rc[PART_END].col = Pixel2Width(x + width + o->TermWin.fwidth - 1);    rc[PART_END].row = Pixel2Row(y + height + o->TermWin.fheight - 1); #if defined(XPM_BACKGROUND) && defined(XPM_BUFFERING)/* round down */    rc[FULL_END].col = Pixel2Width(x + width);    rc[FULL_END].row = Pixel2Row(y + height);/* round up */    rc[FULL_BEG].col = Pixel2Col(x + o->TermWin.fwidth - 1);    rc[FULL_BEG].row = Pixel2Row(y + o->TermWin.fheight - 1);#endif/* sanity checks */    for (i = PART_BEG; i < RC_COUNT; i++) {	MAX_IT(rc[i].col, 0);	MAX_IT(rc[i].row, 0);	MIN_IT(rc[i].col, o->TermWin.ncol - 1);	MIN_IT(rc[i].row, o->TermWin.nrow - 1);    }    D_SCREEN((stderr, "scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)", x, y, width, height, rc[PART_BEG}.col, rc[PART_BEG].row, rc[PART_END].col, rc[PART_END].row));#if defined(XPM_BACKGROUND) && defined(XPM_BUFFERING)/* supposedly we're exposed - so `clear' the fully exposed clear areas */    x = Col2Pixel(rc[FULL_BEG].col);    y = Row2Pixel(rc[FULL_BEG].row);    width = Width2Pixel(rc[FULL_END].col - rc[FULL_BEG].col + 1);    height = Height2Pixel(rc[FULL_END].row - rc[FULL_BEG].row + 1);    XCopyArea (o->Xdisplay, o->TermWin.pixmap, drawBuffer, o->TermWin.gc,	       x, y, width, height, x, y);#endif    for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)	MEMSET(&(o->drawn_text[i][rc[PART_BEG].col]), 0,	       rc[PART_END].col - rc[PART_BEG].col + 1);    rxvtlib_scr_refresh (o, SLOW_REFRESH);}/* ------------------------------------------------------------------------- *//* * Refresh the entire screen *//* EXTPROTO */void            rxvtlib_scr_touch (rxvtlib *o){    rxvtlib_scr_expose (o, 0, 0, o->TermWin.width, o->TermWin.height);}/* ------------------------------------------------------------------------- *//* * Move the display so that the line represented by scrollbar value Y is at * the top of the screen *//* EXTPROTO */int             rxvtlib_scr_move_to (rxvtlib *o, int y, int len){    int             start;    o->want_refresh = 1;    start = o->TermWin.view_start;    if (y >= len)	o->TermWin.view_start = 0;    else {	o->TermWin.view_start = ((len - y)			      * (o->TermWin.nrow - 1 + o->TermWin.nscrolled) / len);	if (o->TermWin.view_start < o->TermWin.nrow)	    o->TermWin.view_start = 0;	else	    o->TermWin.view_start -= (o->TermWin.nrow - 1);    }    D_SCREEN (	      (stderr, "scr_move_to(%d, %d) view_start:%d", y, len,	       o->TermWin.view_start));    MIN_IT (o->TermWin.view_start, o->TermWin.nscrolled);    if (rxvtlib_Gr_Displayed (o))	rxvtlib_Gr_scroll (o, 0);    return (o->TermWin.view_start - start);}/* ------------------------------------------------------------------------- *//* * Page the screen up/down nlines * direction  should be UP or DN *//* EXTPROTO */int             rxvtlib_scr_page (rxvtlib *o, int direction, int nlines){    int             start;    D_SCREEN (	      (stderr, "scr_page(%s, %d) view_start:%d",	       ((direction == UP) ? "UP" : "DN"), nlines, o->TermWin.view_start));    start = o->TermWin.view_start;    MAX_IT (nlines, 1);    MIN_IT (nlines, o->TermWin.nrow);    if (direction == UP)	o->TermWin.view_start = o->TermWin.view_start < o->TermWin.nscrolled - nlines	    ? o->TermWin.view_start + nlines : o->TermWin.nscrolled;    else	o->TermWin.view_start = o->TermWin.view_start > nlines	    ? o->TermWin.view_start - nlines : 0;    if (rxvtlib_Gr_Displayed (o))	rxvtlib_Gr_scroll (o, 0);    if (o->TermWin.view_start != start)	o->want_refresh = 1;    return (int)(o->TermWin.view_start - start);}/* ------------------------------------------------------------------------- *//* EXTPROTO */void            rxvtlib_scr_bell (rxvtlib *o){#ifndef NO_MAPALERT# ifdef MAPALERT_OPTION    if (o->Options & Opt_mapAlert)# endif	XMapWindow (o->Xdisplay, o->TermWin.parent[0]);#endif    if (o->Options & Opt_visualBell) {	rxvtlib_scr_rvideo_mode (o, !o->rvideo);	/* scr_refresh() also done */	rxvtlib_scr_rvideo_mode (o, !o->rvideo);	/* scr_refresh() also done */    } else	XBell (o->Xdisplay, 0);}/* ------------------------------------------------------------------------- *//* ARGSUSED *//* EXTPROTO */void            rxvtlib_scr_printscreen (rxvtlib *o, int fullhist){#ifdef PRINTPIPE    int             i, r, nrows, row_offset;    text_t         *t;    FILE           *fd;    if ((fd = rxvtlib_popen_printer (o)) == NULL)	return;    nrows = o->TermWin.nrow;    row_offset = o->TermWin.saveLines;    if (!fullhist)	row_offset -= o->TermWin.view_start;    else {	nrows += o->TermWin.nscrolled;	row_offset -= o->TermWin.nscrolled;    }    for (r = 0; r < nrows; r++) {	t = o->screen.text[r + row_offset];	for (i = o->TermWin.ncol - 1; i >= 0; i--)	    if (!isspace (t[i]))		break;	fprintf (fd, "%.*s\n", (i + 1), t);    }    pclose_printer (fd);#endif}/* ------------------------------------------------------------------------- *//* * Refresh the screen * drawn_text/drawn_rend contain the screen information before the update. * screen.text/screen.rend contain what the screen will change to. *//* EXTPROTO */void            rxvtlib_scr_refresh (rxvtlib *o, int type){    int             i, j,	/* tmp                                       */                    col, row,	/* column/row we're processing               */                    scrrow,	/* screen row offset                         */                    row_offset,	/* basic offset in screen structure          */                    currow,	/* cursor row at appropriate offset          */                    boldlast,	/* last character in some row was bold       */                    len, wlen,	/* text length screen/buffer                 */                    fprop,	/* proportional font used                    */                    rvid,	/* reverse video this position               */                    rend,	/* rendition                                 */                    fore, back,	/* desired foreground/background             */                    wbyte,	/* we're in multibyte                        */		    fontdiff,	/* current font size different to base font  */                    morecur = 0, xpixel,	/* x offset for start of drawing (font)      */                    ypixel,	/* y offset for start of drawing (font)      */		    ypixelc;	/* y offset for top of drawing               */    long            gcmask,	/* Graphics Context mask                     */                    gcmaskf;    static int      focus = -1;	/* screen in focus?                          */    unsigned long   ltmp;    rend_t          rt1, rt2;	/* tmp rend values                           */#ifndef NO_CURSORCOLOR    rend_t          ccol1,	/* Cursor colour                             */                    ccol2,	/* Cursor colour2                            */                    cc1 = 0;	/* store colours at cursor position(s)       */# ifdef MULTICHAR_SET    rend_t          cc2;	/* store colours at cursor position(s)       */# endif#endif    rend_t         *drp, *srp;	/* drawn-rend-pointer, screen-rend-pointer   */    text_t         *dtp, *stp;	/* drawn-text-pointer, screen-text-pointer   */    XGCValues       gcvalue;	/* Graphics Context values                   */    XFontStruct    *wf;		/* which font are we in                      */    /* is there an old outline cursor on screen? */#ifndef NO_BOLDFONT    int             bfont = 0;	/* we've changed font to bold font           */#endif    int             (*draw_string) (), (*draw_image_string) ();    if (type == NO_REFRESH)	return;    if (!o->TermWin.mapped)	return;/* * A: set up vars */    if (o->currmaxcol < o->TermWin.ncol) {	o->currmaxcol = o->TermWin.ncol;	if (o->buffer)	    o->buffer = REALLOC (o->buffer, (sizeof (char) * (o->currmaxcol + 1)));	else	    o->buffer = MALLOC ((sizeof (char) * (o->currmaxcol + 1)));    }    row_offset = o->TermWin.saveLines - o->TermWin.view_start;    fprop = o->TermWin.fprop;    gcvalue.foreground = o->PixColors[Color_fg];    gcvalue.background = o->PixColors[Color_bg];/* * always go back to the base font - it's much safer */    wbyte = 0;    XSetFont (o->Xdisplay, o->TermWin.gc, o->TermWin.font->fid);    draw_string = XDrawString;    draw_image_string = XDrawImageString;    boldlast = 0;/* * B: reverse any characters which are selected */    rxvtlib_scr_reverse_selection (o);#ifndef NO_BOLDOVERSTRIKE/* * C: Bold Overstrike pixel dropping avoidance.  Do this before the main *    refresh.  Do a pass across each line at the start, require a refresh of *    anything that will need to be refreshed due to pixels being dropped *    into our area by a previous character which has now been changed. */    for (row = 0; row < o->TermWin.nrow; row++) {	scrrow = row + row_offset;	stp = o->screen.text[scrrow];	srp = o->screen.rend[scrrow];	dtp = o->drawn_text[row];	drp = o->drawn_rend[row];# ifndef NO_BOLDFONT	if (o->TermWin.boldFont == NULL) {# endif	    wf = o->TermWin.font;	    j = wbyte;	    for (col = o->TermWin.ncol - 2; col >= 0; col--) {# if ! defined (NO_BRIGHTCOLOR) && ! defined (VERYBOLD)		fore = GET_FGCOLOR (drp[col]);# endif		if (!MONO_BOLD (drp[col]))		    continue;		if (dtp[col] == stp[col]		    && drp[col] == srp[col])		    continue;		if (wbyte) {		    ;		/* TODO: handle multibyte */		    continue;	/* don't go past here */		}		if (dtp[col] == ' ') {	/* TODO: check character set? */		    continue;		}		if (wf->per_char == NULL		    || dtp[col] < wf->min_char_or_byte2		    || dtp[col] > wf->max_char_or_byte2		    || FONT_WIDTH (wf, dtp[col]) == FONT_RBEAR (wf, dtp[col])) {		    dtp[col + 1] = 0;# if defined(MULTICHAR_SET) && ! defined(NO_BOLDOVERSTRIKE_MULTI)		    if ((srp[col] & RS_multiMask) == RS_multi2) {			col--;			wbyte = 1;			continue;		    }# endif		}	    }# if ! defined (NO_BRIGHTCOLOR) && ! defined (VERYBOLD)	    fore = GET_FGCOLOR (srp[o->TermWin.ncol - 1]);# endif	    if (MONO_BOLD (srp[o->TermWin.ncol - 1]))		boldlast = 1;	    wbyte = j;# ifndef NO_BOLDFONT	}# endif    }#endif				/* ! NO_BOLDOVERSTRIKE *//* * D: set the cursor character(s) */    currow = o->screen.cur.row + o->TermWin.saveLines;    if (focus != o->TermWin.focus)	focus = o->TermWin.focus;    if (o->screen.flags & Screen_VisibleCursor && focus) {	srp = &(o->screen.rend[currow][o->screen.cur.col]);	*srp ^= RS_RVid;#ifndef NO_CURSORCOLOR	cc1 = *srp & (RS_fgMask | RS_bgMask);	if (o->Xdepth <= 2 || !o->rs[Rs_color + Color_cursor])	    ccol1 = Color_fg;	else	    ccol1 = Color_cursor;	if (o->Xdepth <= 2 || !o->rs[Rs_color + Color_cursor2])	    ccol2 = Color_bg;	else	    ccol2 = Color_cursor2;	*srp = SET_FGCOLOR (*srp, ccol1);	*srp = SET_BGCOLOR (*srp, ccol2);#endif#ifdef MULTICHAR_SET	rt1 = *srp & RS_multiMask;	if (rt1 == RS_multi1) {	    if (o->screen.cur.col < o->TermWin.ncol - 2		&& ((srp[1] & RS_multiMask) == RS_multi2))		morecur = 1;	} else if (rt1 == RS_multi2) {	    if (o->screen.cur.col > 0 && ((srp[-1] & RS_multiMask) == RS_multi1))		morecur = -1;	}	if (morecur) {	    srp += morecur;	    *srp ^= RS_RVid;	}# ifndef NO_CURSORCOLOR	if (morecur) {	    cc2 = *srp & (RS_fgMask | RS_bgMask);	    *srp = SET_FGCOLOR (*srp, ccol1);	    *srp = SET_BGCOLOR (*srp, ccol2);	}# endif#endif    }    i = 0;    if (o->oldcursor.row != -1) {	/* make sure no outline cursor is left around */	if (o->screen.cur.row + o->TermWin.view_start != o->oldcursor.row	    || o->screen.cur.col != o->oldcursor.col) {	    if (o->oldcursor.row < o->TermWin.nrow && o->oldcursor.col < o->TermWin.ncol) {		o->drawn_text[o->oldcursor.row][o->oldcursor.col] = 0;#ifdef MULTICHAR_SET		if (o->oldcursormulti) {		    col = o->oldcursor.col + o->oldcursormulti;		    if (col < o->TermWin.ncol)			o->drawn_text[o->oldcursor.row][col] = 0;		}#endif	    }	    if (focus || !(o->screen.flags & Screen_VisibleCu

⌨️ 快捷键说明

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