subs.c
资源名称:大熊猫输入法原码.zip [点击查看]
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:33k
源码类别:
输入法编程
开发平台:
C/C++
- /* 大熊猫输入法(Free Chinese Input) 由YJMSIR(yjmsir@163.com)编写
- * 协议: GPL
- * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
- * Licence: GPL
- */
- #include "freepy.h"
- void GetRelativeTableDirList()
- {
- WIN32_FIND_DATA ffd;
- char szDirFile[1024];
- HANDLE hFind;
- sprintf(szDirFile,"%s//mb//*",InstallFromDir);
- hFind = FindFirstFile(szDirFile,&ffd);
- if (hFind != INVALID_HANDLE_VALUE)
- {
- int i=0;
- if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
- strcmp(ffd.cFileName,".") &&
- strcmp(ffd.cFileName,".."))
- {//确定找到一个目录并且不为 . 或 ..
- sprintf(RelativeTableDirList[i],"%s",ffd.cFileName);
- i++;
- }
- while(FindNextFile(hFind,&ffd))
- {
- if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
- strcmp(ffd.cFileName,".") &&
- strcmp(ffd.cFileName,".."))
- {//确定找到一个目录并且不为 . 或 ..
- sprintf(RelativeTableDirList[i],"%s",ffd.cFileName);
- i++;
- }
- }
- FindClose(hFind);
- }
- }
- BOOL IsFileExist(LPCSTR pszFileName)
- {
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- hFind = FindFirstFile(pszFileName, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- return FALSE;//not found
- else
- {
- FindClose(hFind);
- return TRUE;//found it
- }
- }
- void ReadRegRecord()
- {
- HKEY hKey;
- DWORD dwData = sizeof(DWORD),dwData1 = MAX_PATH,dwData2 = MAX_PATH;
- if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- REGKEYNAME,
- 0,
- KEY_READ,
- &hKey) == ERROR_SUCCESS ){
- RegQueryValueEx( hKey,
- _T("InstallFromDir"),
- NULL,
- NULL,
- (LPBYTE)InstallFromDir,
- &dwData1);
- }
- RegCloseKey(hKey);
- }
- BOOL IsIMEOpen(HIMC hIMC)//输入法是否打开
- {
- BOOL fOpen;
- LPINPUTCONTEXT lpIMC;
- if (!(lpIMC = ImmLockIMC(hIMC)))
- return FALSE;
- fOpen = lpIMC->fOpen;
- ImmUnlockIMC(hIMC);
- return fOpen;
- }
- BOOL IsCompStr(HIMC hIMC)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- BOOL fRet = FALSE;
- if (!(lpIMC = ImmLockIMC(hIMC)))
- return FALSE;
- if (ImmGetIMCCSize(lpIMC->hCompStr) < sizeof (COMPOSITIONSTRING))
- {
- ImmUnlockIMC(hIMC);
- return FALSE;
- }
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- fRet = (lpCompStr->dwCompStrLen > 0);
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return fRet;
- }
- /**********************************************************************/
- /* */
- /* InitCompStr() */
- /* */
- /**********************************************************************/
- void InitCompStr(LPCOMPOSITIONSTRING lpCompStr)
- {
- LPFREEPYCOMP lpFreePYComp;
- lpCompStr->dwSize = sizeof(MYCOMPSTR);
- lpCompStr->dwCompStrOffset =
- (DWORD)((LPMYCOMPSTR)lpCompStr)->szCompStr - (DWORD)lpCompStr;
- lpCompStr->dwCompStrLen = 0;
- *GETLPCOMPSTR(lpCompStr) = _T(' ');
- lpCompStr->dwResultStrOffset =
- (DWORD)((LPMYCOMPSTR)lpCompStr)->szResultStr - (DWORD)lpCompStr;
- lpCompStr->dwResultStrLen = 0;
- *GETLPRESULTSTR(lpCompStr) = _T(' ');
- lpCompStr->dwCursorPos = 0;
- lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
- lpFreePYComp->szConvCompStr[0] = _T(' ');
- lpFreePYComp->szPaintCompStr[0] = _T(' ');
- lpFreePYComp->szPreResultStr[0] = _T(' ');
- lpFreePYComp->wEditCaret = 0;
- lpFreePYComp->wUnConvPos = 0;
- lpFreePYComp->wPYArrayLen = 0;
- lpFreePYComp->wPYArrayCurPos = 0;
- }
- void ClearCompStr(LPCOMPOSITIONSTRING lpCompStr)
- {
- LPFREEPYCOMP lpFreePYComp;
- lpCompStr->dwCursorPos = 0;
- lpCompStr->dwCompStrLen = 0;
- ((LPMYCOMPSTR)lpCompStr)->szCompStr[0] = _T(' ');
- lpCompStr->dwResultStrLen = 0;
- ((LPMYCOMPSTR)lpCompStr)->szResultStr[0] = _T(' ');
- lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
- lpFreePYComp->szConvCompStr[0] = _T(' ');
- lpFreePYComp->szPaintCompStr[0] = _T(' ');
- lpFreePYComp->wEditCaret = 0;
- lpFreePYComp->wUnConvPos = 0;
- lpFreePYComp->wPYArrayLen = 0;
- lpFreePYComp->wPYArrayCurPos = 0;
- }
- BOOL IsCandidate(HIMC hIMC)
- {
- LPINPUTCONTEXT lpIMC;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- BOOL fRet = FALSE;
- if (!(lpIMC = ImmLockIMC(hIMC)))
- return FALSE;
- if (ImmGetIMCCSize(lpIMC->hCandInfo) < sizeof (CANDIDATEINFO)){
- ImmUnlockIMC(hIMC);
- return FALSE;
- }
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);
- fRet = (lpCandList->dwCount > 0);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- return fRet;
- }
- void InitCandInfo(LPCANDIDATEINFO lpCandInfo)
- {
- LPCANDIDATELIST lpCandList;
- LPFREEPYCAND lpFreePYCand;
- int i;
- lpCandInfo->dwSize = sizeof(MYCAND);
- lpCandInfo->dwCount = 1;
- lpCandInfo->dwOffset[0] = (DWORD)(&(((LPMYCAND)lpCandInfo)->cl)) - (DWORD)lpCandInfo;
- lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);
- for(i=0;i<MAXCANDSTRNUM;i++) {
- lpCandList->dwOffset[i] = (DWORD)((LPMYCAND)lpCandInfo)->szCandStr[i] - (DWORD)lpCandList;
- }
- lpCandList->dwSize = sizeof(MYCAND) - sizeof(CANDIDATEINFO);
- lpCandList->dwCount = 0L;
- lpCandList->dwSelection = 0L;
- lpCandList->dwPageStart = 0L;
- lpCandList->dwPageSize = 0L;
- lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
- lpFreePYCand->wPhraseNum = 0;
- lpFreePYCand->wHZNum = 0;
- lpFreePYCand->wKeyLen = 0;
- lpFreePYCand->awKey[0] = 0;
- }
- void ClearCandidate(LPCANDIDATEINFO lpCandInfo)
- {
- LPFREEPYCAND lpFreePYCand;
- ((LPMYCAND)lpCandInfo)->cl.dwCount =0L;
- ((LPMYCAND)lpCandInfo)->cl.dwSelection =0L;
- ((LPMYCAND)lpCandInfo)->cl.dwPageStart =0L;
- ((LPMYCAND)lpCandInfo)->cl.dwPageSize =0L;
- lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
- lpFreePYCand->wPhraseNum = 0;
- lpFreePYCand->wHZNum = 0;
- lpFreePYCand->wKeyLen = 0;
- lpFreePYCand->awKey[0] = 0;
- }
- HKL GetMyHKL()
- {
- DWORD dwSize;
- DWORD dwi;
- HKL hKL = 0;
- HKL *lphkl;
- dwSize = GetKeyboardLayoutList(0, NULL);
- lphkl = (HKL *)GlobalAlloc(GPTR, dwSize * sizeof(DWORD));
- if (!lphkl)
- return NULL;
- GetKeyboardLayoutList(dwSize, lphkl);
- for (dwi = 0; dwi < dwSize; dwi++)
- {
- char szFile[32];
- HKL hKLTemp = *(lphkl + dwi);
- ImmGetIMEFileName(hKLTemp, szFile, sizeof(szFile));
- if (!_tcsicmp(szFile, FREEPYFILENAME))
- {
- hKL = hKLTemp;
- goto exit;
- }
- }
- exit:
- GlobalFree((HANDLE)lphkl);
- return hKL;
- }
- /*****************************************************************************
- * *
- * UpdateIndicIcon( hIMC ) *
- * *
- *****************************************************************************/
- void UpdateIndicIcon(HIMC hIMC)
- {
- HWND hwndIndicate;
- BOOL fOpen = FALSE;
- LPINPUTCONTEXT lpIMC;
- if (!hFreePYKL)
- {
- hFreePYKL = GetMyHKL();
- if (!hFreePYKL)
- return;
- }
- hwndIndicate = FindWindow(INDICATOR_CLASS, NULL);
- if (hIMC)
- {
- lpIMC = ImmLockIMC(hIMC);
- if (lpIMC)
- {
- fOpen = lpIMC->fOpen;
- ImmUnlockIMC(hIMC);
- }
- }
- if (IsWindow(hwndIndicate))
- {
- ATOM atomTip;
- atomTip = GlobalAddAtom(ATOMTIP1);
- PostMessage(hwndIndicate, INDICM_SETIMEICON,
- fOpen ? 1 : (-1), (LPARAM)hFreePYKL);
- PostMessage(hwndIndicate, INDICM_SETIMETOOLTIPS,
- fOpen ? atomTip : (-1), (LPARAM)hFreePYKL);
- PostMessage(hwndIndicate, INDICM_REMOVEDEFAULTMENUITEMS,
- // fOpen ? (RDMI_LEFT | RDMI_RIGHT) : 0, (LPARAM)hMyKL);
- fOpen ? (RDMI_LEFT) : 0, (LPARAM)hFreePYKL);
- }
- }
- /**********************************************************************/
- /* */
- /* MyIsIMEMessage(message) */
- /* */
- /* Any UI window should not pass the IME messages to DefWindowProc. */
- /* */
- /**********************************************************************/
- BOOL MyIsIMEMessage(UINT message)
- {
- switch(message){
- case WM_IME_STARTCOMPOSITION:
- case WM_IME_ENDCOMPOSITION:
- case WM_IME_COMPOSITION:
- case WM_IME_NOTIFY:
- case WM_IME_SETCONTEXT:
- case WM_IME_CONTROL:
- case WM_IME_COMPOSITIONFULL:
- case WM_IME_SELECT:
- case WM_IME_CHAR:
- return TRUE;
- }
- return FALSE;
- }
- BOOL MakeResultString( HIMC hIMC,BOOL fFlag)
- {
- GENEMSG GnMsg;
- LPCOMPOSITIONSTRING lpCompStr;
- LPINPUTCONTEXT lpIMC;
- LPTSTR lpConvStr,lpPreResultStr,WubiCode,lpStr;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- char AutoSaveWubiCode[5],AutoSaveWubiChr[3];
- WORD ConvStrLength,i;
- LPTSTR lpDest;
- static TCHAR PreThreeConvStr[3][MAXSTRHZLENGTH*3]={0};
- /*
- if (!IsCompStr(hIMC))
- return FALSE;
- */
- dwCurPhraseAttrib=0;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- lpStr = GETLPCOMPSTR(lpCompStr);
- if(fFlag) {
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETSTATUSWINDOWPOS;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
- if(PunctPushWordFlag){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- if(wConversionMode == CONVERSION_MODE_ENGLISH){
- _tcscpy(lpConvStr,lpStr);
- goto Noaddhistory;//Word_Existed_Hint_next;
- }
- lpPreResultStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr;
- for(i=0;i<=1;i++){
- _tcscpy(PreThreeConvStr[2-i],PreThreeConvStr[1-i]);
- _tcscat(PreThreeConvStr[2-i],lpConvStr);
- }
- _tcscpy(PreThreeConvStr[0],lpPreResultStr);
- _tcscat(PreThreeConvStr[0],lpConvStr);
- _tcscpy(lpPreResultStr,lpConvStr);
- if(wConversionMode == CONVERSION_MODE_WUBI) _tcscpy(szPreResultCode,lpStr);
- //保存输入历史记录
- ConvStrLength=_tcslen(lpConvStr);
- InputAccumulateNum+=ConvStrLength;//输出数目的累积
- if(ConvStrLength%2 || wConversionMode != CONVERSION_MODE_WUBI) goto Noaddhistory;
- //如果是奇数位,可能产生错误,干脆取消
- if(_tcslen(WordHistoryStr)>MAXHISTORYNUM-100){
- _tcscpy(WordHistoryStr,WordHistoryStr+200);
- _tcscpy(HistoryTwoCodes,HistoryTwoCodes+200);
- }
- //自动保存编码首两位
- for(i=0;i<ConvStrLength;i+=2){
- AutoSaveWubiChr[0]=lpConvStr[i];
- AutoSaveWubiChr[1]=lpConvStr[i+1];
- AutoSaveWubiChr[2]=' ';
- //完备了,不会再产生错误了。
- if(wConversionSet &CONVERSION_SET_STANDARDSEARCH)
- {
- if(QueryQuickSearchTablegbk(AutoSaveWubiChr,AutoSaveWubiCode)){
- _tcscat(WordHistoryStr,AutoSaveWubiChr);
- AutoSaveWubiCode[2]=' ';
- _tcscat(HistoryTwoCodes,AutoSaveWubiCode);
- }
- }
- else
- if(WubiCode=FindWuBiCode (AutoSaveWubiChr)){
- _tcscat(WordHistoryStr,AutoSaveWubiChr);
- _tcscpy(AutoSaveWubiCode,WubiCode);
- AutoSaveWubiCode[2]=' ';
- _tcscat(HistoryTwoCodes,AutoSaveWubiCode);
- }
- }
- Noaddhistory:
- //
- if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
- (wConversionMode == CONVERSION_MODE_WUBI)){
- _tcscpy(YJMMessage,"");
- if(lpDest = _tcsstr(WordHistoryStr,PreThreeConvStr[0])){
- lpDest+=_tcslen(PreThreeConvStr[0]);
- _tcsncpy(YJMMessage,lpDest,20);//10个汉字
- }
- }
- //
- if(wConversionSet & CONVERSION_SET_JP)
- gb2jfb(GB2JP,lpConvStr);
- else if(wConversionSet & CONVERSION_SET_GBJT2FT)
- gb2jfb(GB2FT,lpConvStr);
- else if(wConversionSet & CONVERSION_SET_BIG5)
- gb2jfb(GB2BIG5,lpConvStr);
- _tcscpy(GETLPRESULTSTR(lpCompStr),lpConvStr);//?
- lpCompStr->dwResultStrLen = _tcslen(lpConvStr);
- }
- else{//false在此处理
- if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
- wConversionMode =wPreConversionMode;
- lpCandList->dwCount = 0;
- lpCompStr->dwCompStrLen = 0;
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
- //_tcscpy(GETLPCANDSTR(lpCandList,2),_T(""));
- //_tcscpy(YJMMessage,"");
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- GnMsg.msg = WM_IME_ENDCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_makestring_exit;
- }
- lpCandList->dwCount = 0;
- lpCompStr->dwCompStrLen = 0;
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
- //
- if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
- (wConversionMode == CONVERSION_MODE_WUBI)&& _tcslen(YJMMessage)){
- _tcscpy(GETLPCANDSTR(lpCandList,2),YJMMessage);
- //_tcscpy(GETLPCANDSTR(lpCandList,3),_T("用法:\+数字"));
- lpCandList->dwCount=1;
- lpCompStr->dwCompStrLen = 0;
- }
- else if((wConversionSet1 & C_SET1_Word_Existed_Hint) &&
- (wConversionMode == CONVERSION_MODE_WUBI)){
- for(i=0;i<=2;i++){
- if(_tcslen(PreThreeConvStr[2-i])>ConvStrLength &&
- (WubiCode=FindWuBiCode(PreThreeConvStr[2-i]))){
- _stprintf(YJMMessage,_T("已有词组:%s %s"),PreThreeConvStr[2-i],WubiCode);
- _tcscpy(GETLPCANDSTR(lpCandList,2),YJMMessage);
- lpCandList->dwCount=1;
- lpCompStr->dwCompStrLen = 0;
- goto Word_Existed_Hint_next;
- }
- }
- }
- Word_Existed_Hint_next:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_RESULTSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- GnMsg.msg = WM_IME_ENDCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- //
- my_makestring_exit:
- if(wConversionMode == CONVERSION_MODE_ATTACHLIB){
- AttachLibDictCurrentRecord=AttachLibDictHead->next;
- }
- else if(wConversionMode == CONVERSION_MODE_WUBI){
- wubiDictCurrentRecord=wubiDictHead->next;
- }
- else if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB){
- AttachLibDictCurrentRecord=AttachLibDictHead->next;
- wubiDictCurrentRecord=wubiDictHead->next;
- }
- if(fTempState){
- wConversionMode = wPreConversionMode;
- UpdateStatusByMessage(hIMC);
- fTempState=0;
- }
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- /**********************************************************************/
- /* */
- /* GenerateMessage() */
- /* */
- /* Update the transrate key buffer. */
- /* */
- /**********************************************************************/
- BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
- {
- LPINPUTCONTEXT lpIMC;
- if( (lpIMC = ImmLockIMC(hIMC)) == NULL ) return FALSE;
- if (lpdwTransKey){
- ImmUnlockIMC(hIMC);
- return GenerateMessageToTransKey(lpdwTransKey,lpGeneMsg);
- }
- if (IsWindow(lpIMC->hWnd)){
- LPDWORD lpdw;
- if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
- sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
- return FALSE;
- if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
- return FALSE;
- lpdw += (lpIMC->dwNumMsgBuf) * 3;
- *((LPGENEMSG)lpdw) = *lpGeneMsg;
- ImmUnlockIMCC(lpIMC->hMsgBuf);
- lpIMC->dwNumMsgBuf++;
- ImmGenerateMessage(hIMC);
- }
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- /**********************************************************************/
- /* GenerateMessageToTransKey() */
- /* */
- /* Update the transrate key buffer. */
- /**********************************************************************/
- BOOL GenerateMessageToTransKey(LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
- {
- LPDWORD lpdwTemp;
- uNumTransKey++;
- if (uNumTransKey >= (UINT)*lpdwTransKey)
- {
- fOverTransKey = TRUE;
- return FALSE;
- }
- lpdwTemp = (LPDWORD)lpdwTransKey + 1 + (uNumTransKey - 1)*3;
- *(lpdwTemp++) = lpGeneMsg->msg;
- *(lpdwTemp++) = lpGeneMsg->wParam;
- *(lpdwTemp++) = lpGeneMsg->lParam;
- return TRUE;
- }
- /**********************************************************************/
- /* */
- /* DrawUIBorder() */
- /* */
- /* When draging the child window, this function draws the border. */
- /* */
- /**********************************************************************/
- void DrawUIBorder( LPRECT lprc )
- {
- HDC hDC;
- int sbx, sby;
- hDC = CreateDC( "DISPLAY", NULL, NULL, NULL );
- SelectObject( hDC, GetStockObject( GRAY_BRUSH ) );
- sbx = GetSystemMetrics( SM_CXBORDER );
- sby = GetSystemMetrics( SM_CYBORDER );
- PatBlt( hDC, lprc->left,
- lprc->top,
- lprc->right - lprc->left-sbx,
- sby, PATINVERT );
- PatBlt( hDC, lprc->right - sbx,
- lprc->top,
- sbx,
- lprc->bottom - lprc->top-sby, PATINVERT );
- PatBlt( hDC, lprc->right,
- lprc->bottom-sby,
- -(lprc->right - lprc->left-sbx),
- sby, PATINVERT );
- PatBlt( hDC, lprc->left,
- lprc->bottom,
- sbx,
- -(lprc->bottom - lprc->top-sby), PATINVERT );
- DeleteDC( hDC );
- }
- void DragUI( HWND hWnd, HWND hWnd1,UINT message, WPARAM wParam, LPARAM lParam,BOOL fIsCompWnd)
- {
- POINT pt;
- static POINT ptdif,ptdif1;
- static RECT drc,drc1;
- static SIZE sz,sz1;
- DWORD dwT;
- switch (message)
- {
- case WM_SETCURSOR:
- if ( HIWORD(lParam) == WM_LBUTTONDOWN
- || HIWORD(lParam) == WM_RBUTTONDOWN )
- {
- GetCursorPos( &pt );
- SetCapture(hWnd);
- GetWindowRect(hWnd,&drc);
- ptdif.x = pt.x - drc.left;
- ptdif.y = pt.y - drc.top;
- sz.cx = drc.right - drc.left;
- sz.cy = drc.bottom - drc.top;
- if (IsWindow(hWnd1)) {
- GetWindowRect(hWnd1,&drc1);
- ptdif1.x = pt.x - drc1.left;
- ptdif1.y = pt.y - drc1.top;
- sz1.cx = drc1.right - drc1.left;
- sz1.cy = drc1.bottom - drc1.top;
- }
- SetWindowLong(hWnd,FIGWL_MOUSE,FIM_CAPUTURED);
- }
- break;
- case WM_MOUSEMOVE:
- dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
- if (dwT & FIM_MOVED)
- {
- DrawUIBorder(&drc);
- if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
- GetCursorPos( &pt );
- drc.left = pt.x - ptdif.x;
- drc.top = pt.y - ptdif.y;
- drc.right = drc.left + sz.cx;
- drc.bottom = drc.top + sz.cy;
- if (IsWindow(hWnd1)) {
- drc1.left = pt.x - ptdif1.x;
- drc1.top = pt.y - ptdif1.y;
- drc1.right = drc1.left + sz1.cx;
- drc1.bottom = drc1.top + sz1.cy;
- }
- DrawUIBorder(&drc);
- if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
- }
- else if (dwT & FIM_CAPUTURED)
- {
- DrawUIBorder(&drc);
- if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
- SetWindowLong(hWnd,FIGWL_MOUSE,dwT | FIM_MOVED);
- }
- break;
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
- if (dwT & FIM_CAPUTURED)
- {
- ReleaseCapture();
- if (dwT & FIM_MOVED)
- {
- DrawUIBorder(&drc);
- if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
- GetCursorPos( &pt );
- MoveWindow(hWnd,pt.x - ptdif.x,
- pt.y - ptdif.y,
- sz.cx,
- sz.cy,TRUE);
- if(fIsCompWnd) {
- HWND hUIWnd;
- LPARAM mylParam;
- *((LPWORD)(&mylParam)) = (WORD)(pt.x - ptdif.x);
- *((LPWORD)(&mylParam)+1) = (WORD)(pt.y - ptdif.y);
- hUIWnd = (HWND)GetWindowLong(hWnd,FIGWL_SVRWND);
- if (IsWindow(hUIWnd))
- SendMessage(hUIWnd,WM_UI_COMPMOVE,0,mylParam);
- }
- if (IsWindow(hWnd1)) {
- MoveWindow(hWnd1,pt.x - ptdif1.x,
- pt.y - ptdif1.y,
- sz1.cx,
- sz1.cy,TRUE);
- }
- }
- }
- break;
- }
- }
- void SelectCandFromCandlist( HIMC hIMC, WORD wParam)
- {
- if( wParam >= _T('0') && wParam <= _T('9') ){
- DWORD dwIdx;
- LPTSTR lpConvStr,lpStr;
- LPINPUTCONTEXT lpIMC;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- LPCOMPOSITIONSTRING lpCompStr;
- UINT lpConvStrLen;
- lpIMC = ImmLockIMC(hIMC);
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- if( wParam == (WORD)_T('0')) dwIdx=9;
- else dwIdx = wParam - _T('1');
- if(dwIdx < lpCandList->dwPageSize ) {
- dwIdx += lpCandList->dwPageStart;
- //DebugLog(2,(DebugLogFile,"dwIdx: %dn",dwIdx));
- if( dwIdx < (lpCandList->dwCount + 2) && lpCandList->dwCount){
- lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
- _tcscpy(lpConvStr,GETLPCANDSTR(lpCandList,dwIdx));
- lpConvStrLen=_tcslen(lpConvStr);
- //DebugLog(2,(DebugLogFile,"lpConvStr: %sn",lpConvStr));
- //实现五笔的自动提示词的自动加入
- if(wConversionMode == CONVERSION_MODE_WUBI && HaveAutoCandList &&
- (dwIdx==CodeHintTextBegin+1)&&!_tcscmp(AutoWuBiCode1,AutoWuBiCode)){//lpCandList->dwCount+1
- if(wConversionSet1 & C_SET1_ERBIMAKEWORD) AutoGetWordErbiCode(AutoWuBiWord,1);
- else AutoGetWordWubiCode(AutoWuBiWord,1);
- _tcscpy(AutoWuBiCode1,_T(""));
- // SaveWubiUserDict();
- }
- //词频调整,加入if( wConversionSet & CONVERSION_SET_SORT)
- if((wConversionMode == CONVERSION_MODE_WUBI) &&
- (wConversionSet & CONVERSION_SET_SORT) &&
- (lpConvStrLen>2||wConversionSet1 & C_SET1_SingleHZAdjFre)) {
- //AdjustOrderByIndex (dwIdx-2);
- if(dwIdx>CodeHintTextBegin+1 && HaveAutoCandList)
- AdjustOrderByIndexToNo1(dwIdx-3,lpConvStr);
- else
- AdjustOrderByIndexToNo1(dwIdx-2,lpConvStr);
- }
- //DebugLog(2,(DebugLogFile,"dwIdx: %d lpCandList->dwCount:%dn ",dwIdx,lpCandList->dwCount));
- MakeResultString(hIMC,TRUE);
- lpCandList->dwPageStart=2;
- }
- else if(PunctPushWordFlag){
- lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
- _tcscpy(lpConvStr,lpStr);
- lpConvStrLen=_tcslen(lpConvStr);
- }
- else MakeResultString(hIMC,FALSE);
- }
- //myexit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- }
- return;
- }
- void DeleteCharBackward(HIMC hIMC,WORD wParam)
- {
- if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR){
- MakeResultString(hIMC,FALSE);
- }
- else if( wConversionMode == CONVERSION_MODE_I ||
- wConversionMode == CONVERSION_MODE_U ||
- wConversionMode == CONVERSION_MODE_V ) {
- //时间,自定义模式
- LPINPUTCONTEXT lpIMC;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- LPTSTR lpStr;
- lpIMC = ImmLockIMC(hIMC);
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- if( !lpCandList->dwCount ) MakeResultString(hIMC,FALSE);
- else{
- lpCandList->dwCount = 0;
- lpStr = GETLPCOMPSTR(lpCompStr);
- lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
- *lpStr= _T(' ');
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
- *lpStr= _T(' ');
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- }
- else if( wConversionMode == CONVERSION_MODE_WUBIATTACHLIB) {
- //五笔附库模式//退格成功。
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPTSTR lpStr;
- WORD StrLen;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- lpStr = CharPrev(lpStr,lpStr + StrLen);
- *lpStr= _T(' ');
- if(StrLen<=1){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- MakeResultString(hIMC,FALSE);
- return;
- }
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- wParam=*(lpStr+StrLen-1);
- *(lpStr+StrLen-1)=_T(' ');
- wubiDictCurrentRecord=wubiDictHead->next;//应对快速搜索
- AttachLibDictCurrentRecord=AttachLibDictHead->next;//应对快速搜索
- CodeForward=0;
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- CharHandleWuBiAttachLib(hIMC,wParam,0) ;
- }
- else if( wConversionMode == CONVERSION_MODE_WUBI) {
- //五笔模式//退格成功。
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPTSTR lpStr;
- WORD StrLen;
- TCHAR cFirstChr;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- lpStr = CharPrev(lpStr,lpStr + StrLen);
- *lpStr= _T(' ');
- /*if(StrLen==0){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return;
- }
- else*/
- if(StrLen<=1){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- MakeResultString(hIMC,FALSE);
- return;
- }
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- wParam=*(lpStr+StrLen-1);
- *(lpStr+StrLen-1)=_T(' ');
- if(cFirstChr=*lpStr){
- SetwubiFirstLeadChr(cFirstChr);
- wubiDictCurrentRecord=wubiFirstLeadChr[cFirstChr-_T('!')];
- }
- else
- wubiDictCurrentRecord=wubiDictHead->next;//应对快速搜索
- CodeForward=0;
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- CharHandleWuBi(hIMC,wParam,0);
- }
- else if( wConversionMode == CONVERSION_MODE_ATTACHLIB||
- wConversionMode == CONVERSION_MODE_TEMPATTACHLIB) {
- //附加词库模式//退格成功。
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPTSTR lpStr;
- WORD StrLen;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- lpStr = CharPrev(lpStr,lpStr + StrLen);
- *lpStr= _T(' ');
- if(StrLen<=1){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- MakeResultString(hIMC,FALSE);
- return;
- }
- lpStr = GETLPCOMPSTR(lpCompStr);
- StrLen=_tcslen(lpStr);
- wParam=*(lpStr+StrLen-1);
- *(lpStr+StrLen-1)=_T(' ');
- AttachLibDictCurrentRecord=AttachLibDictHead->next;//应对快速搜索
- CodeForward=0;
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- CharHandleAttachLib(hIMC,wParam,0) ;
- }
- else AddChar(hIMC,wParam,EDIT_BACK);
- return;
- }
- void DeleteCharForward(HIMC hIMC,WORD wParam)
- {
- WORD WordHistoryStrLen=_tcslen(WordHistoryStr);
- if(wConversionMode == CONVERSION_MODE_WUBI)
- *(WordHistoryStr+WordHistoryStrLen-2)=_T(' ');
- AddChar(hIMC,wParam,EDIT_DELETE);
- return;
- }
- void SpaceSelect(HIMC hIMC,WORD wParam)
- {
- WORD wCode;
- wCode = (WORD)_T('1');
- //DebugLog(2,(DebugLogFile,"wParam: %d ",wParam));
- if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
- CharHandlePhToCh( hIMC,wCode,0);
- else if( wConversionMode == CONVERSION_MODE_I ||
- wConversionMode == CONVERSION_MODE_U ||
- wConversionMode == CONVERSION_MODE_V ||
- wConversionMode == CONVERSION_MODE_ATTACHLIB ||
- wConversionMode == CONVERSION_MODE_TEMPATTACHLIB ||
- wConversionMode == CONVERSION_MODE_WUBI ||
- wConversionMode == CONVERSION_MODE_WUBIATTACHLIB ) {
- SelectCandFromCandlist( hIMC, wCode);
- }
- else
- SelectCand(hIMC,wCode);
- return;
- }
- void SelectForwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
- {
- HDC hDC;
- HFONT oldFont;
- TCHAR szTotal[200],szTemp[100];
- SIZE sz;
- WORD wPos;
- GENEMSG GnMsg;
- //
- /*if(wConversionMode == CONVERSION_MODE_WUBI&&
- lpCandList->dwPageStart<lpCandList->dwCount-8){
- lpCandList->dwPageStart+=10;
- }*/
- //DebugLog(2,(DebugLogFile,"1 start: %d pagesize: %dn",lpCandList->dwPageStart,lpCandList->dwCount-8));
- //
- if(wConversionSet & CONVERSION_SET_SHAPE) {
- wPos = (WORD) lpCandList->dwSelection;
- if(wPos < lpCandList->dwCount) {
- hDC = GetDC(NULL);
- oldFont = SelectObject(hDC, hUIFont);
- lpCandList->dwPageStart = wPos + 2;
- _tcscpy(szTotal,"<>");
- lpCandList->dwPageSize = 0;
- while(wPos < lpCandList->dwCount && lpCandList->dwPageSize < CAND_PAGESIZE) {
- _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wPos+2));
- _tcscat(szTotal,szTemp);
- GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
- if(sz.cx > sizeCand[1].cx*2) {//yjm
- break;
- }
- (lpCandList->dwPageSize)++;
- wPos++;
- //DebugLog(2,(DebugLogFile,"4 wPos: %d lpCandList->dwPageSize: %dn",wPos,lpCandList->dwPageSize));
- }
- SelectObject(hDC, oldFont);
- ReleaseDC(NULL,hDC);
- lpCandList->dwSelection = wPos;
- if(lpCandList->dwPageStart > 2)
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
- else
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
- if(wPos < lpCandList->dwCount)
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
- else
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- }
- else{
- if( lpCandList->dwPageStart + lpCandList->dwPageSize -2 <
- lpCandList->dwCount) {
- lpCandList->dwPageStart += lpCandList->dwPageSize;
- lpCandList->dwPageSize = CAND_PAGESIZE;
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- }
- }
- void SelectBackwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
- {
- HDC hDC;
- HFONT oldFont;
- TCHAR szTotal[200],szTemp[100];
- SIZE sz;
- WORD wCount;
- GENEMSG GnMsg;
- //
- //DebugLog(2,(DebugLogFile,"1 start: %d pagesize: %dn",lpCandList->dwPageStart,lpCandList->dwCount-8));
- //
- if(lpCandList->dwPageStart > 2) {
- if(wConversionSet & CONVERSION_SET_SHAPE) {
- hDC = GetDC(NULL);
- oldFont = SelectObject(hDC, hUIFont);
- lpCandList->dwSelection = (WORD)lpCandList->dwPageStart - 2;
- wCount = (WORD)lpCandList->dwPageStart - 2;
- _tcscpy(szTotal,"<>");
- lpCandList->dwPageSize = 0;
- while(wCount > 0 && lpCandList->dwPageSize < CAND_PAGESIZE) {
- _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wCount+2));
- _tcscat(szTotal,szTemp);
- GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
- if(sz.cx > sizeCand[1].cx*2) {//yjm
- break;
- }
- (lpCandList->dwPageSize)++;
- wCount--;
- }
- SelectObject(hDC, oldFont);
- ReleaseDC(NULL,hDC);
- lpCandList->dwPageStart -= (lpCandList->dwSelection - wCount);
- if(lpCandList->dwPageStart > 2)
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
- else
- _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
- if(lpCandList->dwSelection < lpCandList->dwCount)
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
- else
- _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
- }
- else {
- if( (int)(lpCandList->dwPageStart) - (int)(lpCandList->dwPageSize) >= 1){
- lpCandList->dwPageStart -= lpCandList->dwPageSize;
- }
- }
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- }
- void SetPaintColor(HDC hDC, WORD wMode)
- {
- if(wMode == CONVERSION_MODE_PHRASETOCHAR) {
- SetTextColor(hDC,RGB(0,0,128));
- }
- else if(wMode == CONVERSION_MODE_U||wMode == CONVERSION_MODE_WUBI) {
- SetTextColor(hDC,RGB(128,0,0));
- }
- else if(wMode == CONVERSION_MODE_I) {
- SetTextColor(hDC,RGB(0,128,128));
- }
- else if(wMode == CONVERSION_MODE_V) {
- SetTextColor(hDC,RGB(128,0,128));
- }
- else{
- SetTextColor(hDC,RGB(0,0,0));
- }
- }