📄 toascii.cpp
字号:
/*++
Copyright (c) 1990-1999 Microsoft Corporation, All Rights Reserved
Module Name:
toascii.c
++*/
#include <windows.h>
#include <imm.h>
#include "imedefs.h"
extern char CurrentPy[PY_EDITER_PY_ITEMS][8];
/**********************************************************************/
/* ProcessKey() */
/* Return Value: */
/* different state which input key will change IME to (CST_ */
/**********************************************************************/
UINT PASCAL ProcessKey( // this key will cause the IME go to what state
WORD wCharCode,
UINT uVirtKey,
UINT uScanCode,
LPBYTE lpbKeyState,
LPINPUTCONTEXT lpIMC,
LPPRIVCONTEXT lpImcP)
{
if (!lpIMC) {
return (CST_INVALID);
}
if (!lpImcP){
return (CST_INVALID);
}
if (!(lpIMC->fdwConversion & IME_CMODE_NATIVE)) {
return (CST_INVALID);
}
if( (uVirtKey == 0x38 || uVirtKey == 0x33)
&& (uVirtKey !=wCharCode)) {/*'*' ,'#' key*/
//check shif key states
if(GetKeyState(VK_SHIFT) & 0x80) {
return ((uVirtKey == 0x38)?CST_BACKSPACE : CST_ESCAPE);
}
}
if (wCharCode>= TEXT('0') && wCharCode<= TEXT('9')) { //input
int count = 0 ;
char code[COMP_MAX_PYLEN+1];
while((count<COMP_MAX_PYLEN -1)
&& lpImcP->bSeq[count] != 0) {
code[count] = (char)lpImcP->bSeq[count];
count++;
}
code[count] = (char)wCharCode ;
code[(count+1)] = 0;
count = EnumPinyinByDigit(code , CurrentPy);
if(count<1)
return CST_INVALID_INPUT;
else
lpImeL->iTotalItem = count;
return (CST_INPUT);
}else if(uVirtKey == VK_RETURN ){ //select
if(lpImcP->fdwImeMsg & MSG_ALREADY_START){
return (CST_SELITEM);
}else{
return (CST_INVALID_INPUT);
}
}else if(uVirtKey == VK_RIGHT ||uVirtKey == VK_LEFT){
if(lpImcP->fdwImeMsg & MSG_ALREADY_START){
return(CST_SELITEMPRE);
}else{
return (CST_INVALID_INPUT);
}
}else if(uVirtKey == VK_BACK || uVirtKey == TEXT('*')||uVirtKey ==VK_MULTIPLY){ //back
return CST_BACKSPACE;
}else if(uVirtKey == VK_ESCAPE){ //ESC
return CST_ESCAPE;
}else{
return (CST_INVALID_INPUT);
}
return (CST_INVALID_INPUT);
}
/**********************************************************************/
/* ImeProcessKey() */
/* Return Value: */
/* TRUE - successful, FALSE - failure */
/**********************************************************************/
BOOL WINAPI ImeProcessKey( // if this key is need by IME?
HIMC hIMC,
UINT uVirtKey,
LPARAM lParam,
CONST LPBYTE lpbKeyState)
{
LPINPUTCONTEXT lpIMC;
LPPRIVCONTEXT lpImcP;
BOOL fRet = FALSE;
// can't compose in NULL hIMC
if (!hIMC) {
return (FALSE);
}
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return (FALSE);
}
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if (!lpImcP) {
ImmUnlockIMC(hIMC);
return (FALSE);
}
if (!(lpIMC->fdwConversion & IME_CMODE_NATIVE)) {
if(uVirtKey ==VK_ESCAPE)
{
DWORD fdwConversion;
fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
}
fRet = FALSE;
}else if ((uVirtKey> 0x29 && uVirtKey< 0x40) ||(uVirtKey> 0x59 && uVirtKey< 0x70)
||(uVirtKey>='a' && uVirtKey <= 'z' )||(uVirtKey>='A' && uVirtKey <= 'Z' )) { //input
fRet = TRUE;
}else if(uVirtKey == VK_RETURN && lpImcP->fdwImeMsg & MSG_ALREADY_START ){ //select
fRet = TRUE;
}else if((uVirtKey == VK_RIGHT ||uVirtKey == VK_LEFT ) && (lpImcP->fdwImeMsg & MSG_ALREADY_START)){ //select pingying
fRet = TRUE;
}else if(uVirtKey == TEXT('*')|| uVirtKey ==VK_MULTIPLY ||uVirtKey ==VK_ESCAPE){ //back
fRet = TRUE;
}else{
fRet = FALSE;
}
ImmUnlockIMCC(lpIMC->hPrivate);
ImmUnlockIMC(hIMC);
return (fRet);
}
/**********************************************************************/
/* TranslateToAscii() */
/* Return Value: */
/* the number of translated chars */
/**********************************************************************/
UINT PASCAL TranslateToAscii( // translate the key to WM_CHAR
// as keyboard driver
UINT uVirtKey,
UINT uScanCode,
LPTRANSMSGLIST lpTransBuf,
WORD wCharCode)
{
LPTRANSMSG lpTransMsg;
lpTransMsg = lpTransBuf->TransMsg;
if (wCharCode) { // one char code
lpTransMsg->message = WM_CHAR;
lpTransMsg->wParam = wCharCode;
lpTransMsg->lParam = (uScanCode << 16) | 1UL;
return (1);
}
// no char code case
return (0);
}
/**********************************************************************/
/* TranslateImeMessage() */
/* Return Value: */
/* the number of translated messages */
/**********************************************************************/
UINT PASCAL TranslateImeMessage(
LPTRANSMSGLIST lpTransBuf,
LPINPUTCONTEXT lpIMC,
LPPRIVCONTEXT lpImcP)
{
UINT uNumMsg;
UINT i;
BOOL bLockMsgBuf;
LPTRANSMSG lpTransMsg;
uNumMsg = 0;
bLockMsgBuf = FALSE;
for (i = 0; i < 2; i++) {
if (lpImcP->fdwImeMsg & MSG_CLOSE_CANDIDATE) {
if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_CLOSECANDIDATE;
lpTransMsg->lParam = 0x0001;
lpTransMsg++;
lpImcP->fdwImeMsg &= ~(MSG_ALREADY_OPEN);
}
}
}
if (lpImcP->fdwImeMsg & MSG_END_COMPOSITION) {
if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_ENDCOMPOSITION;
lpTransMsg->wParam = 0;
lpTransMsg->lParam = 0;
lpTransMsg++;
lpImcP->fdwImeMsg &= ~(MSG_ALREADY_START);
}
}
}
if (lpImcP->fdwImeMsg & MSG_START_COMPOSITION) {
if (!(lpImcP->fdwImeMsg & MSG_ALREADY_START)) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_STARTCOMPOSITION;
lpTransMsg->wParam = 0;
lpTransMsg->lParam = 0;
lpTransMsg++;
lpImcP->fdwImeMsg |= MSG_ALREADY_START;
}
}
}
if (lpImcP->fdwImeMsg & MSG_IMN_COMPOSITIONPOS) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_SETCOMPOSITIONWINDOW;
lpTransMsg->lParam = 0;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_COMPOSITION) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_COMPOSITION;
lpTransMsg->wParam = (DWORD)lpImcP->dwCompChar;
lpTransMsg->lParam = (DWORD)lpImcP->fdwGcsFlag;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_OPEN_CANDIDATE) {
if (!(lpImcP->fdwImeMsg & MSG_ALREADY_OPEN)) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_OPENCANDIDATE;
lpTransMsg->lParam = 0x0001;
lpTransMsg++;
lpImcP->fdwImeMsg |= MSG_ALREADY_OPEN;
}
}
}
if (lpImcP->fdwImeMsg & MSG_CHANGE_CANDIDATE) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_CHANGECANDIDATE;
lpTransMsg->lParam = 0x0001;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_IMN_UPDATE_SOFTKBD) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_PRIVATE;
lpTransMsg->lParam = IMN_PRIVATE_UPDATE_SOFTKBD;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_IMN_UPDATE_STATUS) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_PRIVATE;
lpTransMsg->lParam = IMN_PRIVATE_UPDATE_STATUS;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_IMN_DESTROYCAND) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_IME_NOTIFY;
lpTransMsg->wParam = IMN_PRIVATE;
lpTransMsg->lParam = IMN_PRIVATE_DESTROYCANDWIN;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_BACKSPACE) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_KEYDOWN;
lpTransMsg->wParam = TEXT('\b');
lpTransMsg->lParam = 0xe0001;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_BACKSPACE) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_CHAR;
lpTransMsg->wParam = TEXT('\b');
lpTransMsg->lParam = 0xe0001;
lpTransMsg++;
}
}
if (lpImcP->fdwImeMsg & MSG_BACKSPACE) {
if (!i) {
uNumMsg++;
} else {
lpTransMsg->message = WM_KEYUP;
lpTransMsg->wParam = TEXT('\b');
lpTransMsg->lParam = 0xe0001;
lpTransMsg++;
}
}
if (!i) {
HIMCC hMem;
if (!uNumMsg) {
return (uNumMsg);
}
if (lpImcP->fdwImeMsg & MSG_IN_IMETOASCIIEX) {
UINT uNumMsgLimit;
uNumMsgLimit = lpTransBuf->uMsgCount;
if (uNumMsg <= uNumMsgLimit) {
lpTransMsg = lpTransBuf->TransMsg;
continue;
}
}
// we need to use message buffer
if (!lpIMC->hMsgBuf) {
lpIMC->hMsgBuf = ImmCreateIMCC(uNumMsg * sizeof(TRANSMSG));
lpIMC->dwNumMsgBuf = 0;
} else if (hMem = ImmReSizeIMCC(lpIMC->hMsgBuf,
(lpIMC->dwNumMsgBuf + uNumMsg) * sizeof(TRANSMSG))) {
if (hMem != lpIMC->hMsgBuf) {
ImmDestroyIMCC(lpIMC->hMsgBuf);
lpIMC->hMsgBuf = hMem;
}
} else {
return (0);
}
lpTransMsg= (LPTRANSMSG) ImmLockIMCC(lpIMC->hMsgBuf);
if (!lpTransMsg) {
return (0);
}
lpTransMsg += lpIMC->dwNumMsgBuf;
bLockMsgBuf = TRUE;
} else {
if (bLockMsgBuf) {
ImmUnlockIMCC(lpIMC->hMsgBuf);
}
}
}
return (uNumMsg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -