📄 ui.c
字号:
UI_MODE = LIN_UI;
ptSTFixPos.x = 0;
ptSTFixPos.y = rcWorkArea.bottom - sImeG.yStatusHi;
ImmSetStatusWindowPos(hIMC, (LPPOINT)&ptSTFixPos);
}
InitCandUIData(
GetSystemMetrics(SM_CXBORDER),
GetSystemMetrics(SM_CYBORDER), UI_MODE);
}
SaTC_Trace = sImeG.IC_Trace;
// init Caps
{
BYTE lpbKeyState[256];
DWORD fdwConversion;
GetKeyboardState(lpbKeyState);
if (lpbKeyState[VK_CAPITAL] & 0x01) {
// 10.11 add
uCaps = 1;
// change to alphanumeric mode
fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
IME_CMODE_NATIVE | IME_CMODE_EUDC);
} else {
// change to native mode
if(uCaps == 1) {
fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &
~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
} else {
fdwConversion = lpIMC->fdwConversion;
}
uCaps = 0;
}
ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
}
if ((lpIMC->cfCompForm.dwStyle & CFS_FORCE_POSITION)
&& (sImeG.IC_Trace)) {
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);
}
/**********************************************************************/
/* SelectIME() */
/**********************************************************************/
void PASCAL SelectIME( // switch IMEs
HWND hUIWnd,
BOOL fSelect)
{
if (!fSelect) {
ShowUI(hUIWnd, SW_HIDE);
} else {
ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
}
return;
}
/**********************************************************************/
/* 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)GetWindowLongPtr(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:
if (!sImeG.IC_Trace) {
} else if (lParam & GCS_RESULTSTR) {
MoveDefaultCompPosition(hUIWnd);
} else {
}
{
HWND hCompWnd;
hCompWnd = GetCompWnd(hUIWnd);
if (hCompWnd) {
RECT rcRect;
rcRect = lpImeL->rcCompText;
// off by 1
rcRect.right += 1;
rcRect.bottom += 1;
RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
}
}
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 && GetWindowLongPtr(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;
//COMPOSITIONFORM CompForm;
POINT ptPos;
RECT rcWorkArea;
#ifdef MUL_MONITOR
rcWorkArea = ImeMonitorWorkAreaFromWindow(hUIWnd);
#else
rcWorkArea = sImeG.rcWorkArea;
#endif
ptPos.x = ((LPPOINTS)&lParam)->x;
ptPos.y = ((LPPOINTS)&lParam)->y;
hIMC = (HIMC)GetWindowLongPtr(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);
}
if(!sImeG.IC_Trace) {
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:
//#if defined(LATER)
SetContext(hUIWnd, (BOOL)wParam, 0);
//#else
// SelectIME(hUIWnd, (BOOL)wParam);
//#endif
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 = 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 = 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 = 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 + -