www.pudn.com > freepy.rar > imm.cpp
/*
* Copyright (C) 1999.4 Li ZhenChun
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License; or
* (at your option) any later version.
*
* This program is distributed in the hope that is will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, M A 02139, USA.
*
* Author: Li ZhenChun email: zhchli@163.net or zhchli@126.com
*
*/
#include "freepy.h"
BOOL WINAPI ImeInquire(IN LPIMEINFO lpIMEInfo,IN OUT LPTSTR lpszUIClass,IN DWORD lpszOption)
{
//DebugLog(1,(DebugLogFile,_T("ImeInquire\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeInquire begin\r\n")));
//lpIMEInfo->dwPrivateDataSize = sizeof(UIEXTRA);
lpIMEInfo->dwPrivateDataSize = sizeof(DWORD);
lpIMEInfo->fdwProperty = IME_PROP_KBD_CHAR_FIRST |
#ifdef _UNICODE
IME_PROP_UNICODE |
#endif
IME_PROP_AT_CARET;
//IME_PROP_SPECIAL_UI;
lpIMEInfo->fdwConversionCaps = IME_CMODE_FULLSHAPE |
IME_CMODE_NATIVE;
lpIMEInfo->fdwSentenceCaps = IME_SMODE_NONE;
lpIMEInfo->fdwUICaps = UI_CAP_2700;
lpIMEInfo->fdwSCSCaps = 0L;
lpIMEInfo->fdwSelectCaps = SELECT_CAP_CONVERSION;
//_tcscpy(lpszUIClass,UICLASSNAME);
lstrcpy(lpszUIClass,(LPTSTR)UICLASSNAME);
RETAILMSG(DEBUGMODE,(TEXT("ImeInquire end\r\n")));
return TRUE;
}
BOOL WINAPI ImeConfigure(HKL hKL,HWND hWnd, DWORD dwMode, LPVOID lpData)
{
//DebugLog(1,(DebugLogFile,"ImeConfigure\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeConfigure\r\n")));
DialogBox( hInst,MAKEINTRESOURCE(DIALOGCONFIG),hWnd,ConfigDialogProc);
InvalidateRect(hWnd,NULL,FALSE);
return TRUE;
}
DWORD WINAPI ImeConversionList(HIMC hIMC,LPCTSTR lpSource,LPCANDIDATELIST lpCandList,DWORD dwBufLen,UINT uFlag)
{
//DebugLog(1,(DebugLogFile,"ImeConversionList\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeConversionList\r\n")));
return 0;
}
BOOL WINAPI ImeDestroy(UINT uForce)
{
//DebugLog(1,(DebugLogFile,"ImeDestroy\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeDestroy\r\n")));
return FALSE;
}
LRESULT WINAPI ImeEscape(HIMC hIMC,UINT uSubFunc,LPVOID lpData)
{
//DebugLog(1,(DebugLogFile,"ImeEscape\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeEscape\r\n")));
return FALSE;
}
BOOL WINAPI ImeProcessKey(HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
{
BOOL fRet = FALSE;
BOOL fOpen;
BOOL fCompStr = FALSE;
LPINPUTCONTEXT lpIMC;
LPCOMPOSITIONSTRING lpCompStr;
static BOOL fPressOther = FALSE;
// static BOOL fFirst = TRUE;
//DebugLog(1,(DebugLogFile,"ImeProcessKey\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeProcessKey\r\n")));
if ((lKeyData & 0x80000000) && vKey != VK_CONTROL)
return FALSE;
if (!(lKeyData & 0x80000000) && vKey == VK_CONTROL)
return FALSE;
if (lpbKeyState[VK_MENU] & 0x80 ) return FALSE;
if(vKey != VK_CONTROL && lpbKeyState[VK_CONTROL] & 0x80 ) {
fPressOther = TRUE;
return FALSE;
}
if (!(lpIMC = ImmLockIMC(hIMC)))
return FALSE;
fOpen = lpIMC->fOpen;
if(vKey == VK_CONTROL && (lKeyData & 0x80000000) && !fPressOther){ // && !fFirst){
GENEMSG GnMsg;
fPressOther = FALSE;
if(fOpen) {
lpIMC->fOpen=FALSE;
MakeResultString(hIMC,FALSE);
}
else lpIMC->fOpen=TRUE;
GnMsg.msg = WM_IME_NOTIFY;
GnMsg.wParam = IMN_SETOPENSTATUS;
GnMsg.lParam = 0;
GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
return FALSE;
}
fPressOther = FALSE;
// if(fFirst) fFirst = FALSE;
/*
//if CapsLock is pressed ,then return false;
if (lpbKeyState[VK_CAPITAL] & 0x01) {
return FALSE;
}
if (fOpen)
{
if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
{
if ((lpCompStr->dwSize > sizeof(COMPOSITIONSTRING)) &&
(lpCompStr->dwCompStrLen))
fCompStr = TRUE;
ImmUnlockIMCC(lpIMC->hCompStr);
}
if (dwConversionMode & CONVERSION_MODE_FULLSHAPE){
if (lpbKeyState[VK_SHIFT] & 0x80)
{
if (fCompStr)
fRet = (BOOL)bFullCompSht[vKey];
else
fRet = (BOOL)bFullNoCompSht[vKey];
}
else
{
if (fCompStr)
fRet = (BOOL)bFullComp[vKey];
else
fRet = (BOOL)bFullNoComp[vKey];
}
}
else{
if (lpbKeyState[VK_SHIFT] & 0x80)
{
if (fCompStr)
fRet = (BOOL)bCompSht[vKey];
else
fRet = (BOOL)bNoCompSht[vKey];
}
else
{
if (fCompStr)
fRet = (BOOL)bComp[vKey];
else
fRet = (BOOL)bNoComp[vKey];
}
}
}
*/
if (fOpen)
{
if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
{
if ((lpCompStr->dwSize > sizeof(COMPOSITIONSTRING)) &&
(lpCompStr->dwCompStrLen))
fCompStr = TRUE;
ImmUnlockIMCC(lpIMC->hCompStr);
}
if (fCompStr)
fRet = (BOOL)bComp[vKey];
else
fRet = (BOOL)bNoComp[vKey];
}
ImmUnlockIMC(hIMC);
return fRet;
}
BOOL WINAPI ImeSelect(HIMC hIMC, BOOL fSelect)
{
LPINPUTCONTEXT lpIMC;
//DebugLog(1,(DebugLogFile,"ImeSelect\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeSelect\r\n")));
if (fSelect)
UpdateIndicIcon(hIMC);
// it's NULL context.
if (!hIMC)
return TRUE;
if (lpIMC = ImmLockIMC(hIMC))
{
if (fSelect)
{
LPCOMPOSITIONSTRING lpCompStr;
LPCANDIDATEINFO lpCandInfo;
HKEY hKey;
DWORD dwConvSet;
DWORD dwData = sizeof(DWORD);
BOOL fFlag = TRUE;
// Init the general member of IMC.
lpIMC->fOpen=TRUE;
lpIMC->hCompStr = ImmReSizeIMCC(lpIMC->hCompStr,sizeof(MYCOMPSTR));
if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
{
InitCompStr(lpCompStr);
ImmUnlockIMCC(lpIMC->hCompStr);
}
lpIMC->hCandInfo = ImmReSizeIMCC(lpIMC->hCandInfo,sizeof(MYCAND));
if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
{
InitCandInfo(lpCandInfo);
ImmUnlockIMCC(lpIMC->hCandInfo);
}
if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("Software\\freepy"),
0,
KEY_READ,
&hKey) == ERROR_SUCCESS ){
if( RegQueryValueEx( hKey,
_T("ConversionSet"),
NULL,
NULL,
(LPBYTE)&dwConvSet,
&dwData) == ERROR_SUCCESS ){
wConversionSet = (WORD) dwConvSet;
fFlag = FALSE;
}
RegCloseKey(hKey);
}
if( fFlag) {
wConversionSet = CONVERSION_SET_PUNCT;
wConversionSet |= CONVERSION_SET_SORT;
wConversionSet |= CONVERSION_SET_FOLLOW;
wConversionSet |= CONVERSION_SET_GBK;
}
}
}
ImmUnlockIMC(hIMC);
return TRUE;
}
BOOL WINAPI ImeSetActiveContext(HIMC hIMC,BOOL fFlag)
{
//DebugLog(1,(DebugLogFile,"ImeSetActiveContext\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeSetActiveContext\r\n")));
UpdateIndicIcon(hIMC);
return TRUE;
}
UINT WINAPI ImeToAsciiEx (UINT uVKey,UINT uScanCode,CONST LPBYTE lpbKeyState,LPDWORD lpdwTransKey,UINT fuState,HIMC hIMC)
{
LPARAM lParam;
LPINPUTCONTEXT lpIMC;
BOOL fOpen;
//DebugLog(1,(DebugLogFile,"ImeToAsciiEx\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeToAsciiEx\r\n")));
lpdwCurTransKey = lpdwTransKey;
lParam = ((DWORD)uScanCode << 16) + 1L;
// Init uNumTransKey here.
uNumTransKey = 0;
// if hIMC is NULL, this means DISABLE IME.
if (!hIMC)
return 0;
if (!(lpIMC = ImmLockIMC(hIMC)))
return 0;
fOpen = lpIMC->fOpen;
ImmUnlockIMC(hIMC);
// The current status of IME is "closed".
if (!fOpen)
goto my_exit;
if (uScanCode & 0x8000)
IMEKeyupHandler( hIMC, uVKey, lParam, lpbKeyState);
else
IMEKeydownHandler( hIMC, uVKey, lParam, lpbKeyState);
// Clear static value, no more generated message!
lpdwCurTransKey = NULL;
my_exit:
// If trans key buffer that is allocated by USER.EXE full up,
// the return value is the negative number.
if (fOverTransKey)
{
return (int)uNumTransKey;
}
return (int)uNumTransKey;
}
BOOL WINAPI NotifyIME(HIMC hIMC,DWORD dwAction,DWORD dwIndex,DWORD dwValue)
{
BOOL bRet = FALSE;
LPINPUTCONTEXT lpIMC;
//DebugLog(1,(DebugLogFile,"NotifyIME\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME\r\n")));
switch(dwAction)
{
case NI_OPENCANDIDATE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_OPENCANDIDATE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_OPENCANDIDATE\r\n")));
break;
case NI_CLOSECANDIDATE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CLOSECANDIDATE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CLOSECANDIDATE\r\n")));
break;
case NI_SELECTCANDIDATESTR:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_SELECTCANDIDATESTR\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_SELECTCANDIDATESTR\r\n")));
break;
case NI_CHANGECANDIDATELIST:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CHANGECANDIDATELIST\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CHANGECANDIDATELIST\r\n")));
break;
case NI_SETCANDIDATE_PAGESTART:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_SETCANDIDATE_PAGESTART\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_SETCANDIDATE_PAGESTART\r\n")));
break;
case NI_SETCANDIDATE_PAGESIZE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_SETCANDIDATE_PAGESIZE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_SETCANDIDATE_PAGESIZE\r\n")));
break;
case NI_CONTEXTUPDATED:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED\r\n")));
switch (dwValue)
{
case IMC_SETCONVERSIONMODE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETCONVERSIONMODE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETCONVERSIONMODE\r\n")));
break;
case IMC_SETSENTENCEMODE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETSENTENCEMODE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETSENTENCEMODE\r\n")));
break;
case IMC_SETCANDIDATEPOS:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETCANDIDATEPOS\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETCANDIDATEPOS\r\n")));
break;
case IMC_SETCOMPOSITIONFONT:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETCOMPOSITIONFONT\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETCOMPOSITIONFONT\r\n")));
break;
case IMC_SETCOMPOSITIONWINDOW:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETCOMPOSITIONWINDOW\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETCOMPOSITIONWINDOW\r\n")));
break;
case IMC_SETOPENSTATUS:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_CONTEXTUPDATED:IMC_SETOPENSTATUS\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_CONTEXTUPDATED:IMC_SETOPENSTATUS\r\n")));
lpIMC = ImmLockIMC(hIMC);
if (lpIMC)
{
if (!lpIMC->fOpen && IsCompStr(hIMC))
MakeResultString( hIMC,FALSE);
ImmUnlockIMC(hIMC);
}
UpdateIndicIcon(hIMC);
bRet = TRUE;
break;
default:
break;
}
break;
case NI_COMPOSITIONSTR:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_COMPOSITIONSTR\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_COMPOSITIONSTR\r\n")));
switch (dwIndex)
{
case CPS_COMPLETE:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_COMPOSITIONSTR:CPS_COMPLETE\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_COMPOSITIONSTR:CPS_COMPLETE\r\n")));
break;
case CPS_CONVERT:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_COMPOSITIONSTR:CPS_CONVERT\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_COMPOSITIONSTR:CPS_CONVERT\r\n")));
break;
case CPS_REVERT:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_COMPOSITIONSTR:CPS_REVERT\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_COMPOSITIONSTR:CPS_REVERT\r\n")));
break;
case CPS_CANCEL:
//DebugLog(1,(DebugLogFile,"NotifyIME:NI_COMPOSITIONSTR:CPS_CANCEL\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("NotifyIME:NI_COMPOSITIONSTR:CPS_CANCEL\r\n")));
break;
default:
break;
}
break;
default:
break;
}
return bRet;
}
BOOL WINAPI ImeRegisterWord(LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr)
{
//DebugLog(1,(DebugLogFile,"ImeRegisterWord\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeRegisterWord\r\n")));
return FALSE;
}
BOOL WINAPI ImeUnregisterWord(LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr)
{
//DebugLog(1,(DebugLogFile,"ImeUnregisterWord\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeUnregisterWord\r\n")));
return FALSE;
}
UINT WINAPI ImeGetRegisterWordStyle(UINT nItem, LPSTYLEBUF lp)
{
//DebugLog(1,(DebugLogFile,"ImeGetRegisterWordStyle\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeGetRegisterWordStyle\r\n")));
return 0;
}
UINT WINAPI ImeEnumRegisterWord(REGISTERWORDENUMPROC lpfn, LPCTSTR lpRead, DWORD dw, LPCTSTR lpStr, LPVOID lpData)
{
//DebugLog(1,(DebugLogFile,"ImeEnumRegisterWord\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeEnumRegisterWord\r\n")));
return 0;
}
BOOL WINAPI ImeSetCompositionString(HIMC hIMC, DWORD dwIndex, LPCVOID lpComp, DWORD dwComp, LPCVOID lpRead, DWORD dwRead)
{
//DebugLog(1,(DebugLogFile,"ImeSetCompositionString\r\n")));
RETAILMSG(DEBUGMODE,(TEXT("ImeSetCompositionString\r\n")));
return FALSE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function:
ImeGetImeMenuItems
[Owner:]
Hidei
Description:
This API gets the menu items that are registered in IME Menu.
[Arguments:]
IN HIMC hIMC - The lpMenuItem contains menu items
that are related to this input context.
IN DWORD dwFlags - The combination of the following bits.
IGIMIF_RIGHTMENU
If this bit is 1, this function
returns the menu items for right
click context menu.
IN DWORD dwType - The combination of the following bits.
IGIMII_CMODE
This function returns the menu items
that are related to conversion mode.
IGIMII_SMODE
This function returns the menu items
that are related to sentence mode.
IGIMII_CONFIGURE
This function returns the menu items
that are related to configuration of
IME.
IGIMII_TOOLS
This function returns the menu items
that are related to IME tools.
IGIMII_HELP
This function returns the menu items
that are related to IME help.
IGIMII_OTHER
This function returns the menu items
that are related to others.
IGIMII_INPUTTOOLS
This function returns the menu items
that are related to IME input tools
that provide the extended way to input
the charactors.
IN LPMENUITEMINFO lpImeParentMenu - The pointer to the IMEMENUINFO Structure that
has MFT_SUBMENU in fType. This function will
return the submenu items of this menu item.
If this is NULL lpImeMenu contains the top
level ime menu items.
IN OUT LPMENUITEMINFO lpImeMenu - The pointer to the buffer to receive the
contents of Menu Items. This buffer will be
the array of IMEMENUITEMINFO structure.
If this is NULL, this API returns the number
of the registered Menu Items.
IN DWORD dwSize - The size of buffer to receive IMEMENUITEMINFO
Structure
[Return Value:]
The return value is the number of the menu items that were set into lpIM.
If lpImeMenu is NULL, this function return the number of menu items that
are registered in the specified hKL.
-------------------------------------------------------------------*/
DWORD WINAPI ImeGetImeMenuItems(HIMC hIMC, DWORD dwFlags, DWORD dwType,
LPIMEMENUITEMINFOW lpParentMenu,
LPIMEMENUITEMINFOW lpMenu, DWORD dwSize)
{
//
// We don't support ImeGetImeMenuItems. so this API always returns 0.
//
return 0;
}