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.

840 lines
28 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. INIT.C
  5. ++*/
  6. #include <windows.h>
  7. #include <winerror.h>
  8. #include <memory.h>
  9. #include <immdev.h>
  10. #include <immsec.h>
  11. #include <imedefs.h>
  12. #include <regstr.h>
  13. void PASCAL InitStatusUIData(
  14. int cxBorder,
  15. int cyBorder,
  16. int iActMBIndex)
  17. {
  18. int iContentHi;
  19. // iContentHi is to get the maximum value of predefined STATUS_DIM_Y and
  20. // a real Chinese character's height in the current HDC.
  21. iContentHi = STATUS_DIM_Y;
  22. if ( iContentHi < sImeG.yChiCharHi )
  23. iContentHi = sImeG.yChiCharHi ;
  24. // right bottom of status
  25. sImeG.rcStatusText.left = 0;
  26. sImeG.rcStatusText.top = 0;
  27. sImeG.rcStatusText.right = sImeG.rcStatusText.left +
  28. lstrlen(MBIndex.MBDesc[iActMBIndex].szName) * sImeG.xChiCharWi*sizeof(TCHAR)/2 + STATUS_NAME_MARGIN + STATUS_DIM_X * 4;
  29. sImeG.rcStatusText.bottom = sImeG.rcStatusText.top + iContentHi;
  30. sImeG.xStatusWi = STATUS_DIM_X * 4 + STATUS_NAME_MARGIN +
  31. lstrlen(MBIndex.MBDesc[iActMBIndex].szName) * sImeG.xChiCharWi*sizeof(TCHAR)/2 + 6 * cxBorder;
  32. sImeG.yStatusHi = iContentHi + 6 * cxBorder;
  33. // left bottom of imeicon bar
  34. sImeG.rcImeIcon.left = sImeG.rcStatusText.left;
  35. sImeG.rcImeIcon.top = sImeG.rcStatusText.top;
  36. sImeG.rcImeIcon.right = sImeG.rcImeIcon.left + STATUS_DIM_X;
  37. sImeG.rcImeIcon.bottom = sImeG.rcImeIcon.top + iContentHi;
  38. // left bottom of imename bar
  39. sImeG.rcImeName.left = sImeG.rcImeIcon.right;
  40. sImeG.rcImeName.top = sImeG.rcStatusText.top;
  41. sImeG.rcImeName.right = sImeG.rcImeName.left +
  42. lstrlen(MBIndex.MBDesc[iActMBIndex].szName) * sImeG.xChiCharWi*sizeof(TCHAR)/2 + STATUS_NAME_MARGIN;
  43. sImeG.rcImeName.bottom = sImeG.rcImeName.top + iContentHi;
  44. // middle bottom of Shape bar
  45. sImeG.rcShapeText.left = sImeG.rcImeName.right;
  46. sImeG.rcShapeText.top = sImeG.rcStatusText.top;
  47. sImeG.rcShapeText.right = sImeG.rcShapeText.left + STATUS_DIM_X;
  48. sImeG.rcShapeText.bottom = sImeG.rcShapeText.top + iContentHi;
  49. // middle bottom of Symbol bar
  50. sImeG.rcSymbol.left = sImeG.rcShapeText.right;
  51. sImeG.rcSymbol.top = sImeG.rcStatusText.top;
  52. sImeG.rcSymbol.right = sImeG.rcSymbol.left + STATUS_DIM_X;
  53. sImeG.rcSymbol.bottom = sImeG.rcSymbol.top + iContentHi;
  54. // right bottom of SK bar
  55. sImeG.rcSKText.left = sImeG.rcSymbol.right;
  56. sImeG.rcSKText.top = sImeG.rcStatusText.top;
  57. sImeG.rcSKText.right = sImeG.rcSKText.left + STATUS_DIM_X;
  58. sImeG.rcSKText.bottom = sImeG.rcSKText.top + iContentHi;
  59. return;
  60. }
  61. void PASCAL InitCandUIData(
  62. int cxBorder,
  63. int cyBorder,
  64. int UIMode)
  65. {
  66. int iContentHi;
  67. // iContentHi is to get the maximum value of predefined COMP_TEXT_Y and
  68. // a real Chinese character's height in the current HDC.
  69. iContentHi = COMP_TEXT_Y;
  70. if ( iContentHi < sImeG.yChiCharHi )
  71. iContentHi = sImeG.yChiCharHi ;
  72. sImeG.cxCandBorder = cxBorder * 2;
  73. sImeG.cyCandBorder = cyBorder * 2;
  74. if(UIMode == LIN_UI) {
  75. sImeG.rcCandIcon.left = 0;
  76. sImeG.rcCandIcon.top = cyBorder + 2;
  77. sImeG.rcCandIcon.right = sImeG.rcCandIcon.left + UI_CANDICON;
  78. sImeG.rcCandIcon.bottom = sImeG.rcCandIcon.top + UI_CANDICON;
  79. sImeG.rcCandText.left = sImeG.rcCandIcon.right + 3;
  80. sImeG.rcCandText.top = cyBorder ;
  81. sImeG.rcCandText.right = sImeG.rcCandText.left + UI_CANDSTR;
  82. sImeG.rcCandText.bottom = sImeG.rcCandText.top + iContentHi;
  83. sImeG.rcCandBTH.top = cyBorder * 4;
  84. sImeG.rcCandBTH.left = sImeG.rcCandText.right + 5;
  85. sImeG.rcCandBTH.right = sImeG.rcCandBTH.left + UI_CANDBTW;
  86. sImeG.rcCandBTH.bottom = sImeG.rcCandBTH.top + UI_CANDBTH;
  87. sImeG.rcCandBTU.top = cyBorder * 4;
  88. sImeG.rcCandBTU.left = sImeG.rcCandBTH.right;
  89. sImeG.rcCandBTU.right = sImeG.rcCandBTU.left + UI_CANDBTW;
  90. sImeG.rcCandBTU.bottom = sImeG.rcCandBTU.top + UI_CANDBTH;
  91. sImeG.rcCandBTD.top = cyBorder * 4;
  92. sImeG.rcCandBTD.left = sImeG.rcCandBTU.right;
  93. sImeG.rcCandBTD.right = sImeG.rcCandBTD.left + UI_CANDBTW;
  94. sImeG.rcCandBTD.bottom = sImeG.rcCandBTD.top + UI_CANDBTH;
  95. sImeG.rcCandBTE.top = cyBorder * 4;
  96. sImeG.rcCandBTE.left = sImeG.rcCandBTD.right;
  97. sImeG.rcCandBTE.right = sImeG.rcCandBTE.left + UI_CANDBTW;
  98. sImeG.rcCandBTE.bottom = sImeG.rcCandBTE.top + UI_CANDBTH;
  99. sImeG.xCandWi = sImeG.rcCandBTE.right + sImeG.cxCandBorder * 2 + cxBorder * 4;
  100. sImeG.yCandHi = sImeG.rcCandText.bottom + sImeG.cyCandBorder * 2 + cyBorder * 4;
  101. } else {
  102. sImeG.rcCandText.left = cxBorder;
  103. sImeG.rcCandText.top = 2 * cyBorder + UI_CANDINF;
  104. if(sImeG.xChiCharWi*11 > (UI_CANDICON*6 + UI_CANDBTH*4))
  105. sImeG.rcCandText.right = sImeG.rcCandText.left + sImeG.xChiCharWi * 11;
  106. else
  107. sImeG.rcCandText.right = sImeG.rcCandText.left + (UI_CANDICON*6 + UI_CANDBTH*4);
  108. sImeG.rcCandText.bottom = sImeG.rcCandText.top + sImeG.yChiCharHi * CANDPERPAGE;
  109. sImeG.xCandWi = sImeG.rcCandText.right + sImeG.cxCandBorder * 2 + cxBorder * 4;
  110. sImeG.yCandHi = sImeG.rcCandText.bottom + sImeG.cyCandBorder * 2 + cyBorder * 4;
  111. sImeG.rcCandIcon.left = cxBorder;
  112. sImeG.rcCandIcon.top = cyBorder + 2;
  113. sImeG.rcCandIcon.right = sImeG.rcCandIcon.left + UI_CANDICON;
  114. sImeG.rcCandIcon.bottom = sImeG.rcCandIcon.top + UI_CANDICON;
  115. sImeG.rcCandInf.left = sImeG.rcCandIcon.right;
  116. sImeG.rcCandInf.top = cyBorder + 3;
  117. sImeG.rcCandInf.right = sImeG.rcCandInf.left + UI_CANDICON * 5;
  118. sImeG.rcCandInf.bottom = sImeG.rcCandInf.top + UI_CANDBTH;
  119. sImeG.rcCandBTE.top = cyBorder * 5;
  120. sImeG.rcCandBTE.right = sImeG.rcCandText.right + cxBorder;
  121. sImeG.rcCandBTE.bottom = sImeG.rcCandBTE.top + UI_CANDBTH;
  122. sImeG.rcCandBTE.left = sImeG.rcCandBTE.right - UI_CANDBTW;
  123. sImeG.rcCandBTD.top = cyBorder * 5;
  124. sImeG.rcCandBTD.right = sImeG.rcCandBTE.left;
  125. sImeG.rcCandBTD.bottom = sImeG.rcCandBTD.top + UI_CANDBTH;
  126. sImeG.rcCandBTD.left = sImeG.rcCandBTD.right - UI_CANDBTW;
  127. sImeG.rcCandBTU.top = cyBorder * 5;
  128. sImeG.rcCandBTU.right = sImeG.rcCandBTD.left;
  129. sImeG.rcCandBTU.bottom = sImeG.rcCandBTU.top + UI_CANDBTH;
  130. sImeG.rcCandBTU.left = sImeG.rcCandBTU.right - UI_CANDBTW;
  131. sImeG.rcCandBTH.top = cyBorder * 5;
  132. sImeG.rcCandBTH.right = sImeG.rcCandBTU.left;
  133. sImeG.rcCandBTH.bottom = sImeG.rcCandBTH.top + UI_CANDBTH;
  134. sImeG.rcCandBTH.left = sImeG.rcCandBTH.right - UI_CANDBTW;
  135. }
  136. }
  137. /**********************************************************************/
  138. /* InitImeGlobalData() */
  139. /**********************************************************************/
  140. void PASCAL InitImeGlobalData(
  141. HINSTANCE hInstance)
  142. {
  143. int cxBorder, cyBorder;
  144. int UI_MODE;
  145. HDC hDC;
  146. HGDIOBJ hOldFont;
  147. LOGFONT lfFont;
  148. TCHAR szChiChar[4];
  149. SIZE lTextSize;
  150. HGLOBAL hResData;
  151. int i;
  152. DWORD dwSize;
  153. HKEY hKeyIMESetting;
  154. LONG lRet;
  155. hInst = hInstance;
  156. // get the UI class name
  157. LoadString(hInst, IDS_IMEUICLASS, szUIClassName, CLASS_LEN);
  158. // get the composition class name
  159. LoadString(hInst, IDS_IMECOMPCLASS, szCompClassName, CLASS_LEN);
  160. // get the candidate class name
  161. LoadString(hInst, IDS_IMECANDCLASS, szCandClassName, CLASS_LEN);
  162. // get the status class name
  163. LoadString(hInst, IDS_IMESTATUSCLASS, szStatusClassName, CLASS_LEN);
  164. //get the ContextMenu class name
  165. LoadString(hInst, IDS_IMECMENUCLASS, szCMenuClassName, CLASS_LEN);
  166. //get the softkeyboard Menu class name
  167. LoadString(hInst, IDS_IMESOFTKEYMENUCLASS, szSoftkeyMenuClassName, CLASS_LEN);
  168. // get ime org name
  169. LoadString(hInst, IDS_ORG_NAME, szOrgName, NAMESIZE/2);
  170. // get ime version info
  171. LoadString(hInst, IDS_VER_INFO, szVerInfo, NAMESIZE);
  172. // work area
  173. SystemParametersInfo(SPI_GETWORKAREA, 0, &sImeG.rcWorkArea, 0);
  174. // border
  175. cxBorder = GetSystemMetrics(SM_CXBORDER);
  176. cyBorder = GetSystemMetrics(SM_CYBORDER);
  177. // get the Chinese char
  178. LoadString(hInst, IDS_CHICHAR, szChiChar, sizeof(szChiChar)/sizeof(TCHAR));
  179. // get size of Chinese char
  180. hDC = GetDC(NULL);
  181. hOldFont = GetCurrentObject(hDC, OBJ_FONT);
  182. GetObject(hOldFont, sizeof(LOGFONT), &lfFont);
  183. sImeG.fDiffSysCharSet = TRUE;
  184. ZeroMemory(&lfFont, sizeof(lfFont));
  185. lfFont.lfHeight = -MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  186. lfFont.lfCharSet = NATIVE_CHARSET;
  187. lstrcpy(lfFont.lfFaceName, TEXT("Simsun"));
  188. SelectObject(hDC, CreateFontIndirect(&lfFont));
  189. if(!GetTextExtentPoint(hDC, (LPTSTR)szChiChar, lstrlen(szChiChar), &lTextSize))
  190. memset(&lTextSize, 0, sizeof(SIZE));
  191. if (sImeG.rcWorkArea.right < 2 * UI_MARGIN) {
  192. sImeG.rcWorkArea.left = 0;
  193. sImeG.rcWorkArea.right = GetDeviceCaps(hDC, HORZRES);
  194. }
  195. if (sImeG.rcWorkArea.bottom < 2 * UI_MARGIN) {
  196. sImeG.rcWorkArea.top = 0;
  197. sImeG.rcWorkArea.bottom = GetDeviceCaps(hDC, VERTRES);
  198. }
  199. if (sImeG.fDiffSysCharSet) {
  200. DeleteObject(SelectObject(hDC, hOldFont));
  201. }
  202. ReleaseDC(NULL, hDC);
  203. // get text metrics to decide the width & height of composition window
  204. // these IMEs always use system font to show
  205. sImeG.xChiCharWi = lTextSize.cx;
  206. sImeG.yChiCharHi = lTextSize.cy;
  207. if(MBIndex.IMEChara[0].IC_Trace) {
  208. UI_MODE = BOX_UI;
  209. } else {
  210. UI_MODE = LIN_UI;
  211. }
  212. InitCandUIData(cxBorder, cyBorder, UI_MODE);
  213. InitStatusUIData(cxBorder, cyBorder ,0);
  214. // load full ABC table
  215. {
  216. HRSRC hResSrc;
  217. hResSrc = FindResource(hInst,TEXT("FULLABC"), RT_RCDATA);
  218. if(hResSrc == NULL){
  219. return;
  220. }
  221. hResData = LoadResource(hInst, hResSrc);
  222. }
  223. *(LPFULLABC)sImeG.wFullABC = *(LPFULLABC)LockResource(hResData);
  224. // full shape space
  225. sImeG.wFullSpace = sImeG.wFullABC[0];
  226. #ifdef LATER
  227. // reverse internal code to internal code, NT don't need it
  228. for (i = 0; i < (sizeof(sImeG.wFullABC) / 2); i++) {
  229. sImeG.wFullABC[i] = (sImeG.wFullABC[i] << 8) |
  230. (sImeG.wFullABC[i] >> 8);
  231. }
  232. #endif
  233. LoadString(hInst, IDS_STATUSERR, sImeG.szStatusErr,
  234. sizeof(sImeG.szStatusErr)/sizeof(TCHAR));
  235. sImeG.cbStatusErr = lstrlen(sImeG.szStatusErr);
  236. sImeG.iCandStart = CAND_START;
  237. // get the UI offset for near caret operation
  238. RegCreateKey(HKEY_CURRENT_USER, szRegIMESetting, &hKeyIMESetting);
  239. dwSize = sizeof(DWORD);
  240. lRet = RegQueryValueEx(hKeyIMESetting, szPara, NULL, NULL,
  241. (LPBYTE)&sImeG.iPara, &dwSize);
  242. if (lRet != ERROR_SUCCESS) {
  243. sImeG.iPara = 0;
  244. RegSetValueEx(hKeyIMESetting, szPara, (DWORD) 0, REG_BINARY,
  245. (LPBYTE)&sImeG.iPara, sizeof(int));
  246. }
  247. dwSize = sizeof(DWORD);
  248. lRet = RegQueryValueEx(hKeyIMESetting, szPerp, NULL, NULL,
  249. (LPBYTE)&sImeG.iPerp, &dwSize);
  250. if (lRet != ERROR_SUCCESS) {
  251. sImeG.iPerp = sImeG.yChiCharHi;
  252. RegSetValueEx(hKeyIMESetting, szPerp, (DWORD) 0, REG_BINARY,
  253. (LPBYTE)&sImeG.iPerp, sizeof(int));
  254. }
  255. dwSize = sizeof(DWORD);
  256. lRet = RegQueryValueEx(hKeyIMESetting, szParaTol, NULL, NULL,
  257. (LPBYTE)&sImeG.iParaTol, &dwSize);
  258. if (lRet != ERROR_SUCCESS) {
  259. sImeG.iParaTol = sImeG.xChiCharWi * 4;
  260. RegSetValueEx(hKeyIMESetting, szParaTol, (DWORD) 0, REG_BINARY,
  261. (LPBYTE)&sImeG.iParaTol, sizeof(int));
  262. }
  263. dwSize = sizeof(DWORD);
  264. lRet = RegQueryValueEx(hKeyIMESetting, szPerpTol, NULL, NULL,
  265. (LPBYTE)&sImeG.iPerpTol, &dwSize);
  266. if (lRet != ERROR_SUCCESS) {
  267. sImeG.iPerpTol = lTextSize.cy;
  268. RegSetValueEx(hKeyIMESetting, szPerpTol, (DWORD) 0, REG_BINARY,
  269. (LPBYTE)&sImeG.iPerpTol, sizeof(int));
  270. }
  271. RegCloseKey(hKeyIMESetting);
  272. return;
  273. }
  274. /**********************************************************************/
  275. /* InitImeLocalData() */
  276. /**********************************************************************/
  277. BOOL PASCAL InitImeLocalData(
  278. HINSTANCE hInstL)
  279. {
  280. int cxBorder, cyBorder;
  281. int iContentHi;
  282. // iContentHi is to get the maximum value of predefined COMP_TEXT_Y and
  283. // a real Chinese character's height in the current HDC.
  284. iContentHi = COMP_TEXT_Y;
  285. if ( iContentHi < sImeG.yChiCharHi )
  286. iContentHi = sImeG.yChiCharHi ;
  287. lpImeL->hInst = hInstL;
  288. lpImeL->nMaxKey = MBIndex.MBDesc[0].wMaxCodes;
  289. // border + raising edge + sunken edge
  290. cxBorder = GetSystemMetrics(SM_CXBORDER);
  291. cyBorder = GetSystemMetrics(SM_CYBORDER);
  292. // text position relative to the composition window
  293. lpImeL->cxCompBorder = cxBorder * 2;
  294. lpImeL->cyCompBorder = cyBorder * 2;
  295. lpImeL->rcCompText.left = cxBorder;
  296. lpImeL->rcCompText.top = cyBorder;
  297. #ifdef KEYSTICKER
  298. lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi * ((lpImeL->nMaxKey * 2 + 2) / 2);
  299. #else
  300. lpImeL->rcCompText.right = lpImeL->rcCompText.left + sImeG.xChiCharWi * ((lpImeL->nMaxKey + 2) / 2);
  301. #endif //KEYSTICKER
  302. lpImeL->rcCompText.bottom = lpImeL->rcCompText.top + iContentHi;
  303. // set the width & height for composition window
  304. lpImeL->xCompWi = lpImeL->rcCompText.right + lpImeL->cxCompBorder * 2 + cxBorder * 4;
  305. lpImeL->yCompHi = lpImeL->rcCompText.bottom + lpImeL->cyCompBorder * 2 + cyBorder * 4;
  306. // default position of composition window
  307. lpImeL->ptDefComp.x = sImeG.rcWorkArea.right -
  308. lpImeL->xCompWi - cxBorder * 2;
  309. lpImeL->ptDefComp.y = sImeG.rcWorkArea.bottom -
  310. lpImeL->yCompHi - cyBorder * 2;
  311. return (TRUE);
  312. }
  313. /**********************************************************************/
  314. /* RegisterIme() */
  315. /**********************************************************************/
  316. void PASCAL RegisterIme(
  317. HINSTANCE hInstance)
  318. {
  319. UINT j;
  320. HKEY hKeyCurrVersion;
  321. DWORD retCode;
  322. DWORD retValue;
  323. HKEY hKey;
  324. LANGID LangID;
  325. #ifdef UNICODE
  326. TCHAR ValueName[][9] = {
  327. {0x8BCD, 0x8BED, 0x8054, 0x60F3, 0x0000},
  328. {0x8BCD, 0x8BED, 0x8F93, 0x5165, 0x0000},
  329. {0x9010, 0x6E10, 0x63D0, 0x793A, 0x0000},
  330. {0x5916, 0x7801, 0x63D0, 0x793A, 0x0000},
  331. {0x63D2, 0x7A7A, 0x683C, 0x0000},
  332. {0x5149, 0x6807, 0x8DDF, 0x968F, 0x0000},
  333. #else
  334. TCHAR ValueName[][9] = {
  335. TEXT("��������"),
  336. TEXT("��������"),
  337. TEXT("������ʾ"),
  338. TEXT("������ʾ"),
  339. TEXT("���ո�"),
  340. TEXT("��������"),
  341. #endif
  342. TEXT("<SPACE>"),
  343. TEXT("<ENTER>"),
  344. TEXT("FC Input"),
  345. TEXT("FC aid"),
  346. #if defined(COMBO_IME)
  347. TEXT("GB/GBK")
  348. #endif
  349. };
  350. DWORD dwcValueName = MAXSTRLEN;
  351. TCHAR bData[MAXSTRLEN];
  352. LONG bcData = sizeof(DWORD);
  353. // load mb file name string according to current locale.
  354. TCHAR szMBFilePath[MAX_PATH];
  355. BYTE szAnsiMBFilePath[MAX_PATH];
  356. OFSTRUCT OpenBuff;
  357. HFILE hFile;
  358. GetSystemDirectory(szMBFilePath, MAX_PATH);
  359. LoadString(hInstance, IDS_IMEMBFILENAME, szImeMBFileName, MAX_PATH);
  360. lstrcat(szMBFilePath, TEXT("\\"));
  361. lstrcat(szMBFilePath, szImeMBFileName);
  362. WideCharToMultiByte(NATIVE_ANSI_CP,
  363. WC_COMPOSITECHECK,
  364. szMBFilePath,
  365. -1,
  366. szAnsiMBFilePath,
  367. MAX_PATH,
  368. NULL,
  369. NULL);
  370. if ((hFile = OpenFile(szAnsiMBFilePath, &OpenBuff, OF_EXIST))==HFILE_ERROR)
  371. {
  372. if (LOWORD(GetSystemDefaultLangID()) == 0xC04) {
  373. // for HongKong Special treat.
  374. ZeroMemory(szImeMBFileName,sizeof(TCHAR)*MAX_PATH);
  375. LoadString(hInstance, IDS_IMEHKMBFILENAME, szImeMBFileName,MAX_PATH);
  376. }
  377. }
  378. lstrcpy((LPTSTR)HMapTab[0].MB_Name, szImeMBFileName);
  379. if(!ReadDescript((LPTSTR)szMBFilePath, &(MBIndex.MBDesc[0]))) {
  380. return;
  381. }
  382. MBIndex.MBNums = 1;
  383. retCode = OpenReg_PathSetup(&hKeyCurrVersion);
  384. if (retCode) {
  385. RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_SETUP, &hKeyCurrVersion);
  386. }
  387. retCode = OpenReg_User (hKeyCurrVersion,
  388. MBIndex.MBDesc[0].szName,
  389. &hKey);
  390. if (retCode) {
  391. HGLOBAL hResData;
  392. WORD wIMECharac;
  393. DWORD dwDisposition;
  394. retCode = RegCreateKeyEx (hKeyCurrVersion,
  395. MBIndex.MBDesc[0].szName,
  396. 0,
  397. 0,
  398. REG_OPTION_NON_VOLATILE,
  399. KEY_ALL_ACCESS,
  400. NULL,
  401. &hKey,
  402. &dwDisposition);
  403. // set value
  404. // load imecharac
  405. {
  406. HRSRC hResSrc;
  407. hResSrc = FindResource(hInstance,TEXT("IMECHARAC"), RT_RCDATA);
  408. if(hResSrc == NULL){
  409. return;
  410. }
  411. hResData = LoadResource(hInstance, hResSrc);
  412. }
  413. if(hResData == NULL){
  414. return;
  415. }
  416. memcpy(&wIMECharac, LockResource(hResData), sizeof(WORD));
  417. for(j=0; j<IC_NUMBER; j++) {
  418. DWORD Value;
  419. switch (j)
  420. {
  421. case 0:
  422. Value = wIMECharac & 0x0001;
  423. break;
  424. case 1:
  425. Value = (wIMECharac & 0x0002) >> 1;
  426. break;
  427. case 2:
  428. Value = (wIMECharac & 0x0004) >> 2;
  429. break;
  430. case 3:
  431. Value = (wIMECharac & 0x0008) >> 3;
  432. break;
  433. case 4:
  434. Value = (wIMECharac & 0x0010) >> 4;
  435. break;
  436. case 5:
  437. Value = (wIMECharac & 0x0020) >> 5;
  438. break;
  439. case 6:
  440. Value = (wIMECharac & 0x0040) >> 6;
  441. break;
  442. case 7:
  443. Value = (wIMECharac & 0x0080) >> 7;
  444. break;
  445. //CHP
  446. case 8:
  447. Value = (wIMECharac & 0x0100) >> 8;
  448. break;
  449. case 9:
  450. Value = (wIMECharac & 0x0200) >> 9;
  451. break;
  452. #if defined(COMBO_IME)
  453. case 10:
  454. Value = (wIMECharac & 0x0400) >> 10;
  455. break;
  456. #endif
  457. }
  458. RegSetValueEx (hKey, ValueName[j],
  459. (DWORD) 0,
  460. REG_DWORD,
  461. (LPBYTE)&Value,
  462. sizeof(DWORD));
  463. }
  464. }
  465. for(j=0; j<IC_NUMBER; j++) {
  466. bData[0] = TEXT('\0');
  467. bcData = MAXSTRLEN;
  468. retValue = RegQueryValueEx (hKey, ValueName[j],
  469. NULL,
  470. NULL, //&dwType,
  471. (unsigned char *)bData, //&bData,
  472. &bcData); //&bcData);
  473. switch (j)
  474. {
  475. case 0:
  476. MBIndex.IMEChara[0].IC_LX = *((LPDWORD)bData);
  477. break;
  478. case 1:
  479. MBIndex.IMEChara[0].IC_CZ = *((LPDWORD)bData);
  480. break;
  481. case 2:
  482. MBIndex.IMEChara[0].IC_TS = *((LPDWORD)bData);
  483. break;
  484. case 3:
  485. MBIndex.IMEChara[0].IC_CTC = *((LPDWORD)bData);
  486. break;
  487. case 4:
  488. MBIndex.IMEChara[0].IC_INSSPC = *((LPDWORD)bData);
  489. break;
  490. case 5:
  491. MBIndex.IMEChara[0].IC_Trace = *((LPDWORD)bData);
  492. break;
  493. case 6:
  494. MBIndex.IMEChara[0].IC_Space = *((LPDWORD)bData);
  495. break;
  496. case 7:
  497. MBIndex.IMEChara[0].IC_Enter = *((LPDWORD)bData);
  498. break;
  499. //CHP
  500. case 8:
  501. MBIndex.IMEChara[0].IC_FCSR = *((LPDWORD)bData);
  502. break;
  503. case 9:
  504. MBIndex.IMEChara[0].IC_FCTS = *((LPDWORD)bData);
  505. break;
  506. #if defined(COMBO_IME)
  507. case 10:
  508. MBIndex.IMEChara[0].IC_GB = *((LPDWORD)bData);
  509. break;
  510. #endif
  511. default:
  512. break;
  513. }
  514. }
  515. #ifdef EUDC
  516. //just query the value, do not set any value here
  517. bcData = sizeof(TCHAR) * MAX_PATH;
  518. RegQueryValueEx (hKey, szRegEudcDictName,
  519. NULL,
  520. NULL, //null-terminate string
  521. (unsigned char *)MBIndex.EUDCData.szEudcDictName, //&bData,
  522. &bcData); //&bcData);
  523. bcData = sizeof(TCHAR) * MAX_PATH;
  524. RegQueryValueEx (hKey, szRegEudcMapFileName,
  525. NULL,
  526. NULL, //null-terminate string
  527. (unsigned char *)MBIndex.EUDCData.szEudcMapFileName,//&bData,
  528. &bcData); //&bcData);
  529. #endif //EUDC
  530. #ifdef CROSSREF
  531. bcData = sizeof(HKL);
  532. if(RegQueryValueEx (hKey, szRegRevKL,
  533. NULL,
  534. NULL, //null-terminate string
  535. (LPBYTE)&MBIndex.hRevKL, //&bData,
  536. &bcData) != ERROR_SUCCESS)
  537. MBIndex.hRevKL = NULL;
  538. bcData = sizeof(DWORD);
  539. if(RegQueryValueEx (hKey, szRegRevMaxKey,
  540. NULL,
  541. NULL, //null-terminate string
  542. (LPBYTE)&MBIndex.nRevMaxKey, //&bData,
  543. &bcData) != ERROR_SUCCESS)
  544. MBIndex.hRevKL = NULL;
  545. #endif
  546. RegCloseKey(hKey);
  547. RegCloseKey(hKeyCurrVersion);
  548. return;
  549. }
  550. /**********************************************************************/
  551. /* RegisterImeClass() */
  552. /**********************************************************************/
  553. void PASCAL RegisterImeClass(
  554. HINSTANCE hInstance,
  555. HINSTANCE hInstL)
  556. {
  557. WNDCLASSEX wcWndCls;
  558. // IME UI class
  559. // Register IME UI class
  560. wcWndCls.cbSize = sizeof(WNDCLASSEX);
  561. wcWndCls.cbClsExtra = 0;
  562. wcWndCls.cbWndExtra = WND_EXTRA_SIZE;
  563. wcWndCls.hIcon = LoadImage(hInstL,
  564. MAKEINTRESOURCE(IDI_IME),
  565. IMAGE_ICON,
  566. 16,
  567. 16,
  568. LR_DEFAULTCOLOR);
  569. wcWndCls.hInstance = hInstance;
  570. wcWndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
  571. wcWndCls.hbrBackground = GetStockObject(NULL_BRUSH);
  572. wcWndCls.lpszMenuName = (LPTSTR)NULL;
  573. wcWndCls.hIconSm = LoadImage(hInstL,
  574. MAKEINTRESOURCE(IDI_IME),
  575. IMAGE_ICON,
  576. 16,
  577. 16,
  578. LR_DEFAULTCOLOR);
  579. // IME UI class
  580. if (!GetClassInfoEx(hInstance, szUIClassName, &wcWndCls)) {
  581. wcWndCls.style = CS_IME;
  582. wcWndCls.lpfnWndProc = UIWndProc;
  583. wcWndCls.lpszClassName = (LPTSTR)szUIClassName;
  584. RegisterClassEx(&wcWndCls);
  585. }
  586. wcWndCls.style = CS_IME|CS_HREDRAW|CS_VREDRAW;
  587. wcWndCls.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  588. // IME composition class
  589. // register IME composition class
  590. if (!GetClassInfoEx(hInstance, szCompClassName, &wcWndCls)) {
  591. wcWndCls.lpfnWndProc = CompWndProc;
  592. wcWndCls.lpszClassName = (LPTSTR)szCompClassName;
  593. RegisterClassEx(&wcWndCls);
  594. }
  595. // IME candidate class
  596. // register IME candidate class
  597. if (!GetClassInfoEx(hInstance, szCandClassName, &wcWndCls)) {
  598. wcWndCls.lpfnWndProc = CandWndProc;
  599. wcWndCls.lpszClassName = (LPTSTR)szCandClassName;
  600. RegisterClassEx(&wcWndCls);
  601. }
  602. // IME status class
  603. // register IME status class
  604. if (!GetClassInfoEx(hInstance, szStatusClassName, &wcWndCls)) {
  605. wcWndCls.lpfnWndProc = StatusWndProc;
  606. wcWndCls.lpszClassName = (LPTSTR)szStatusClassName;
  607. RegisterClassEx(&wcWndCls);
  608. }
  609. // IME context menu class
  610. if (!GetClassInfoEx(hInstance, szCMenuClassName, &wcWndCls)) {
  611. wcWndCls.style = 0;
  612. wcWndCls.hbrBackground = GetStockObject(NULL_BRUSH);
  613. wcWndCls.lpfnWndProc = ContextMenuWndProc;
  614. wcWndCls.lpszClassName = (LPTSTR)szCMenuClassName;
  615. RegisterClassEx(&wcWndCls);
  616. }
  617. // IME softkeyboard menu class
  618. if (!GetClassInfoEx(hInstance, szSoftkeyMenuClassName, &wcWndCls)) {
  619. wcWndCls.style = 0;
  620. wcWndCls.hbrBackground = GetStockObject(NULL_BRUSH);
  621. wcWndCls.lpfnWndProc = SoftkeyMenuWndProc;
  622. wcWndCls.lpszClassName = (LPTSTR)szSoftkeyMenuClassName;
  623. RegisterClassEx(&wcWndCls);
  624. }
  625. return;
  626. }
  627. /**********************************************************************/
  628. /* ImeDllInit() */
  629. /* Return Value: */
  630. /* TRUE - successful */
  631. /* FALSE - failure */
  632. /**********************************************************************/
  633. BOOL CALLBACK ImeDllInit(
  634. HINSTANCE hInstance, // instance handle of this library
  635. DWORD fdwReason, // reason called
  636. LPVOID lpvReserve) // reserve pointer
  637. {
  638. switch (fdwReason) {
  639. case DLL_PROCESS_ATTACH:
  640. // init MB Index
  641. RegisterIme(hInstance);
  642. // init globaldata & load globaldata from resource
  643. if (!hInst) {
  644. InitImeGlobalData(hInstance);
  645. }
  646. if (!lpImeL) {
  647. lpImeL = &sImeL;
  648. InitImeLocalData(hInstance);
  649. }
  650. RegisterImeClass(hInstance, hInstance);
  651. break;
  652. case DLL_PROCESS_DETACH:
  653. {
  654. WNDCLASSEX wcWndCls;
  655. if (GetClassInfoEx(hInstance, szCMenuClassName, &wcWndCls)) {
  656. UnregisterClass(szCMenuClassName, hInstance);
  657. }
  658. if (GetClassInfoEx(hInstance, szSoftkeyMenuClassName, &wcWndCls)) {
  659. UnregisterClass(szSoftkeyMenuClassName, hInstance);
  660. }
  661. if (GetClassInfoEx(hInstance, szStatusClassName, &wcWndCls)) {
  662. UnregisterClass(szStatusClassName, hInstance);
  663. }
  664. if (GetClassInfoEx(hInstance, szCandClassName, &wcWndCls)) {
  665. UnregisterClass(szCandClassName, hInstance);
  666. }
  667. if (GetClassInfoEx(hInstance, szCompClassName, &wcWndCls)) {
  668. UnregisterClass(szCompClassName, hInstance);
  669. }
  670. if (!GetClassInfoEx(hInstance, szUIClassName, &wcWndCls)) {
  671. } else if (!UnregisterClass(szUIClassName, hInstance)) {
  672. } else {
  673. DestroyIcon(wcWndCls.hIcon);
  674. DestroyIcon(wcWndCls.hIconSm);
  675. }
  676. }
  677. break;
  678. default:
  679. break;
  680. }
  681. return (TRUE);
  682. }