Exemple #1
0
void
_DtTermPrimRefreshText(Widget w, short startColumn, short startRow,
	short endColumn, short endRow)
{
    DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
    struct termData *tpd = tw->term.tpd;
    TermBuffer tBuffer = tpd->termBuffer;
    int lineWidth;
    unsigned char *linePtr;
    TermFont termFont;
    int currentColorPair = 0;
    int currentVideo = 0;
    short chunkStartColumn;
    short chunkWidth;
    enhValues enhancements;
    int i;
    int lineNum;
    unsigned long valueMask;
    GC gc;
    XGCValues values;
    TermEnhInfoRec enhInfo;
    Boolean checkSelection = False;
    int selectionEnd;
    Pixel tmpPixel;
    XmTextPosition  begin, end;
    
    DebugF('t', 0, fprintf(stderr, ">>_DtTermPrimRefreshText() starting\n"));
    DebugF('t', 0, fprintf(stderr,
	    ">>_DtTermPrimRefreshText() startCol=%hd  startRow=%hd  endCol=%hd  endRow=%hd\n",
	    startColumn, startRow, endColumn, endRow));

    if (tpd->mbCurMax > 1)
    {
        _DtTermPrimRefreshTextWc(w, startColumn, startRow, endColumn, endRow);
        return;
    }

    /* clip start/end x/y... */
    if (startColumn <= 0)
	startColumn = 0;
    if (startRow <= 0)
	startRow = 0;
    if (endColumn >= tw->term.columns)
	endColumn = tw->term.columns - 1;
    if (endRow >= tw->term.rows)
	endRow = tw->term.rows - 1;

    /*
    ** don't display if we are in jump scroll and in the process
    ** of scrolling and inside the scroll region...
    */
    if (tw->term.jumpScroll && tpd->scroll.jump.scrolled) {
	/* set all the scrollRefreshRows flags... */
	for (; startRow <= endRow; startRow++) {
	    tpd->scrollRefreshRows[startRow] = True;
	}

	DebugF('t', 0,
		fprintf(stderr,
		">>_DtTermPrimRefreshText() jump scroll in progress, no render\n"));
        return;
    }

    if (!tpd->renderGC.gc) {
	/* get a drawImageString GC... */
	int i;
	XGCValues values;

	/***********************************************************
	 * renderGC...
	 */
	/* set the GC fg and bg... */
	values.foreground = tw->term.reverseVideo ?
		tw->core.background_pixel : tw->primitive.foreground;
	values.background = tw->term.reverseVideo ?
		tw->primitive.foreground : tw->core.background_pixel;

	tpd->renderGC.gc = XCreateGC(XtDisplay(w), XtWindow(w),
		GCForeground | GCBackground, &values);

	/* set the GC cache values... */
	tpd->renderGC.foreground = values.foreground;
	tpd->renderGC.background = values.background;
	tpd->renderGC.fid = (Font) 0;

	/***********************************************************
	 * renderReverseGC...
	 */
	values.foreground = tw->term.reverseVideo ?
		tw->primitive.foreground : tw->core.background_pixel;
	values.background = tw->term.reverseVideo ?
		tw->core.background_pixel : tw->primitive.foreground;

	tpd->renderReverseGC.gc = XCreateGC(XtDisplay(w), XtWindow(w),
		GCForeground | GCBackground, &values);

	/* set the GC cache values... */
	tpd->renderReverseGC.foreground = values.foreground;
	tpd->renderReverseGC.background = values.background;
	tpd->renderReverseGC.fid = (Font) 0;

	/***********************************************************
	 * clearGC...
	 */
	values.foreground = tw->term.reverseVideo ?
		tw->primitive.foreground : tw->core.background_pixel;
	values.background = tw->term.reverseVideo ?
		tw->core.background_pixel : tw->primitive.foreground;

	tpd->clearGC.gc = XCreateGC(XtDisplay(w), XtWindow(w),
		GCForeground | GCBackground, &values);

	/* set the GC cache values... */
	tpd->clearGC.foreground = values.foreground;
	tpd->clearGC.background = values.background;
	tpd->clearGC.fid = (Font) 0;
    }

#ifdef SUN_MOTIF_PERF
    /* use the clear GC... */
    gc = tpd->clearGC.gc;

    valueMask = (unsigned long) 0;
    if (tpd->clearGC.foreground !=
	    tw->term.reverseVideo ?
	    tw->core.background_pixel : tw->primitive.foreground) {
        values.foreground =
	        tw->term.reverseVideo ?
	        tw->primitive.foreground :
	        tw->core.background_pixel;
        tpd->clearGC.foreground = values.foreground;
        valueMask |= GCForeground;
    }
    if (tpd->clearGC.background !=
	    tw->term.reverseVideo ?
	    tw->primitive.foreground :
	    tw->core.background_pixel) {
        values.background =
	        tw->term.reverseVideo ?
	        tw->core.background_pixel :
	        tw->primitive.foreground;
        tpd->clearGC.background = values.background;
        valueMask |= GCBackground;
    }
    if (valueMask) {
        (void) XChangeGC(XtDisplay(w), tpd->clearGC.gc,
	        valueMask, &values);
    }
    (void) XFillRectangle(XtDisplay(w),         /* Display		*/
		    XtWindow(w),		/* Drawable		*/
		    gc,				/* GC			*/
		    startColumn * tpd->cellWidth + tpd->offsetX,
						/* x			*/
		    startRow * tpd->cellHeight + tpd->offsetY,
						/* y			*/
		    (endColumn - startColumn + 1) * tpd->cellWidth,
						/* width		*/
		    (endRow - startRow + 1) * tpd->cellHeight);		
						/* height		*/
#endif /* SUN_MOTIF_PERF */

    for (; startRow <= endRow; startRow++) {
	/* if we are refreshing a full line, then we can clear the
	 * scrollRefreshRows flag for this line...
	 */
	if ((startColumn == 0) && (endColumn >= tw->term.columns - 1)) {
	    tpd->scrollRefreshRows[startRow] = False;
	}

	lineNum = startRow + tpd->topRow;
	if (!tw->term.jumpScroll && tpd->scroll.nojump.pendingScroll) {
            if (lineNum != tpd->scrollLockBottomRow)
            {
                lineNum -= tpd->scroll.nojump.pendingScrollLines;
            }
    	}

	/* are we in the selected area?... */
        if (tpd->useHistoryBuffer)
        {
            if (_DtTermPrimSelectGetSelection(w, &begin, &end) &&
                (begin < end) &&
                (lineNum >= (begin / (tpd->selectInfo->columns + 1)) - 
                            tpd->lastUsedHistoryRow) &&
                (lineNum <= (end   / (tpd->selectInfo->columns + 1)) - 
                            tpd->lastUsedHistoryRow)) {
                checkSelection = True;
            } else {
                checkSelection = False;
            }
        }
        else
        {
            if (_DtTermPrimSelectGetSelection(w, &begin, &end) &&
                (begin < end) &&
                (lineNum >= (begin / (tpd->selectInfo->columns + 1))) &&
                (lineNum <= (end   / (tpd->selectInfo->columns + 1))))  {
                checkSelection = True;
            } else {
                checkSelection = False;
            }
        }

	chunkStartColumn = startColumn;
	if (startColumn > endColumn) {
	    /* nothing to render on this line... */
	    continue;
	}

	if (lineNum >= tpd->lastUsedRow) {
	    /* we are pointing to empty screen space below the last used
	     * line of the display...
	     */
	    lineWidth = 0;
	    linePtr = NULL;
	} else if (lineNum < 0) {
	    if ((tpd->useHistoryBuffer) &&
		    (-lineNum <= tpd->lastUsedHistoryRow)) {
		/* get a line out of the history buffer... */
		lineWidth = MAX(0, MIN(endColumn - startColumn + 1,
		    _DtTermPrimBufferGetLineWidth(tpd->historyBuffer,
		    tpd->lastUsedHistoryRow + lineNum) - startColumn));
		linePtr =
		    _DtTermPrimBufferGetCharacterPointer(tpd->historyBuffer,
		    tpd->lastUsedHistoryRow + lineNum, startColumn);
	    } else {
		/* we are above the history buffer.  Should not happen, but...
		 */
		lineWidth = 0;
		linePtr = NULL;
	    }
	} else {
	    /* get the line width and a pointer to the data... */
	    lineWidth = MAX(0, MIN(endColumn - startColumn + 1,
		    _DtTermPrimBufferGetLineWidth(tBuffer, lineNum) -
		    startColumn));
	    linePtr = _DtTermPrimBufferGetCharacterPointer(tBuffer, lineNum,
		    startColumn);
	}

	while (lineWidth > 0) {
	    /* get the enhancement values for the first chunk of the
	     * string...
	     */
	    if (lineNum >= 0) {
		(void) _DtTermPrimBufferGetEnhancement(tBuffer,
						/* TermBuffer		*/
			lineNum,		/* row			*/
			chunkStartColumn,	/* col			*/
			&enhancements,		/* enhancements		*/
			&chunkWidth,		/* width        	*/
			countAll);		/* countWhich		*/
	    } else {
		/* get it from the history buffer... */
		(void) _DtTermPrimBufferGetEnhancement(tpd->historyBuffer,
						/* TermBuffer		*/
			tpd->lastUsedHistoryRow + lineNum,
						/* row			*/
			chunkStartColumn,	/* col			*/
			&enhancements,		/* enhancements		*/
			&chunkWidth,		/* width		*/
			countAll);		/* countWhich		*/
	    }

	    /* clip chunkWidth... */
	    if (chunkWidth > lineWidth)
		chunkWidth = lineWidth;

	    /* set reasonable defaults for our render info... */
	    enhInfo.fg = tw->primitive.foreground;
	    enhInfo.bg = tw->core.background_pixel;
	    enhInfo.font = tpd->defaultTermFont;
	    enhInfo.flags = (unsigned long) 0;

	    /* set our font and color from the enhancements... */
	    if (ENH_PROC(tBuffer)) {
                (void) (*(ENH_PROC(tBuffer)))(w, enhancements, &enhInfo);
	    }

	    /* if we are in reverse video mode... */
	    if (tw->term.reverseVideo) {
		/* flip fg and bg... */
		tmpPixel = enhInfo.fg;
		enhInfo.fg = enhInfo.bg;
		enhInfo.bg = tmpPixel;
	    }

	    /* are we in the selection area?... */
	    if (checkSelection && 
                _DtTermPrimSelectIsInSelection(w, lineNum, chunkStartColumn,
		                         chunkWidth, &chunkWidth)) {

		/* flip fg and bg... */
		tmpPixel = enhInfo.fg;
		enhInfo.fg = enhInfo.bg;
		enhInfo.bg = tmpPixel;
	    }
			
	    /* if secure, we will use a XFillRectangle, and we need
	     * foreground set to the background...
	     */

	    if (TermIS_SECURE(enhInfo.flags)) {
		/* render secure video locally...
		 */
		/* set the renderReverseGC... */
		valueMask = (unsigned long) 0;
		if (tpd->renderReverseGC.foreground != enhInfo.bg) {
		    tpd->renderReverseGC.foreground = enhInfo.bg;
		    values.foreground = enhInfo.bg;
		    valueMask |= GCForeground;
		}
		if (valueMask) {
		    (void) XChangeGC(XtDisplay(w), tpd->renderReverseGC.gc,
			    valueMask, &values);
		}
		(void) XFillRectangle(XtDisplay(w),
			XtWindow(w),
			tpd->renderReverseGC.gc,
			chunkStartColumn * tpd->cellWidth + tpd->offsetX,
			startRow * tpd->cellHeight + tpd->offsetY,
			tpd->cellWidth *  chunkWidth,
			tpd->cellHeight);

		/* underline as well... */
		if (TermIS_UNDERLINE(enhInfo.flags)) {
		    valueMask = (unsigned long) 0;
		    if (tpd->renderGC.foreground != enhInfo.fg) {
			tpd->renderGC.foreground = enhInfo.fg;
			values.foreground = enhInfo.fg;
			valueMask |= GCForeground;
		    }
		    if (valueMask) {
			(void) XChangeGC(XtDisplay(w), tpd->renderGC.gc,
				valueMask, &values);
		    }
		    (void) XDrawLine(XtDisplay(w),
						/* Display		*/
			    XtWindow(w),	/* Drawable		*/
			    tpd->renderGC.gc,	/* GC			*/
			    chunkStartColumn * tpd->cellWidth + tpd->offsetX,
						/* X1			*/
			    startRow * tpd->cellHeight + tpd->offsetY +
			    tpd->cellHeight - 1,
						/* Y1			*/
			    (chunkStartColumn + chunkWidth) * tpd->cellWidth +
			    tpd->offsetX,	/* X2			*/
			    startRow * tpd->cellHeight + tpd->offsetY +
			    tpd->cellHeight - 1);
						/* Y2			*/
		}
	    } else {
		(void) _DtTermPrimRenderText(
		    w,				/* Widget		*/
		    enhInfo.font,		/* TermFont		*/
		    enhInfo.fg,			/* fg Pixel		*/
		    enhInfo.bg,			/* bg Pixel		*/
		    enhInfo.flags,		/* flags		*/
		    chunkStartColumn * tpd->cellWidth + tpd->offsetX,
						/* x			*/
		    startRow * tpd->cellHeight + tpd->offsetY,
						/* y			*/
		    linePtr,			/* string		*/
		    chunkWidth);		/* width		*/
	    }
	    chunkStartColumn += chunkWidth;
	    lineWidth -= chunkWidth;
	    linePtr += chunkWidth;
	}

	/* clear any extra space in the line.  chunkStartColumn now points to
	 * the end of the line, and lineWidth == 0...
	 */
	while (endColumn - chunkStartColumn >= 0) {
	    chunkWidth = endColumn - chunkStartColumn + 1;
	    if (checkSelection && 
                _DtTermPrimSelectIsInSelection(w, lineNum, chunkStartColumn,
		                         chunkWidth, &chunkWidth)) {
		/* use the render gc set to the fg color... */
		gc = tpd->renderReverseGC.gc;

		valueMask = (unsigned long) 0;
		if (tpd->renderReverseGC.foreground !=
			tw->term.reverseVideo ?
			tw->core.background_pixel : tw->primitive.foreground) {
		    values.foreground =
			    tw->term.reverseVideo ?
			    tw->core.background_pixel :
			    tw->primitive.foreground;
		    tpd->renderReverseGC.foreground = values.foreground;
		    valueMask |= GCForeground;
		}
		if (valueMask) {
		    (void) XChangeGC(XtDisplay(w), tpd->renderReverseGC.gc,
			    valueMask, &values);
		}
#ifndef SUN_MOTIF_PERF
	    } else {
		/* use the clear GC... */
		gc = tpd->clearGC.gc;

		valueMask = (unsigned long) 0;
		if (tpd->clearGC.foreground !=
			tw->term.reverseVideo ?
			tw->core.background_pixel : tw->primitive.foreground) {
		    values.foreground =
			    tw->term.reverseVideo ?
			    tw->primitive.foreground :
			    tw->core.background_pixel;
		    tpd->clearGC.foreground = values.foreground;
		    valueMask |= GCForeground;
		}
		if (tpd->clearGC.background !=
			tw->term.reverseVideo ?
			tw->primitive.foreground :
			tw->core.background_pixel) {
		    values.background =
			    tw->term.reverseVideo ?
			    tw->core.background_pixel :
			    tw->primitive.foreground;
		    tpd->clearGC.background = values.background;
		    valueMask |= GCBackground;
		}
		if (valueMask) {
		    (void) XChangeGC(XtDisplay(w), tpd->clearGC.gc,
			    valueMask, &values);
		}
	    }
#endif /* not SUN_MOTIF_PERF */

	    if (isDebugFSet('t', 1)) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
		/* Fill in the clear area so we can see what is going to
		 * be displayed...
		 */
		(void) XFillRectangle(XtDisplay(w),
			XtWindow(w),
			tpd->renderGC.gc,
			chunkStartColumn * tpd->cellWidth + tpd->offsetX,
			startRow * tpd->cellHeight + tpd->offsetY,
			chunkWidth * tpd->cellWidth,
			tpd->cellHeight);
		(void) XSync(XtDisplay(w), False);
		(void) shortSleep(100000);
	    }
	    (void) XFillRectangle(XtDisplay(w),
						/* Display		*/
		    XtWindow(w),		/* Drawable		*/
		    gc,				/* GC			*/
		    chunkStartColumn * tpd->cellWidth + tpd->offsetX,
						/* x			*/
		    startRow * tpd->cellHeight + tpd->offsetY,
						/* y			*/
		    chunkWidth * tpd->cellWidth,
						/* width		*/
		    tpd->cellHeight);		/* height		*/
#ifdef SUN_MOTIF_PERF
	    }
#endif /* SUN_MOTIF_PERF */
	    chunkStartColumn += chunkWidth;
	}
    }
Exemple #2
0
void
_DtTermPrimCursorOn(Widget w)
{
    DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
    struct termData *tpd = tw->term.tpd;
    XPoint point;
    static Boolean alreadyActive = False;
    short chunkWidth;
    enhValues enhancements;
    unsigned long valueMask = 0L;
    XGCValues values;
    TermEnhInfoRec enhInfo;
    int cursorRow;

    /* if we are being called cyclically (by _DtTermPrimScrollWait ->
     * _DtTermPrimExposeText -> _DtTermPrimCursorOn), just return...
     */
    _DtTermProcessLock();
    if (alreadyActive) {
	/*DKS!!! vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
	fprintf(stderr, "tell Dave _DtTermPrimCursorOn has alreadyActive == True\n");
	/*DKS!!! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
	_DtTermProcessUnlock();
	return;
    }

    /* this is where we will actually perform a pending scroll and
     * text refresh...
     */
    if (tw->term.jumpScroll && tpd->scroll.jump.scrolled) {
	/* make sure we don't end up in an infinite loop... */
	alreadyActive = True;
	Debug('t', fprintf(stderr,
		">>_DtTermPrimCursorOn() calling _DtTermPrimScrollWait()\n"));
	(void) _DtTermPrimScrollWait(w);
	alreadyActive = False;
    }
    _DtTermProcessUnlock();

#ifdef	DISOWN_SELECTION_ON_CURSOR_ON_OR_OFF 
    if ( _DtTermPrimSelectIsAboveSelection(w,tpd->cursorRow,
	    tpd->cursorColumn)) {
        _DtTermPrimSelectDisown(w) ;
    }
#endif	/* DISOWN_SELECTION_ON_CURSOR_ON_OR_OFF */

    /* update the input method spot location...
     */
    if ((tpd->IMCursorColumn != tpd->cursorColumn) ||
	    (tpd->IMCursorRow != tpd->cursorRow)) {
	tpd->IMCursorColumn = tpd->cursorColumn;
	tpd->IMCursorRow = tpd->cursorRow;
	point.x = tpd->cursorColumn * tpd->cellWidth + tpd->offsetX;
	point.y = tpd->cursorRow * tpd->cellHeight + tpd->offsetY + tpd->ascent;
	DebugF('F', 1, fprintf(stderr,
		"%s() %s calling %s\n",
		"_DtTermPrimCursorOn",
		"dont care",
		"XmImVaSetValues()"));
	(void) XmImVaSetValues(w,
		XmNspotLocation, &point,
		NULL);
    }
#ifdef	NOT_NEEDED
    if (!tw->term.hasFocus) {
	(void) fprintf(stderr,
		"%s() %s calling %s\n",
		"_DtTermPrimCursorOn",
		"!hasFocus",
		"XmImUnsetFocus()");
	(void) XmImUnsetFocus(w);
    }
#endif	/* NOT_NEEDED */

    /* update the scrollbar and position indicator... */
    (void) _DtTermPrimCursorUpdate(w);

    /* if the cursor is not visible, we are done now... */
    if (!tpd->cursorVisible) {
	return;
    }

    /* set up the GC... */
    if (!tpd->cursorGC.gc) {
	tpd->cursorGC.foreground =
		tw->primitive.foreground ^ tw->core.background_pixel;
	values.foreground = tpd->cursorGC.foreground;
	values.function = GXxor;
	tpd->cursorGC.gc = XCreateGC(XtDisplay(w), XtWindow(w),
		GCForeground | GCFunction, &values);
    }

    /* update the cursor's foreground and background...
     */
    /* if we are past the lastUsedRow, or the column > width, use color
     * pair 0...
     */

    /* reasonable defaults... */
    enhInfo.fg = tw->primitive.foreground;
    enhInfo.bg = tw->core.background_pixel;
    if (!((tpd->lastUsedRow <= tpd->topRow + tpd->cursorRow) ||
	    (_DtTermPrimBufferGetLineWidth(tpd->termBuffer,
		    tpd->topRow + tpd->cursorRow) <= MIN(tpd->cursorColumn,
		    tw->term.columns - 1)))) {
	/* get the current enhancement to determine the color pair to use...
	 */
	(void) _DtTermPrimBufferGetEnhancement(tpd->termBuffer,
						/* TermBuffer		*/
		    tpd->topRow + tpd->cursorRow,
						/* row			*/
		    MIN(tpd->cursorColumn, tw->term.columns - 1),
						/* col			*/
		    &enhancements,		/* enhancements		*/
		    &chunkWidth,		/* width		*/
		    countNew);			/* countWhich		*/
	/* set our font and color from the enhancements... */
	if (ENH_PROC(tpd->termBuffer)) {
	    (void) (*(ENH_PROC(tpd->termBuffer)))(w, enhancements, &enhInfo);
	}
    }

    /* set the GC... */
    if (tpd->cursorGC.foreground != enhInfo.fg ^ enhInfo.bg) {
	tpd->cursorGC.foreground = enhInfo.fg ^ enhInfo.bg;
	values.foreground = enhInfo.fg ^ enhInfo.bg;
	valueMask |= GCForeground;
    }
    if (valueMask) {
	(void) XChangeGC(XtDisplay(w), tpd->cursorGC.gc, valueMask, &values);
    }

    if (tpd->cursorState != CURSORoff) {
	return;
    }

    tpd->cursorState = CURSORon;
    (void) cursorToggle(w);

    if (tw->term.hasFocus) {
	/* add a timeout... */
	if (tw->term.blinkRate > 0) {
	    tpd->cursorTimeoutId =
		    XtAppAddTimeOut(XtWidgetToApplicationContext(w),
		    tw->term.blinkRate, (XtTimerCallbackProc) timeoutCallback,
		    (XtPointer) w);
	}
    }

}