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.

434 lines
13 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. REGWORD.C - register word into dictionary of IME
  5. ++*/
  6. #include <windows.h>
  7. #include <immdev.h>
  8. #include <imedefs.h>
  9. #include <regstr.h>
  10. #ifdef EUDC
  11. /**********************************************************************/
  12. /* ImeRegsisterWord */
  13. /* Return Value: */
  14. /* TRUE - successful, FALSE - failure */
  15. /**********************************************************************/
  16. BOOL WINAPI ImeRegisterWord(
  17. LPCTSTR lpszReading,
  18. DWORD dwStyle,
  19. LPCTSTR lpszString)
  20. {
  21. HIMCC hPrivate;
  22. if (!lpszString || (lpszString[0] ==TEXT('\0'))) {
  23. return (FALSE);
  24. }
  25. if (!lpszReading || (lpszReading[0] == TEXT('\0'))) {
  26. return (FALSE);
  27. }
  28. // only handle word not string now, should consider string later?
  29. if (*(LPCTSTR)((LPBYTE)lpszString + sizeof(WORD)) != TEXT('\0')) {
  30. return (FALSE);
  31. }
  32. hPrivate = (HIMCC)ImmCreateIMCC(sizeof(PRIVCONTEXT));
  33. if (hPrivate != (HIMCC)NULL){
  34. StartEngine(hPrivate);
  35. AddZCItem(hPrivate, (LPTSTR)lpszReading, (LPTSTR)lpszString);
  36. EndEngine(hPrivate);
  37. ImmDestroyIMCC(hPrivate);
  38. return (TRUE);
  39. }
  40. else
  41. return (FALSE);
  42. }
  43. /**********************************************************************/
  44. /* ImeUnregsisterWord */
  45. /* Return Value: */
  46. /* TRUE - successful, FALSE - failure */
  47. /**********************************************************************/
  48. BOOL WINAPI ImeUnregisterWord(
  49. LPCTSTR lpszReading,
  50. DWORD dwStyle,
  51. LPCTSTR lpszString)
  52. {
  53. BOOL fRet;
  54. HANDLE hUsrDicMem, hUsrDicFile;
  55. LPTSTR lpUsrDicStart, lpCurr, lpUsrDicLimit, lpUsrDic;
  56. LPWORD lpwStart;
  57. WORD wNum_EMB;
  58. TCHAR szReading[MAXCODE];
  59. int i;
  60. fRet = FALSE;
  61. if (!lpszString || !lpszReading) {
  62. return (fRet);
  63. }
  64. if (!(dwStyle & IME_REGWORD_STYLE_EUDC)) {
  65. return (fRet);
  66. }
  67. // only handle word not string now, should consider string later?
  68. if (*(LPCTSTR)((LPBYTE)lpszString + sizeof(WORD)) != TEXT('\0')) {
  69. return (fRet);
  70. }
  71. if (!MBIndex.EUDCData.szEudcDictName[0]) {
  72. return (fRet);
  73. }
  74. hUsrDicFile = CreateFile(MBIndex.EUDCData.szEudcDictName,
  75. GENERIC_READ | GENERIC_WRITE,
  76. FILE_SHARE_READ|FILE_SHARE_WRITE,
  77. NULL,
  78. OPEN_EXISTING,
  79. FILE_ATTRIBUTE_NORMAL,
  80. (HANDLE)NULL);
  81. if (hUsrDicFile == INVALID_HANDLE_VALUE) {
  82. return FALSE;
  83. }
  84. hUsrDicMem = CreateFileMapping(hUsrDicFile,
  85. NULL,
  86. PAGE_READWRITE,
  87. 0,
  88. sizeof(EMB_Head)*MAXNUMBER_EMB+2,
  89. MBIndex.EUDCData.szEudcMapFileName);
  90. if (!hUsrDicMem) {
  91. CloseHandle(hUsrDicFile);
  92. return (fRet);
  93. }
  94. lpUsrDic = MapViewOfFile(hUsrDicMem, FILE_MAP_WRITE, 0, 0, 0);
  95. if (!lpUsrDic) {
  96. CloseHandle(hUsrDicFile);
  97. CloseHandle(hUsrDicMem);
  98. return (fRet);
  99. }
  100. lpwStart = (LPWORD)lpUsrDic;
  101. wNum_EMB = *lpwStart;
  102. // skip the first two bytes which contain the numeber of EMB records.
  103. lpUsrDicStart =(LPTSTR) ( (LPBYTE)lpUsrDic + sizeof(WORD) );
  104. lpUsrDicLimit=lpUsrDicStart+(sizeof(EMB_Head)*wNum_EMB)/sizeof(TCHAR);
  105. for (i=0; i<MAXCODE; i++)
  106. szReading[i] = TEXT('\0');
  107. for (i=0; i<lstrlen(lpszReading); i++)
  108. szReading[i] = lpszReading[i];
  109. for (lpCurr = lpUsrDicStart; lpCurr < lpUsrDicLimit;
  110. lpCurr += sizeof(EMB_Head) / sizeof(TCHAR) ) {
  111. EMB_Head *lpEMB_Head;
  112. lpEMB_Head = (EMB_Head *)lpCurr;
  113. // find the internal code, if this record contains a phrase, skip it.
  114. if ( lpEMB_Head->C_Char[sizeof(WORD)/sizeof(TCHAR)] != TEXT('\0') )
  115. continue;
  116. if (memcmp((LPBYTE)lpszString, (LPBYTE)(lpEMB_Head->C_Char), 2) != 0)
  117. continue;
  118. if (memcmp((LPBYTE)szReading,(LPBYTE)(lpEMB_Head->W_Code),
  119. MAXCODE*sizeof(TCHAR) ) == 0 )
  120. break;
  121. }
  122. if (lpCurr < lpUsrDicLimit) {
  123. // we found a record matching the requested lpszReading and lpszString
  124. LPTSTR lpCurrNext;
  125. wNum_EMB --;
  126. *lpwStart = wNum_EMB;
  127. lpCurrNext = lpCurr + sizeof(EMB_Head)/sizeof(TCHAR);
  128. // move every next EMB record ahead.
  129. while (lpCurrNext < lpUsrDicLimit) {
  130. for (i=0; i<sizeof(EMB_Head)/sizeof(TCHAR); i++)
  131. *lpCurr++ = *lpCurrNext++;
  132. }
  133. // put zero to the last EMB record.
  134. for (i=0; i<sizeof(EMB_Head)/sizeof(TCHAR); i++)
  135. *lpCurr++ = TEXT('\0');
  136. }
  137. UnmapViewOfFile(lpUsrDic);
  138. CloseHandle(hUsrDicMem);
  139. CloseHandle(hUsrDicFile);
  140. return (TRUE);
  141. }
  142. /**********************************************************************/
  143. /* ImeGetRegsisterWordStyle */
  144. /* Return Value: */
  145. /* number of styles copied/required */
  146. /**********************************************************************/
  147. UINT WINAPI ImeGetRegisterWordStyle(
  148. UINT nItem,
  149. LPSTYLEBUF lpStyleBuf)
  150. {
  151. if (!nItem) {
  152. return (1);
  153. }
  154. // invalid case
  155. if (!lpStyleBuf) {
  156. return (0);
  157. }
  158. lpStyleBuf->dwStyle = IME_REGWORD_STYLE_EUDC;
  159. LoadString(hInst, IDS_EUDC, lpStyleBuf->szDescription,
  160. sizeof(lpStyleBuf->szDescription)/sizeof(TCHAR));
  161. return (1);
  162. }
  163. /**********************************************************************/
  164. /* ImeEnumRegisterWord */
  165. /* Return Value: */
  166. /* the last value return by the callback function */
  167. /**********************************************************************/
  168. UINT WINAPI ImeEnumRegisterWord(
  169. REGISTERWORDENUMPROC lpfnRegisterWordEnumProc,
  170. LPCTSTR lpszReading,
  171. DWORD dwStyle,
  172. LPCTSTR lpszString,
  173. LPVOID lpData)
  174. {
  175. HANDLE hUsrDicMem;
  176. HANDLE hUsrDicFile;
  177. LPTSTR lpUsrDicStart, lpCurr, lpUsrDicLimit, lpUsrDic;
  178. UINT uRet;
  179. int i;
  180. LPWORD lpwStart;
  181. WORD wNum_EMB;
  182. TCHAR szReading[MAXCODE];
  183. TCHAR szString[MAXINPUTWORD];
  184. uRet = 0;
  185. if (dwStyle != IME_REGWORD_STYLE_EUDC) {
  186. return (uRet);
  187. }
  188. if (lpszString && (*(LPCTSTR)((LPBYTE)lpszString+sizeof(WORD))!=TEXT('\0')) )
  189. return (uRet);
  190. if (!MBIndex.EUDCData.szEudcDictName[0]) {
  191. return (uRet);
  192. }
  193. hUsrDicFile = CreateFile(MBIndex.EUDCData.szEudcDictName,
  194. GENERIC_READ | GENERIC_WRITE,
  195. FILE_SHARE_READ|FILE_SHARE_WRITE,
  196. NULL,
  197. OPEN_EXISTING,
  198. FILE_ATTRIBUTE_NORMAL,
  199. (HANDLE)NULL);
  200. if (hUsrDicFile == INVALID_HANDLE_VALUE) {
  201. return (uRet);
  202. }
  203. hUsrDicMem = CreateFileMapping(hUsrDicFile,
  204. NULL,
  205. PAGE_READWRITE,
  206. 0,
  207. sizeof(EMB_Head)*MAXNUMBER_EMB+2,
  208. MBIndex.EUDCData.szEudcMapFileName);
  209. if (!hUsrDicMem) {
  210. CloseHandle(hUsrDicFile);
  211. return (uRet);
  212. }
  213. lpUsrDic = MapViewOfFile(hUsrDicMem, FILE_MAP_WRITE, 0, 0, 0);
  214. if (!lpUsrDic) {
  215. CloseHandle(hUsrDicMem);
  216. CloseHandle(hUsrDicFile);
  217. return (uRet);
  218. }
  219. lpwStart = (LPWORD)lpUsrDic;
  220. wNum_EMB = *lpwStart;
  221. lpUsrDicStart = (LPTSTR)( (LPBYTE)lpUsrDic + sizeof(WORD) );
  222. lpUsrDicLimit = lpUsrDicStart+(sizeof(EMB_Head)*wNum_EMB)/sizeof(TCHAR);
  223. for (i=0; i<MAXCODE; i++)
  224. szReading[i] = TEXT('\0');
  225. for (i=0; i<MAXINPUTWORD; i++)
  226. szString[i] = TEXT('\0');
  227. if ( lpszReading )
  228. for (i=0; i<lstrlen(lpszReading); i++)
  229. szReading[i] = lpszReading[i];
  230. if ( lpszString )
  231. for (i=0; i<lstrlen(lpszString); i++)
  232. szString[i]=lpszString[i];
  233. for (lpCurr = lpUsrDicStart; lpCurr < lpUsrDicLimit;
  234. lpCurr += (sizeof(EMB_Head)*wNum_EMB)/sizeof(TCHAR)) {
  235. TCHAR szBufReading[MAXCODE];
  236. TCHAR szBufString[MAXINPUTWORD];
  237. EMB_Head *lpEMB_Head;
  238. BOOL fMatched;
  239. lpEMB_Head = (EMB_Head *)lpCurr;
  240. for ( i=0; i<MAXCODE; i++)
  241. szBufReading[i] = lpEMB_Head->W_Code[i];
  242. for ( i=0; i<MAXINPUTWORD; i++)
  243. szBufString[i] = lpEMB_Head->C_Char[i];
  244. // Because here we handle only EUDC chars, if it is a phrase,
  245. // just skip it.
  246. fMatched = FALSE;
  247. if ( szBufString[sizeof(WORD)/sizeof(TCHAR)] != TEXT('\0') )
  248. continue;
  249. if ( !lpszReading && !lpszString) {
  250. fMatched = TRUE;
  251. }
  252. else {
  253. // if lpszReading is NULL, enumerate all availible reading strings
  254. // matching with the specified lpszString
  255. if ( !lpszReading) {
  256. if (memcmp((LPBYTE)szBufString,(LPBYTE)szString, 2) ==0) {
  257. fMatched = TRUE;
  258. }
  259. }
  260. if ( !lpszString ) {
  261. if (memcmp((LPBYTE)szBufReading, (LPBYTE)szReading,
  262. MAXCODE*sizeof(TCHAR) ) == 0 ) {
  263. fMatched = TRUE;
  264. }
  265. }
  266. if ( lpszReading && lpszString) {
  267. if ( (memcmp((LPBYTE)szBufString,(LPBYTE)szString, 2) ==0) &&
  268. (memcmp((LPBYTE)szBufReading, (LPBYTE)szReading,
  269. MAXCODE*sizeof(TCHAR) ) == 0 ) ) {
  270. fMatched = TRUE;
  271. }
  272. }
  273. }
  274. if ( fMatched == TRUE ) {
  275. uRet=(*lpfnRegisterWordEnumProc)((const unsigned short *)szBufReading,
  276. IME_REGWORD_STYLE_EUDC,
  277. (const unsigned short *)szBufString,
  278. lpData);
  279. if (!uRet) break;
  280. }
  281. }
  282. UnmapViewOfFile(lpUsrDic);
  283. CloseHandle(hUsrDicMem);
  284. CloseHandle(hUsrDicFile);
  285. return (uRet);
  286. }
  287. #else
  288. /**********************************************************************/
  289. /* ImeRegsisterWord */
  290. /* Return Value: */
  291. /* TRUE - successful, FALSE - failure */
  292. /**********************************************************************/
  293. BOOL WINAPI ImeRegisterWord(
  294. LPCTSTR lpszReading,
  295. DWORD dwStyle,
  296. LPCTSTR lpszString)
  297. {
  298. return (FALSE);
  299. }
  300. /**********************************************************************/
  301. /* ImeUnregsisterWord */
  302. /* Return Value: */
  303. /* TRUE - successful, FALSE - failure */
  304. /**********************************************************************/
  305. BOOL WINAPI ImeUnregisterWord(
  306. LPCTSTR lpszReading,
  307. DWORD dwStyle,
  308. LPCTSTR lpszString)
  309. {
  310. return (FALSE);
  311. }
  312. /**********************************************************************/
  313. /* ImeGetRegsisterWordStyle */
  314. /* Return Value: */
  315. /* number of styles copied/required */
  316. /**********************************************************************/
  317. UINT WINAPI ImeGetRegisterWordStyle(
  318. UINT nItem,
  319. LPSTYLEBUF lpStyleBuf)
  320. {
  321. return (FALSE);
  322. }
  323. /**********************************************************************/
  324. /* ImeEnumRegisterWord */
  325. /* Return Value: */
  326. /* the last value return by the callback function */
  327. /**********************************************************************/
  328. UINT WINAPI ImeEnumRegisterWord(
  329. REGISTERWORDENUMPROC lpfnRegisterWordEnumProc,
  330. LPCTSTR lpszReading,
  331. DWORD dwStyle,
  332. LPCTSTR lpszString,
  333. LPVOID lpData)
  334. {
  335. return (FALSE);
  336. }
  337. #endif //EUDC