00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
#include "precomp.h"
00012
#pragma hdrstop
00013
00014
#include "softkbd.h"
00015
00016
00017 CONST LPCWSTR
SoftKeyboardClassName[] = {
00018
L"",
00019
L"SoftKBDClsT1",
00020
L"SoftKBDClsC1"
00021 };
00022
00023
00024 BOOL RegisterSoftKeyboard(
00025 UINT uType)
00026 {
00027 WNDCLASSEX wcWndCls;
00028
00029
if (
GetClassInfoEx(
ghInst,
SoftKeyboardClassName[uType], &wcWndCls)) {
00030
return (
TRUE);
00031 }
00032
00033 wcWndCls.cbSize =
sizeof(WNDCLASSEX);
00034 wcWndCls.style = CS_IME;
00035 wcWndCls.cbClsExtra = 0;
00036 wcWndCls.cbWndExtra =
sizeof(HGLOBAL);
00037 wcWndCls.hIcon = LoadIcon(
NULL, IDI_APPLICATION);
00038 wcWndCls.hInstance =
ghInst;
00039 wcWndCls.hCursor = LoadCursor(
NULL, IDC_SIZEALL);
00040 wcWndCls.lpszMenuName = (LPWSTR)
NULL;
00041 wcWndCls.lpszClassName =
SoftKeyboardClassName[uType];
00042 wcWndCls.hIconSm =
NULL;
00043
00044
switch (uType) {
00045
case SOFTKEYBOARD_TYPE_T1:
00046 wcWndCls.lpfnWndProc =
SKWndProcT1;
00047 wcWndCls.hbrBackground = GetStockObject(NULL_BRUSH);
00048
break;
00049
case SOFTKEYBOARD_TYPE_C1:
00050 wcWndCls.lpfnWndProc =
SKWndProcC1;
00051 wcWndCls.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00052
break;
00053
default:
00054
return (
TRUE);
00055 }
00056
00057
if (
RegisterClassEx(&wcWndCls)) {
00058
return (
TRUE);
00059 }
else {
00060
return (
FALSE);
00061 }
00062 }
00063
00064
00065 VOID GetSoftKeyboardDimension(
00066 UINT uType,
00067 LPINT lpnWidth,
00068 LPINT lpnHeight)
00069 {
00070
switch (uType) {
00071
case SOFTKEYBOARD_TYPE_T1:
00072 {
00073 TEXTMETRIC tm;
00074
00075
GetSKT1TextMetric(&tm);
00076
00077 *lpnWidth = 2 *
SKT1_XOUT + 2 *
gptRaiseEdge.x +
00078 (tm.tmMaxCharWidth +
SKT1_LABEL_BMP_X -
SKT1_XOVERLAP +
00079
SKT1_XIN) *
SKT1_TOTAL_COLUMN_NUM + 1 + 1;
00080
00081 *lpnHeight = 2 *
SKT1_YOUT + 2 *
gptRaiseEdge.y +
00082 (tm.tmHeight +
SKT1_LABEL_BMP_Y +
SKT1_YIN) *
00083
SKT1_TOTAL_ROW_NUM + 1;
00084 }
00085
break;
00086
case SOFTKEYBOARD_TYPE_C1:
00087 {
00088 *lpnWidth =
WIDTH_SOFTKBD_C1 +
00089 2 *
GetSystemMetrics(SM_CXBORDER) +
00090 2 *
GetSystemMetrics(SM_CXEDGE);
00091
00092 *lpnHeight =
HEIGHT_SOFTKBD_C1 +
00093 2 *
GetSystemMetrics(SM_CXBORDER) +
00094 2 *
GetSystemMetrics(SM_CXEDGE);
00095 }
00096
break;
00097
default:
00098
return;
00099 }
00100 }
00101
00102
00103 void GetAllMonitorSize(LPRECT lprc)
00104 {
00105
if (
GetSystemMetrics(SM_CMONITORS) == 1) {
00106
SystemParametersInfo(SPI_GETWORKAREA, 0, lprc, 0);
00107 }
else {
00108
00109 lprc->left =
GetSystemMetrics(SM_XVIRTUALSCREEN);
00110 lprc->top =
GetSystemMetrics(SM_YVIRTUALSCREEN);
00111 lprc->right = lprc->left +
GetSystemMetrics(SM_CXVIRTUALSCREEN);
00112 lprc->bottom = lprc->top +
GetSystemMetrics(SM_CYVIRTUALSCREEN);
00113 }
00114 }
00115
00116 BOOL GetNearestMonitorSize(HWND hwndOwner, LPRECT lprc)
00117 {
00118
if (
GetSystemMetrics(SM_CMONITORS) == 1) {
00119
GetAllMonitorSize(lprc);
00120 }
00121
else {
00122 HMONITOR hmonitor =
MonitorFromWindow(hwndOwner, MONITOR_DEFAULTTONEAREST);
00123 MONITORINFO mInfo = {
00124
sizeof(MONITORINFO),
00125 };
00126
00127
if (hmonitor ==
NULL) {
00128
return FALSE;
00129 }
00130 GetMonitorInfoW(hmonitor, &mInfo);
00131 *lprc = mInfo.rcWork;
00132 }
00133
return TRUE;
00134 }
00135
00136 HWND WINAPI
00137 ImmCreateSoftKeyboard(
00138 UINT uType,
00139 HWND hOwner,
00140
int x,
00141
int y)
00142 {
00143
static BOOL fFirstSoftKeyboard =
TRUE;
00144
PIMEDPI pImeDpi;
00145
DWORD fdwUICaps;
00146
int nWidth, nHeight;
00147 HKL hCurrentKL;
00148
UINT i;
00149 HWND hSKWnd;
00150 RECT rcWork;
00151 SIZE szWork;
00152
00153
if (!uType) {
00154
return (HWND)
NULL;
00155 }
00156
00157
if (uType >=
sizeof(
SoftKeyboardClassName) /
sizeof(LPWSTR)) {
00158
return (HWND)
NULL;
00159 }
00160
00161 hCurrentKL =
GetKeyboardLayout(0);
00162
00163 pImeDpi =
ImmLockImeDpi(hCurrentKL);
00164
if (pImeDpi ==
NULL) {
00165 RIPMSG1(RIP_WARNING,
00166
"ImmCreateSoftKeyboard, pImeDpi = NULL (hkl = 0x%x).\n", hCurrentKL);
00167
return (HWND)
NULL;
00168 }
00169
00170 fdwUICaps = pImeDpi->
ImeInfo.fdwUICaps;
00171
ImmUnlockImeDpi(pImeDpi);
00172
00173
if (!(fdwUICaps & UI_CAP_SOFTKBD)) {
00174
return (HWND)
NULL;
00175 }
00176
00177
if (fFirstSoftKeyboard) {
00178
if (!
GetNearestMonitorSize(hOwner, &rcWork)) {
00179
00180
return NULL;
00181 }
00182
00183
for (i = 0; i <
sizeof(
guScanCode) /
sizeof(
UINT); i++) {
00184
guScanCode[i] =
MapVirtualKey(i, 0);
00185 }
00186
00187
00188
00189
00190 szWork.cx = rcWork.right - rcWork.left;
00191
00192 UserAssert(szWork.cx >
UI_MARGIN * 2);
00193 szWork.cy = rcWork.bottom - rcWork.top;
00194 UserAssert(szWork.cy >
UI_MARGIN * 2);
00195
00196
gptRaiseEdge.x =
GetSystemMetrics(SM_CXEDGE) +
00197
GetSystemMetrics(SM_CXBORDER);
00198
gptRaiseEdge.y =
GetSystemMetrics(SM_CYEDGE) +
00199
GetSystemMetrics(SM_CYBORDER);
00200
00201 fFirstSoftKeyboard =
FALSE;
00202 }
00203
00204
if (!
RegisterSoftKeyboard(uType)) {
00205
return (HWND)
NULL;
00206 }
00207
00208
GetSoftKeyboardDimension(uType, &nWidth, &nHeight);
00209
00210
00211
if (x < 0) {
00212 x = 0;
00213 }
else if (x + nWidth > szWork.cx) {
00214 x = szWork.cx - nWidth;
00215 }
00216
00217
if (y < 0) {
00218 y = 0;
00219 }
else if (y + nHeight > szWork.cy) {
00220 y = szWork.cy - nHeight;
00221 }
00222
00223
switch (uType) {
00224
case SOFTKEYBOARD_TYPE_T1:
00225 hSKWnd =
CreateWindowEx(0,
00226
SoftKeyboardClassName[uType],
00227 (LPCWSTR)
NULL,
00228 WS_POPUP|WS_DISABLED,
00229 x, y, nWidth, nHeight,
00230 (HWND)hOwner, (HMENU)
NULL,
ghInst,
NULL);
00231
break;
00232
case SOFTKEYBOARD_TYPE_C1:
00233 hSKWnd =
CreateWindowEx(WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME,
00234
SoftKeyboardClassName[uType],
00235 (LPCWSTR)
NULL,
00236 WS_POPUP|WS_DISABLED|WS_BORDER,
00237 x, y, nWidth, nHeight,
00238 (HWND)hOwner, (HMENU)
NULL,
ghInst,
NULL);
00239
break;
00240
default:
00241
return (HWND)
NULL;
00242 }
00243
00244
ShowWindow(hSKWnd, SW_HIDE);
00245
UpdateWindow(hSKWnd);
00246
00247
return (hSKWnd);
00248 }
00249
00250
00251
BOOL WINAPI
00252 ImmDestroySoftKeyboard(
00253 HWND hSKWnd)
00254 {
00255
return DestroyWindow(hSKWnd);
00256 }
00257
00258
00259
BOOL WINAPI
00260 ImmShowSoftKeyboard(
00261 HWND hSKWnd,
00262
int nCmdShow)
00263 {
00264
if (!hSKWnd) {
00265
return (
FALSE);
00266 }
00267
return ShowWindow(hSKWnd, nCmdShow);
00268 }