📄 ui.c
字号:
lpIMC->fdwConversion & IME_CMODE_SOFTKBD);
break;
case IMN_OPENCANDIDATE:
CreateCandWindow(hWnd,lpUIExtra,lpIMC );
break;
case IMN_CHANGECANDIDATE:
ResizeCandWindow(lpUIExtra,lpIMC);
MoveCandWindow(hWnd,lpIMC,lpUIExtra, FALSE);
break;
case IMN_CLOSECANDIDATE:
HideCandWindow(lpUIExtra);
break;
case IMN_GUIDELINE:
if (ImmGetGuideLine(hUICurIMC,GGL_LEVEL,NULL,0))
{
if (!IsWindow(lpUIExtra->uiGuide.hWnd))
{
HDC hdcIC;
TEXTMETRIC tm;
int dx,dy;
if (lpUIExtra->uiGuide.pt.x == -1)
{
GetWindowRect(lpIMC->hWnd,&rc);
lpUIExtra->uiGuide.pt.x = rc.left;
lpUIExtra->uiGuide.pt.y = rc.bottom;
}
hdcIC = CreateIC(TEXT("DISPLAY"),NULL,NULL,NULL);
GetTextMetrics(hdcIC,&tm);
dx = tm.tmAveCharWidth * MAXGLCHAR;
dy = tm.tmHeight + tm.tmExternalLeading;
DeleteDC(hdcIC);
lpUIExtra->uiGuide.hWnd =
CreateWindowEx( WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME,
(LPTSTR)szGuideClassName,NULL,
WS_DISABLED | WS_POPUP | WS_BORDER,
lpUIExtra->uiGuide.pt.x,
lpUIExtra->uiGuide.pt.y,
dx + 2 * GetSystemMetrics(SM_CXBORDER)
+ 2 * GetSystemMetrics(SM_CXEDGE),
dy + GetSystemMetrics(SM_CYSMCAPTION)
+ 2 * GetSystemMetrics(SM_CYBORDER)
+ 2 * GetSystemMetrics(SM_CYEDGE),
hWnd,NULL,hInst,NULL);
}
ShowWindow(lpUIExtra->uiGuide.hWnd,SW_SHOWNOACTIVATE);
lpUIExtra->uiGuide.bShow = TRUE;
SetWindowLongPtr(lpUIExtra->uiGuide.hWnd,FIGWL_SVRWND,(LONG_PTR)hWnd);
UpdateGuideWindow(lpUIExtra);
}
break;
case IMN_SETCANDIDATEPOS:
// SAENARU supports only one candidate list.
if (lParam != 0x01)
break;
MoveCandWindow(hWnd,lpIMC,lpUIExtra, FALSE);
break;
case IMN_SETCOMPOSITIONWINDOW:
MoveCompWindow(lpUIExtra,lpIMC);
MoveCandWindow(hWnd,lpIMC,lpUIExtra, TRUE);
break;
case IMN_SETSTATUSWINDOWPOS:
case IMN_PRIVATE:
break;
default:
break;
}
GlobalUnlock(hUIExtra);
ImmUnlockIMC(hUICurIMC);
return lRet;
}
/**********************************************************************/
/* */
/* ControlCommand() */
/* */
/* Handle WM_IME_CONTROL messages. */
/* */
/**********************************************************************/
#define lpcfCandForm ((LPCANDIDATEFORM)lParam)
LONG PASCAL ControlCommand(HIMC hUICurIMC, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LONG lRet = 1L;
LPINPUTCONTEXT lpIMC;
HGLOBAL hUIExtra;
LPUIEXTRA lpUIExtra;
if (!(lpIMC = ImmLockIMC(hUICurIMC)))
return 1L;
hUIExtra = (HGLOBAL)GetWindowLongPtr(hWnd,IMMGWLP_PRIVATE);
lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);
switch (wParam)
{
TCHAR szDev[80];
case IMC_GETCANDIDATEPOS:
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
// SAENARU has only one candidate list.
*(LPCANDIDATEFORM)lParam = lpIMC->cfCandForm[0];
lRet = 0;
}
break;
case IMC_SETCANDIDATEPOS:
MyDebugPrint((TEXT("IMC_SETCANDIDATEPOS\n")));
break;
case IMC_SETCOMPOSITIONFONT:
wsprintf((LPTSTR)szDev,TEXT("SETCOMPOSITIONFONT\r\n"));
OutputDebugString((LPTSTR)szDev);
break;
case IMC_GETCOMPOSITIONWINDOW:
*(LPCOMPOSITIONFORM)lParam = lpIMC->cfCompForm;
lRet = 0;
break;
case IMC_GETSTATUSWINDOWPOS:
lRet = (lpUIExtra->uiStatus.pt.x << 16) & lpUIExtra->uiStatus.pt.x;
break;
default:
break;
}
GlobalUnlock(hUIExtra);
ImmUnlockIMC(hUICurIMC);
return lRet;
}
/**********************************************************************/
/* */
/* DrawUIBorder() */
/* */
/* When draging the child window, this function draws the border. */
/* */
/**********************************************************************/
void PASCAL DrawUIBorder( LPRECT lprc )
{
HDC hDC;
int sbx, sby;
hDC = CreateDC( TEXT("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 );
}
/**********************************************************************/
/* */
/* DragUI(hWnd,message,wParam,lParam) */
/* */
/* Handling mouse messages for the child windows. */
/* */
/**********************************************************************/
void PASCAL DragUI( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
POINT pt;
static POINT ptdif;
static RECT drc;
static RECT rc;
DWORD dwT;
switch (message)
{
case WM_SETCURSOR:
if ( HIWORD(lParam) == WM_LBUTTONDOWN
|| HIWORD(lParam) == WM_RBUTTONDOWN )
{
SetCursor(LoadCursor(NULL,IDC_SIZEALL));
GetCursorPos( &pt );
SetCapture(hWnd);
GetWindowRect(hWnd,&drc);
ptdif.x = pt.x - drc.left;
ptdif.y = pt.y - drc.top;
rc = drc;
rc.right -= rc.left;
rc.bottom -= rc.top;
SetWindowLong(hWnd,FIGWL_MOUSE,FIM_CAPUTURED);
} else
SetCursor(LoadCursor(NULL,IDC_HAND));
break;
case WM_MOUSEMOVE:
dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
if (dwT & FIM_MOVED)
{
DrawUIBorder(&drc);
GetCursorPos( &pt );
drc.left = pt.x - ptdif.x;
drc.top = pt.y - ptdif.y;
drc.right = drc.left + rc.right;
drc.bottom = drc.top + rc.bottom;
DrawUIBorder(&drc);
}
else if (dwT & FIM_CAPUTURED)
{
DrawUIBorder(&drc);
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);
GetCursorPos( &pt );
MoveWindow(hWnd,pt.x - ptdif.x,
pt.y - ptdif.y,
rc.right,
rc.bottom,TRUE);
}
}
break;
}
}
/**********************************************************************/
/* */
/* MyIsIMEMessage(message) */
/* */
/* Any UI window should not pass the IME messages to DefWindowProc. */
/* */
/**********************************************************************/
BOOL PASCAL 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;
}
/**********************************************************************/
/* */
/* ShowUIWindows(hWnd,fFlag) */
/* */
/**********************************************************************/
void PASCAL ShowUIWindows(HWND hWnd, BOOL fFlag)
{
HGLOBAL hUIExtra;
LPUIEXTRA lpUIExtra;
int nsw = fFlag ? SW_SHOWNOACTIVATE : SW_HIDE;
if (!(hUIExtra = (HGLOBAL)GetWindowLongPtr(hWnd,IMMGWLP_PRIVATE)))
return;
if (!(lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra)))
return;
if (IsWindow(lpUIExtra->uiStatus.hWnd))
{
ShowWindow(lpUIExtra->uiStatus.hWnd,nsw);
lpUIExtra->uiStatus.bShow = fFlag;
}
if (IsWindow(lpUIExtra->uiCand.hWnd))
{
ShowWindow(lpUIExtra->uiCand.hWnd,nsw);
lpUIExtra->uiCand.bShow = fFlag;
}
if (IsWindow(lpUIExtra->uiDefComp.hWnd))
{
ShowWindow(lpUIExtra->uiDefComp.hWnd,nsw);
lpUIExtra->uiDefComp.bShow = fFlag;
}
if (IsWindow(lpUIExtra->uiGuide.hWnd))
{
ShowWindow(lpUIExtra->uiGuide.hWnd,nsw);
lpUIExtra->uiGuide.bShow = fFlag;
}
GlobalUnlock(hUIExtra);
}
/**********************************************************************/
/* UpdateSoftKbd() */
/**********************************************************************/
void PASCAL UpdateSoftKeyboard(
LPUIEXTRA lpUIExtra, int mode)
{
LPINPUTCONTEXT lpIMC;
if (!mode)
{
ImmShowSoftKeyboard(lpUIExtra->uiSoftKbd.hWnd,SW_HIDE);
}
else
{
SetSoftKbdData(lpUIExtra->uiSoftKbd.hWnd);
ImmShowSoftKeyboard(lpUIExtra->uiSoftKbd.hWnd,SW_SHOWNOACTIVATE);
}
return;
}
static HHOOK hHookWnd = 0;
BOOL WINAPI SetHookFunc(void)
{
if((hHookWnd=SetWindowsHookEx(WH_GETMESSAGE, SAENARUKbdProc, (HINSTANCE) NULL, GetCurrentThreadId())) == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -