Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
6.9 KiB

  1. /**************************************************************************\
  2. * Module Name: softkbd.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Soft keyboard APIs
  7. *
  8. * History:
  9. * 03-Jan-1996 wkwok Ported from Win95
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include "softkbd.h"
  14. CONST LPCWSTR SoftKeyboardClassName[] = {
  15. L"",
  16. L"SoftKBDClsT1",
  17. L"SoftKBDClsC1"
  18. };
  19. BOOL RegisterSoftKeyboard(
  20. UINT uType)
  21. {
  22. WNDCLASSEX wcWndCls;
  23. if (GetClassInfoEx(ghInst, SoftKeyboardClassName[uType], &wcWndCls)) {
  24. return (TRUE);
  25. }
  26. wcWndCls.cbSize = sizeof(WNDCLASSEX);
  27. wcWndCls.style = CS_IME;
  28. wcWndCls.cbClsExtra = 0;
  29. wcWndCls.cbWndExtra = sizeof(HGLOBAL);
  30. wcWndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31. wcWndCls.hInstance = ghInst;
  32. wcWndCls.hCursor = LoadCursor(NULL, IDC_SIZEALL);
  33. wcWndCls.lpszMenuName = (LPWSTR)NULL;
  34. wcWndCls.lpszClassName = SoftKeyboardClassName[uType];
  35. wcWndCls.hIconSm = NULL;
  36. switch (uType) {
  37. case SOFTKEYBOARD_TYPE_T1:
  38. wcWndCls.lpfnWndProc = SKWndProcT1;
  39. wcWndCls.hbrBackground = GetStockObject(NULL_BRUSH);
  40. break;
  41. case SOFTKEYBOARD_TYPE_C1:
  42. wcWndCls.lpfnWndProc = SKWndProcC1;
  43. wcWndCls.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  44. break;
  45. default:
  46. return (TRUE);
  47. }
  48. if (RegisterClassEx(&wcWndCls)) {
  49. return (TRUE);
  50. } else {
  51. return (FALSE);
  52. }
  53. }
  54. VOID GetSoftKeyboardDimension(
  55. UINT uType,
  56. LPINT lpnWidth,
  57. LPINT lpnHeight)
  58. {
  59. switch (uType) {
  60. case SOFTKEYBOARD_TYPE_T1:
  61. {
  62. TEXTMETRIC tm;
  63. GetSKT1TextMetric(&tm);
  64. *lpnWidth = 2 * SKT1_XOUT + 2 * gptRaiseEdge.x +
  65. (tm.tmMaxCharWidth + SKT1_LABEL_BMP_X - SKT1_XOVERLAP +
  66. SKT1_XIN) * SKT1_TOTAL_COLUMN_NUM + 1 + 1;
  67. *lpnHeight = 2 * SKT1_YOUT + 2 * gptRaiseEdge.y +
  68. (tm.tmHeight + SKT1_LABEL_BMP_Y + SKT1_YIN) *
  69. SKT1_TOTAL_ROW_NUM + 1;
  70. }
  71. break;
  72. case SOFTKEYBOARD_TYPE_C1:
  73. {
  74. *lpnWidth = WIDTH_SOFTKBD_C1 +
  75. 2 * GetSystemMetrics(SM_CXBORDER) +
  76. 2 * GetSystemMetrics(SM_CXEDGE);
  77. *lpnHeight = HEIGHT_SOFTKBD_C1 +
  78. 2 * GetSystemMetrics(SM_CXBORDER) +
  79. 2 * GetSystemMetrics(SM_CXEDGE);
  80. }
  81. break;
  82. default:
  83. return;
  84. }
  85. }
  86. void GetAllMonitorSize(LPRECT lprc)
  87. {
  88. if (GetSystemMetrics(SM_CMONITORS) == 1) {
  89. SystemParametersInfo(SPI_GETWORKAREA, 0, lprc, 0);
  90. } else {
  91. // We have multi-monitor !
  92. lprc->left = GetSystemMetrics(SM_XVIRTUALSCREEN);
  93. lprc->top = GetSystemMetrics(SM_YVIRTUALSCREEN);
  94. lprc->right = lprc->left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
  95. lprc->bottom = lprc->top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
  96. }
  97. }
  98. BOOL GetNearestMonitorSize(HWND hwndOwner, LPRECT lprc)
  99. {
  100. if (GetSystemMetrics(SM_CMONITORS) == 1) {
  101. GetAllMonitorSize(lprc);
  102. }
  103. else {
  104. HMONITOR hmonitor = MonitorFromWindow(hwndOwner, MONITOR_DEFAULTTONEAREST);
  105. MONITORINFO mInfo = {
  106. sizeof(MONITORINFO),
  107. };
  108. if (hmonitor == NULL) {
  109. return FALSE;
  110. }
  111. GetMonitorInfoW(hmonitor, &mInfo);
  112. *lprc = mInfo.rcWork;
  113. }
  114. return TRUE;
  115. }
  116. HWND WINAPI
  117. ImmCreateSoftKeyboard(
  118. UINT uType,
  119. HWND hOwner,
  120. int x,
  121. int y)
  122. {
  123. static BOOL fFirstSoftKeyboard = TRUE;
  124. PIMEDPI pImeDpi;
  125. DWORD fdwUICaps;
  126. int nWidth, nHeight;
  127. HKL hCurrentKL;
  128. UINT i;
  129. HWND hSKWnd;
  130. RECT rcWork;
  131. SIZE szWork;
  132. if (!uType) {
  133. return (HWND)NULL;
  134. }
  135. if (uType >= sizeof(SoftKeyboardClassName) / sizeof(LPWSTR)) {
  136. return (HWND)NULL;
  137. }
  138. hCurrentKL = GetKeyboardLayout(0);
  139. pImeDpi = ImmLockImeDpi(hCurrentKL);
  140. if (pImeDpi == NULL) {
  141. RIPMSG1(RIP_WARNING,
  142. "ImmCreateSoftKeyboard, pImeDpi = NULL (hkl = 0x%x).\n", hCurrentKL);
  143. return (HWND)NULL;
  144. }
  145. fdwUICaps = pImeDpi->ImeInfo.fdwUICaps;
  146. ImmUnlockImeDpi(pImeDpi);
  147. if (!(fdwUICaps & UI_CAP_SOFTKBD)) {
  148. return (HWND)NULL;
  149. }
  150. if (fFirstSoftKeyboard) {
  151. if (!GetNearestMonitorSize(hOwner, &rcWork)) {
  152. // failed
  153. return NULL;
  154. }
  155. for (i = 0; i < sizeof(guScanCode) / sizeof(UINT); i++) {
  156. guScanCode[i] = MapVirtualKey(i, 0);
  157. }
  158. // LATER: have to consider the dynamic resolution change
  159. szWork.cx = rcWork.right - rcWork.left;
  160. UserAssert(szWork.cx > UI_MARGIN * 2);
  161. szWork.cy = rcWork.bottom - rcWork.top;
  162. UserAssert(szWork.cy > UI_MARGIN * 2);
  163. gptRaiseEdge.x = GetSystemMetrics(SM_CXEDGE) +
  164. GetSystemMetrics(SM_CXBORDER);
  165. gptRaiseEdge.y = GetSystemMetrics(SM_CYEDGE) +
  166. GetSystemMetrics(SM_CYBORDER);
  167. fFirstSoftKeyboard = FALSE;
  168. }
  169. if (!RegisterSoftKeyboard(uType)) {
  170. return (HWND)NULL;
  171. }
  172. GetSoftKeyboardDimension(uType, &nWidth, &nHeight);
  173. // boundry check
  174. if (x < 0) {
  175. x = 0;
  176. } else if (x + nWidth > szWork.cx) {
  177. x = szWork.cx - nWidth;
  178. }
  179. if (y < 0) {
  180. y = 0;
  181. } else if (y + nHeight > szWork.cy) {
  182. y = szWork.cy - nHeight;
  183. }
  184. switch (uType) {
  185. case SOFTKEYBOARD_TYPE_T1:
  186. hSKWnd = CreateWindowEx(0,
  187. SoftKeyboardClassName[uType],
  188. (LPCWSTR)NULL,
  189. WS_POPUP|WS_DISABLED,
  190. x, y, nWidth, nHeight,
  191. (HWND)hOwner, (HMENU)NULL, ghInst, NULL);
  192. break;
  193. case SOFTKEYBOARD_TYPE_C1:
  194. hSKWnd = CreateWindowEx(WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME,
  195. SoftKeyboardClassName[uType],
  196. (LPCWSTR)NULL,
  197. WS_POPUP|WS_DISABLED|WS_BORDER,
  198. x, y, nWidth, nHeight,
  199. (HWND)hOwner, (HMENU)NULL, ghInst, NULL);
  200. break;
  201. default:
  202. return (HWND)NULL;
  203. }
  204. ShowWindow(hSKWnd, SW_HIDE);
  205. UpdateWindow(hSKWnd);
  206. return (hSKWnd);
  207. }
  208. BOOL WINAPI
  209. ImmDestroySoftKeyboard(
  210. HWND hSKWnd)
  211. {
  212. return DestroyWindow(hSKWnd);
  213. }
  214. BOOL WINAPI
  215. ImmShowSoftKeyboard(
  216. HWND hSKWnd,
  217. int nCmdShow)
  218. {
  219. if (!hSKWnd) {
  220. return (FALSE);
  221. }
  222. return ShowWindow(hSKWnd, nCmdShow);
  223. }