示例#1
0
/* Updates cursor position */
static void
text_update_text(TW *tw, int count)
{
HDC hdc;
int xpos, ypos;
        xpos = tw->CursorPos.x*tw->CharSize.x - tw->ScrollPos.x;
        ypos = tw->CursorPos.y*tw->CharSize.y - tw->ScrollPos.y;
        hdc = GetDC(tw->hwnd);
        SelectFont(hdc, tw->hfont);
#ifdef WINDOWS_NO_UNICODE
        TextOut(hdc,xpos,ypos,
                (LPSTR)(tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x
                + tw->CursorPos.x), count);
#else
        TextOutW(hdc,xpos,ypos,
                 (LPCWSTR)(tw->ScreenBuffer +
                           tw->CursorPos.y*tw->ScreenSize.x +
                           tw->CursorPos.x),
                 count);
#endif
        (void)ReleaseDC(tw->hwnd,hdc);
        tw->CursorPos.x += count;
        if (tw->CursorPos.x >= tw->ScreenSize.x)
                text_new_line(tw);
}
示例#2
0
void
text_write_buf(TW *tw, const char *str, int cnt)
{
#ifdef WINDOWS_NO_UNICODE
BYTE *p;
#else
wchar_t *p;
#endif
int count, limit;
int n;
    if (tw->quitnow)
        return;		/* don't write error message as we shut down */
    while (cnt>0) {
        p = tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x;
        limit = tw->ScreenSize.x - tw->CursorPos.x;
        for (count=0; (count < limit) && (cnt>0) &&
            (
#ifdef WINDOWS_NO_UNICODE
             isprint((unsigned char)(*str))
#else
             ((*str >= 32) && (*str <= 0x7F))
#endif
             || *str=='\t'); count++) {
            if (*str=='\t') {
                for (n = 8 - ((tw->CursorPos.x+count) % 8); (count < limit) & (n>0); n--, count++ )
                    *p++ = ' ';
                str++;
                count--;
            }
            else {
                *p++ = *str++;
            }
            cnt--;
        }
        if (count>0) {
            text_update_text(tw, count);
        }
        if (cnt > 0) {
            if (*str=='\n') {
                text_new_line(tw);
                str++;
                cnt--;
            }
            else if (!
#ifdef WINDOWS_NO_UNICODE
                isprint((unsigned char)(*str))
#else
                ((*str >= 32) && (*str <= 0x7f))
#endif
                && *str!='\t') {
                text_putch(tw, *(const unsigned char *)str++);
                cnt--;
            }
        }
    }
}
示例#3
0
int
text_putch(TW *tw, int ch)
{
int pos;
int n;
    if (tw->quitnow)
	return ch;	/* don't write error message as we shut down */
    switch(ch) {
	case '\r':
		tw->CursorPos.x = 0;
		if (tw->CursorFlag)
		    text_to_cursor(tw);
		break;
	case '\n':
		text_new_line(tw);
		break;
	case 7:
		MessageBeep(-1);
		if (tw->CursorFlag)
		    text_to_cursor(tw);
		break;
	case '\t':
		{
		    for (n = 8 - (tw->CursorPos.x % 8); n>0; n-- )
			    text_putch(tw, ' ');
		}
		break;
	case 0x08:
	case 0x7f:
		tw->CursorPos.x--;
		if (tw->CursorPos.x < 0) {
		    tw->CursorPos.x = tw->ScreenSize.x - 1;
		    tw->CursorPos.y--;
		}
		if (tw->CursorPos.y < 0)
		    tw->CursorPos.y = 0;
		break;
	default:
		pos = tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x;
		tw->ScreenBuffer[pos] = ch;
		text_update_text(tw, 1);
    }
    return ch;
}
示例#4
0
void 
text_write_buf(TW *tw, const char *str, int cnt)
{
BYTE *p;
int count, limit;
int n;
    if (tw->quitnow)
	return;		/* don't write error message as we shut down */
    while (cnt>0) {
	p = tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x;
	limit = tw->ScreenSize.x - tw->CursorPos.x;
	for (count=0; (count < limit) && (cnt>0) && 
	    (isprint((unsigned char)(*str)) || *str=='\t'); count++) {
	    if (*str=='\t') {
		for (n = 8 - ((tw->CursorPos.x+count) % 8); (count < limit) & (n>0); n--, count++ )
		    *p++ = ' ';
		str++;
		count--;
   	    }
	    else {
		*p++ = *str++;
	    }
	    cnt--;
	}
	if (count>0) {
	    text_update_text(tw, count);
	}
	if (cnt > 0) {
	    if (*str=='\n') {
		text_new_line(tw);
		str++;
		cnt--;
	    }
	    else if (!isprint((unsigned char)(*str)) && *str!='\t') {
		text_putch(tw, *str++);
		cnt--;
	    }
	}
    }
}
示例#5
0
int
text_putch(TW *tw, int ch)
{
int pos;
int n;
#ifndef WINDOWS_NO_UNICODE
int shift = tw->utf8shift;
    tw->utf8shift=0;
#endif
    if (tw->quitnow)
        return ch;	/* don't write error message as we shut down */
    switch(ch) {
        case '\r':
                tw->CursorPos.x = 0;
                if (tw->CursorFlag)
                    text_to_cursor(tw);
                break;
        case '\n':
                text_new_line(tw);
                break;
        case 7:
                MessageBeep(-1);
                if (tw->CursorFlag)
                    text_to_cursor(tw);
                break;
        case '\t':
                {
                    for (n = 8 - (tw->CursorPos.x % 8); n>0; n-- )
                            text_putch(tw, ' ');
                }
                break;
        case 0x08:
        case 0x7f:
                tw->CursorPos.x--;
                if (tw->CursorPos.x < 0) {
                    tw->CursorPos.x = tw->ScreenSize.x - 1;
                    tw->CursorPos.y--;
                }
                if (tw->CursorPos.y < 0)
                    tw->CursorPos.y = 0;
                break;
        default:
                pos = tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x;
#ifndef WINDOWS_NO_UNICODE
                /* Are we continuing a unicode char? */
                if ((ch & 0xC0) == 0x80) {
                    tw->ScreenBuffer[pos] |= (ch & 0x3F)<<shift;
                    if (shift > 0)
                        tw->utf8shift = shift-6;
                    else
                        text_update_text(tw, 1); /* Only update when complete */
                } else if (ch >= 0xe0) { /* 2 more to come */
                    tw->ScreenBuffer[pos] = (ch & 0x0f)<<12;
                    tw->utf8shift = 6;
                } else if (ch >= 0xC0) { /* 1 more to come */
                    tw->ScreenBuffer[pos] = (ch & 0x01f)<<6;
                    tw->utf8shift = 0;
                }
                else
#endif
                {
                    tw->ScreenBuffer[pos] = ch;
                    text_update_text(tw, 1);
                }
    }
    return ch;
}