コード例 #1
0
ファイル: input.c プロジェクト: LeonardoPhysh/YB_IV
/*
 * ui_pinyin - show pinyin spell and corresponding chinese 
 *  @cont : buffer 
 *  @return : one choose chinese 
 */
static int ui_pinyin(char *cont)
{
    int keycode, ime_state, count;
    int pos, page;
    char *chn = NULL;
    char spell[6] = {0};
    char chn_content[CONTENT_SIZE];
    char *ime_pad[] = {
        "        ",  
        "大写数字",
        "小写数字",
        "拼音输入",
        "符号输入"
    };

    ime_state = get_ime_status();
    if (ime_state == INPUT_FUNC) {
        set_ime_status(INPUT_PINYIN);
        ime_state = INPUT_PINYIN;
    }

    show_ime_pad(4, 1, ime_pad[ime_state]);
    clear_cache();

    pos = page = count = 0;
    while (1) {
        keycode = get_keycode();
        switch (keycode) {
            case SHIFT:
                if (ime_state == INPUT_SIGN) 
                    ime_state = INPUT_UP_CASE;
                else 
                    ime_state ++;

                count = 0;
                chn = NULL;    
                memset(spell, 0, 6); 
                memset(chn_content, 0, CONTENT_SIZE);

                /* somewhere blink cursor, concel it */ 
                if (pos > 0) {
                    //set_cursor_off(4, 5 + (pos - 1) * 2);
                    pos = page = 0;
                }
                set_ime_status(ime_state);
                show_str(4, 1, ime_pad[ime_state]);

                break;

            case ESC:
                if (pos > 0) {
                    //set_cursor_off(4, 5 + (pos - 1) * 2);
                    pos = page = 0;
                }

                show_str(4, 1, CHAR_BLANK); 
                return -EUI_ESC;

                break;

            case BACK:
                if (ime_state != INPUT_PINYIN)
                    return -EUI_BACK;

                if (count > 0) {
                    if (pos > 0) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos = page = 0;
                    }

                    spell[--count] = '\0';
                    if (count == 0) {
                        show_str(4, 1, ime_pad[ime_state]);
                        chn = NULL;
                        memset(chn_content, 0, CONTENT_SIZE);
                    } else {
                        show_ime_pad(4, 1, spell);
                        chn = py_ime(spell);
                        if (chn != NULL) {
                            get_chn_pad(chn, chn_content);
                            show_chn_pad(4, 4, chn_content);
                        } else 
                            show_chn_pad(4, 4, NULL);
                    }
                } else {
                    return -EUI_BACK;
                }

                break;

            case ENTER:
                if (count > 0) {
                    if (chn != NULL && pos > 0) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos = page = 0;
                        show_str(4, 1, ime_pad[ime_state]);

                        memcpy(cont, chn + (pos - 1) * 2, 2);
                        goto handled;
                    }
                } else 
                    return ENTER;

                break;
#if 0
            // cursor function error, remove it    
            case LEFT:
                if (chn != NULL) {
                    if (pos > 1) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos --;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                    } 
                }

                break;

            case RIGHT:
                if (chn != NULL) {
                    if (pos < 4 && strlen(chn) / 2 > pos){
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        pos ++;  
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                    }
                }
                break;
#endif 
            case UP:
                if (chn != NULL) {
                    if (page > 0) {
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        chn -= 8;
                        get_chn_pad(chn, chn_content);
                        show_chn_pad(4, 4, chn_content);

                        pos = 1;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                        page --;
                    }
                }
                break;

            case DOWN:
                if (chn != NULL) {
                    if (strlen(chn) > 8) {
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        chn += 8;
                        get_chn_pad(chn, chn_content);
                        show_chn_pad(4, 4, chn_content);

                        pos = 1;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                        page ++;
                    }
                }
                break;

            default:
                if (ime_state != INPUT_PINYIN) {
                    if (keycode != '\0') {
                        cont[0] = keycode;
                        goto handled;
                    }
                } else {
                    if (islower(keycode)) {
                        if (count < 5) {
                            if (pos > 0) {
                                //set_cursor_off(4, 5 + (pos - 1) * 2);
                                pos = page = 0;
                            }

                            spell[count++] = (char)keycode;
                            show_ime_pad(4, 1, spell);
                            chn = py_ime(spell);
                            if (chn != NULL) {
                                get_chn_pad(chn, chn_content);
                                show_chn_pad(4, 4, chn_content);
                            } else {
                                show_chn_pad(4, 4, NULL);
                            }
                        }
                    }

                    if (isdigit(keycode)) {
                        if (chn != NULL) {
                            if ((keycode - '0') <= (strlen(chn) / 2)) {
                                if (pos > 0) 
                                    //set_cursor_off(4, 5 + (pos - 1) * 2);

                                count = pos = page = 0;
                                memcpy(cont, chn + (keycode - '1') * 2, 2);
                                show_str(4, 1, ime_pad[ime_state]);
                                goto handled;
                            }
                        }
                    }
                }

                break;
        }
    }

handled:
    return SUCCESS;
}
コード例 #2
0
ファイル: window.c プロジェクト: Coxious/dos-student-info
int IMEWindowOnKey(LPVOID lpWindow, LPVOID lParameter, LPVOID lpContext)
{
	int  bUpdateWindow;

	char cKey;
	char cKeyString[2];

	int nSelect;
	int nLength;

	char * szDeliverHZ;

	PWINDOW_SHOW_BOX pShowBox;
	PWINDOW_IME pIME = (PWINDOW_IME)lpWindow;
	cKey = *(char *)lParameter;

	pShowBox = (PWINDOW_SHOW_BOX)pIME->wBasic.wChildrenHead;

	nSelect = 0;
	szDeliverHZ = 0;
	cKey = *((char *)lParameter);

	cKeyString[0] = cKey;
	cKeyString[1] = '\0';

	bUpdateWindow = 0;

	if(!(pIME->bShow)){
		pIME->bShow = 1;
		bUpdateWindow = 1;
	}

	if(pIME->bShowHZ){

		//			ESC 			Backspace
		if(cKey == 0x1B || cKey == '\b'){

			pIME->bShowHZ = 0;
			bUpdateWindow = 1;

			pShowBox->bUseHZK  = 0;
			pShowBox->szBuffer = pIME->szKeys;

		}else if(cKey == ' '){
			szDeliverHZ   = pIME->szHz;
			pIME->szKeys[0] = '\0';
			pIME->szKeys[1] = '\0';
		}else if( cKey < 10 && cKey > 0 ){
			nSelect = cKey;
			szDeliverHZ   = &pIME->szHz[2*(nSelect -1)];
			pIME->szKeys[0] = '\0';
			pIME->szKeys[1] = '\0';
		}
		if(szDeliverHZ){
			pIME->bShow   = 0;
			pIME->bShowHZ = 0;

			pShowBox->bUseHZK  = 0;
			pShowBox->szBuffer = pIME->szKeys;

			//rectangle(200,300,100,100);//´Ë´¦²»Ö´ÐÐ
			pIME->szKeys[0] = '\0';
			DeliverEvent(
				pwFoucus,
				EVENT_ON_HZ,
				0,0,
				1,
				szDeliverHZ
				);
			bUpdateWindow = 1;
		}
	}else{

		if(cKey == 0x1B){

			pIME->bShow = 0;
			*(pIME->szKeys)='\0';
			bUpdateWindow = 1;

		}else if(cKey == '\b'){

			pIME->szKeys[0] = '\0';
			pIME->szKeys[1] = '\0';
			if(strlen(pIME->szKeys) == 0){
				DeliverEvent(
					pwFoucus,
					EVENT_ON_HZ,
					0,0,
					1,
					"\b"
					);
			}
			// pIME->szKeys[strlen(pIME->szKeys)] = '\0';
			bUpdateWindow = 1;
		}else if(cKey == ' '){

			pIME->szHz = py_ime(pIME->szKeys);
			if(pIME->szHz){
				pIME->bShowHZ = 1;
				pShowBox->szBuffer = pIME->szHz;
				pShowBox->bUseHZK  = 1;
				bUpdateWindow = 1;
			}

		}else if(cKey >= 'a' && cKey <= 'z' ){
		//rectangle(100,100,
		//cKey%100,cKey%100);¿ÉÒÔÖ´Ðе½´Ë
			nLength = strlen(pIME->szKeys);
			pIME->szKeys[nLength] = cKey;
			pIME->szKeys[nLength +1 ] = '\0';
			bUpdateWindow = 1;
		}
	}

	if(bUpdateWindow){
		//pShowBox->szBuffer = "test";
		RenderWindowAndSubwindow((PWINDOW)pIME);
		//rectangle(500,400,100,100);¿ÉÒÔÖ´Ðе½´Ë
	}
	return 1;
}