diff options
Diffstat (limited to 'app/xterm/util.c')
-rw-r--r-- | app/xterm/util.c | 227 |
1 files changed, 132 insertions, 95 deletions
diff --git a/app/xterm/util.c b/app/xterm/util.c index af57be569..2a05264f4 100644 --- a/app/xterm/util.c +++ b/app/xterm/util.c @@ -1,7 +1,7 @@ -/* $XTermId: util.c,v 1.504 2009/10/11 20:23:19 tom Exp $ */ +/* $XTermId: util.c,v 1.523 2010/01/03 23:56:24 tom Exp $ */ /* - * Copyright 1999-2008,2009 by Thomas E. Dickey + * Copyright 1999-2009,2010 by Thomas E. Dickey * * All Rights Reserved * @@ -104,33 +104,53 @@ int DamagedCells(TScreen * screen, unsigned n, int *klp, int *krp, int row, int col) { LineData *ld = getLineData(screen, row); - int kl = col; - int kr = col + (int) n; + int result = False; - if (ld->charData[kl] == HIDDEN_CHAR) { - while (kl > 0) { - if (ld->charData[--kl] != HIDDEN_CHAR) { - break; - } + assert(ld); + if (col < (int) ld->lineSize) { + int nn = (int) n; + int kl = col; + int kr = col + nn; + + if (kr >= ld->lineSize) { + nn = (ld->lineSize - col - 1); + kr = col + nn; } - } else { - kl = col + 1; - } - if (ld->charData[kr] == HIDDEN_CHAR) { - while (kr < screen->max_col) { - if (ld->charData[++kr] != HIDDEN_CHAR) { - --kr; - break; + + if (nn > 0) { + assert(kl < ld->lineSize); + if (ld->charData[kl] == HIDDEN_CHAR) { + while (kl > 0) { + if (ld->charData[--kl] != HIDDEN_CHAR) { + break; + } + } + } else { + kl = col + 1; } + + assert(kr < (int) ld->lineSize); + if (ld->charData[kr] == HIDDEN_CHAR) { + while (kr < screen->max_col) { + assert((kr + 1) < (int) ld->lineSize); + if (ld->charData[++kr] != HIDDEN_CHAR) { + --kr; + break; + } + } + } else { + kr = col - 1; + } + + if (klp) + *klp = kl; + if (krp) + *krp = kr; + result = (kr >= kl); } - } else { - kr = col - 1; } - if (klp) - *klp = kl; - if (krp) - *krp = kr; - return (kr >= kl); + + return result; } int @@ -146,7 +166,7 @@ DamagedCurCells(TScreen * screen, unsigned n, int *klp, int *krp) void FlushScroll(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int i; int shift = INX2ROW(screen, 0); int bot = screen->max_row - shift; @@ -232,7 +252,7 @@ FlushScroll(XtermWidget xw) int AddToRefresh(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int amount = screen->refresh_amt; int row = screen->cur_row; int result; @@ -278,7 +298,7 @@ AddToRefresh(XtermWidget xw) static Bool AddToVisible(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); Bool result = False; if (INX2ROW(screen, screen->cur_row) <= screen->max_row) { @@ -297,7 +317,7 @@ AddToVisible(XtermWidget xw) static void adjustHiliteOnFwdScroll(XtermWidget xw, int amount, Bool all_lines) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int lo_row = (all_lines ? (screen->bot_marg - screen->savelines) : screen->top_marg); @@ -357,7 +377,7 @@ adjustHiliteOnFwdScroll(XtermWidget xw, int amount, Bool all_lines) static void adjustHiliteOnBakScroll(XtermWidget xw, int amount) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int lo_row = screen->top_marg; int hi_row = screen->bot_marg; @@ -416,7 +436,7 @@ adjustHiliteOnBakScroll(XtermWidget xw, int amount) void xtermScroll(XtermWidget xw, int amount) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int i = screen->bot_marg - screen->top_marg + 1; int shift; int bot; @@ -552,7 +572,7 @@ xtermScroll(XtermWidget xw, int amount) void RevScroll(XtermWidget xw, int amount) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int i = screen->bot_marg - screen->top_marg + 1; int shift; int bot; @@ -636,8 +656,9 @@ RevScroll(XtermWidget xw, int amount) void WriteText(XtermWidget xw, IChar * str, Cardinal len) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld = 0; + int fg; unsigned test; unsigned flags = xw->flags; CellColor fg_bg = makeColorPair(xw->cur_foreground, xw->cur_background); @@ -691,7 +712,12 @@ WriteText(XtermWidget xw, IChar * str, Cardinal len) screen->cur_row)); test = flags; - checkVeryBoldColors(test, xw->cur_foreground); + if (screen->colorAttrMode) { + fg = MapToColorMode(xw->cur_foreground, screen, flags); + } else { + fg = xw->cur_foreground; + } + checkVeryBoldColors(test, fg); /* make sure that the correct GC is current */ currentGC = updatedXtermGC(xw, flags, fg_bg, False); @@ -724,7 +750,7 @@ WriteText(XtermWidget xw, IChar * str, Cardinal len) screen->zIconBeep_flagged = True; ChangeIconName(xw, icon_name); } - xtermBell(xw, resource.zIconBeep, XkbBI_Info); + xtermBell(xw, XkbBI_Info, 0); } mapstate = -1; #endif /* OPT_ZICONBEEP */ @@ -739,7 +765,7 @@ WriteText(XtermWidget xw, IChar * str, Cardinal len) void InsertLine(XtermWidget xw, int n) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int i; int shift; int bot; @@ -817,7 +843,7 @@ InsertLine(XtermWidget xw, int n) void DeleteLine(XtermWidget xw, int n) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int i; int shift; int bot; @@ -929,7 +955,7 @@ DeleteLine(XtermWidget xw, int n) void InsertChar(XtermWidget xw, unsigned n) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld; unsigned limit; int row = INX2ROW(screen, screen->cur_row); @@ -1007,7 +1033,7 @@ InsertChar(XtermWidget xw, unsigned n) void DeleteChar(XtermWidget xw, unsigned n) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld; unsigned limit; int row = INX2ROW(screen, screen->cur_row); @@ -1073,7 +1099,7 @@ DeleteChar(XtermWidget xw, unsigned n) static void ClearAbove(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); if (screen->protected_mode != OFF_PROTECT) { int row; @@ -1112,7 +1138,7 @@ ClearAbove(XtermWidget xw) static void ClearBelow(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); ClearRight(xw, -1); @@ -1149,7 +1175,7 @@ ClearBelow(XtermWidget xw) static int ClearInLine2(XtermWidget xw, int flags, int row, int col, unsigned len) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld; int rc = 1; @@ -1204,8 +1230,9 @@ ClearInLine2(XtermWidget xw, int flags, int row, int col, unsigned len) } while (!done); screen->protected_mode = saved_mode; - if (len <= 0) + if (len <= 0) { return 0; + } } /* fall through to the final non-protected segment */ @@ -1233,7 +1260,7 @@ ClearInLine2(XtermWidget xw, int flags, int row, int col, unsigned len) int ClearInLine(XtermWidget xw, int row, int col, unsigned len) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int flags = 0; /* @@ -1255,7 +1282,7 @@ ClearInLine(XtermWidget xw, int row, int col, unsigned len) void ClearRight(XtermWidget xw, int n) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld; unsigned len = (unsigned) (MaxCols(screen) - screen->cur_col); @@ -1305,10 +1332,10 @@ ClearRight(XtermWidget xw, int n) static void ClearLeft(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); unsigned len = (unsigned) screen->cur_col + 1; - assert(screen->cur_col >= 0); + assert(screen->cur_col >= 0); if (AddToVisible(xw)) { if_OPT_WIDE_CHARS(screen, { int row = screen->cur_row; @@ -1330,7 +1357,7 @@ ClearLeft(XtermWidget xw) static void ClearLine(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); unsigned len = (unsigned) MaxCols(screen); assert(screen->max_col >= 0); @@ -1340,7 +1367,7 @@ ClearLine(XtermWidget xw) void ClearScreen(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int top; if (screen->cursor_state) @@ -1369,7 +1396,7 @@ ClearScreen(XtermWidget xw) void do_erase_line(XtermWidget xw, int param, int mode) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int saved_mode = screen->protected_mode; if (saved_mode == DEC_PROTECT @@ -1401,7 +1428,7 @@ do_erase_line(XtermWidget xw, int param, int mode) void do_erase_display(XtermWidget xw, int param, int mode) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int saved_mode = screen->protected_mode; if (saved_mode == DEC_PROTECT @@ -1464,7 +1491,7 @@ do_erase_display(XtermWidget xw, int param, int mode) static void CopyWait(XtermWidget xw) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); XEvent reply; XEvent *rep = &reply; @@ -1512,7 +1539,7 @@ copy_area(XtermWidget xw, int dest_x, int dest_y) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); if (width != 0 && height != 0) { /* wait for previous CopyArea to complete unless @@ -1545,7 +1572,7 @@ horizontal_copy_area(XtermWidget xw, int nchars, int amount) /* number of characters to move right */ { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); LineData *ld; if ((ld = getLineData(screen, screen->cur_row)) != 0) { @@ -1568,7 +1595,7 @@ vertical_copy_area(XtermWidget xw, int nlines, int amount) /* number of lines to move up (neg=down) */ { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); if (nlines > 0) { int src_x = OriginX(screen); @@ -1603,7 +1630,7 @@ scrolling_copy_area(XtermWidget xw, int HandleExposure(XtermWidget xw, XEvent * event) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); XExposeEvent *reply = (XExposeEvent *) event; #ifndef NO_ACTIVE_ICON @@ -1659,7 +1686,7 @@ HandleExposure(XtermWidget xw, XEvent * event) static void set_background(XtermWidget xw, int color GCC_UNUSED) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); Pixel c = getXtermBackground(xw, xw->flags, color); TRACE(("set_background(%d) %#lx\n", color, c)); @@ -1679,7 +1706,7 @@ handle_translated_exposure(XtermWidget xw, int rect_width, int rect_height) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int toprow, leftcol, nrows, ncols; int x0, x1; int y0, y1; @@ -1745,7 +1772,7 @@ handle_translated_exposure(XtermWidget xw, void GetColors(XtermWidget xw, ScrnColors * pColors) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); int n; pColors->which = 0; @@ -1758,7 +1785,7 @@ void ChangeColors(XtermWidget xw, ScrnColors * pNew) { Bool repaint = False; - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); VTwin *win = WhichVWin(screen); TRACE(("ChangeColors\n")); @@ -1833,7 +1860,7 @@ ChangeColors(XtermWidget xw, ScrnColors * pNew) } #if OPT_TEK4014 if (TEK4014_SHOWN(xw)) { - TekScreen *tekscr = &(tekWidget->screen); + TekScreen *tekscr = TekScreenOf(tekWidget); Window tekwin = TWindow(tekscr); if (tekwin) { recolor_cursor(screen, @@ -1870,7 +1897,7 @@ ChangeColors(XtermWidget xw, ScrnColors * pNew) void xtermClear(XtermWidget xw) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); TRACE(("xtermClear\n")); XClearWindow(screen->display, VWindow(screen)); @@ -1879,7 +1906,7 @@ xtermClear(XtermWidget xw) void xtermRepaint(XtermWidget xw) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); TRACE(("xtermRepaint\n")); xtermClear(xw); @@ -2008,7 +2035,7 @@ swapVTwinGCs(XtermWidget xw, VTwin * win) void ReverseVideo(XtermWidget xw) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); ToSwap listToSwap[5]; int numToSwap = 0; @@ -2051,7 +2078,7 @@ ReverseVideo(XtermWidget xw) } #if OPT_TEK4014 if (TEK4014_SHOWN(xw)) { - TekScreen *tekscr = &(tekWidget->screen); + TekScreen *tekscr = TekScreenOf(tekWidget); Window tekwin = TWindow(tekscr); recolor_cursor(screen, tekscr->arrow, @@ -2131,7 +2158,7 @@ getXftColor(XtermWidget xw, Pixel pixel) } i = oldest; color.pixel = pixel; - XQueryColor(xw->screen.display, xw->core.colormap, &color); + XQueryColor(TScreenOf(xw)->display, xw->core.colormap, &color); cache[i].color.color.red = color.red; cache[i].color.color.green = color.green; cache[i].color.color.blue = color.blue; @@ -2154,7 +2181,7 @@ getXftColor(XtermWidget xw, Pixel pixel) ? 0 \ : (((ch) < 256) \ ? (((ch) >= 128 && (ch) < 160) \ - ? ((xw)->screen.c1_printable ? 1 : 0) \ + ? (TScreenOf(xw)->c1_printable ? 1 : 0) \ : 1) \ : my_wcwidth(ch))) #else @@ -2191,7 +2218,7 @@ xtermXftDrawString(XtermWidget xw, Cardinal len, Bool really) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int ncells = 0; if (len != 0) { @@ -2208,12 +2235,14 @@ xtermXftDrawString(XtermWidget xw, #if OPT_ISO_COLORS if ((flags & UNDERLINE) + && !screen->colorULMode && screen->italicULMode && XFT_FONT(renderWideItal[fontnum])) { wfont = XFT_FONT(renderWideItal[fontnum]); } else #endif if ((flags & BOLDATTR(screen)) + && !screen->colorBDMode && XFT_FONT(renderWideBold[fontnum])) { wfont = XFT_FONT(renderWideBold[fontnum]); } else { @@ -2342,7 +2371,7 @@ ucs_workaround(XtermWidget xw, int chrset, int on_wide) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); int fixed = False; if (screen->wide_chars && screen->utf8_mode && ch > 256) { @@ -2391,7 +2420,7 @@ xtermFillCells(XtermWidget xw, int y, Cardinal len) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); VTwin *currentWin = WhichVWin(screen); if (!(flags & NOBACKGROUND)) { @@ -2478,7 +2507,7 @@ xtermSetClipRectangles(Display * dpy, int order) { #if 0 - TScreen *screen = &(term->screen); + TScreen *screen = TScreenOf(term); Drawable draw = VWindow(screen); XSetClipMask(dpy, gc, None); @@ -2563,7 +2592,7 @@ drawClippedXftString(XtermWidget xw, font, x, y, text, len); - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); beginXftClipping(screen, x, y, ncells); xtermXftDrawString(xw, flags, @@ -2601,7 +2630,7 @@ drawXtermText(XtermWidget xw, Cardinal len, int on_wide) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); Cardinal real_length = len; Cardinal underline_len = 0; /* Intended width of the font to draw (as opposed to the actual width of @@ -2745,6 +2774,7 @@ drawXtermText(XtermWidget xw, } #if OPT_ISO_COLORS if ((flags & UNDERLINE) + && !screen->colorULMode && screen->italicULMode && XFT_FONT(renderFontItal[fontnum])) { font = XFT_FONT(renderFontItal[fontnum]); @@ -2752,6 +2782,9 @@ drawXtermText(XtermWidget xw, } else #endif if ((flags & BOLDATTR(screen)) +#if OPT_ISO_COLORS + && !screen->colorBDMode +#endif && XFT_FONT(renderFontBold[fontnum])) { font = XFT_FONT(renderFontBold[fontnum]); } else { @@ -3019,7 +3052,7 @@ drawXtermText(XtermWidget xw, if (!isMissing && ch > 255 && ucs2dec(ch) < 32 - && xw->screen.force_box_chars) { + && TScreenOf(xw)->force_box_chars) { ch = ucs2dec(ch); isMissing = True; } @@ -3288,7 +3321,7 @@ allocXtermChars(ScrnPtr * buffer, Cardinal length) void xtermSizeHints(XtermWidget xw, int scrollbarWidth) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); TRACE(("xtermSizeHints\n")); TRACE((" border %d\n", xw->core.border_width)); @@ -3321,7 +3354,7 @@ xtermSizeHints(XtermWidget xw, int scrollbarWidth) void getXtermSizeHints(XtermWidget xw) { - TScreen *screen = &xw->screen; + TScreen *screen = TScreenOf(xw); long supp; if (!XGetWMNormalHints(screen->display, XtWindow(SHELL_OF(xw)), @@ -3338,7 +3371,7 @@ getXtermSizeHints(XtermWidget xw) GC updatedXtermGC(XtermWidget xw, unsigned flags, CellColor fg_bg, Bool hilite) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); VTwin *win = WhichVWin(screen); CgsEnum cgsId = gcMAX; unsigned my_fg = extract_fg(xw, fg_bg, flags); @@ -3360,6 +3393,9 @@ updatedXtermGC(XtermWidget xw, unsigned flags, CellColor fg_bg, Bool hilite) (void) my_bg; (void) my_fg; + /* + * Discard video attributes overridden by colorXXXMode's. + */ checkVeryBoldColors(flags, my_fg); if (ReverseOrHilite(screen, flags, hilite)) { @@ -3434,7 +3470,7 @@ updatedXtermGC(XtermWidget xw, unsigned flags, CellColor fg_bg, Bool hilite) void resetXtermGC(XtermWidget xw, unsigned flags, Bool hilite) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); VTwin *win = WhichVWin(screen); CgsEnum cgsId = gcMAX; Pixel fg_pix = getXtermForeground(xw, flags, xw->cur_foreground); @@ -3474,14 +3510,9 @@ extract_fg(XtermWidget xw, CellColor color, unsigned flags) { unsigned fg = ExtractForeground(color); - if (xw->screen.colorAttrMode + if (TScreenOf(xw)->colorAttrMode || (fg == ExtractBackground(color))) { - if (xw->screen.colorULMode && (flags & UNDERLINE)) - fg = COLOR_UL; - if (xw->screen.colorBDMode && (flags & BOLD)) - fg = COLOR_BD; - if (xw->screen.colorBLMode && (flags & BLINK)) - fg = COLOR_BL; + fg = MapToColorMode(fg, TScreenOf(xw), flags); } return fg; } @@ -3495,9 +3526,9 @@ extract_bg(XtermWidget xw, CellColor color, unsigned flags) { unsigned bg = ExtractBackground(color); - if (xw->screen.colorAttrMode + if (TScreenOf(xw)->colorAttrMode || (bg == ExtractForeground(color))) { - if (xw->screen.colorRVMode && (flags & INVERSE)) + if (TScreenOf(xw)->colorRVMode && (flags & INVERSE)) bg = COLOR_RV; } return bg; @@ -3531,7 +3562,7 @@ ClearCurBackground(XtermWidget xw, unsigned height, unsigned width) { - TScreen *screen = &(xw->screen); + TScreen *screen = TScreenOf(xw); TRACE(("ClearCurBackground(%d,%d,%d,%d) %d\n", top, left, height, width, xw->cur_background)); @@ -3555,7 +3586,10 @@ getXtermCell(TScreen * screen, int row, int col) { LineData *ld = getLineData(screen, row); - return ld->charData[col]; + assert(ld && (col < (int) ld->lineSize)); + return ((ld && (col < (int) ld->lineSize)) + ? ld->charData[col] + : (unsigned) ' '); } /* @@ -3566,13 +3600,16 @@ putXtermCell(TScreen * screen, int row, int col, int ch) { LineData *ld = getLineData(screen, row); - ld->charData[col] = (CharData) ch; - if_OPT_WIDE_CHARS(screen, { - size_t off; - for_each_combData(off, ld) { - ld->combData[off][col] = 0; - } - }); + assert(ld && (col < (int) ld->lineSize)); + if (ld && (col < (int) ld->lineSize)) { + ld->charData[col] = (CharData) ch; + if_OPT_WIDE_CHARS(screen, { + size_t off; + for_each_combData(off, ld) { + ld->combData[off][col] = 0; + } + }); + } } #if OPT_WIDE_CHARS |