Example #1
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;
}
Example #2
0
static void
text_new_line(TW *tw)
{
	tw->CursorPos.x = 0;
	tw->CursorPos.y++;
	if (tw->CursorPos.y >= tw->ScreenSize.y) {
	    int i =  tw->ScreenSize.x * (tw->ScreenSize.y - 1);
		memmove(tw->ScreenBuffer, tw->ScreenBuffer+tw->ScreenSize.x, i);
		memset(tw->ScreenBuffer + i, ' ', tw->ScreenSize.x);
		tw->CursorPos.y--;
		ScrollWindow(tw->hwnd,0,-tw->CharSize.y,NULL,NULL);
		UpdateWindow(tw->hwnd);
	}
	if (tw->CursorFlag)
		text_to_cursor(tw);

/*	TextMessage(); */
}
Example #3
0
/* need to add extended codes */
int
text_getch(TW *tw)
{
    MSG msg;
    int ch;
    text_to_cursor(tw);
    tw->bGetCh = TRUE;
    if (tw->bFocus) {
	SetCaretPos(tw->CursorPos.x*tw->CharSize.x - tw->ScrollPos.x,
	    tw->CursorPos.y*tw->CharSize.y + tw->CharAscent 
	    - tw->CaretHeight - tw->ScrollPos.y);
	ShowCaret(tw->hwnd);
    }

    while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_NOREMOVE)) {
	if (GetMessage(&msg, (HWND)NULL, 0, 0)) {
	    TranslateMessage(&msg);
	    DispatchMessage(&msg);
	}
    }
    if (tw->quitnow)
       return EOF;	/* window closed */

    while (!text_kbhit(tw)) {
        if (!tw->quitnow) {
	    if (GetMessage(&msg, (HWND)NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	    }
	}
	else
	   return EOF;	/* window closed */
    }

    ch = *tw->KeyBufOut++;
    if (ch=='\r')
	ch = '\n';
    if (tw->KeyBufOut - tw->KeyBuf >= tw->KeyBufSize)
	tw->KeyBufOut = tw->KeyBuf;		/* wrap around */
    if (tw->bFocus)
	HideCaret(tw->hwnd);
    tw->bGetCh = FALSE;
    return ch;
}
Example #4
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;
}