rem: if (tPtr->flags.ownsSelection) greyGC = WMColorGC(WMGrayColor(scr));
add: if (tPtr->flags.ownsSelection) { color = WMGrayColor(scr); greyGC = WMColorGC(color); WMReleaseColor(color); }
context: paintText(Text *tPtr){       TextBlock *tb;    WMFont *font;    GC gc, greyGC;    char *text;    int len, y, c, s, done=False, prev_y=-23, dir /* 1 = down */;    WMScreen *scr = tPtr->view->screen;    Display *dpy = tPtr->view->screen->display;    Window win = tPtr->view->window;    if (!tPtr->view->flags.realized || !tPtr->db || tPtr->flags.frozen)        return;    XFillRectangle(dpy, tPtr->db, tPtr->bgGC,        0, 0, tPtr->visible.w, tPtr->visible.h);    if (tPtr->bgPixmap) {        WMDrawPixmap(tPtr->bgPixmap, tPtr->db,             (tPtr->visible.w-tPtr->visible.x-tPtr->bgPixmap->width)/2,            (tPtr->visible.h-tPtr->visible.y-tPtr->bgPixmap->height)/2);    }    if (! (tb = tPtr->currentTextBlock)) {        if (! (tb = tPtr->firstTextBlock)) {            goto _copy_area;        }    }            if (tPtr->flags.ownsSelection)         greyGC = WMColorGC(WMGrayColor(scr));    done = False;    /* first, which direction? Don't waste time looking all over,       since the parts to be drawn will most likely be near what         was previously drawn */    if(!updateStartForCurrentTextBlock(tPtr, 0, tPtr->vpos, &dir, tb))        goto _copy_area;        while(tb) {        if (tb->graphic && tPtr->flags.monoFont)            goto _getSibling;       if(dir) {             if(tPtr->vpos <= tb->sections[tb->nsections-1]._y                 + tb->sections[tb->nsections-1].h)                 break;       } else {            if(tPtr->vpos >= tb->sections[tb->nsections-1]._y                + tb->sections[tb->nsections-1].h)                 break;       }_getSibling:       if(dir) {            if(tb->next)                tb = tb->next;           else break;       } else {           if(tb->prior)               tb = tb->prior;           else break;       }   }    /* first, place all text that can be viewed */    while (!done && tb) {/* paragraph diagnostic if(tb->blank) {tb->text[0] = 'F'; } */        if (tb->graphic) {            tb = tb->next;            continue;        }        tb->selected = False;        for(s=0; s<tb->nsections && !done; s++) {            if (tb->sections[s]._y  > tPtr->vpos + tPtr->visible.h) {                done = True;                break;            }            if ( tb->sections[s].y + tb->sections[s].h < tPtr->vpos)                 continue;             if (tPtr->flags.monoFont) {                font = tPtr->dFont;                gc = tPtr->fgGC;            } else {                font = tb->d.font;                gc = WMColorGC(tb->color);            }            if (tPtr->flags.ownsSelection) {                XRectangle rect;                if ( sectionWasSelected(tPtr, tb, &rect, s)) {                    tb->selected = True;                    XFillRectangle(dpy, tPtr->db, greyGC,                         rect.x, rect.y, rect.width, rect.height);                }            }            prev_y = tb->sections[s]._y;            len = tb->sections[s].end - tb->sections[s].begin;            text = &(tb->text[tb->sections[s].begin]);            y = tb->sections[s].y - tPtr->vpos;            WMDrawString(scr, tPtr->db, gc, font,                 tb->sections[s].x - tPtr->hpos, y, text, len);            if (!tPtr->flags.monoFont && tb->underlined) {                 XDrawLine(dpy, tPtr->db, gc,                         tb->sections[s].x - tPtr->hpos,                     y + font->y + 1,                    tb->sections[s].x + tb->sections[s].w - tPtr->hpos,                    y + font->y + 1);            }                                }        tb = (!done? tb->next : NULL);    }                /* now , show all graphic items that can be viewed */    c = WMGetArrayItemCount(tPtr->gfxItems);    if (c > 0 && !tPtr->flags.monoFont) {        int j, h;        for(j=0; j<c; j++) {            tb = (TextBlock *) WMGetFromArray(tPtr->gfxItems, j);                        /* if it's not viewable, and mapped, unmap it */            if (tb->sections[0]._y + tb->sections[0].h <= tPtr->vpos                 || tb->sections[0]._y >= tPtr->vpos + tPtr->visible.h ) {                        if(tb->object) {                    if ((W_VIEW(tb->d.widget))->flags.mapped) {                        WMUnmapWidget(tb->d.widget);                    }                }            } else {            /* if it's viewable, and not mapped, map it */                if(tb->object) {                     W_View *view = W_VIEW(tb->d.widget);                    if (!view->flags.realized)                        WMRealizeWidget(tb->d.widget);                    if(!view->flags.mapped) {                         XMapWindow(view->screen->display, view->window);                        XFlush(view->screen->display);                        view->flags.mapped = 1;                    }                }                                if (tPtr->flags.ownsSelection) {                    XRectangle rect;                    if ( sectionWasSelected(tPtr, tb, &rect, 0)) {                        tb->selected = True;                        XFillRectangle(dpy, tPtr->db, greyGC,                            rect.x, rect.y, rect.width, rect.height);                    }                }                if(tb->object) {                    WMMoveWidget(tb->d.widget,                         tb->sections[0].x + tPtr->visible.x - tPtr->hpos,                         tb->sections[0].y + tPtr->visible.y - tPtr->vpos);                    h = WMWidgetHeight(tb->d.widget) + 1;                } else {                    WMDrawPixmap(tb->d.pixmap, tPtr->db,                         tb->sections[0].x - tPtr->hpos,                         tb->sections[0].y - tPtr->vpos);                    h = tb->d.pixmap->height + 1;                }                if (!tPtr->flags.monoFont && tb->underlined) {                     XDrawLine(dpy, tPtr->db, WMColorGC(tb->color),                     tb->sections[0].x - tPtr->hpos,                    tb->sections[0].y + h - tPtr->vpos,                    tb->sections[0].x + tb->sections[0].w - tPtr->hpos,                    tb->sections[0].y + h - tPtr->vpos);      } } } } _copy_area:    if (tPtr->flags.editable && tPtr->flags.cursorShown         && tPtr->cursor.x != -23 && tPtr->flags.focused) {         int y = tPtr->cursor.y - tPtr->vpos;        XDrawLine(dpy, tPtr->db, tPtr->fgGC,            tPtr->cursor.x, y,            tPtr->cursor.x, y + tPtr->cursor.h);    }    XCopyArea(dpy, tPtr->db, win, tPtr->bgGC, 0, 0,        tPtr->visible.w, tPtr->visible.h,         tPtr->visible.x, tPtr->visible.y);    W_DrawRelief(scr, win, 0, 0,        tPtr->view->size.width, tPtr->view->size.height,         tPtr->flags.relief);            if (tPtr->ruler && tPtr->flags.rulerShown)        XDrawLine(dpy, win, tPtr->fgGC,             2, 42, tPtr->view->size.width-4, 42);}