📄 hzinput.c
字号:
{ int inkey = 0; switch ( key ) { case '\010': /* BackSpace Ctrl+H */ case '\177': /* BackSpace */ if ( InputCount > 0 ) { InpKey[--InputCount]=0; if (InputCount == 0) { ClrIn(); } else if (InputCount >= 2) { IntCode_FindMatchKey(); MultiPageMode = 0; CurrentPageIndex = StartKey; IntCode_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 - 10; else CurrentPageIndex = StartKey; IntCode_FillMatchChars(CurrentPageIndex); } else outchar(key,lParam); break; case '=': if ( MultiPageMode ) { CurrentPageIndex = NextPageIndex; IntCode_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]; switch(InputCount) { case 0: /* A-F */ case 1: /* 0-F */ case 2: /* A-F */ if (inkey >=0 && !(InputCount != 1 && inkey < 10) && !(InputCount == 1 && ( (InpKey[0]==10 && inkey>9) || //A1-A9 (InpKey[0]==10 && inkey==0) || (InpKey[0]==15 && inkey>7)) ) ) //B0-F7 { InpKey[InputCount++] = inkey; if (InputCount >=2) { IntCode_FindMatchKey(); MultiPageMode = 0; CurrentPageIndex = StartKey; IntCode_FillMatchChars(StartKey); } } else if (InputCount == 2 && inkey >= 0 && inkey < CurSelNum && seltab[inkey][0]) { putstr(seltab[inkey],lParam); } else /* not select key or input key */ { ClrIn(); outchar(key,lParam); return; } break; case 3: /* output char */ if (inkey >=1 && !(InpKey[2] == 10 && inkey == 0) && !(InpKey[2] == 15 && inkey == 15)) { seltab[0][0] = (InpKey[0] << 4) | InpKey[1]; seltab[0][1] = (InpKey[2] << 4) | inkey ; seltab[0][2] = '\0'; putstr(seltab[0],lParam); } else { ClrIn(); outchar(key,lParam); return; } break; } } /* switch */}/*************** below are interface to other modules **************//* use these functions in other modules only *//* set current active input method *//* this function sets the active input method to ime *//* ime value can be: 0 for internal code *//* 1 for pinyin *//* 2 for wubi */static void imeSetStatus(int iStatusCode, int Value){ switch (iStatusCode) { case IS_ENABLE: if (Value && !IsHanziInput) toggle_input_method (); else if (!Value && IsHanziInput) toggle_input_method (); break; case IS_FULLCHAR: if (Value && !IsFullChar) toggle_half_full (); else if (!Value && IsFullChar) toggle_half_full (); break; case IS_FULLPUNC: if (Value && !IsFullPunc) toggle_punc (); else if (!Value && IsFullPunc) toggle_punc (); break; case IS_METHOD: if (Value < 0) { Value = (CurIME + 1) % nIMENr; set_active_input_method (Value); } else { if (Value >= nIMENr) Value = nIMENr - 1; if (Value != CurIME) set_active_input_method (Value); else return; } break; default: break; }}static int imeGetStatus(int iStatusCode){ switch (iStatusCode) { case IS_ENABLE: return IsHanziInput; break; case IS_FULLCHAR: return IsFullChar; break; case IS_FULLPUNC: return IsFullPunc; break; case IS_METHOD: return CurIME; break; default: break; } return 0;}static inline BOOL imeIsSpecialChar (int chr){ if (chr == '\t' || chr == '\n' || chr == '\r') return TRUE; return FALSE;}static inline BOOL imeIsSpecialKey (int scancode){ if (scancode == SCANCODE_TAB || scancode == SCANCODE_ENTER || scancode > SCANCODE_F1) return TRUE; return FALSE;}static inline BOOL imeIsEffectiveIME (void){ return IsHanziInput || IsFullChar || IsFullPunc;}static int clean_left_ctrl = 1;static void InitIMEWinCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_BORDER | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_TOPMOST; pCreateInfo->spCaption = "The IME Window" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = IMEWinProc; pCreateInfo->lx = GetGDCapability (HDC_SCREEN, GDCAP_MAXX) - 400; pCreateInfo->ty = GetGDCapability (HDC_SCREEN, GDCAP_MAXY) - 80; pCreateInfo->rx = GetGDCapability (HDC_SCREEN, GDCAP_MAXX); pCreateInfo->by = GetGDCapability (HDC_SCREEN, GDCAP_MAXY) - 40; pCreateInfo->iBkColor = PIXEL_lightgray; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}/************************************************************************* * extern function * *************************************************************************/void writemsg (BYTE *buffer, int len, LPARAM lParam, BOOL bDByte){ WORD wDByte; int i; if (bDByte) { for (i=0; i<len; i+=2) { wDByte = MAKEWORD (buffer[i], buffer[i+1]); PostMessage (sg_hTargetWnd, MSG_CHAR, wDByte, 0); } } else { for (i=0; i<len; i++) { PostMessage (sg_hTargetWnd, MSG_CHAR, buffer[i], 0); } }}void outchar (unsigned char c, LPARAM lParam){ int scancode = 0; switch (c) { case '\010': scancode = SCANCODE_BACKSPACE; break; case '\033': scancode = SCANCODE_ESCAPE; break; case '\t': scancode = SCANCODE_TAB; break; } if (scancode) { PostMessage (sg_hTargetWnd, MSG_KEYDOWN, scancode, (LPARAM)KS_IMEPOST); PostMessage (sg_hTargetWnd, MSG_KEYUP, scancode, (LPARAM)KS_IMEPOST); } else writemsg(&c, 1, lParam, FALSE);}/* this is the ime window proc */int IMEWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; static BOOL fCaptured = FALSE; static int oldx, oldy; int x, y; int maxx, maxy; RECT rcWindow; RECT *prcExpect, *prcResult; switch (message) { case MSG_NCCREATE: // init ime system if (hz_input_init()) // Register before show the window. SendMessage (HWND_DESKTOP, MSG_IME_REGISTER, (WPARAM)hWnd, 0); else return -1; break; case MSG_IME_OPEN: if ( !IsOpened ) { ShowWindow(hWnd, SW_SHOW); IsOpened = 1; IsEnabled = 1; } break; case MSG_IME_CLOSE: if (IsOpened) { ShowWindow(hWnd, SW_HIDE); IsOpened = 0; IsEnabled = 0; } break; case MSG_IME_SETSTATUS: imeSetStatus ((int)wParam, (int)lParam); break; case MSG_IME_GETSTATUS: return imeGetStatus ((int)wParam); break; case MSG_IME_SETTARGET: if (sg_hTargetWnd != hWnd) sg_hTargetWnd = (HWND)wParam; break; case MSG_IME_GETTARGET: return (int)sg_hTargetWnd; break; case MSG_CHAR: if (IsOpened && !imeIsSpecialChar (wParam)) { if (hz_filter ((BYTE)wParam, lParam)) InvalidateRect (hWnd, NULL, TRUE); } return 0; case MSG_KEYDOWN: if (wParam != SCANCODE_LEFTCONTROL) clean_left_ctrl = 0; else clean_left_ctrl = 1; if (IsOpened) { if (wParam == SCANCODE_SPACE && (lParam & KS_CTRL)) { toggle_half_full (); InvalidateRect (hWnd, NULL, TRUE); return 0; } else if (wParam == SCANCODE_PERIOD && (lParam & KS_CTRL)) { toggle_punc (); InvalidateRect (hWnd, NULL, TRUE); return 0; } else if ((wParam == SCANCODE_LEFTSHIFT) && (lParam & KS_CTRL)) { imeSetStatus (IS_METHOD, -1); InvalidateRect (hWnd, NULL, TRUE); return 0; } if (sg_hTargetWnd && imeIsEffectiveIME () && imeIsSpecialKey (wParam)) PostMessage (sg_hTargetWnd, MSG_KEYDOWN, wParam, lParam); } return 0; case MSG_KEYUP: if (IsOpened) { if (wParam == SCANCODE_LEFTCONTROL && clean_left_ctrl ) { if (toggle_input_method ()) { ShowWindow(hWnd, SW_SHOW); InvalidateRect (hWnd, NULL, TRUE); IsEnabled = 1; } else { ShowWindow(hWnd, SW_HIDE); IsEnabled = 0; } } if (sg_hTargetWnd && imeIsEffectiveIME () && imeIsSpecialKey (wParam)) PostMessage (sg_hTargetWnd, MSG_KEYUP, wParam, lParam); } return 0; case MSG_PAINT: hdc = BeginPaint (hWnd); SetBkColor (hdc, PIXEL_lightgray); refresh_input_method_area(hdc); EndPaint (hWnd, hdc); return 0; case MSG_LBUTTONDOWN: { int zwidth = GetSysCCharWidth(); int zheight = GetSysCharHeight(); oldx = LOWORD (lParam); oldy = HIWORD (lParam); if (IsHanziInput && oldx > 0 && oldx < 4*zwidth && oldy > 2 && oldy < zheight+2){ imeSetStatus (IS_METHOD, -1); InvalidateRect (hWnd, NULL, TRUE); return 0; } if (oldx > 396-32 && oldx < 396-16 && oldy > 2 && oldy < 16+2){ toggle_half_full (); InvalidateRect (hWnd, NULL, TRUE); return 0; } if (oldx > 396-16 && oldx < 396 && oldy > 2 && oldy < 16+2){ toggle_punc (); InvalidateRect (hWnd, NULL, TRUE); return 0; } SetCapture (hWnd); ClientToScreen (hWnd, &oldx, &oldy); fCaptured = TRUE; } break; case MSG_LBUTTONUP: ReleaseCapture (); fCaptured = FALSE; break; case MSG_MOUSEMOVE: if (fCaptured) { GetWindowRect (hWnd, &rcWindow); x = LOWORD (lParam); y = HIWORD (lParam); OffsetRect (&rcWindow, x - oldx, y - oldy); MoveWindow (hWnd, rcWindow.left, rcWindow.top, RECTW (rcWindow), RECTH (rcWindow), FALSE); oldx = x; oldy = y; } break; case MSG_SIZECHANGING: prcExpect = (PRECT)wParam; prcResult = (PRECT)lParam; *prcResult = *prcExpect; if (prcExpect->left < 0) { prcResult->left = 0; prcResult->right = RECTWP (prcExpect); } if (prcExpect->top < 0) { prcResult->top = 0; prcResult->bottom = RECTHP (prcExpect); } maxx = GetGDCapability (HDC_SCREEN, GDCAP_HPIXEL); maxy = GetGDCapability (HDC_SCREEN, GDCAP_VPIXEL); if (prcExpect->right > maxx) { prcResult->right = maxx; prcResult->left = maxx - RECTWP (prcExpect); } if (prcExpect->bottom > maxy) { prcResult->bottom = maxy; prcResult->top = maxy - RECTHP (prcExpect); } return 0; case MSG_CLOSE: SendMessage (HWND_DESKTOP, MSG_IME_UNREGISTER, (WPARAM)hWnd, 0); hz_input_done (); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}void* GUIAPI IMEWindow(void* data){ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd; InitIMEWinCreateInfo(&CreateInfo); hMainWnd = CreateMainWindow(&CreateInfo); if (hMainWnd == HWND_INVALID) return NULL; ShowWindow (hMainWnd, SW_SHOWNORMAL); while( GetMessage(&Msg, hMainWnd) ) { if (Msg.message == MSG_KEYDOWN || Msg.message == MSG_KEYUP) { if (IsOpened && (IsHanziInput || IsFullChar || IsFullPunc)) TranslateMessage (&Msg); else PostMessage (sg_hTargetWnd, Msg.message, Msg.wParam, Msg.lParam | KS_IMEPOST); } DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd); return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -