📄 uicand.c
字号:
/*
* This file is part of Saenaru.
*
* Copyright (C) 2003 Hye-Shik Chang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Perky$
*/
/*++
Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
Module Name:
UICAND.C
++*/
/**********************************************************************/
#include "windows.h"
#include "immdev.h"
#include "saenaru.h"
int PASCAL GetCompFontHeight(LPUIEXTRA lpUIExtra);
/**********************************************************************/
/* */
/* CandWndProc() */
/* IME UI window procedure */
/* */
/**********************************************************************/
LRESULT CALLBACK CandWndProc( hWnd, message, wParam, lParam )
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
HWND hUIWnd;
#if 1
HWND hSvrWnd;
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
static INT dy=0;
#endif
DWORD dwPushedCand;
POINT pt;
RECT rc;
INT select;
INT offset;
switch (message)
{
case WM_PAINT:
PaintCandWindow(hWnd);
break;
case WM_SETCURSOR:
SetCursor(LoadCursor(NULL,IDC_HAND));
if (dy == 0)
{
TEXTMETRIC tm;
HDC hDC;
hDC = CreateIC(TEXT("DISPLAY"),NULL,NULL,NULL);
GetTextMetrics(hDC,&tm);
dy = tm.tmHeight + tm.tmExternalLeading;
DeleteDC(hDC);
}
select = 0;
offset = 0;
{
GetCursorPos(&pt);
ScreenToClient(hWnd,&pt);
GetClientRect(hWnd,&rc);
if (!PtInRect(&rc,pt))
return 0;
pt.y -= GetSystemMetrics(SM_CYEDGE);
if (pt.y > 0)
select = pt.y / dy + ((pt.y % dy) ? 1:0);
if (select == 0)
offset = -2;
}
if ((HIWORD(lParam) != WM_LBUTTONDOWN) &&
(HIWORD(lParam) != WM_RBUTTONDOWN))
return DefWindowProc(hWnd,message,wParam,lParam);
if ((HIWORD(lParam) == WM_LBUTTONDOWN))
{
#if 0
else if (select > 9)
{
if (pt.x < 14)
offset = -2;
else
offset = 2;
select = 0;
}
#endif
MyDebugPrint((TEXT("Cand offset %d\n"),offset));
hSvrWnd = (HWND)GetWindowLongPtr(hWnd,FIGWL_SVRWND);
if (select > 0 &&
(hIMC = (HIMC)GetWindowLongPtr(hSvrWnd,IMMGWLP_IMC)) )
{
lpIMC = ImmLockIMC(hIMC);
ConvHanja(hIMC,offset,select);
ImmUnlockIMC(hIMC);
break;
}
}
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
DragUI(hWnd,message,wParam,lParam);
if ((message == WM_LBUTTONUP) || (message == WM_RBUTTONUP)) {
MyDebugPrint((TEXT(" $ CANDMOVE %dx%d\n"),LOWORD(lParam),HIWORD(lParam)));
SetWindowLong(hWnd,FIGWL_MOUSE,0L);
}
break;
case WM_MOVE:
hUIWnd = (HWND)GetWindowLongPtr(hWnd,FIGWL_SVRWND);
MyDebugPrint((TEXT(" x CANDMOVE %dx%d\n"),LOWORD(lParam),HIWORD(lParam)));
if (IsWindow(hUIWnd))
SendMessage(hUIWnd,WM_UI_CANDMOVE,wParam,lParam);
break;
default:
if (!MyIsIMEMessage(message))
return DefWindowProc(hWnd,message,wParam,lParam);
break;
}
return 0L;
}
/**********************************************************************/
/* */
/* GetCandPosFromCompWnd() */
/* */
/**********************************************************************/
BOOL PASCAL GetCandPosFromCompWnd(LPUIEXTRA lpUIExtra,LPPOINT lppt)
{
RECT rc;
if (lpUIExtra->dwCompStyle)
{
if (lpUIExtra->uiComp[0].bShow)
{
GetWindowRect(lpUIExtra->uiComp[0].hWnd,&rc);
lppt->x = rc.left;
lppt->y = rc.bottom+1;
return TRUE;
}
}
else
{
if (lpUIExtra->uiDefComp.bShow)
{
GetWindowRect(lpUIExtra->uiDefComp.hWnd,&rc);
lppt->x = rc.left;
lppt->y = rc.bottom+1;
return TRUE;
}
}
return FALSE;
}
/**********************************************************************/
/* */
/* GetCandPosFromCompForm() */
/* */
/**********************************************************************/
BOOL PASCAL GetCandPosFromCompForm(LPINPUTCONTEXT lpIMC, LPUIEXTRA lpUIExtra,LPPOINT lppt)
{
if (lpUIExtra->dwCompStyle)
{
if (lpIMC && lpIMC->fdwInit & INIT_COMPFORM)
{
if (!lpUIExtra->bVertical)
{
UINT dy = GetCompFontHeight(lpUIExtra);
UINT hy = GetSystemMetrics(SM_CYFULLSCREEN);
POINT pt;
lppt->x = lpIMC->cfCompForm.ptCurrentPos.x;
lppt->y = lpIMC->cfCompForm.ptCurrentPos.y + dy;
//GetCompFontHeight(lpUIExtra);
//
pt.x = lppt->x;
pt.y = lppt->y;
ClientToScreen(lpIMC->hWnd,&pt);
if ((pt.y + 9 * dy) > hy) {
pt.x += dy + 2;
pt.y = hy - 10 * dy;
ScreenToClient(lpIMC->hWnd,&pt);
lppt->x = pt.x;
lppt->y = pt.y;
}
MyDebugPrint((TEXT("XXX #1\n")));
}
else
{
lppt->x = lpIMC->cfCompForm.ptCurrentPos.x -
GetCompFontHeight(lpUIExtra);
lppt->y = lpIMC->cfCompForm.ptCurrentPos.y;
}
return TRUE;
}
}
else
{
if (GetCandPosFromCompWnd(lpUIExtra,lppt))
{
ScreenToClient(lpIMC->hWnd,lppt);
return TRUE;
}
}
return FALSE;
}
/**********************************************************************/
/* */
/* CreateCandWindow() */
/* */
/**********************************************************************/
void PASCAL CreateCandWindow( HWND hUIWnd,LPUIEXTRA lpUIExtra, LPINPUTCONTEXT lpIMC )
{
POINT pt;
if (GetCandPosFromCompWnd(lpUIExtra,&pt))
{
lpUIExtra->uiCand.pt.x = pt.x;
lpUIExtra->uiCand.pt.y = pt.y;
}
if (!IsWindow(lpUIExtra->uiCand.hWnd))
{
lpUIExtra->uiCand.hWnd =
CreateWindowEx(WS_EX_WINDOWEDGE,
(LPTSTR)szCandClassName,NULL,
WS_COMPNODEFAULT,
//WS_COMPDEFAULT | WS_DLGFRAME,
lpUIExtra->uiCand.pt.x,
lpUIExtra->uiCand.pt.y,
1,1,
hUIWnd,NULL,hInst,NULL);
}
SetWindowLongPtr(lpUIExtra->uiCand.hWnd,FIGWL_SVRWND,(LONG_PTR)hUIWnd);
ShowWindow(lpUIExtra->uiCand.hWnd, SW_HIDE);
lpUIExtra->uiCand.bShow = FALSE;
return;
}
/**********************************************************************/
/* */
/* PaintCandWindow() */
/* */
/**********************************************************************/
void PASCAL PaintCandWindow( HWND hCandWnd)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -