📄 subs.c
字号:
/*
* 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 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('\0');
lpCompStr->dwResultStrOffset =
(DWORD)((LPMYCOMPSTR)lpCompStr)->szResultStr - (DWORD)lpCompStr;
lpCompStr->dwResultStrLen = 0;
*GETLPRESULTSTR(lpCompStr) = _T('\0');
lpCompStr->dwCursorPos = 0;
lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
lpFreePYComp->szConvCompStr[0] = _T('\0');
lpFreePYComp->szPaintCompStr[0] = _T('\0');
lpFreePYComp->szPreResultStr[0] = _T('\0');
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('\0');
lpCompStr->dwResultStrLen = 0;
((LPMYCOMPSTR)lpCompStr)->szResultStr[0] = _T('\0');
lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
lpFreePYComp->szConvCompStr[0] = _T('\0');
lpFreePYComp->szPaintCompStr[0] = _T('\0');
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->abKey[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->abKey[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(ATOMTIP);
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;
LPCANDIDATEINFO lpCandInfo;
LPCANDIDATELIST lpCandList;
/*
if (!IsCompStr(hIMC))
return FALSE;
*/
wConversionMode = 0;
lpIMC = ImmLockIMC(hIMC);
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
if(fFlag) {
lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
lpPreResultStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr;
_tcscpy(GETLPRESULTSTR(lpCompStr),lpConvStr);
_tcscpy(lpPreResultStr,lpConvStr);
lpCompStr->dwResultStrLen = _tcslen(lpConvStr);
}
else{
*GETLPRESULTSTR(lpCompStr) = _T('\0');
lpCompStr->dwResultStrLen = 0;
}
lpCandList->dwCount = 0;
lpCompStr->dwCompStrLen = 0;
_tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
_tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
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);
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -