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.

356 lines
15 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. init.cpp
  5. Abstract:
  6. This file implements an initialization.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "globals.h"
  13. #include "msime.h"
  14. #include "context.h"
  15. #include "uicomp.h"
  16. #include "caret.h"
  17. //+---------------------------------------------------------------------------
  18. //
  19. // RegisterImeClass
  20. //
  21. //----------------------------------------------------------------------------
  22. BOOL PASCAL RegisterImeClass()
  23. {
  24. WNDCLASSEXW wcWndCls;
  25. // register class of IME UI window.
  26. wcWndCls.cbSize = sizeof(WNDCLASSEX);
  27. wcWndCls.cbClsExtra = 0;
  28. wcWndCls.cbWndExtra = sizeof(LONG_PTR) * 2; // 0: IMMGWL_IMC
  29. // 1: IMMGWL_PRIVATE = class UI
  30. wcWndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31. wcWndCls.hInstance = GetInstance();
  32. wcWndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
  33. wcWndCls.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
  34. wcWndCls.lpszMenuName = (LPWSTR)NULL;
  35. wcWndCls.hIconSm = NULL;
  36. if (!GetClassInfoExW(GetInstance(), s_szUIClassName, &wcWndCls)) {
  37. wcWndCls.style = CS_IME | CS_GLOBALCLASS;
  38. wcWndCls.lpfnWndProc = UIWndProc;
  39. wcWndCls.lpszClassName = s_szUIClassName;
  40. ATOM atom = RegisterClassExW(&wcWndCls);
  41. if (atom == 0)
  42. return FALSE;
  43. }
  44. // register class of composition window.
  45. wcWndCls.cbSize = sizeof(WNDCLASSEX);
  46. wcWndCls.cbClsExtra = 0;
  47. wcWndCls.cbWndExtra = sizeof(LONG_PTR); // COMPUI_WINDOW_INDEX: index of first/middle/last
  48. wcWndCls.hIcon = NULL;
  49. wcWndCls.hInstance = GetInstance();
  50. wcWndCls.hCursor = LoadCursor(NULL, IDC_IBEAM);
  51. wcWndCls.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
  52. wcWndCls.lpszMenuName = (LPWSTR)NULL;
  53. wcWndCls.hIconSm = NULL;
  54. if (!GetClassInfoExW(GetInstance(), s_szCompClassName, &wcWndCls)) {
  55. wcWndCls.style = CS_IME | CS_VREDRAW | CS_HREDRAW;
  56. wcWndCls.lpfnWndProc = UIComposition::CompWndProc;
  57. wcWndCls.lpszClassName = s_szCompClassName;
  58. ATOM atom = RegisterClassExW(&wcWndCls);
  59. if (atom == 0)
  60. return FALSE;
  61. }
  62. return TRUE;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // UnregisterImeClass
  67. //
  68. //----------------------------------------------------------------------------
  69. void PASCAL UnregisterImeClass()
  70. {
  71. WNDCLASSEXW wcWndCls;
  72. BOOL ret;
  73. // IME UI class
  74. GetClassInfoExW(GetInstance(), s_szUIClassName, &wcWndCls);
  75. ret = UnregisterClassW(s_szUIClassName, GetInstance());
  76. Assert(ret);
  77. DestroyIcon(wcWndCls.hIcon);
  78. DestroyIcon(wcWndCls.hIconSm);
  79. // IME composition class
  80. GetClassInfoExW(GetInstance(), s_szCompClassName, &wcWndCls);
  81. ret = UnregisterClassW(s_szCompClassName, GetInstance());
  82. Assert(ret);
  83. DestroyIcon(wcWndCls.hIcon);
  84. DestroyIcon(wcWndCls.hIconSm);
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // RegisterMSIMEMessage
  89. //
  90. //----------------------------------------------------------------------------
  91. BOOL RegisterMSIMEMessage()
  92. {
  93. WM_MSIME_SERVICE = RegisterWindowMessage( RWM_SERVICE );
  94. WM_MSIME_UIREADY = RegisterWindowMessage( RWM_UIREADY );
  95. WM_MSIME_RECONVERTREQUEST = RegisterWindowMessage( RWM_RECONVERTREQUEST );
  96. WM_MSIME_RECONVERT = RegisterWindowMessage( RWM_RECONVERT );
  97. WM_MSIME_DOCUMENTFEED = RegisterWindowMessage( RWM_DOCUMENTFEED );
  98. WM_MSIME_QUERYPOSITION = RegisterWindowMessage( RWM_QUERYPOSITION );
  99. WM_MSIME_MODEBIAS = RegisterWindowMessage( RWM_MODEBIAS );
  100. WM_MSIME_SHOWIMEPAD = RegisterWindowMessage( RWM_SHOWIMEPAD );
  101. WM_MSIME_MOUSE = RegisterWindowMessage( RWM_MOUSE );
  102. WM_MSIME_KEYMAP = RegisterWindowMessage( RWM_KEYMAP );
  103. if (!WM_MSIME_SERVICE ||
  104. !WM_MSIME_UIREADY ||
  105. !WM_MSIME_RECONVERTREQUEST ||
  106. !WM_MSIME_RECONVERT ||
  107. !WM_MSIME_DOCUMENTFEED ||
  108. !WM_MSIME_QUERYPOSITION ||
  109. !WM_MSIME_MODEBIAS ||
  110. !WM_MSIME_SHOWIMEPAD ||
  111. !WM_MSIME_MOUSE ||
  112. !WM_MSIME_KEYMAP)
  113. return FALSE;
  114. return TRUE;
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // AttachIME
  119. //
  120. //----------------------------------------------------------------------------
  121. BOOL PASCAL AttachIME()
  122. {
  123. if (!RegisterImeClass())
  124. return FALSE;
  125. if (!RegisterMSIMEMessage())
  126. return FALSE;
  127. return TRUE;
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // DetachIME
  132. //
  133. //----------------------------------------------------------------------------
  134. void PASCAL DetachIME()
  135. {
  136. UnregisterImeClass();
  137. }
  138. //+---------------------------------------------------------------------------
  139. //
  140. // Inquire
  141. //
  142. //----------------------------------------------------------------------------
  143. HRESULT WINAPI Inquire(
  144. LPIMEINFO lpImeInfo, // IME specific data report to IMM
  145. LPWSTR lpszWndCls, // the class name of UI
  146. DWORD dwSystemInfoFlags,
  147. HKL hKL)
  148. {
  149. if (! lpImeInfo)
  150. return E_OUTOFMEMORY;
  151. DebugMsg(TF_FUNC, TEXT("Inquire(hKL=%x)"), hKL);
  152. // UI class name
  153. wcscpy(lpszWndCls, s_szUIClassName);
  154. // Private data size.
  155. lpImeInfo->dwPrivateDataSize = 0;
  156. // Properties
  157. if (LOWORD(HandleToUlong(hKL)) == MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT))
  158. {
  159. lpImeInfo->fdwProperty =
  160. IME_PROP_KBD_CHAR_FIRST | // This bit on indicates the system translates the character
  161. // by keyboard first. This character is passed to IME as aid
  162. // information. No aid information is provided when this bit
  163. // is off.
  164. IME_PROP_UNICODE | // If set, the IME is viewed as a Unicode IME. The system and
  165. // the IME will communicate through the Unicode IME interface.
  166. // If clear, IME will use the ANSI interface to communicate
  167. // with the system.
  168. IME_PROP_AT_CARET | // If set, conversion window is at the caret position.
  169. // If clear, the window is near caret position.
  170. IME_PROP_CANDLIST_START_FROM_1 | // If set, strings in the candidate list are numbered
  171. // starting at 1. If clear, strings start at 0.
  172. IME_PROP_NEED_ALTKEY | // This IME needs the ALT key to be passed to ImmProcessKey.
  173. IME_PROP_COMPLETE_ON_UNSELECT; // Windows 98 and Windows 2000:
  174. // If set, the IME will complete the composition
  175. // string when the IME is deactivated.
  176. // If clear, the IME will cancel the composition
  177. // string when the IME is deactivated.
  178. // (for example, from a keyboard layout change).
  179. lpImeInfo->fdwConversionCaps =
  180. IME_CMODE_JAPANESE | // This bit on indicates IME is in JAPANESE(NATIVE) mode. Otherwise, the
  181. // IME is in ALPHANUMERIC mode.
  182. IME_CMODE_KATAKANA | //
  183. IME_CMODE_FULLSHAPE;
  184. lpImeInfo->fdwSentenceCaps =
  185. IME_SMODE_PLAURALCLAUSE |
  186. IME_SMODE_CONVERSATION;
  187. lpImeInfo->fdwSCSCaps =
  188. SCS_CAP_COMPSTR | // This IME can generate the composition string by SCS_SETSTR.
  189. SCS_CAP_MAKEREAD | // When calling ImmSetCompositionString with SCS_SETSTR, the IME can
  190. // create the reading of composition string without lpRead. Under IME
  191. // that has this capability, the application does not need to set
  192. // lpRead for SCS_SETSTR.
  193. SCS_CAP_SETRECONVERTSTRING; // This IME can support reconversion. Use ImmSetComposition
  194. // to do reconversion.
  195. lpImeInfo->fdwUICaps = UI_CAP_ROT90;
  196. // IME want to decide conversion mode on ImeSelect
  197. lpImeInfo->fdwSelectCaps = SELECT_CAP_CONVERSION | SELECT_CAP_SENTENCE;
  198. }
  199. else if (LOWORD(HandleToUlong(hKL)) == MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT))
  200. {
  201. lpImeInfo->fdwProperty =
  202. IME_PROP_KBD_CHAR_FIRST | // This bit on indicates the system translates the character
  203. // by keyboard first. This character is passed to IME as aid
  204. // information. No aid information is provided when this bit
  205. // is off.
  206. IME_PROP_UNICODE | // If set, the IME is viewed as a Unicode IME. The system and
  207. // the IME will communicate through the Unicode IME interface.
  208. // If clear, IME will use the ANSI interface to communicate
  209. // with the system.
  210. IME_PROP_AT_CARET | // If set, conversion window is at the caret position.
  211. // If clear, the window is near caret position.
  212. IME_PROP_CANDLIST_START_FROM_1 | // If set, strings in the candidate list are numbered
  213. // starting at 1. If clear, strings start at 0.
  214. IME_PROP_NEED_ALTKEY | // This IME needs the ALT key to be passed to ImmProcessKey.
  215. IME_PROP_COMPLETE_ON_UNSELECT; // Windows 98 and Windows 2000:
  216. // If set, the IME will complete the composition
  217. // string when the IME is deactivated.
  218. // If clear, the IME will cancel the composition
  219. // string when the IME is deactivated.
  220. // (for example, from a keyboard layout change).
  221. lpImeInfo->fdwConversionCaps =
  222. IME_CMODE_HANGUL | // This bit on indicates IME is in HANGUL(NATIVE) mode. Otherwise, the
  223. // IME is in ALPHANUMERIC mode.
  224. IME_CMODE_FULLSHAPE;
  225. lpImeInfo->fdwSentenceCaps = 0;
  226. lpImeInfo->fdwSCSCaps =
  227. SCS_CAP_COMPSTR | // This IME can generate the composition string by SCS_SETSTR.
  228. #if 0
  229. SCS_CAP_COMPSTR | // This IME can generate the composition string by SCS_SETSTR.
  230. SCS_CAP_MAKEREAD | // When calling ImmSetCompositionString with SCS_SETSTR, the IME can
  231. // create the reading of composition string without lpRead. Under IME
  232. // that has this capability, the application does not need to set
  233. // lpRead for SCS_SETSTR.
  234. #endif
  235. SCS_CAP_SETRECONVERTSTRING; // This IME can support reconversion. Use ImmSetComposition
  236. // to do reconversion.
  237. lpImeInfo->fdwUICaps = UI_CAP_ROT90;
  238. // IME want to decide conversion mode on ImeSelect
  239. lpImeInfo->fdwSelectCaps = SELECT_CAP_CONVERSION;
  240. }
  241. else if (LOWORD(HandleToUlong(hKL)) == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) ||
  242. LOWORD(HandleToUlong(hKL)) == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL))
  243. {
  244. lpImeInfo->fdwProperty =
  245. IME_PROP_KBD_CHAR_FIRST | // This bit on indicates the system translates the character
  246. // by keyboard first. This character is passed to IME as aid
  247. // information. No aid information is provided when this bit
  248. // is off.
  249. IME_PROP_UNICODE | // If set, the IME is viewed as a Unicode IME. The system and
  250. // the IME will communicate through the Unicode IME interface.
  251. // If clear, IME will use the ANSI interface to communicate
  252. // with the system.
  253. IME_PROP_AT_CARET | // If set, conversion window is at the caret position.
  254. // If clear, the window is near caret position.
  255. IME_PROP_CANDLIST_START_FROM_1 | // If set, strings in the candidate list are numbered
  256. // starting at 1. If clear, strings start at 0.
  257. IME_PROP_NEED_ALTKEY; // This IME needs the ALT key to be passed to ImmProcessKey.
  258. lpImeInfo->fdwConversionCaps =
  259. IME_CMODE_CHINESE | // This bit on indicates IME is in CHINESE(NATIVE) mode. Otherwise, the
  260. // IME is in ALPHANUMERIC mode.
  261. IME_CMODE_FULLSHAPE;
  262. lpImeInfo->fdwSentenceCaps =
  263. IME_SMODE_PLAURALCLAUSE;
  264. lpImeInfo->fdwSCSCaps =
  265. SCS_CAP_COMPSTR | // This IME can generate the composition string by SCS_SETSTR.
  266. SCS_CAP_MAKEREAD | // When calling ImmSetCompositionString with SCS_SETSTR, the IME can
  267. // create the reading of composition string without lpRead. Under IME
  268. // that has this capability, the application does not need to set
  269. // lpRead for SCS_SETSTR.
  270. SCS_CAP_SETRECONVERTSTRING; // This IME can support reconversion. Use ImmSetComposition
  271. // to do reconversion.
  272. lpImeInfo->fdwUICaps = UI_CAP_ROT90;
  273. // IME want to decide conversion mode on ImeSelect
  274. lpImeInfo->fdwSelectCaps = 0;
  275. }
  276. else
  277. {
  278. lpImeInfo->fdwProperty =
  279. IME_PROP_UNICODE | // If set, the IME is viewed as a Unicode IME. The system and
  280. // the IME will communicate through the Unicode IME interface.
  281. // If clear, IME will use the ANSI interface to communicate
  282. // with the system.
  283. IME_PROP_AT_CARET; // If set, conversion window is at the caret position.
  284. // If clear, the window is near caret position.
  285. lpImeInfo->fdwConversionCaps = 0;
  286. lpImeInfo->fdwSentenceCaps = 0;
  287. lpImeInfo->fdwSCSCaps = 0;
  288. lpImeInfo->fdwUICaps = 0;
  289. // IME want to decide conversion mode on ImeSelect
  290. lpImeInfo->fdwSelectCaps = 0;
  291. }
  292. return S_OK;
  293. }