?? hzinput.c
字號(hào):
/************************************************************************* * extern function * *************************************************************************/void __mg_ime_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]); if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_CHAR, wDByte, 0);#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) else Send2ActiveClient (MSG_CHAR, wDByte, 0);#endif } } else { for (i=0; i<len; i++) { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_CHAR, buffer[i], 0);#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) else Send2ActiveClient (MSG_CHAR, buffer[i], 0);#endif } }}void __mg_ime_outchar (unsigned char c, LPARAM lParam){ int scancode = 0; switch (c) { case '\010': case '\177': /* BackSpace */ scancode = SCANCODE_BACKSPACE; break; case '\033': scancode = SCANCODE_ESCAPE; break; case '\t': scancode = SCANCODE_TAB; break; } if (scancode) {#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (!sg_hTargetWnd) { Send2ActiveClient (MSG_KEYDOWN, scancode, (LPARAM)KS_IMEPOST); Send2ActiveClient (MSG_KEYUP, scancode, (LPARAM)KS_IMEPOST); return; }#endif PostMessage (sg_hTargetWnd, MSG_KEYDOWN, scancode, (LPARAM)KS_IMEPOST); PostMessage (sg_hTargetWnd, MSG_KEYUP, scancode, (LPARAM)KS_IMEPOST); } else __mg_ime_writemsg (&c, 1, lParam, FALSE);}/* this is the ime window proc */int GBIMEWinProc (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;#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (message == MSG_KEYDOWN || message == MSG_KEYUP) { if (IsOpened && IsHanziInput) { MSG Msg = {hWnd, message, wParam, lParam}; TranslateMessage (&Msg); } } else if (message == MSG_SYSKEYDOWN) { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, message, wParam, lParam); else Send2ActiveClient (MSG_KEYDOWN, wParam, lParam); } else if (message == MSG_SYSKEYUP) { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, message, wParam, lParam); else Send2ActiveClient (MSG_KEYUP, wParam, lParam); }#endif switch (message) { case MSG_NCCREATE: 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; } break; case MSG_IME_CLOSE: if (IsOpened) { ShowWindow(hWnd, SW_HIDE); IsOpened = 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_SETFOCUS: case MSG_KILLFOCUS: return 0; 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; } #ifndef _LITE_VERSION if (sg_hTargetWnd && imeIsEffectiveIME () && imeIsSpecialKey (wParam)) PostMessage (sg_hTargetWnd, MSG_KEYDOWN, wParam, lParam);#else if (!IsHanziInput || (imeIsEffectiveIME () && imeIsSpecialKey (wParam))) { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_KEYDOWN, wParam, lParam);#ifndef _STAND_ALONE else Send2ActiveClient (MSG_KEYDOWN, wParam, lParam);#endif }#endif }#ifdef _LITE_VERSION else { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_KEYDOWN, wParam, lParam);#ifndef _STAND_ALONE else Send2ActiveClient (MSG_KEYDOWN, wParam, lParam);#endif }#endif return 0; case MSG_KEYUP: if (IsOpened) { if (wParam == SCANCODE_LEFTCONTROL && clean_left_ctrl ) { toggle_input_method (); InvalidateRect (hWnd, NULL, TRUE); }#ifndef _LITE_VERSION if (sg_hTargetWnd && imeIsEffectiveIME () && imeIsSpecialKey (wParam)) PostMessage (sg_hTargetWnd, MSG_KEYUP, wParam, lParam);#else if (!IsHanziInput || (imeIsEffectiveIME () && imeIsSpecialKey (wParam))) { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_KEYUP, wParam, lParam);#ifndef _STAND_ALONE else Send2ActiveClient (MSG_KEYUP, wParam, lParam);#endif }#endif }#ifdef _LITE_VERSION else { if (sg_hTargetWnd) PostMessage (sg_hTargetWnd, MSG_KEYUP, wParam, lParam);#ifndef _STAND_ALONE else Send2ActiveClient (MSG_KEYUP, wParam, lParam);#endif }#endif return 0; case MSG_PAINT: hdc = BeginPaint (hWnd); SetBkColor (hdc, GetWindowElementColor (BKC_CONTROL_DEF)); refresh_input_method_area (hWnd, hdc); EndPaint (hWnd, hdc); return 0; case MSG_LBUTTONDOWN: { RECT rc; int zwidth = GetSysCCharWidth(); int zheight = GetSysCharHeight(); GetClientRect (hWnd, &rc); 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 > rc.right - 4 - 32 && oldx < rc.right - 4 - 16 && oldy > 2 && oldy < 16+2){ toggle_half_full (); InvalidateRect (hWnd, NULL, TRUE); return 0; } if (oldx > rc.right - 4 - 16 && oldx < rc.right - 4 && 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 = LOSWORD (lParam); y = HISWORD (lParam); OffsetRect (&rcWindow, x - oldx, y - oldy);#ifndef _LITE_VERSION MoveWindow (hWnd, rcWindow.left, rcWindow.top, RECTW (rcWindow), RECTH (rcWindow), FALSE);#endif 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);#ifndef _LITE_VERSION PostQuitMessage (hWnd);#endif return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}static void InitIMEWinCreateInfo (PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_ABSSCRPOS | 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 = GBIMEWinProc; 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 = GetWindowElementColor (BKC_CONTROL_DEF); pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = 0;}#ifdef _LITE_VERSIONHWND GBIMEWindowEx (HWND hosting, int lx, int ty, int rx, int by, BOOL two_lines){ MAINWINCREATE CreateInfo; HWND hMainWnd; InitIMEWinCreateInfo (&CreateInfo); CreateInfo.hHosting = hosting; if (lx != 0 || ty != 0 || rx != 0 || by != 0) { CreateInfo.lx = lx; CreateInfo.ty = ty; CreateInfo.rx = rx; CreateInfo.by = by; bTwoLines = two_lines; } else bTwoLines = TRUE; hMainWnd = CreateMainWindow(&CreateInfo); if (hMainWnd == HWND_INVALID) return HWND_INVALID; ShowWindow (hMainWnd, SW_SHOWNORMAL); return hMainWnd;}#elsetypedef struct ime_info{ sem_t wait; HWND hwnd;} IME_INFO;static void* start_gb_ime (void* data){ MSG Msg; MAINWINCREATE CreateInfo; IME_INFO* ime_info = (IME_INFO*) data; HWND ime_hwnd; InitIMEWinCreateInfo (&CreateInfo); bTwoLines = TRUE; ime_hwnd = ime_info->hwnd = CreateMainWindow (&CreateInfo); sem_post (&ime_info->wait); if (ime_hwnd == HWND_INVALID) return NULL; while (GetMessage (&Msg, ime_hwnd) ) { if (Msg.message == MSG_KEYDOWN || Msg.message == MSG_KEYUP) { if (IsOpened && IsHanziInput) TranslateMessage (&Msg); else if (sg_hTargetWnd) { PostMessage (sg_hTargetWnd, Msg.message, Msg.wParam, Msg.lParam | KS_IMEPOST); } } DispatchMessage(&Msg); } MainWindowThreadCleanup (ime_hwnd); return NULL;}static pthread_t imethread;/* the argument of 'hosting' is ignored. */HWND GBIMEWindow (HWND hosting){ IME_INFO ime_info; pthread_attr_t new_attr; sem_init (&ime_info.wait, 0, 0); pthread_attr_init (&new_attr); pthread_attr_setdetachstate (&new_attr, PTHREAD_CREATE_DETACHED); pthread_create (&imethread, &new_attr, start_gb_ime, &ime_info); pthread_attr_destroy (&new_attr); sem_wait (&ime_info.wait); sem_destroy (&ime_info.wait); return ime_info.hwnd;}#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -