📄 ui.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:
UI.C
++*/
/**********************************************************************/
#include <windows.h>
#include <immdev.h>
#include "saenaru.h"
#include "vksub.h"
void PASCAL ShowUIWindows(HWND hWnd, BOOL fFlag);
void PASCAL UpdateSoftKeyboard(LPUIEXTRA, int);
#ifdef DEBUG
void PASCAL DumpUIExtra(LPUIEXTRA lpUIExtra);
#endif
LRESULT CALLBACK SAENARUKbdProc(int, WPARAM, LPARAM);
BOOL WINAPI SetHookFunc(void);
BOOL WINAPI UnsetHookFunc(void);
#if 0
void PASCAL HideGuideLine (LPUIEXTRA lpUIExtra);
void PASCAL CreateGuideLine (HWND, LPUIEXTRA, LPINPUTCONTEXT);
#endif
#define CS_SAENARU (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_IME)
/**********************************************************************/
/* */
/* IMERegisterClass() */
/* */
/* This function is called by IMMInquire. */
/* Register the classes for the child windows. */
/* Create global GDI objects. */
/* */
/**********************************************************************/
BOOL IMERegisterClass( hInstance )
HANDLE hInstance;
{
WNDCLASSEX wc;
//
// register class of UI window.
//
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_SAENARU;
wc.lpfnWndProc = SAENARUWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 8;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = NULL;
wc.lpszMenuName = (LPTSTR)NULL;
wc.lpszClassName = (LPTSTR)szUIClassName;
wc.hbrBackground = NULL;
wc.hIconSm = NULL;
if( !RegisterClassEx( (LPWNDCLASSEX)&wc ) )
return FALSE;
//
// register class of composition window.
//
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_SAENARU;
wc.lpfnWndProc = CompStrWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = UIEXTRASIZE;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = NULL;
wc.lpszMenuName = (LPTSTR)NULL;
wc.lpszClassName = (LPTSTR)szCompStrClassName;
wc.hbrBackground = NULL;
wc.hIconSm = NULL;
if( !RegisterClassEx( (LPWNDCLASSEX)&wc ) )
return FALSE;
//
// register class of candidate window.
//
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_SAENARU;
wc.lpfnWndProc = CandWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = UIEXTRASIZE;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = NULL;
wc.lpszMenuName = (LPTSTR)NULL;
wc.lpszClassName = (LPTSTR)szCandClassName;
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
//wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.hIconSm = NULL;
if( !RegisterClassEx( (LPWNDCLASSEX)&wc ) )
return FALSE;
//
// register class of status window.
//
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_SAENARU;
wc.lpfnWndProc = StatusWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = UIEXTRASIZE;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = NULL;
wc.lpszMenuName = (LPTSTR)NULL;
wc.lpszClassName = (LPTSTR)szStatusClassName;
wc.hbrBackground = NULL;
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
//wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.hIconSm = NULL;
if( !RegisterClassEx( (LPWNDCLASSEX)&wc ) )
return FALSE;
//
// register class of guideline window.
//
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_SAENARU;
wc.lpfnWndProc = GuideWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = UIEXTRASIZE;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = NULL;
wc.lpszMenuName = (LPTSTR)NULL;
wc.lpszClassName = (LPTSTR)szGuideClassName;
wc.hbrBackground = NULL;
//wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.hIconSm = NULL;
if( !RegisterClassEx( (LPWNDCLASSEX)&wc ) )
return FALSE;
return TRUE;
}
/**********************************************************************/
/* */
/* SAENARUWndProc() */
/* */
/* IME UI window procedure */
/* */
/**********************************************************************/
LRESULT CALLBACK SAENARUWndProc( hWnd, message, wParam, lParam )
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
HIMC hUICurIMC;
LPINPUTCONTEXT lpIMC;
LPUIEXTRA lpUIExtra;
HGLOBAL hUIExtra;
LONG lRet = 0L;
int i;
hUICurIMC = (HIMC)GetWindowLongPtr(hWnd,IMMGWLP_IMC);
//
// Even if there is no current UI. these messages should not be pass to
// DefWindowProc().
//
if (!hUICurIMC)
{
switch (message)
{
case WM_IME_STARTCOMPOSITION:
case WM_IME_ENDCOMPOSITION:
case WM_IME_COMPOSITION:
case WM_IME_NOTIFY:
case WM_IME_CONTROL:
case WM_IME_COMPOSITIONFULL:
case WM_IME_SELECT:
case WM_IME_CHAR:
#ifdef DEBUG
{
TCHAR szDev[80];
OutputDebugString((LPTSTR)TEXT("Why hUICurIMC is NULL????\r\n"));
wsprintf((LPTSTR)szDev,TEXT("\thWnd is %x\r\n"),hWnd);
OutputDebugString((LPTSTR)szDev);
wsprintf((LPTSTR)szDev,TEXT("\tmessage is %x\r\n"),message);
OutputDebugString((LPTSTR)szDev);
wsprintf((LPTSTR)szDev,TEXT("\twParam is %x\r\n"),wParam);
OutputDebugString((LPTSTR)szDev);
wsprintf((LPTSTR)szDev,TEXT("\tlParam is %x\r\n"),lParam);
OutputDebugString((LPTSTR)szDev);
}
#endif
return 0L;
default:
break;
}
}
switch (message)
{
case WM_CREATE:
//
// Allocate UI's extra memory block.
//
hUIExtra = GlobalAlloc(GHND,sizeof(UIEXTRA));
lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);
//
// Initialize the extra memory block.
//
lpUIExtra->uiStatus.pt.x = -1;
lpUIExtra->uiStatus.pt.y = -1;
lpUIExtra->uiDefComp.pt.x = -1;
lpUIExtra->uiDefComp.pt.y = -1;
lpUIExtra->uiCand.pt.x = -1;
lpUIExtra->uiCand.pt.y = -1;
lpUIExtra->uiGuide.pt.x = -1;
lpUIExtra->uiGuide.pt.y = -1;
#if 1
lpUIExtra->uiSoftKbd.pt.x = -1;
lpUIExtra->uiSoftKbd.pt.y = -1;
#endif
lpUIExtra->hFont = (HFONT)NULL;
GlobalUnlock(hUIExtra);
SetWindowLongPtr(hWnd,IMMGWLP_PRIVATE,(LONG_PTR)hUIExtra);
MyDebugPrint((TEXT("WM_CREATE\n")));
SetHookFunc();
break;
case WM_IME_SETCONTEXT:
MyDebugPrint((TEXT("WM_IME_SETCONTEXT\n")));
if (wParam)
{
hUIExtra = (HGLOBAL)GetWindowLongPtr(hWnd,IMMGWLP_PRIVATE);
lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);
lpUIExtra->hIMC = hUICurIMC;
if (hUICurIMC)
{
LPINPUTCONTEXT lpIMCT = NULL;
//
// input context was chenged.
// if there are the child windows, the diplay have to be
// updated.
//
lpIMC = ImmLockIMC(hUICurIMC);
if (lpIMC)
{
LPCOMPOSITIONSTRING lpCompStr;
LPCANDIDATEINFO lpCandInfo;
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
if (IsWindow(lpUIExtra->uiCand.hWnd))
HideCandWindow(lpUIExtra);
if (lParam & ISC_SHOWUICANDIDATEWINDOW)
{
if (lpCandInfo->dwCount)
{
CreateCandWindow(hWnd,lpUIExtra,lpIMC );
ResizeCandWindow(lpUIExtra,lpIMC);
MoveCandWindow(hWnd,lpIMC,lpUIExtra,FALSE);
}
}
if (IsWindow(lpUIExtra->uiDefComp.hWnd))
HideCompWindow(lpUIExtra);
if (lParam & ISC_SHOWUICANDIDATEWINDOW)
{
if (0 && lpCompStr->dwCompStrLen)
{
CreateCompWindow(hWnd,lpUIExtra,lpIMC );
MoveCompWindow(lpUIExtra,lpIMC);
}
}
#if 0
if (lParam & ISC_SHOWUIGUIDELINE) {
DWORD dwLevel, dwSize = 0;
if (ImmGetGuideLine (hUICurIMC, GGL_LEVEL, NULL, 0))
{
dwLevel = ImmGetGuideLine (hUICurIMC, GGL_LEVEL, NULL, 0);
if (dwLevel)
dwSize = ImmGetGuideLine (hUICurIMC, GGL_STRING, NULL, 0);
}
if (dwSize > 0) {
CreateGuideLine (hWnd, lpUIExtra, lpIMC);
ShowWindow (lpUIExtra->uiGuide.hWnd, SW_SHOWNOACTIVATE);
lpUIExtra->uiGuide.bShow = TRUE;
} else {
HideGuideLine (lpUIExtra);
}
} else {
HideGuideLine (lpUIExtra);
}
#endif
ImmUnlockIMCC(lpIMC->hCompStr);
ImmUnlockIMCC(lpIMC->hCandInfo);
}
else
{
HideCandWindow(lpUIExtra);
HideCompWindow(lpUIExtra);
}
UpdateStatusWindow(lpUIExtra);
ImmUnlockIMC(hUICurIMC);
}
else // it is NULL input context.
{
HideCandWindow(lpUIExtra);
HideCompWindow(lpUIExtra);
}
GlobalUnlock(hUIExtra);
}
//else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -