📄 uicand.c
字号:
PAINTSTRUCT ps;
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
LPCANDIDATEINFO lpCandInfo;
LPCANDIDATELIST lpCandList;
HBRUSH hbr;
HDC hDC;
RECT rc;
LPMYSTR lpstr;
int height;
DWORD i;
SIZE sz;
HWND hSvrWnd;
HBRUSH hbrHightLight = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
#if 0
HBRUSH hbrLGR = GetStockObject(LTGRAY_BRUSH);
#else
HBRUSH hbrLGR = (HBRUSH)(COLOR_BTNFACE + 1);
#endif
HFONT hOldFont = NULL;
GetClientRect(hCandWnd,&rc);
hDC = BeginPaint(hCandWnd,&ps);
FillRect(hDC,&rc,(HBRUSH) (COLOR_BTNFACE + 1));
SetBkMode(hDC,TRANSPARENT);
#if 0
MoveToEx(hDC, rc.left+1,rc.top+1,NULL);
LineTo(hDC, rc.left+1,rc.bottom-1);
LineTo(hDC, rc.right-1,rc.bottom-1);
LineTo(hDC, rc.right-1,rc.top+1);
LineTo(hDC, rc.left+1,rc.top+1);
#endif
hSvrWnd = (HWND)GetWindowLongPtr(hCandWnd,FIGWL_SVRWND);
if (hIMC = (HIMC)GetWindowLongPtr(hSvrWnd,IMMGWLP_IMC))
{
lpIMC = ImmLockIMC(hIMC);
hOldFont = CheckNativeCharset(hDC);
if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
{
height = GetSystemMetrics(SM_CYEDGE);
lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
for (i = lpCandList->dwPageStart;
i < (lpCandList->dwPageStart + lpCandList->dwPageSize); i++)
{
TCHAR num[3];
wsprintf(num, TEXT("%d "), i % lpCandList->dwPageSize + 1);
if (i >= lpCandList->dwCount)
lpstr=(LPMYSTR)(LPSTR)" ";
else
lpstr=(LPMYSTR)((LPSTR)lpCandList +lpCandList->dwOffset[i]);
MyGetTextExtentPoint(hDC,lpstr,Mylstrlen(lpstr),&sz);
if (((LPMYCAND)lpCandInfo)->cl.dwSelection == (DWORD)i)
{
hbr = SelectObject(hDC,hbrHightLight);
PatBlt(hDC,0,height,rc.right,sz.cy,PATCOPY);
SelectObject(hDC,hbr);
SetTextColor(hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
}
else
{
hbr = SelectObject(hDC,hbrLGR);
//PatBlt(hDC,0,height,rc.right,sz.cy,PATCOPY);
SelectObject(hDC,hbr);
SetTextColor(hDC,RGB(0,0,0));
}
if (i < lpCandList->dwCount)
MyTextOut(hDC,GetSystemMetrics(SM_CXEDGE),height,num,Mylstrlen(num));
MyTextOut(hDC,10 + GetSystemMetrics(SM_CXEDGE),height,lpstr,Mylstrlen(lpstr));
height += sz.cy;
}
ImmUnlockIMCC(lpIMC->hCandInfo);
}
if (hOldFont) {
DeleteObject(SelectObject(hDC, hOldFont));
}
ImmUnlockIMC(hIMC);
}
EndPaint(hCandWnd,&ps);
DeleteObject(hbrHightLight);
}
/**********************************************************************/
/* */
/* ResizeCandWindow() */
/* */
/**********************************************************************/
void PASCAL ResizeCandWindow( LPUIEXTRA lpUIExtra,LPINPUTCONTEXT lpIMC )
{
LPCANDIDATEINFO lpCandInfo;
LPCANDIDATELIST lpCandList;
HDC hDC;
LPMYSTR lpstr;
int width;
int height;
DWORD i;
RECT rc;
SIZE sz;
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
HFONT hOldFont;
hDC = GetDC(lpUIExtra->uiCand.hWnd);
hOldFont = CheckNativeCharset(hDC);
if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
{
width = 0;
height = 0;
lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
for (i = lpCandList->dwPageStart;
i < (lpCandList->dwPageStart + lpCandList->dwPageSize); i++)
{
lpstr = (LPMYSTR)((LPSTR)lpCandList + lpCandList->dwOffset[i]);
MyGetTextExtentPoint(hDC,lpstr,Mylstrlen(lpstr),&sz);
if (width < sz.cx)
width = sz.cx;
height += sz.cy;
}
ImmUnlockIMCC(lpIMC->hCandInfo);
}
if (hOldFont) {
DeleteObject(SelectObject(hDC, hOldFont));
}
ReleaseDC(lpUIExtra->uiCand.hWnd,hDC);
GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
MoveWindow(lpUIExtra->uiCand.hWnd,
rc.left,
rc.top,
width+ 10 + 4 * GetSystemMetrics(SM_CXEDGE),
/* 10 is a left margin */
height+ 4 * GetSystemMetrics(SM_CYEDGE),
TRUE);
}
}
/**********************************************************************/
/* */
/* HideCandWindow() */
/* */
/**********************************************************************/
void PASCAL HideCandWindow( LPUIEXTRA lpUIExtra)
{
RECT rc;
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
GetWindowRect(lpUIExtra->uiCand.hWnd,(LPRECT)&rc);
lpUIExtra->uiCand.pt.x = rc.left;
lpUIExtra->uiCand.pt.y = rc.top;
MoveWindow(lpUIExtra->uiCand.hWnd, -1 , -1 , 0 , 0, TRUE);
ShowWindow(lpUIExtra->uiCand.hWnd, SW_HIDE);
lpUIExtra->uiCand.bShow = FALSE;
}
}
/**********************************************************************/
/* */
/* MoveCandWindow() */
/* */
/**********************************************************************/
void PASCAL MoveCandWindow(HWND hUIWnd, LPINPUTCONTEXT lpIMC, LPUIEXTRA lpUIExtra, BOOL fForceComp)
{
RECT rc;
POINT pt;
CANDIDATEFORM caf;
if (fForceComp)
{
if (GetCandPosFromCompForm(lpIMC, lpUIExtra, &pt))
{
caf.dwIndex = 0;
caf.dwStyle = CFS_CANDIDATEPOS;
caf.ptCurrentPos.x = pt.x;
caf.ptCurrentPos.y = pt.y;
#if 0
GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
if ((int)rc.left != -1 && (int)rc.left < 4096 ) {
POINT spt;
spt.x = (int)rc.left;
spt.y = (int)rc.top;
MyDebugPrint((TEXT("S X,Y:%d,%d\n"),spt.x,spt.y));
ScreenToClient(lpIMC->hWnd, &spt);
MyDebugPrint((TEXT("C X,Y:%d,%d\n"),spt.x,spt.y));
caf.ptCurrentPos.x = spt.x;
caf.ptCurrentPos.y = spt.y;
}
#endif
ImmSetCandidateWindow(lpUIExtra->hIMC,&caf);
}
return;
}
// Not initialized !!
if (lpIMC->cfCandForm[0].dwIndex == -1)
{
if (GetCandPosFromCompWnd(lpUIExtra,&pt))
{
lpUIExtra->uiCand.pt.x = pt.x;
lpUIExtra->uiCand.pt.y = pt.y;
GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
lpUIExtra->uiCand.bShow = TRUE;
InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
}
return;
}
if (!IsCandidate(lpIMC))
return;
if (lpIMC->cfCandForm[0].dwStyle == CFS_EXCLUDE)
{
RECT rcWork;
RECT rcAppWnd;
SystemParametersInfo(SPI_GETWORKAREA,0,&rcWork,FALSE);
GetClientRect(lpUIExtra->uiCand.hWnd,&rc);
GetWindowRect(lpIMC->hWnd,&rcAppWnd);
if (!lpUIExtra->bVertical)
{
pt.x = lpIMC->cfCandForm[0].ptCurrentPos.x;
pt.y = lpIMC->cfCandForm[0].rcArea.bottom;
ClientToScreen(lpIMC->hWnd,&pt);
if (pt.y + rc.bottom > rcWork.bottom)
pt.y = rcAppWnd.top +
lpIMC->cfCandForm[0].rcArea.top - rc.bottom;
}
else
{
pt.x = lpIMC->cfCandForm[0].rcArea.left - rc.right;
pt.y = lpIMC->cfCandForm[0].ptCurrentPos.y;
ClientToScreen(lpIMC->hWnd,&pt);
if (pt.x < 0)
pt.x = rcAppWnd.left +
lpIMC->cfCandForm[0].rcArea.right;
}
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
lpUIExtra->uiCand.bShow = TRUE;
InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
}
SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
}
else if (lpIMC->cfCandForm[0].dwStyle == CFS_CANDIDATEPOS)
{
pt.x = lpIMC->cfCandForm[0].ptCurrentPos.x;
pt.y = lpIMC->cfCandForm[0].ptCurrentPos.y;
ClientToScreen(lpIMC->hWnd,&pt);
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
lpUIExtra->uiCand.bShow = TRUE;
InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
}
SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -