📄 ddis.c
字号:
/*++
Copyright (c) 1990-1999 Microsoft Corporation, All Rights Reserved
Module Name:
ddis.c
++*/
#include <windows.h>
#include <windowsx.h>
#include <winerror.h>
#include <imm.h>
#include <imedefs.h>
#include <resource.h>
#include <regstr.h>
#include <winuser.h>
HWND hCrtDlg = NULL;
/**********************************************************************/
/* ImeInquire() */
/* Return Value: */
/* TRUE - successful, FALSE - failure */
/**********************************************************************/
BOOL WINAPI ImeInquire( // initialized data structure of IME
LPIMEINFO lpImeInfo, // IME specific data report to IMM
LPTSTR lpszWndCls, // the class name of UI
DWORD lpszOptions) // this is for 3.1 IME only, chicago IME
// should not use this
{
if (!lpImeInfo) {
return (FALSE);
}
lpImeInfo->dwPrivateDataSize = sizeof(PRIVCONTEXT);
lpImeInfo->fdwProperty = IME_PROP_KBD_CHAR_FIRST|
IME_PROP_UNICODE|
IME_PROP_CANDLIST_START_FROM_1|
IME_PROP_IGNORE_UPKEYS;
lpImeInfo->fdwConversionCaps = IME_CMODE_NATIVE|IME_CMODE_FULLSHAPE|
IME_CMODE_CHARCODE|IME_CMODE_SOFTKBD|IME_CMODE_NOCONVERSION;
lpImeInfo->fdwSentenceCaps = 0;
// IME will have different distance base multiple of 900 escapement
lpImeInfo->fdwUICaps = UI_CAP_ROT90|UI_CAP_SOFTKBD;
// composition string is the reading string for simple IME
lpImeInfo->fdwSCSCaps = SCS_CAP_COMPSTR|SCS_CAP_MAKEREAD;
// IME want to decide conversion mode on ImeSelect
lpImeInfo->fdwSelectCaps = (DWORD)0;
lstrcpy(lpszWndCls, (LPTSTR)szUIClassName);
return (TRUE);
}
#if defined(CROSSREF)
/**********************************************************************/
/* ReverseConversionList() */
/**********************************************************************/
void PASCAL ReverseConversionList(HWND hLayoutListBox)
{
int nLayouts, i, nIMEs;
TCHAR szTmpImeName[24];
HKL FAR *lpKLMem;
LoadString(hInst, IDS_NONE, szTmpImeName, sizeof(szTmpImeName)/sizeof(TCHAR));
SendMessage(hLayoutListBox, LB_INSERTSTRING,
0, (LPARAM)szTmpImeName);
SendMessage(hLayoutListBox, LB_SELECTSTRING,
0, (LPARAM)szTmpImeName);
SendMessage(hLayoutListBox, LB_SETITEMDATA,
0, (LPARAM)(HKL)NULL);
nLayouts = GetKeyboardLayoutList(0, NULL);
lpKLMem = GlobalAlloc(GPTR, sizeof(HKL) * nLayouts);
if (!lpKLMem) {
return;
}
GetKeyboardLayoutList(nLayouts, lpKLMem);
for (i = 0, nIMEs = 0; i < nLayouts; i++) {
HKL hKL;
hKL = *(lpKLMem + i);
if (LOWORD(hKL) != NATIVE_LANGUAGE) {
// not support other language
continue;
}
if (!ImmGetConversionList(hKL, (HIMC)NULL, NULL,
NULL, 0, GCL_REVERSECONVERSION)) {
// this IME not support reverse conversion
continue;
}
if (!ImmEscape(hKL, (HIMC)NULL, IME_ESC_IME_NAME,
szTmpImeName)) {
// this IME does not report the IME name
continue;
}
if( lstrcmp(szTmpImeName, szImeName) == 0)
continue;
nIMEs++;
SendMessage(hLayoutListBox, LB_INSERTSTRING,
nIMEs, (LPARAM)szTmpImeName);
if (hKL == sImeG.hRevKL) {
SendMessage(hLayoutListBox, LB_SELECTSTRING, nIMEs,
(LPARAM)szTmpImeName);
}
SendMessage(hLayoutListBox, LB_SETITEMDATA,
nIMEs, (LPARAM)hKL);
}
GlobalFree((HGLOBAL)lpKLMem);
return;
}
#endif //CROSSREF
/**********************************************************************/
/* ImeSetDlgProc() */
/* Return Value: */
/* TRUE - successful, FALSE - failure */
/**********************************************************************/
BOOL FAR PASCAL ImeSetDlgProc( // dialog procedure of configuration
HWND hDlg,
UINT uMessage,
WORD wParam,
LONG lParam)
{
RECT rc;
LONG DlgWidth, DlgHeight;
static DWORD TempParam;
#ifdef CROSSREF
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
HWND hLayoutListBox;
static HIMC hOldIMC;
#endif //CROSSREF
switch (uMessage) {
case WM_INITDIALOG:
hCrtDlg = hDlg;
// reset position
GetWindowRect(hDlg, &rc);
DlgWidth = rc.right - rc.left;
DlgHeight = rc.bottom - rc.top;
SetWindowPos(hDlg, HWND_TOP,
(int)(sImeG.rcWorkArea.right - DlgWidth)/2,
(int)(sImeG.rcWorkArea.bottom - DlgHeight)/2,
(int)0, (int)0, SWP_NOSIZE);
TempParam = sImeG.IC_Trace;
CheckDlgButton (hDlg, IDC_TRACE, sImeG.IC_Trace);
#ifdef CROSSREF
hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
hIMC = ImmGetContext(hLayoutListBox);
if(hIMC){
ImmSetOpenStatus(hIMC, FALSE);
}
ImmReleaseContext(hLayoutListBox, hIMC);
// put all reverse conversion hKL into this list
ReverseConversionList(hLayoutListBox);
#endif //CROSSREF
return (TRUE); // don't want to set focus to special control
case WM_COMMAND:
switch (wParam) {
case IDOK:
{
HKEY hKeyCurrVersion;
HKEY hKeyGB;
DWORD retCode;
//CHAR Buf[LINE_LEN];
sImeG.IC_Trace = TempParam;
retCode = OpenReg_PathSetup(&hKeyCurrVersion);
if (retCode) {
RegCreateKey(HKEY_CURRENT_USER,
REGSTR_PATH_SETUP,
&hKeyCurrVersion);
}
retCode = RegCreateKeyEx(hKeyCurrVersion,
szImeRegName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKeyGB,
NULL);
if (retCode){
RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_SETUP, &hKeyCurrVersion);
}
RegSetValueEx (hKeyGB,
szTrace,
(DWORD)0,
REG_DWORD,
(LPBYTE)&sImeG.IC_Trace,
sizeof(DWORD));
RegCloseKey(hKeyGB);
RegCloseKey(hKeyCurrVersion);
#ifdef CROSSREF
{
HWND hLayoutListBox;
int iCurSel;
HKL hKL;
DWORD retCode;
hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
iCurSel = (int)SendMessage(hLayoutListBox, LB_GETCURSEL, 0, 0);
hKL = (HKL)SendMessage(hLayoutListBox, LB_GETITEMDATA,
iCurSel, 0);
if (sImeG.hRevKL != hKL) {
WORD nRevMaxKey;
HKEY hKeyAppUser, hKeyIMEUser;
LPPRIVCONTEXT lpImcP;
sImeG.hRevKL = hKL;
//set reverse layout to registry
retCode = OpenReg_PathSetup(&hKeyAppUser);
if (retCode) {
RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_SETUP, &hKeyCurrVersion);
}
retCode = RegCreateKeyEx(hKeyAppUser, szImeRegName, 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS , NULL, &hKeyIMEUser, NULL);
if (retCode) {
DWORD dwDisposition;
retCode = RegCreateKeyEx (hKeyCurrVersion,
szImeRegName,
0,
0,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKeyGB,
&dwDisposition);
}
RegSetValueEx(hKeyIMEUser, szRegRevKL, 0, REG_DWORD, (LPBYTE)&hKL,sizeof(hKL));
// get the new size
nRevMaxKey = (WORD)ImmEscape(hKL, (HIMC)NULL, IME_ESC_MAX_KEY,
NULL);
if (lpImeL->nMaxKey != nRevMaxKey) {
if(lpImeL->nMaxKey < nRevMaxKey)
lpImeL->nMaxKey = nRevMaxKey;
//__asm int 3;
// set the width & height for composition window
lpImeL->rcCompText.right = lpImeL->rcCompText.left +
sImeG.xChiCharWi * ((lpImeL->nMaxKey+2)/2);
lpImeL->xCompWi = lpImeL->rcCompText.right + lpImeL->cxCompBorder * (2 + 4);
//generate message to broadcast change comp win size
hIMC = (HIMC)ImmGetContext(hDlg);
if (!hIMC) {
return TRUE;
}
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return TRUE;
}
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if (!lpImcP) {
goto ChgConfigUnlockIMC;
}
lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS;
GenerateMessage(hIMC, lpIMC, lpImcP);
ImmUnlockIMCC(lpIMC->hPrivate);
ChgConfigUnlockIMC:
ImmUnlockIMC(hIMC);
} //end of change nMaxKey
RegSetValueEx(hKeyIMEUser, szRegRevMaxKey, 0, REG_DWORD, (LPBYTE)&lpImeL->nMaxKey,sizeof(DWORD));
RegCloseKey(hKeyAppUser);
RegCloseKey(hKeyIMEUser);
} //end of change RegRevKL
}
#endif //CROSSREF
}
#ifdef CROSSREF
hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
hIMC = ImmGetContext(hLayoutListBox);
if(hIMC) {
ImmSetOpenStatus(hIMC, TRUE);
}
ImmReleaseContext(hLayoutListBox, hIMC);
#endif //CROSSREF
EndDialog(hDlg, FALSE);
break;
case IDCANCEL:
#ifdef CROSSREF
hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
hIMC = ImmGetContext(hLayoutListBox);
if(hIMC) {
ImmSetOpenStatus(hIMC, TRUE);
}
ImmReleaseContext(hLayoutListBox, hIMC);
#endif //CROSSREF
EndDialog(hDlg, FALSE);
break;
case IDC_TRACE:
// Set Current InputMode Param(temp)
TempParam = (TempParam ^ 0x00000001) & 0x00000001;
break;
default:
return (FALSE);
}
return (TRUE);
case WM_PAINT:
{
RECT rc;
GetClientRect(hDlg, &rc);
DrawConvexRect(GetDC(hDlg),
rc.left + 7,
rc.top + 7,
rc.right - 7 - 1,
rc.bottom - 40 - 1);
DrawConvexRectP(GetDC(hDlg),
rc.left + 7,
rc.top + 7,
rc.right - 7,
rc.bottom - 40);
}
return (FALSE);
case WM_CLOSE:
#ifdef CROSSREF
hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
hIMC = ImmGetContext(hLayoutListBox);
if(hIMC) {
ImmSetOpenStatus(hIMC, TRUE);
}
ImmReleaseContext(hLayoutListBox, hIMC);
#endif //CROSSREF
EndDialog(hDlg, FALSE);
return (TRUE);
default:
return (FALSE);
}
return (TRUE);
}
/**********************************************************************/
/* ImeConfigure() */
/* Return Value: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -