📄 ui.cpp
字号:
DWORD dwRegImeIndex=0;
RECT rcWorkArea;
rcWorkArea = sImeG.rcWorkArea;
hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWLP_IMC);
if (!hIMC) {
return ;
}
// get lpIMC
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return;
}
hUIPrivate = (HGLOBAL)GetWindowLong(hUIWnd, IMMGWLP_PRIVATE);
if (!hUIPrivate) {
ImmUnlockIMC(hIMC);
return;
}
lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
if (!lpUIPrivate) {
ImmUnlockIMC(hIMC);
return;
}
if (fOn) {
register DWORD fdwSetContext;
lpUIPrivate->fdwSetContext = lpUIPrivate->fdwSetContext &
~(ISC_SHOWUIALL|ISC_HIDE_SOFTKBD);
lpUIPrivate->fdwSetContext |= (lShowUI & ISC_SHOWUIALL) |
ISC_SHOW_SOFTKBD;
fdwSetContext = lpUIPrivate->fdwSetContext &
(ISC_SHOWUICOMPOSITIONWINDOW|ISC_HIDE_COMP_WINDOW);
if (fdwSetContext == ISC_HIDE_COMP_WINDOW) {
ShowComp( hUIWnd, SW_HIDE);
} else if (fdwSetContext & ISC_HIDE_COMP_WINDOW) {
lpUIPrivate->fdwSetContext &= ~(ISC_HIDE_COMP_WINDOW);
}
fdwSetContext = lpUIPrivate->fdwSetContext &
(ISC_SHOWUICANDIDATEWINDOW|ISC_HIDE_CAND_WINDOW);
if (fdwSetContext == ISC_HIDE_CAND_WINDOW) {
ShowCand( hUIWnd, SW_HIDE);
} else if (fdwSetContext & ISC_HIDE_CAND_WINDOW) {
lpUIPrivate->fdwSetContext &= ~(ISC_HIDE_CAND_WINDOW);
}
if (lpIMC->cfCandForm[0].dwIndex != 0) {
lpIMC->cfCandForm[0].dwStyle = CFS_DEFAULT;
}
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if (!lpImcP) {
GlobalUnlock(hUIPrivate);
ImmUnlockIMC(hIMC);
return;
}
if(sImeL.dwRegImeIndex != dwRegImeIndex) {
DWORD dwConvMode;
int cxBorder, cyBorder;
//change current IME index
dwConvMode = lpIMC->fdwConversion ^ (IME_CMODE_INDEX_FIRST << sImeL.dwRegImeIndex);
sImeL.dwRegImeIndex = 0;
szImeName = pszImeName;
dwConvMode |= (IME_CMODE_INDEX_FIRST << dwRegImeIndex);
// re-caculate statusuidata
cxBorder = GetSystemMetrics(SM_CXBORDER);
cyBorder = GetSystemMetrics(SM_CYBORDER);
InitStatusUIData(cxBorder, cyBorder);
ImmSetConversionStatus(hIMC, dwConvMode, lpIMC->fdwSentence);
}
if ((lpIMC->cfCompForm.dwStyle & CFS_FORCE_POSITION) ) {
POINT ptNew; // new position of UI
POINT ptSTWPos;
ImmGetStatusWindowPos(hIMC, (LPPOINT)&ptSTWPos);
ptNew.x = ptSTWPos.x + sImeG.xStatusWi + UI_MARGIN;
if((ptSTWPos.x + sImeG.xStatusWi + sImeG.xCandWi + lpImeL->xCompWi + 2 * UI_MARGIN) >=
rcWorkArea.right) {
ptNew.x = ptSTWPos.x - lpImeL->xCompWi - UI_MARGIN;
}
ptNew.x += lpImeL->cxCompBorder;
ptNew.y = ptSTWPos.y + lpImeL->cyCompBorder;
lpIMC->cfCompForm.ptCurrentPos = ptNew;
ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
lpIMC->cfCompForm.dwStyle = CFS_DEFAULT;
}
} else {
lpUIPrivate->fdwSetContext &= ~ISC_SETCONTEXT_UI;
}
GlobalUnlock(hUIPrivate);
UIPaint(hUIWnd);
ImmUnlockIMC(hIMC);
return;
}
/**********************************************************************/
/* GetCompWindow() */
/**********************************************************************/
LRESULT PASCAL GetCompWindow(
HWND hUIWnd,
LPCOMPOSITIONFORM lpCompForm)
{
HWND hCompWnd;
RECT rcCompWnd;
hCompWnd = GetCompWnd(hUIWnd);
if (!hCompWnd) {
return (1L);
}
if (!GetWindowRect(hCompWnd, &rcCompWnd)) {
return (1L);
}
lpCompForm->dwStyle = CFS_POINT|CFS_RECT;
lpCompForm->ptCurrentPos = *(LPPOINT)&rcCompWnd;
lpCompForm->rcArea = rcCompWnd;
return (0L);
}
/**********************************************************************/
/* UIPaint() */
/**********************************************************************/
LRESULT PASCAL UIPaint(
HWND hUIWnd)
{
PAINTSTRUCT ps;
MSG sMsg;
HGLOBAL hUIPrivate;
LPUIPRIV lpUIPrivate;
// for safety
BeginPaint(hUIWnd, &ps);
EndPaint(hUIWnd, &ps);
// some application will not remove the WM_PAINT messages
PeekMessage(&sMsg, hUIWnd, WM_PAINT, WM_PAINT, PM_REMOVE|PM_NOYIELD);
hUIPrivate = (HGLOBAL)GetWindowLong(hUIWnd, IMMGWLP_PRIVATE);
if (!hUIPrivate) {
return (0L);
}
lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
if (!lpUIPrivate) {
return (0L);
}
if (lpUIPrivate->fdwSetContext & ISC_SETCONTEXT_UI) {
ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
} else {
ShowUI(hUIWnd, SW_HIDE);
}
GlobalUnlock(hUIPrivate);
return (0L);
}
/**********************************************************************/
/* UIWndProc() */
/**********************************************************************/
LRESULT CALLBACK UIWndProc(
HWND hUIWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_CREATE:
CreateUIWindow(hUIWnd);
break;
case WM_DESTROY:
DestroyUIWindow(hUIWnd);
break;
case WM_IME_STARTCOMPOSITION:
// you can create a window as the composition window here
StartComp(hUIWnd);
break;
case WM_IME_COMPOSITION:
{
HWND hCompWnd;
HWND hCandWnd;
hCompWnd = GetCompWnd(hUIWnd);
hCandWnd = GetCandWnd(hUIWnd);
if (hCompWnd) {
RECT rcRect;
//__asm int 3;
rcRect = lpImeL->rcCompText;
// off by 1
rcRect.right += 1;
rcRect.bottom += 1;
MoveWindow( hCompWnd,
lpImeL->ptNewComp.x,
lpImeL->ptNewComp.y ,
lpImeL->xCompWi,
lpImeL->yCompHi,
TRUE);
RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
rcRect.left = lpImeL->rcCompText.left -lpImeL->xComSelWi;
rcRect.right = lpImeL->rcCompText.left -2 ;
rcRect.top = lpImeL->rcCompText.top;
rcRect.bottom = lpImeL->rcCompText.bottom;
RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
}
if( hCandWnd ) {
int CandTop ;
CandTop = lpImeL->ptNewComp.y-sImeG.yCandHi ;
if(CandTop<0) CandTop = lpImeL->ptNewComp.y+ lpImeL->yCompHi;
MoveWindow( hCandWnd,
lpImeL->ptNewComp.x,
CandTop,
sImeG.xCandWi,
sImeG.yCandHi,
TRUE);
}
}
break;
case WM_IME_ENDCOMPOSITION:
// you can destroy the composition window here
EndComp(hUIWnd);
break;
case WM_IME_NOTIFY:
NotifyUI(hUIWnd, wParam, lParam);
break;
case WM_IME_SETCONTEXT:
SetContext(hUIWnd, (BOOL)wParam, lParam);
if (wParam && GetWindowLong(hUIWnd, IMMGWLP_IMC))
SetWindowPos(hUIWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOMOVE);
break;
case WM_IME_CONTROL:
switch (wParam) {
case IMC_GETCANDIDATEPOS:
return (1L); // not implemented yet
case IMC_GETCOMPOSITIONFONT:
return (1L); // not implemented yet
case IMC_GETCOMPOSITIONWINDOW:
return GetCompWindow(hUIWnd, (LPCOMPOSITIONFORM)lParam);
case IMC_GETSTATUSWINDOWPOS:
{
HWND hStatusWnd;
RECT rcStatusWnd;
LPARAM lParam;
hStatusWnd = GetStatusWnd(hUIWnd);
if (!hStatusWnd) {
return (0L); // fail, return (0, 0)?
}
if (!GetWindowRect(hStatusWnd, &rcStatusWnd)) {
return (0L); // fail, return (0, 0)?
}
lParam = MAKELRESULT(rcStatusWnd.left, rcStatusWnd.top);
return (lParam);
}
return (0L);
case IMC_SETSTATUSWINDOWPOS:
{
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
LPPRIVCONTEXT lpImcP;
POINT ptPos;
RECT rcWorkArea;
rcWorkArea = sImeG.rcWorkArea;
ptPos.x = ((LPPOINTS)&lParam)->x;
ptPos.y = ((LPPOINTS)&lParam)->y;
hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWLP_IMC);
if (!hIMC) {
return (1L);
}
if(!ImmSetStatusWindowPos(hIMC, &ptPos)) {
return (1L);
}
// set comp window position when TraceCuer
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return (1L);
}
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if (!lpImcP) {
return (1L);
}
lpIMC->cfCompForm.dwStyle = CFS_RECT;
lpIMC->cfCompForm.ptCurrentPos.x = ptPos.x + sImeG.xStatusWi + UI_MARGIN;
lpIMC->cfCompForm.ptCurrentPos.y = ptPos.y;
CopyRect(&lpIMC->cfCompForm.rcArea, &rcWorkArea);
ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
// set composition window to the new poosition
PostMessage(GetCompWnd(hUIWnd), WM_IME_NOTIFY, IMN_SETCOMPOSITIONWINDOW, 0);
ImmUnlockIMCC(lpIMC->hPrivate);
ImmUnlockIMC(hIMC);
return (0L);
}
return (1L);
default:
return (1L);
}
break;
case WM_IME_COMPOSITIONFULL:
return (0L);
case WM_IME_SELECT:
SetContext(hUIWnd, (BOOL)wParam, 0);
return (0L);
case WM_MOUSEACTIVATE:
return (MA_NOACTIVATE);
case WM_PAINT:
return UIPaint(hUIWnd);
default:
return DefWindowProc(hUIWnd, uMsg, wParam, lParam);
}
return (0L);
}
void DrawConvexRect(HDC hDC, int x1, int y1, int x2, int y2)
{
HPEN hPen, hOldPen;
SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(hDC, GetStockObject(WHITE_PEN));
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x2, y1);
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x1, y2);
hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
hOldPen = (HPEN)SelectObject (hDC, hPen);
MoveToEx(hDC, x2-1, y2-1,NULL);
LineTo(hDC, x2-1, y1);
MoveToEx(hDC, x2-1, y2-1,NULL);
LineTo(hDC, x1, y2-1);
SelectObject(hDC, hOldPen);
DeleteObject(hPen);
}
void DrawConvexRectP(HDC hDC, int x1, int y1, int x2, int y2)
{
HPEN hPen, hOldPen;
SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(hDC, GetStockObject(WHITE_PEN));
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x2 - 1, y1);
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x1, y2 - 1);
hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
hOldPen = (HPEN)SelectObject (hDC, hPen);
MoveToEx(hDC, x2-1, y2-1,NULL);
LineTo(hDC, x2-1, y1);
MoveToEx(hDC, x2-1, y2-1,NULL);
LineTo(hDC, x1, y2-1);
SelectObject(hDC, hOldPen);
DeleteObject(hPen);
}
void DrawConcaveRect(HDC hDC, int x1, int y1, int x2, int y2)
{
HPEN hLtPen = CreatePen(PS_SOLID, 1, 0x00808080);
HPEN OldPen = (HPEN)SelectObject(hDC, hLtPen);
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x2, y1);
MoveToEx(hDC, x1, y1,NULL);
LineTo(hDC, x1, y2);
SelectObject(hDC, GetStockObject(WHITE_PEN));
MoveToEx(hDC, x2 , y2,NULL);
LineTo(hDC, x2 , y1-1);
MoveToEx(hDC, x2 , y2,NULL);
LineTo(hDC, x1-1, y2);
SelectObject(hDC, OldPen);
DeleteObject(hLtPen);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -