⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hzinput.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 3 页
字号:
            len = epunc2cpunc (key, cpunc);            if (len != 0) {                writemsg(cpunc, len, lParam, TRUE);                ClrIn();                return TRUE;            }            if (!IsHanziInput && !IsFullChar) {                outchar (key, lParam);                return FALSE;            }        }            if (IsFullChar && key >= ' ' && key <= 127) {            key = (key - ' ') << 1;            cc[0] = (unsigned char)(fullchar[key]);            cc[1] = (unsigned char)(fullchar[key+1]);                   writemsg(cc, 2, lParam, TRUE);            return FALSE;        }    }    else {        outchar (key, lParam);        return FALSE;    }    if (CurIME == 0) {        intcode_hz_filter(key, lParam);        return TRUE;    }#ifdef _IME_GB2312_PINYIN    if (CurIME == 1) {        Pinyin_HZFilter (&Pinyin_Module, key, lParam);        return TRUE;    }#endif    switch ( key ) {    case '\010':  /* BackSpace Ctrl+H */    case '\177':  /* BackSpace */        if ( InputCount > 0 )         {           InpKey[--InputCount]=0;           if (InputCount == 0)           {               ClrIn();             }           else if (InputCount < InputMatch)           {               FindMatchKey();               MultiPageMode = 0;               CurrentPageIndex = StartKey;               FillMatchChars(StartKey);            }          }        else outchar(key,lParam);        break;     case '\033':  /* ESCAPE */        if (InputCount > 0)         {           ClrIn();         }        else outchar(key,lParam);        break;     case '-':        if ( MultiPageMode )        {           if ( CurrentPageIndex > StartKey)                 CurrentPageIndex = CurrentPageIndex - cur_table->MaxDupSel;           else CurrentPageIndex = StartKey;           if (IsAssociateMode)                FillAssociateChars(CurrentPageIndex);           else FillMatchChars(CurrentPageIndex);         }        else outchar(key,lParam);        break;     case '=':        if ( MultiPageMode )        {           CurrentPageIndex = NextPageIndex;           if (IsAssociateMode)               FillAssociateChars(CurrentPageIndex);           else FillMatchChars(CurrentPageIndex);                   }        else outchar(key,lParam);        break;     case ' ':        if ( CurSelNum == 0 )           outchar(key,lParam);        if ( seltab[0][0] )           putstr(seltab[0],lParam);        break;     default:        inkey   = cur_table->KeyMap[key];        is_sel_key = strchr( cur_table->selkey, key);        vv = is_sel_key - cur_table->selkey;           /* selkey index, strchr may return NULL */       /* if a key is simultaneously inkey & is_sel_key, then selkey first?*/        if ( (!inkey && !is_sel_key) ||              (!inkey && is_sel_key && (CurSelNum == 0 || seltab[vv][0] == 0)) )        {           IsAssociateMode = 0;           ClrIn();           outchar(key,lParam);           break;        }        if (is_sel_key && CurSelNum > 0 && seltab[vv][0])        {            putstr(seltab[vv],lParam);            break;        }                /* now it must be inkey? */        IsAssociateMode = 0;         if ( inkey >= 1 && InputCount < MAX_INPUT_LENGTH )            InpKey[InputCount++] = inkey;                     if (InputCount <= InputMatch+1)         {             FindMatchKey();             CurrentPageIndex = StartKey;             MultiPageMode = 0;             FillMatchChars(StartKey);             if (InputCount >= cur_table->MaxPress && CurSelNum == 1 &&                 cur_table->last_full)             {                // left only one selection                  putstr(seltab[0],lParam);             }        }                break;  } /* switch */  return TRUE;}static void DispSelection(HDC hDC){  int i, pos = 1;  char str[100];  char minibuf[2];  minibuf[1]=0;  str[0]=0;  if (MultiPageMode && CurrentPageIndex != StartKey)   {    strcat(str,"< ");      pos += 2;  }  for( i = 0; i < CurSelNum; i++ )  {     if ( !seltab[i][0] ) {        if (CurIME == 0 && i == 0) 	        continue; 	    else	        break;     }     minibuf[0]= input_table[CurIME]->selkey[i];     strcat(str,minibuf);     strcat(str,seltab[i]);     strcat(str," ");   }  if ( MultiPageMode && NextPageIndex != StartKey)    {     strcat (str,"> ");  }    TextOut (hDC, 2, 18, str);}static void unload_input_table(int i){  if (((i >= 0) && (i < 10)) && input_table[i])  {    if (i == CurIME)    {      if (IsHanziInput)          toggle_input_method();      CurIME = 0;    }    if (input_table[i]->PhraseFile)        fclose(input_table[i]->PhraseFile);    if (input_table[i]->AssocFile)        fclose(input_table[i]->AssocFile);    free_input_method(input_table[i]);    input_table[i] = NULL;  }}static int toggle_input_method(void){  if (input_table[CurIME] || CurIME == 1)  {    IsHanziInput ^= 1;    cur_table = input_table[CurIME];    ClrIn();  }    return IsHanziInput;}static void toggle_half_full(void){   IsFullChar = 1 - IsFullChar;   ClrIn();}static void toggle_punc (void){   IsFullPunc = 1 - IsFullPunc;   ClrIn();}static BOOL hz_input_init(void){    char szFileName[MAX_PATH + 1];    char szKey[10];    char szValue[MAX_FILENAME + 1];    int number;    int i;    if( GetValueFromEtcFile(ETCFILEPATH, "imeinfo", "imetabpath",            ime_tab_path, MAX_PATH) < 0 ) {        fprintf (stderr, "IME: Get imetab file path error!\n");        return FALSE;    }    IsOpened = 1;    IsEnabled = 1;    IsHanziInput = 1;	// default is hanzi input     IsFullChar = 0;    IsFullPunc = 0;    CurIME = 0;    input_table[0] = IntCode_Init();    if (input_table[0] == NULL)        return FALSE;#ifdef _IME_GB2312_PINYIN    if (!InitPinyinInput (ime_tab_path, &Pinyin_Module)) {        fprintf (stderr, "IME: Init Pinyin module failure!\n");        unload_input_table (0);        return FALSE;    }    nIMENr = 2;#else    nIMENr = 1;#endif    if( !LoadSystemBitmap (&sg_bmpIME, "IMEctrlbtn") ){		fprintf (stderr, "IME: Load the control button failure!\n");		return FALSE;	}    if( GetValueFromEtcFile (ETCFILEPATH, "imeinfo", "imenumber",            szValue, 10) < 0 )        goto error;            number = atoi (szValue);    if(number <= 0)        goto error;    number = (number < NR_INPUTMETHOD) ? number : NR_INPUTMETHOD;    for (i = 0; i < number; i++) {        sprintf(szKey, "ime%d", i);        if( GetValueFromEtcFile(ETCFILEPATH, "imeinfo",            szKey, szValue, MAX_FILENAME) < 0 )        goto error;                fprintf (stderr, "IME: Loading Input Method %d: %s\n",i, szValue);        strcpy(szFileName, ime_tab_path);        strcat(szFileName, szValue);        strcat(szFileName, ".tab");        input_table [i + nIMENr] = load_input_method(szFileName);        if (!input_table [i + nIMENr])            goto error;    }    nIMENr += number;    if (nIMENr > 1)        CurIME = 1;    cur_table = input_table [CurIME];    return TRUE;    error:#ifdef _IME_GB2312_PINYIN    for (i = 0; i < nIMENr; i++) {        if (i != 1)            unload_input_table (i);    }    PinyinInputCleanup (ime_tab_path, &Pinyin_Module);#else    for (i = 0; i < nIMENr; i++)        unload_input_table (i);#endif    return FALSE;}static void hz_input_done(void){  int i;  for (i = 0; i < NR_INPUTMETHOD; i++)    if (input_table[i]) {        if (input_table[i]->PhraseFile)            fclose(input_table[i]->PhraseFile);        if (input_table[i]->AssocFile)            fclose(input_table[i]->AssocFile);        free_input_method(input_table[i]);    }#ifdef _IME_GB2312_PINYIN    PinyinInputCleanup (ime_tab_path, &Pinyin_Module);#endif}static void set_active_input_method(int active){#if _IME_GB2312_PINYIN  if (input_table[active] || active == 1)#else  if (input_table[active])#endif  {    CurIME = active;    cur_table = input_table[active];    ClrIn();#if _IME_GB2312_PINYIN    if (CurIME == 1 || CurIME == 0)#else    if (CurIME == 0)#endif        UseAssociateMode = 0;    else         UseAssociateMode = 1;  }}static void refresh_input_method_area(HDC hDC){    char str[100];    int i;    char minibuf[2];        FillBoxWithBitmapPart (hDC, 396-32, 2,                            CTRLBTN_WIDTH, CTRLBTN_HEIGHT,                           0, 0,                           &sg_bmpIME,                           0, (IsFullChar*CTRLBTN_HEIGHT));		    FillBoxWithBitmapPart (hDC, 396-16, 2,                            CTRLBTN_WIDTH, CTRLBTN_HEIGHT,                           0, 0,                           &sg_bmpIME,                           CTRLBTN_WIDTH, (IsFullPunc*CTRLBTN_HEIGHT));            if (!IsHanziInput) {            DisabledTextOut (hDC, 2, 2, "【英文】");    }#ifdef _IME_GB2312_PINYIN    else if (CurIME != 1)#else    else#endif    {        minibuf[1] = 0;		strcpy (str, input_table[CurIME]->cname);                for( i = 0; i <= MAX_INPUT_LENGTH ; i++)        {            if (i < InputCount)                minibuf[0] = input_table[CurIME]->KeyName[InpKey[i]];            else                 minibuf[0]=' ';                            if (i == InputMatch && InputCount > InputMatch && i != 0)                strcat (str,"-");                            strcat (str,minibuf);        }                TextOut (hDC, 2, 2, str);                                                DispSelection (hDC);    }#ifdef _IME_GB2312_PINYIN    else        RefreshPYInputArea (&Pinyin_Module, hDC);#endif}/************************************************************************* *                       Internal Code Input Method                      * *************************************************************************/static hz_input_table *IntCode_Init(void){  hz_input_table *table;  int i,index;  UseAssociateMode = 1;  /* force to no associate */  table = malloc(sizeof(hz_input_table));  if (table == NULL)     {      fprintf(stderr, "IME: load_input_method");      return NULL;     }    /* reset to zero. */   memset (table, 0, sizeof (hz_input_table));   strcpy(table->magic_number,MAGIC_NUMBER);   strcpy(table->ename, "IntCode");   strcpy(table->cname, "【内码】");   strcpy(table->selkey, "0123456789abcdef");   table->last_full = 1;   for(i = 0; i < 128; i++)   {      table->KeyMap[i] = 0;      if ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'f'))      {         if (i >= '0' && i <= '9')            index = i - '0';         else index = i -'a' + 10;         table->KeyMap[i] = index;         table->KeyName[index] = toupper(i);      }   }       return table;}/* StartKey <= index < EndKey is valid */static void IntCode_FindMatchKey(void){   unsigned long Key = (InpKey[0] << 12) | (InpKey[1] << 8);   switch(InputCount)   {      case 0:      case 1:         StartKey = EndKey = 0;    /* not display selection */         break;      case 2:         StartKey = Key + 0xA1;          EndKey = Key + 0xFF;  /* A1-A9,B0-F7 A1-FE */         break;      case 3:         StartKey = Key + (InpKey[2] << 4);         if (InpKey[2] == 10) StartKey++; /* A1 */         EndKey = StartKey + 0x10;           if (InpKey[2] == 15) EndKey--;  /* FE */          break;    }}/* ABCD  AB then C=a..f, Sel=0-9 begin display selection        ABC then D=0-f,  Sel=0-f */static void IntCode_FillMatchChars(int index){    int MaxSel,i;       CurSelNum = 0;    if (InputCount < 2) return;    if (InputCount == 2) MaxSel = 10; else MaxSel = 16;        if (index % 256 == 0xA1 && InputCount == 3)     {       seltab[0][0] = '\0';       CurSelNum++;    }    while( CurSelNum < MaxSel && index < EndKey)    {         seltab[CurSelNum][0] = index / 256;          seltab[CurSelNum][1] = index % 256;         seltab[CurSelNum][2] = '\0';         CurSelNum++;         index++;    }        for(i = CurSelNum; i < 16; i++)       seltab[i][0] = '\0';  /* zero out the unused area */    InputMatch = InputCount;    /* check if more than one page */    if ( index < EndKey && CurSelNum == MaxSel && MaxSel == 10)    {      /* has another matched key, so enter MultiPageMode, has more pages */        NextPageIndex = index;        MultiPageMode = 1;    }      else if (MultiPageMode)    {        NextPageIndex = StartKey; /* rotate selection */    }    else MultiPageMode = 0;}static void intcode_hz_filter(unsigned char key,LPARAM lParam)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -