Source code of Windows XP (NT5)
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.

263 lines
8.0 KiB

  1. /*************************************************
  2. * config.c *
  3. * *
  4. * Copyright (C) 1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. /**********************************************************************/
  8. #include <windows.h>
  9. #include <immdev.h>
  10. #include "imeattr.h"
  11. #include "imedefs.h"
  12. #include "imerc.h"
  13. /**********************************************************************/
  14. /* ResourceLocked() */
  15. /**********************************************************************/
  16. void PASCAL ResourceLocked(
  17. HWND hWnd)
  18. {
  19. TCHAR szErrMsg[32];
  20. LoadString(hInst, IDS_SHARE_VIOLATION, szErrMsg, sizeof(szErrMsg)/sizeof(TCHAR));
  21. MessageBeep((UINT)-1);
  22. MessageBox(hWnd, szErrMsg, lpImeL->szIMEName,
  23. MB_OK|MB_ICONHAND|MB_TASKMODAL|MB_TOPMOST);
  24. return;
  25. }
  26. /**********************************************************************/
  27. /* ReverseConversionList() */
  28. /**********************************************************************/
  29. void PASCAL ReverseConversionList(
  30. HWND hLayoutListBox)
  31. {
  32. TCHAR szImeName[16];
  33. HKL FAR *lpKLMem;
  34. int nLayouts, i, nIMEs;
  35. LoadString(hInst, IDS_NONE, szImeName, sizeof(szImeName)/sizeof(TCHAR));
  36. SendMessage(hLayoutListBox, LB_INSERTSTRING,
  37. 0, (LPARAM)szImeName);
  38. SendMessage(hLayoutListBox, LB_SELECTSTRING,
  39. 0, (LPARAM)szImeName);
  40. SendMessage(hLayoutListBox, LB_SETITEMDATA,
  41. 0, (LPARAM)(HKL)NULL);
  42. nLayouts = GetKeyboardLayoutList(0, NULL);
  43. lpKLMem = GlobalAlloc(GPTR, sizeof(HKL) * nLayouts);
  44. if (!lpKLMem) {
  45. return;
  46. }
  47. GetKeyboardLayoutList(nLayouts, lpKLMem);
  48. for (i = 0, nIMEs = 0; i < nLayouts; i++) {
  49. HKL hKL;
  50. hKL = *(lpKLMem + i);
  51. if (LOWORD(hKL) != NATIVE_LANGUAGE) {
  52. // not support other language
  53. continue;
  54. }
  55. // NULL hIMC ???????
  56. if (!ImmGetConversionList(hKL, (HIMC)NULL, NULL,
  57. NULL, 0, GCL_REVERSECONVERSION)) {
  58. // this IME not support reverse conversion
  59. continue;
  60. }
  61. if (!ImmEscape(hKL, (HIMC)NULL, IME_ESC_IME_NAME,
  62. szImeName)) {
  63. // this IME does not report the IME name
  64. continue;
  65. }
  66. nIMEs++;
  67. SendMessage(hLayoutListBox, LB_INSERTSTRING,
  68. nIMEs, (LPARAM)szImeName);
  69. if (hKL == lpImeL->hRevKL) {
  70. SendMessage(hLayoutListBox, LB_SELECTSTRING, nIMEs,
  71. (LPARAM)szImeName);
  72. }
  73. SendMessage(hLayoutListBox, LB_SETITEMDATA,
  74. nIMEs, (LPARAM)hKL);
  75. }
  76. GlobalFree((HGLOBAL)lpKLMem);
  77. return;
  78. }
  79. /**********************************************************************/
  80. /* ImeConfigure() / UniImeConfigure() */
  81. /* Return Value: */
  82. /* TRUE - successful, FALSE - failure */
  83. /**********************************************************************/
  84. // configurate the IME setting
  85. BOOL WINAPI ImeConfigure(
  86. HKL hKL, // hKL of this IME
  87. HWND hAppWnd, // the owner window
  88. DWORD dwMode, // mode of dialog
  89. LPVOID lpData) // the data depend on each mode
  90. {
  91. return (TRUE);
  92. }
  93. /**********************************************************************/
  94. /* ImeEscape() / UniImeEscape() */
  95. /* Return Value: */
  96. /* TRUE - successful, FALSE - failure */
  97. /**********************************************************************/
  98. #define IME_INPUTKEYTOSEQUENCE 0x22
  99. // escape function of IMEs
  100. LRESULT WINAPI ImeEscape(
  101. HIMC hIMC,
  102. UINT uSubFunc,
  103. LPVOID lpData)
  104. {
  105. LRESULT lRet;
  106. switch (uSubFunc) {
  107. case IME_ESC_QUERY_SUPPORT:
  108. if (!lpData) {
  109. return (FALSE);
  110. }
  111. switch (*(LPUINT)lpData) {
  112. case IME_ESC_QUERY_SUPPORT:
  113. case IME_ESC_MAX_KEY:
  114. case IME_ESC_IME_NAME:
  115. case IME_ESC_SYNC_HOTKEY:
  116. case IME_ESC_PRIVATE_HOTKEY:
  117. return (TRUE);
  118. default:
  119. return (FALSE);
  120. }
  121. break;
  122. case IME_ESC_MAX_KEY:
  123. return (lpImeL->nMaxKey);
  124. case IME_ESC_IME_NAME:
  125. if (!lpData) {
  126. return (FALSE);
  127. }
  128. *(LPMETHODNAME)lpData = *(LPMETHODNAME)lpImeL->szIMEName;
  129. // append a NULL terminator
  130. *(LPTSTR)((LPBYTE)lpData + sizeof(METHODNAME)) = '\0';
  131. return (TRUE);
  132. case IME_ESC_SYNC_HOTKEY:
  133. return (TRUE);
  134. case IME_ESC_PRIVATE_HOTKEY: {
  135. LPINPUTCONTEXT lpIMC;
  136. lRet = FALSE;
  137. //
  138. // early return for invalid input context
  139. //
  140. if ( (lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC)) == NULL ) {
  141. return (FALSE);
  142. }
  143. //
  144. // those private hotkeys are effective only in NATIVE mode
  145. //
  146. if ((lpIMC->fdwConversion & (IME_CMODE_NATIVE|IME_CMODE_EUDC|
  147. IME_CMODE_NOCONVERSION|IME_CMODE_CHARCODE)) == IME_CMODE_NATIVE) {
  148. LPPRIVCONTEXT lpImcP;
  149. LPCOMPOSITIONSTRING lpCompStr;
  150. if ( (lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate)) == NULL ) {
  151. ImmUnlockIMC(hIMC);
  152. return (FALSE);
  153. }
  154. switch (*(LPUINT)lpData) {
  155. case IME_ITHOTKEY_RESEND_RESULTSTR: // 0x200
  156. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  157. if ( lpCompStr != NULL ) {
  158. if (lpCompStr->dwResultStrLen) {
  159. lpImcP->fdwImeMsg |= MSG_COMPOSITION;
  160. lpImcP->dwCompChar = 0;
  161. lpImcP->fdwGcsFlag |= GCS_RESULTREAD|GCS_RESULT;
  162. GenerateMessage(hIMC, lpIMC, lpImcP);
  163. lRet = TRUE;
  164. }
  165. ImmUnlockIMCC(lpIMC->hCompStr);
  166. }
  167. break;
  168. case IME_ITHOTKEY_PREVIOUS_COMPOSITION: // 0x201
  169. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  170. if ( lpCompStr == NULL ) {
  171. break;
  172. }
  173. if (lpCompStr->dwResultReadStrLen) {
  174. DWORD dwResultReadStrLen;
  175. TCHAR szReading[16];
  176. dwResultReadStrLen = lpCompStr->dwResultReadStrLen;
  177. if (dwResultReadStrLen > lpImeL->nMaxKey*sizeof(WCHAR)/sizeof(TCHAR)) {
  178. dwResultReadStrLen = lpImeL->nMaxKey*sizeof(WCHAR)/sizeof(TCHAR);
  179. }
  180. CopyMemory(szReading, (LPBYTE)lpCompStr +
  181. lpCompStr->dwResultReadStrOffset,
  182. dwResultReadStrLen * sizeof(TCHAR));
  183. // NULL termainator
  184. szReading[dwResultReadStrLen] = TEXT('\0');
  185. GenerateMessage(hIMC, lpIMC, lpImcP);
  186. lRet = TRUE;
  187. }
  188. ImmUnlockIMCC(lpIMC->hCompStr);
  189. break;
  190. case IME_ITHOTKEY_UISTYLE_TOGGLE: // 0x202
  191. lpImeL->fdwModeConfig ^= MODE_CONFIG_OFF_CARET_UI;
  192. InitImeUIData(lpImeL);
  193. lpImcP->fdwImeMsg |= MSG_IMN_TOGGLE_UI;
  194. GenerateMessage(hIMC, lpIMC, lpImcP);
  195. lRet = TRUE;
  196. break;
  197. default:
  198. break;
  199. }
  200. ImmUnlockIMCC(lpIMC->hPrivate);
  201. if ( ! lRet ) {
  202. MessageBeep((UINT)-1);
  203. }
  204. }
  205. ImmUnlockIMC(hIMC);
  206. return (lRet);
  207. }
  208. default:
  209. return (FALSE);
  210. }
  211. return (lRet);
  212. }