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.

1156 lines
37 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : hwxfe.cpp
  3. // Purpose : Class for Fareast functionality.
  4. // #define FE_JAPANESE //Japanese specific
  5. // #define FE_CHINESE_SIMPLIFIED //P.R.C specific
  6. //
  7. // Date : Tue Aug 04 05:27:58 1998
  8. // Author : ToshiaK
  9. //
  10. // Copyright(c) 1995-1998, Microsoft Corp. All rights reserved
  11. //////////////////////////////////////////////////////////////////
  12. #include "hwxobj.h"
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "resource.h"
  16. #include "hwxfe.h"
  17. #include "cexres.h"
  18. #include "instr.h"
  19. #include "memmgr.h"
  20. #include "hwxobj.h"
  21. #include "dbg.h"
  22. #include "cmnhdr.h"
  23. #include "../common/cutil.h" //990722:ToshiaK for KOTAE #1090
  24. #include "../common/cfont.h" //990722:ToshiaK for KOTAE #1030
  25. #ifdef FE_KOREAN
  26. #include "hanja.h"
  27. #endif
  28. #ifdef UNDER_CE // Windows CE Stub for unsupported APIs
  29. #include "stub_ce.h"
  30. #endif // UNDER_CE
  31. // Safe String
  32. #define STRSAFE_NO_DEPRECATE
  33. #include "strsafe.h"
  34. //----------------------------------------------------------------
  35. //Helpfile definition.
  36. //----------------------------------------------------------------
  37. #ifdef FE_JAPANESE
  38. //990113 ToshiaK: created ../common/namesjp.h for KK's string define
  39. # include "../common/namesjp.h"
  40. # include "../common/htmlhelp.h"
  41. # include "hlpidjpn.h"
  42. # include "hlpidjpn.tbl"
  43. #ifndef UNDER_CE //#ifndef UNICODE
  44. # define SZHELPFILE_MAIN SZFILENAME_HELP //defined KK's ../common/namesjp.h
  45. # define SZHELPFILE_CONTEXTMENU SZFILENAME_CONTEXTHELP //defined KK's ../common/namesjp.h
  46. # define SZHELPFILE_MAIN_ENG SZFILENAME_ENG_HELP
  47. # define SZHELPFILE_CONTEXTMENU_ENG SZFILENAME_ENG_CONTEXTHELP
  48. #else // UNDER_CE
  49. # define SZHELPFILE_MAIN WSZFILENAME_HELP //defined KK's ../common/namesjp.h
  50. # define SZHELPFILE_CONTEXTMENU WSZFILENAME_CONTEXTHELP //defined KK's ../common/namesjp.h
  51. # define SZHELPFILE_MAIN_ENG WSZFILENAME_ENG_HELP
  52. # define SZHELPFILE_CONTEXTMENU_ENG WSZFILENAME_ENG_CONTEXTHELP
  53. #endif // UNDER_CE
  54. #elif FE_CHINESE_SIMPLIFIED
  55. # include "../common/htmlhelp.h"
  56. # include "hlpidsc.h"
  57. # include "hlpidsc.tbl"
  58. # define SZHELPFILE_MAIN "PIntlpad.chm"
  59. # define SZHELPFILE_CONTEXTMENU "PIntlpad.hlp"
  60. #elif FE_KOREAN
  61. # include "hlpidkor.h"
  62. # include "hlpidkor.tbl"
  63. # define SZHELPFILE_MAIN "impdko61.chm" // Kor Pad CHM Help
  64. # define SZHELPFILE_CONTEXTMENU "imkr61.hlp" // Kor Context Help
  65. # define SZHELPFILE_MAIN_ENG "korpaden.chm" // Eng Pad CHM Help
  66. # define SZHELPFILE_CONTEXTMENU_ENG "imkren61.hlp" // Eng Context Help
  67. #else
  68. # include "hlpideng.h"
  69. # include "hlpideng.tbl"
  70. # define SZHELPFILE_MAIN ""
  71. # define SZHELPFILE_CONTEXTMENU ""
  72. #endif
  73. //----------------------------------------------------------------
  74. //codepage define
  75. //----------------------------------------------------------------
  76. #define CP_KOREAN 949
  77. #define CP_JAPANESE 932
  78. #define CP_CHINESE_SIMPLIFIED 936
  79. #define CP_CHINESE_TRADITIONAL 950
  80. BOOL CHwxFE::IsActiveIMEEnv(VOID)
  81. {
  82. #ifdef FE_JAPANESE
  83. if(MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) != ::GetSystemDefaultLangID() &&
  84. (IsWin95() || IsWin98() || IsWinNT4())) {
  85. return TRUE;
  86. }
  87. return FALSE;
  88. #elif FE_KOREAN || FE_CHINESE_SIMPLIFIED
  89. return FALSE;
  90. #else
  91. return FALSE;
  92. #endif
  93. }
  94. //////////////////////////////////////////////////////////////////
  95. // Function : CHwxFE::GetAppLangID
  96. // Type : LANGID
  97. // Purpose : Get this Applet's Language Id.
  98. // Args : None
  99. // Return :
  100. // DATE : Mon Aug 03 22:56:44 1998
  101. // Histroy :
  102. //////////////////////////////////////////////////////////////////
  103. LANGID CHwxFE::GetAppLangID(VOID)
  104. {
  105. #ifdef FE_KOREAN
  106. if(MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT) == ::GetSystemDefaultLangID()) {
  107. return MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT);
  108. }
  109. else {
  110. return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  111. }
  112. #elif FE_JAPANESE
  113. if(MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) == ::GetSystemDefaultLangID()) {
  114. return MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT);
  115. }
  116. else {
  117. return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  118. }
  119. #elif FE_CHINESE_SIMPLIFIED
  120. return MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
  121. #else
  122. return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  123. #endif
  124. }
  125. //////////////////////////////////////////////////////////////////
  126. // Function : CHwxFE::GetAppCodePage
  127. // Type : INT
  128. // Purpose : Get this Applet's Code Page.
  129. // Japanese version return 932.
  130. // Simplified Chinese version, return 936.
  131. // Args : None
  132. // Return :
  133. // DATE : Mon Aug 03 23:24:30 1998
  134. // Histroy :
  135. //////////////////////////////////////////////////////////////////
  136. INT CHwxFE::GetAppCodePage(VOID)
  137. {
  138. #ifdef FE_JAPANESE
  139. return CP_JAPANESE;
  140. #elif FE_KOREAN
  141. return CP_KOREAN;
  142. #elif FE_CHINESE_SIMPLIFIED
  143. return CP_CHINESE_SIMPLIFIED;
  144. #else
  145. return CP_ACP;
  146. #endif
  147. }
  148. #define TSZ_KEY_PROGRAMFILESDIR TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
  149. #define TSZ_NAME_PROGRAMFILESDIR TEXT("ProgramFilesDir")
  150. #define TSZ_INK_PATH TEXT("Common Files\\Microsoft Shared\\Ink")
  151. BOOL
  152. chwxfe_GetProgramFilesDir(LPTSTR lpstr, INT maxLen)
  153. {
  154. HKEY hKey;
  155. INT ret;
  156. ret = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  157. TSZ_KEY_PROGRAMFILESDIR,
  158. 0, KEY_READ, &hKey);
  159. if(ret != ERROR_SUCCESS) {
  160. //DBG(("-->RegOpenKeyEx error [0x%08x]\n", ret));
  161. return FALSE;
  162. }
  163. ULONG ulSize = sizeof(TCHAR)*(maxLen-1);
  164. ret = ::RegQueryValueEx(hKey,
  165. TSZ_NAME_PROGRAMFILESDIR,
  166. NULL,
  167. NULL,
  168. (LPBYTE)lpstr, &ulSize);
  169. if(ret != ERROR_SUCCESS) {
  170. //DBG(("-->RegQueryValueEx error [0x%08x]\n", ret));
  171. ::RegCloseKey( hKey );
  172. return FALSE;
  173. }
  174. //DBG(("CRegUtil::GetProgramFilesDir() [%s]\n", lpstr));
  175. ::RegCloseKey( hKey );
  176. return TRUE;
  177. }
  178. INT
  179. CHwxFE::GetRecognizerFileName(HINSTANCE hInst, LPTSTR lpstr, INT cchMax)
  180. {
  181. TCHAR tszModPath[MAX_PATH];
  182. TCHAR tszFileName[64];
  183. TCHAR tszPF[MAX_PATH];
  184. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  185. CHwxFE::GetAppLangID(),
  186. hInst,
  187. IDS_RECOG_FILE,
  188. tszFileName,
  189. sizeof(tszFileName)/sizeof(tszFileName[0]));
  190. chwxfe_GetProgramFilesDir(tszPF, sizeof(tszPF)/sizeof(tszPF[0]));
  191. wsprintf(tszModPath,
  192. TEXT("%s\\%s\\%s"),
  193. tszPF,
  194. TSZ_INK_PATH,
  195. tszFileName);
  196. //OutputDebugString(tszModPath);
  197. HANDLE hFile;
  198. LPSECURITY_ATTRIBUTES pSec = (LPSECURITY_ATTRIBUTES)NULL;
  199. //=======================================================
  200. ::SetLastError(ERROR_SUCCESS);
  201. hFile = ::CreateFile(tszModPath,
  202. GENERIC_READ,
  203. FILE_SHARE_READ,
  204. pSec,
  205. OPEN_EXISTING,
  206. FILE_ATTRIBUTE_NORMAL,
  207. 0);
  208. if(hFile != INVALID_HANDLE_VALUE) {
  209. ::CloseHandle(hFile);
  210. StringCchCopy(lpstr, cchMax, tszModPath);
  211. //OutputDebugString("tszModPath\n");
  212. return 0;
  213. }
  214. //Cannot find
  215. GetModuleFileName(hInst,
  216. tszModPath,
  217. sizeof(tszModPath)/sizeof(tszModPath[0]));
  218. TCHAR *p = strrchr(tszModPath, (TCHAR)'\\');
  219. if(!p) {
  220. return -1;
  221. }
  222. p[1] = (TCHAR)0x00;
  223. StringCchCat(tszModPath, MAX_PATH, tszFileName);
  224. StringCchCopy(lpstr, cchMax, tszModPath);
  225. //OutputDebugString("tszModPath\n");
  226. return 0;
  227. cchMax;
  228. }
  229. INT CHwxFE::LoadStrWithLangId(LANGID langId,
  230. HINSTANCE hInst,
  231. INT id,
  232. LPWSTR lpwstr,
  233. INT cchMax)
  234. {
  235. CExres::LoadStringW(langId, hInst, id, lpwstr, cchMax);
  236. return 0;
  237. }
  238. //////////////////////////////////////////////////////////////////
  239. // Function : CHwxFE::GetTitleStringW
  240. // Type : INT
  241. // Purpose : Get Handwriting applet's title string.
  242. // Args :
  243. // : HINSTANCE hInst
  244. // : LPWSTR lpwstr
  245. // : INT cchMax
  246. // Return :
  247. // DATE : Mon Aug 03 22:44:49 1998
  248. // Histroy :
  249. //////////////////////////////////////////////////////////////////
  250. INT CHwxFE::GetTitleStringW(HINSTANCE hInst, LPWSTR lpwstr, INT cchMax)
  251. {
  252. #ifdef FE_CHINESE_SIMPLIFIED
  253. if(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) == ::GetSystemDefaultLangID()) {
  254. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  255. hInst,
  256. IDS_TITLE,
  257. lpwstr,
  258. cchMax);
  259. }
  260. else {
  261. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  262. hInst,
  263. IDS_TITLE_US,
  264. lpwstr,
  265. cchMax);
  266. }
  267. #else
  268. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  269. hInst,
  270. IDS_TITLE,
  271. lpwstr,
  272. cchMax);
  273. #endif
  274. return 0;
  275. }
  276. INT CHwxFE::GetDispFontW(HINSTANCE hInst, LPWSTR lpwstr, INT cchMax)
  277. {
  278. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  279. hInst,
  280. IDS_FONT_DEFAULT,
  281. lpwstr,
  282. cchMax);
  283. return 0;
  284. }
  285. #ifndef UNDER_CE // Windows CE always UNICODE
  286. INT CHwxFE::GetDispFontA(HINSTANCE hInst, LPSTR lpstr, INT cchMax)
  287. {
  288. #ifdef FE_CHINESE_SIMPLIFIED
  289. if(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) == ::GetSystemDefaultLangID()) {
  290. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  291. CHwxFE::GetAppLangID(),
  292. hInst,
  293. IDS_FONT_DEFAULT,
  294. lpstr,
  295. cchMax);
  296. }
  297. else {
  298. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  299. CHwxFE::GetAppLangID(),
  300. hInst,
  301. IDS_FONT_DEFAULT_US,
  302. lpstr,
  303. cchMax);
  304. }
  305. #elif FE_JAPANESE
  306. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  307. CHwxFE::GetAppLangID(),
  308. hInst,
  309. IDS_FONT_DEFAULT,
  310. lpstr,
  311. cchMax);
  312. //990810:ToshiaK for KOTAE #1030
  313. BOOL fRet = CFont::IsFontExist(lpstr, SHIFTJIS_CHARSET);
  314. if(fRet) {
  315. Dbg(("Found Fond[%s]\n", lpstr));
  316. return 0;
  317. }
  318. else {
  319. static TCHAR szFontUIGothic[]=TEXT("MS UI Gothic");
  320. fRet = CFont::IsFontExist(szFontUIGothic, SHIFTJIS_CHARSET);
  321. if(fRet) {
  322. Dbg(("Found MS UI Gothic\n"));
  323. StrcpySafeA(lpstr, szFontUIGothic, cchMax);
  324. }
  325. else {
  326. CFont::GetFontNameByCharSet(SHIFTJIS_CHARSET, lpstr, cchMax);
  327. }
  328. }
  329. #elif FE_KOREAN
  330. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  331. CHwxFE::GetAppLangID(),
  332. hInst,
  333. IDS_FONT_DEFAULT,
  334. lpstr,
  335. cchMax);
  336. //990810:ToshiaK for KOTAE #1030
  337. //Korean version: CSLim
  338. BOOL fRet = CFont::IsFontExist(lpstr, HANGUL_CHARSET);
  339. if(fRet) {
  340. Dbg(("Found Fond[%s]\n", lpstr));
  341. return 0;
  342. }
  343. else {
  344. static TCHAR szFontGulim[]=TEXT("Gulim");
  345. fRet = CFont::IsFontExist(szFontGulim, HANGUL_CHARSET);
  346. if(fRet) {
  347. Dbg(("Found Gulim\n"));
  348. StrcpySafeA(lpstr, szFontGulim, cchMax);
  349. }
  350. else {
  351. CFont::GetFontNameByCharSet(HANGUL_CHARSET, lpstr, cchMax);
  352. }
  353. }
  354. #endif
  355. return 0;
  356. }
  357. #endif // UNDER_CE
  358. INT CHwxFE::GetInkExpTextW(HINSTANCE hInst, LPWSTR lpwstr, INT cchMax)
  359. {
  360. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  361. hInst,
  362. IDS_CACINK,
  363. lpwstr,
  364. cchMax);
  365. return 0;
  366. }
  367. #ifndef UNDER_CE // Windows CE always UNICODE
  368. INT CHwxFE::GetInkExpTextA(HINSTANCE hInst, LPSTR lpstr, INT cchMax)
  369. {
  370. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  371. CHwxFE::GetAppLangID(),
  372. hInst,
  373. IDS_CACINK,
  374. lpstr,
  375. cchMax);
  376. return 0;
  377. }
  378. #endif // UNDER_CE
  379. INT CHwxFE::GetListExpTextW (HINSTANCE hInst, LPWSTR lpwstr, INT cchMax)
  380. {
  381. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  382. hInst,
  383. IDS_CACPLV,
  384. lpwstr,
  385. cchMax);
  386. return 0;
  387. }
  388. #ifndef UNDER_CE // Windows CE always UNICODE
  389. INT CHwxFE::GetListExpTextA(HINSTANCE hInst, LPSTR lpstr, INT cchMax)
  390. {
  391. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  392. CHwxFE::GetAppLangID(),
  393. hInst,
  394. IDS_CACPLV,
  395. lpstr,
  396. cchMax);
  397. return 0;
  398. }
  399. #endif // UNDER_CE
  400. #ifdef UNDER_CE
  401. INT CHwxFE::GetHeaderStringW(HINSTANCE hInst, INT index, LPWSTR lpstr, INT cchMax)
  402. {
  403. CExres::LoadStringW(CHwxFE::GetAppLangID(),
  404. hInst,
  405. IDS_LVC0+index,
  406. lpstr, cchMax);
  407. return 0;
  408. }
  409. #endif // UNDER_CE
  410. #ifndef UNDER_CE // Windows CE always UNICODE
  411. INT CHwxFE::GetHeaderStringA(HINSTANCE hInst, INT index, LPSTR lpstr, INT cchMax)
  412. {
  413. CExres::LoadStringA(CHwxFE::GetAppCodePage(),
  414. CHwxFE::GetAppLangID(),
  415. hInst,
  416. IDS_LVC0+index,
  417. lpstr, cchMax);
  418. return 0;
  419. }
  420. #endif // UNDER_CE
  421. INT CHwxFE::ShowHelp(HWND hwnd)
  422. {
  423. #ifdef FE_KOREAN
  424. if (CHwxFE::Is16bitApplication())
  425. return 0;
  426. LPTSTR lpstrArg = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH*2+32);
  427. LPTSTR lpstrHelp = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  428. LPTSTR lpstrWinDir = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  429. LPTSTR lpstrName = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  430. LPTSTR lpstrHelpName = NULL;
  431. INT size;
  432. if (!lpstrArg || !lpstrHelp || !lpstrWinDir || !lpstrName)
  433. goto LError;
  434. *lpstrHelp = (TCHAR)0x00;
  435. if (CHwxFE::GetAppLangID() == MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT))
  436. lpstrHelpName = SZHELPFILE_MAIN;
  437. else
  438. lpstrHelpName = SZHELPFILE_MAIN_ENG;
  439. StringCchCat(lpstrHelp, MAX_PATH, lpstrHelpName);
  440. GetSystemWindowsDirectory(lpstrWinDir, MAX_PATH);
  441. wsprintf(lpstrName,
  442. TEXT("%s\\hh.exe"),
  443. lpstrWinDir);
  444. wsprintf(lpstrArg,
  445. TEXT("%s %s::/howIMETopic135_UsingTheHandwritingAppletTOC.htm"),
  446. lpstrName,
  447. lpstrHelp);
  448. Dbg(("lpstrHelp [%s]\n", lpstrHelp));
  449. {
  450. PROCESS_INFORMATION pi = {0};
  451. STARTUPINFO si = {0};
  452. si.cb = sizeof(si);
  453. si.wShowWindow = SW_SHOWNORMAL;
  454. ::CreateProcess(lpstrName, lpstrArg, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
  455. if (pi.hProcess)
  456. CloseHandle(pi.hProcess);
  457. if (pi.hThread)
  458. CloseHandle(pi.hThread);
  459. }
  460. LError:
  461. if (lpstrArg)
  462. MemFree(lpstrArg);
  463. if (lpstrHelp)
  464. MemFree(lpstrHelp);
  465. if(lpstrWinDir)
  466. MemFree(lpstrWinDir);
  467. if(lpstrName)
  468. MemFree(lpstrName);
  469. #elif FE_JAPANESE
  470. if(CHwxFE::Is16bitApplication()) {
  471. return 0;
  472. }
  473. LPTSTR lpstrArg = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  474. LPTSTR lpstrHelp= (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  475. LPTSTR lpstrHelpName = NULL;
  476. INT size;
  477. if(!lpstrArg) {
  478. goto LError;
  479. }
  480. if(!lpstrHelp) {
  481. goto LError;
  482. }
  483. *lpstrHelp = (TCHAR)0x00;
  484. if(CHwxFE::GetAppLangID() == MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)) {
  485. lpstrHelpName = SZHELPFILE_MAIN;
  486. }
  487. else {
  488. lpstrHelpName = SZHELPFILE_MAIN_ENG;
  489. }
  490. if(CUtil::IsHydra() && CUtil::IsWinNT4()) {
  491. size = CUtil::GetWINDIR(lpstrHelp, MAX_PATH);
  492. lpstrHelp[size] = (TCHAR)0x00;
  493. StringCchCat(lpstrHelp, MAX_PATH, TEXT("\\help\\"));
  494. }
  495. StringCchCat(lpstrHelp, MAX_PATH, lpstrHelpName);
  496. wsprintf(lpstrArg,
  497. TEXT("hh.exe %s::/IDH_TOC_HW_fake.htm"),
  498. lpstrHelp);
  499. Dbg(("lpstrHelp [%s]\n", lpstrHelp));
  500. #ifndef UNDER_CE // Windows CE does not support WinExec
  501. ::WinExec(lpstrArg, SW_SHOWNORMAL);
  502. #else // UNDER_CE
  503. //temp
  504. ::CreateProcess(lpstrArg, L"", NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);
  505. #endif // UNDER_CE
  506. LError:
  507. if(lpstrArg) {
  508. MemFree(lpstrArg);
  509. }
  510. if(lpstrHelp) {
  511. MemFree(lpstrHelp);
  512. }
  513. #elif FE_CHINESE_SIMPLIFIED
  514. if(CHwxFE::Is16bitApplication()) {
  515. ::WinHelp(hwnd, SZHELPFILE_CONTEXTMENU, HELP_CONTEXT, IDH_TOC_HW);
  516. } else {
  517. LPSTR lpstrArg = (CHAR *)MemAlloc(sizeof(CHAR)*256);
  518. if(lpstrArg) {
  519. wsprintf(lpstrArg,
  520. "hh.exe %s::/pad_sum.htm",
  521. SZHELPFILE_MAIN);
  522. INT ret = ::WinExec(lpstrArg, SW_SHOWNORMAL);
  523. //WinExec return code is greater than 31 if succeeded
  524. if(ret <= 31) {
  525. ::WinHelp(hwnd, SZHELPFILE_CONTEXTMENU, HELP_CONTEXT, IDH_TOC_HW);
  526. }
  527. MemFree(lpstrArg);
  528. }
  529. else {
  530. ::WinHelp(hwnd, SZHELPFILE_CONTEXTMENU, HELP_CONTEXT, IDH_TOC_HW);
  531. }
  532. }
  533. # ifdef HTMLHELPBUG
  534. if(CHwxFE::Is16bitApplication()) {
  535. ::WinHelp(hwnd, SZHELPFILE_CONTEXTMENU, HELP_CONTEXT, IDH_TOC_HW);
  536. } else if (!::HtmlHelp(hwnd, SZHELPFILE_MAIN, HH_DISPLAY_TOPIC,
  537. (LPARAM)"pad_sum.htm")) {
  538. ::WinHelp(hwnd, SZHELPFILE_CONTEXTMENU, HELP_CONTEXT, IDH_TOC_HW);
  539. }
  540. # endif //HTMLHELPBUG
  541. #endif
  542. return 0;
  543. Unref(hwnd);
  544. }
  545. INT CHwxFE::HandleWmHelp(HWND hwnd, BOOL fCAC)
  546. {
  547. #ifndef UNDER_CE // Windows CE does not support WinHelp
  548. #ifdef FE_KOREAN
  549. if(CHwxFE::GetAppLangID() == MAKELANGID(LANG_KOREAN,
  550. SUBLANG_DEFAULT)) {
  551. ::WinHelp(hwnd,
  552. SZHELPFILE_CONTEXTMENU,
  553. HELP_WM_HELP,
  554. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  555. }
  556. else {
  557. ::WinHelp(hwnd,
  558. SZHELPFILE_CONTEXTMENU_ENG,
  559. HELP_WM_HELP,
  560. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  561. }
  562. #elif FE_JAPANESE
  563. if(CHwxFE::GetAppLangID() == MAKELANGID(LANG_JAPANESE,
  564. SUBLANG_DEFAULT)) {
  565. ::WinHelp(hwnd,
  566. SZHELPFILE_CONTEXTMENU,
  567. HELP_WM_HELP,
  568. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  569. }
  570. else {
  571. ::WinHelp(hwnd,
  572. SZHELPFILE_CONTEXTMENU_ENG,
  573. HELP_WM_HELP,
  574. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  575. }
  576. #elif FE_CHINESE_SIMPLIFIED
  577. ::WinHelp(hwnd,
  578. SZHELPFILE_CONTEXTMENU,
  579. HELP_WM_HELP,
  580. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  581. #endif
  582. #endif // UNDER_CE
  583. return 0;
  584. }
  585. INT CHwxFE::HandleWmContextMenu (HWND hwnd, BOOL fCAC)
  586. {
  587. #ifndef UNDER_CE // Windows CE does not support WinHelp
  588. #ifdef FE_KOREAN
  589. if(CHwxFE::GetAppLangID() == MAKELANGID(LANG_KOREAN,
  590. SUBLANG_DEFAULT)) {
  591. ::WinHelp(hwnd,
  592. SZHELPFILE_CONTEXTMENU,
  593. HELP_CONTEXTMENU,
  594. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  595. }
  596. else {
  597. ::WinHelp(hwnd,
  598. SZHELPFILE_CONTEXTMENU_ENG,
  599. HELP_CONTEXTMENU,
  600. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  601. }
  602. #elif FE_JAPANESE
  603. if(CHwxFE::GetAppLangID() == MAKELANGID(LANG_JAPANESE,
  604. SUBLANG_DEFAULT)) {
  605. ::WinHelp(hwnd,
  606. SZHELPFILE_CONTEXTMENU,
  607. HELP_CONTEXTMENU,
  608. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  609. }
  610. else {
  611. ::WinHelp(hwnd,
  612. SZHELPFILE_CONTEXTMENU_ENG,
  613. HELP_CONTEXTMENU,
  614. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  615. }
  616. #elif FE_CHINESE_SIMPLIFIED
  617. ::WinHelp(hwnd,
  618. SZHELPFILE_CONTEXTMENU,
  619. HELP_CONTEXTMENU,
  620. fCAC ? (ULONG_PTR)CACHelpIdList : (ULONG_PTR)MBHelpIdList);
  621. #endif
  622. #endif // UNDER_CE
  623. return 0;
  624. }
  625. //////////////////////////////////////////////////////////////////
  626. // Function : CHwxFE::GetMenu
  627. // Type : HMENU
  628. // Purpose :
  629. // Args :
  630. // : HINSTANCE hInst
  631. // : LPSTR lpstrResId
  632. // Return :
  633. // DATE : Wed Sep 09 18:47:21 1998
  634. // Histroy :
  635. //////////////////////////////////////////////////////////////////
  636. #ifndef UNDER_CE
  637. HMENU CHwxFE::GetMenu(HINSTANCE hInst, LPSTR lpstrResId)
  638. #else // UNDER_CE
  639. HMENU CHwxFE::GetMenu(HINSTANCE hInst, LPTSTR lpstrResId)
  640. #endif // UNDER_CE
  641. {
  642. #ifndef UNDER_CE
  643. return CExres::LoadMenuA(CHwxFE::GetAppLangID(),
  644. hInst,
  645. lpstrResId);
  646. #else // UNDER_CE
  647. return CExres::LoadMenu(CHwxFE::GetAppLangID(),
  648. hInst,
  649. lpstrResId);
  650. #endif // UNDER_CE
  651. }
  652. //////////////////////////////////////////////////////////////////
  653. // Function : CHwxFE::GetTipText
  654. // Type : INT
  655. // Purpose : Get HanCharacter's Reading text for Tooltip.
  656. // Args :
  657. // : WCHAR wch
  658. // : LPWSTR lpwstrTip
  659. // : INT cchMax
  660. // : LPVOID lpSkdic
  661. // Return :
  662. // DATE : Wed Aug 05 18:45:36 1998
  663. // Histroy :
  664. //////////////////////////////////////////////////////////////////
  665. //----------------------------------------------------------------
  666. //Japanese version.
  667. //----------------------------------------------------------------
  668. #ifdef FE_JAPANESE
  669. INT CHwxFE::GetTipText(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  670. {
  671. static KANJIINFO kanji;
  672. IImeSkdic *lpIImeSkdic = (IImeSkdic *)lpSkdic;
  673. if(!wch || !lpIImeSkdic|| !lpwstrTip ) {
  674. return -1;
  675. }
  676. kanji.mask = KIF_YOMI;
  677. if(S_OK != lpIImeSkdic->GetKanjiInfo(wch,&kanji)) {
  678. return -1;
  679. }
  680. if( kanji.wchOnYomi1[0] ) {
  681. if( kanji.wchOnYomi2[0] ) {
  682. if( kanji.wchKunYomi1[0] ) {
  683. if( kanji.wchKunYomi2[0] ){
  684. swprintf(lpwstrTip,
  685. L"%s %s\n%s %s",
  686. kanji.wchOnYomi1,
  687. kanji.wchOnYomi2,
  688. kanji.wchKunYomi1,
  689. kanji.wchKunYomi2);
  690. }
  691. else {
  692. swprintf(lpwstrTip,
  693. L"%s %s\n%s",
  694. kanji.wchOnYomi1,
  695. kanji.wchOnYomi2,
  696. kanji.wchKunYomi1);
  697. }
  698. }
  699. else {
  700. if( kanji.wchKunYomi2[0] ) {
  701. swprintf(lpwstrTip,
  702. L"%s %s\n%s",
  703. kanji.wchOnYomi1,
  704. kanji.wchOnYomi2,
  705. kanji.wchKunYomi2);
  706. }
  707. else {
  708. swprintf(lpwstrTip,
  709. L"%s %s",
  710. kanji.wchOnYomi1,
  711. kanji.wchOnYomi2);
  712. }
  713. }
  714. }
  715. else {
  716. if(kanji.wchKunYomi1[0]) {
  717. if ( kanji.wchKunYomi2[0] ) {
  718. swprintf(lpwstrTip,
  719. L"%s\n%s %s",
  720. kanji.wchOnYomi1,
  721. kanji.wchKunYomi1,
  722. kanji.wchKunYomi2);
  723. }
  724. else {
  725. swprintf(lpwstrTip,
  726. L"%s\n%s",
  727. kanji.wchOnYomi1,
  728. kanji.wchKunYomi1);
  729. }
  730. }
  731. else{
  732. if ( kanji.wchKunYomi2[0] ) {
  733. swprintf(lpwstrTip,
  734. L"%s\n%s",
  735. kanji.wchOnYomi1,
  736. kanji.wchKunYomi2);
  737. }
  738. else {
  739. swprintf(lpwstrTip,
  740. L"%s",
  741. kanji.wchOnYomi1);
  742. }
  743. }
  744. }
  745. }
  746. else {
  747. if(kanji.wchOnYomi2[0] ){
  748. if ( kanji.wchKunYomi1[0] ) {
  749. if ( kanji.wchKunYomi2[0] ) {
  750. swprintf(lpwstrTip,
  751. L"%s\n%s %s",
  752. kanji.wchOnYomi2,
  753. kanji.wchKunYomi1,
  754. kanji.wchKunYomi2);
  755. }
  756. else {
  757. swprintf(lpwstrTip,
  758. L"%s\n%s",
  759. kanji.wchOnYomi2,
  760. kanji.wchKunYomi1);
  761. }
  762. }
  763. else {
  764. if ( kanji.wchKunYomi2[0] ) {
  765. swprintf(lpwstrTip,
  766. L"%s\n%s",
  767. kanji.wchOnYomi2,
  768. kanji.wchKunYomi2);
  769. }
  770. else {
  771. swprintf(lpwstrTip,
  772. L"%s",
  773. kanji.wchOnYomi2);
  774. }
  775. }
  776. }
  777. else{
  778. if( kanji.wchKunYomi1[0] ){
  779. if ( kanji.wchKunYomi2[0] ) {
  780. swprintf(lpwstrTip,
  781. L"%s %s",
  782. kanji.wchKunYomi1,
  783. kanji.wchKunYomi2);
  784. }
  785. else {
  786. swprintf(lpwstrTip,
  787. L"%s",
  788. kanji.wchKunYomi1);
  789. }
  790. }
  791. else {
  792. if( kanji.wchKunYomi2[0] ){
  793. swprintf(lpwstrTip,
  794. L"%s",
  795. kanji.wchKunYomi2);
  796. }
  797. else {
  798. return -1; //bEmpty = TRUE;
  799. }
  800. }
  801. }
  802. }
  803. return 0;
  804. Unref(cchMax);
  805. }
  806. //
  807. // FE_JAPANESE CHwxFE::GetTipText() End
  808. //
  809. #elif FE_CHINESE_SIMPLIFIED
  810. //----------------------------------------------------------------
  811. //
  812. //Simplified Chinese version.
  813. //
  814. //----------------------------------------------------------------
  815. #include "imm.h"
  816. //----------------------------------------------------------------
  817. //helper function's prototype
  818. //----------------------------------------------------------------
  819. HKL GetIntelligentKL(VOID);
  820. int CALLBACK QueryDicDataA(LPCSTR lpszReading,
  821. DWORD dwStyle,
  822. LPCSTR lpszString,
  823. LPVOID lpvData);
  824. int CALLBACK QueryDicDataW(LPCWSTR lpszReading,
  825. DWORD dwStyle,
  826. LPCWSTR lpszString,
  827. LPVOID lpvData);
  828. INT GetTipTextA(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  829. {
  830. CHAR ach[4];
  831. DWORD dwBuf[30];
  832. PCHAR pchReading = PCHAR(dwBuf + 1);
  833. static HKL hKL = NULL;
  834. if(!hKL) {
  835. hKL = GetIntelligentKL();
  836. }
  837. dwBuf[0] = 0;
  838. pchReading[0] = pchReading[1] = 0;
  839. ::WideCharToMultiByte(936, WC_COMPOSITECHECK, &wch, 1, ach,
  840. sizeof(WCHAR)/sizeof(TCHAR), NULL, NULL);
  841. ach[2] = NULL;
  842. ::ImmEnumRegisterWordA(hKL,
  843. QueryDicDataA,
  844. NULL,
  845. (IME_REGWORD_STYLE_USER_FIRST + 1),
  846. ach, (LPVOID)dwBuf);
  847. if(*pchReading) {
  848. DWORD dwReadLen = ::MultiByteToWideChar(936,
  849. MB_COMPOSITE,
  850. pchReading,
  851. lstrlenA(pchReading),
  852. lpwstrTip,
  853. cchMax);
  854. lpwstrTip[dwReadLen] = NULL;
  855. return 0;
  856. }
  857. return -1;
  858. UNREFERENCED_PARAMETER(lpSkdic);
  859. }
  860. INT GetTipTextW(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  861. {
  862. DWORD dwBuf[30];
  863. PWCHAR pwchReading = PWCHAR(dwBuf + 1);
  864. WCHAR awch[2];
  865. static HKL hKL = NULL;
  866. if(!hKL) {
  867. hKL = GetIntelligentKL();
  868. }
  869. dwBuf[0] = 0;
  870. pwchReading[0] = 0;
  871. awch[0] = wch;
  872. awch[1] = NULL;
  873. ::ImmEnumRegisterWordW(hKL,
  874. QueryDicDataW,
  875. NULL,
  876. (IME_REGWORD_STYLE_USER_FIRST + 1),
  877. awch, (LPVOID)dwBuf);
  878. if(*pwchReading) {
  879. int nStrLen = lstrlenW(pwchReading);
  880. CopyMemory(lpwstrTip, pwchReading, nStrLen*sizeof(WCHAR));
  881. lpwstrTip[nStrLen] = NULL;
  882. return 0;
  883. }
  884. return -1;
  885. UNREFERENCED_PARAMETER(lpSkdic);
  886. UNREFERENCED_PARAMETER(cchMax);
  887. }
  888. INT CHwxFE::GetTipText(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  889. {
  890. if (IsWinNT()) {
  891. return GetTipTextW(wch, lpwstrTip, cchMax, lpSkdic);
  892. } else {
  893. return GetTipTextA(wch, lpwstrTip, cchMax, lpSkdic);
  894. }
  895. }
  896. //////////////////////////////////////////////////////////////////
  897. // Function : GetIntelligentKL
  898. // Type : HKL
  899. // Purpose :
  900. // Args : None
  901. // Return :
  902. // DATE : Wed Aug 05 18:56:22 1998
  903. // Author : Hail(Hai Liu(PRC))
  904. // Histroy : 980805: merged with prc source.
  905. //////////////////////////////////////////////////////////////////
  906. HKL GetIntelligentKL(VOID)
  907. {
  908. return (HKL)0xE00E0804;
  909. }
  910. //////////////////////////////////////////////////////////////////
  911. // Function : QueryDicData
  912. // Type : int CALLBACK
  913. // Purpose :
  914. // Args :
  915. // : LPCSTR lpszReading
  916. // : DWORD dwStyle
  917. // : LPCSTR lpszString
  918. // : LPVOID lpvData
  919. // Return :
  920. // DATE : Wed Aug 05 18:59:07 1998
  921. // Author : Hail(Hai Liu (MSPRC))
  922. // Histroy : 980805: merged with prc source by ToshiaK(MSKK).
  923. //////////////////////////////////////////////////////////////////
  924. int CALLBACK QueryDicDataA(LPCSTR lpszReading,
  925. DWORD dwStyle,
  926. LPCSTR lpszString,
  927. LPVOID lpvData)
  928. {
  929. if (!*lpszReading) { return 1; }
  930. PDWORD pdwHomNum = (LPDWORD)lpvData;
  931. PCHAR pchReadingList = (PCHAR)(pdwHomNum+1);
  932. pchReadingList += lstrlenA(pchReadingList);
  933. if (*pdwHomNum == 0) {
  934. } else if ((*pdwHomNum % 3) == 0) {
  935. *pchReadingList++ = '\n';
  936. } else {
  937. *pchReadingList++ = ' ';
  938. }
  939. while(*lpszReading != ' ' && *lpszReading != NULL) {
  940. *pchReadingList++ = *lpszReading++;
  941. }
  942. *pchReadingList = NULL;
  943. (*pdwHomNum)++;
  944. return 1;
  945. UNREFERENCED_PARAMETER(lpszString);
  946. UNREFERENCED_PARAMETER(dwStyle);
  947. }
  948. int CALLBACK QueryDicDataW(LPCWSTR lpwszReading,
  949. DWORD dwStyle,
  950. LPCWSTR lpwszString,
  951. LPVOID lpvData)
  952. {
  953. if (!*lpwszReading) { return 1; }
  954. PDWORD pdwHomNum = (LPDWORD)lpvData;
  955. PWCHAR pwchReadingList = (PWCHAR)(pdwHomNum+1);
  956. pwchReadingList += lstrlenW(pwchReadingList);
  957. if (*pdwHomNum == 0) {
  958. } else if ((*pdwHomNum % 3) == 0) {
  959. *pwchReadingList++ = L'\n';
  960. } else {
  961. *pwchReadingList++ = L' ';
  962. }
  963. while(*lpwszReading != ' ' && *lpwszReading != NULL) {
  964. *pwchReadingList++ = *lpwszReading++;
  965. }
  966. *pwchReadingList = NULL;
  967. (*pdwHomNum)++;
  968. return 1;
  969. UNREFERENCED_PARAMETER(dwStyle);
  970. UNREFERENCED_PARAMETER(lpwszString);
  971. }
  972. //---FE_CHINESE_SIMPLIFIED CHwxFE::GetTipText() End
  973. #elif FE_KOREAN
  974. //---FE_KOREAN CHwxFE::GetTipText() Start
  975. #define UNICODE_CJK_UNIFIED_IDEOGRAPHS_START 0x4E00
  976. #define UNICODE_CJK_UNIFIED_IDEOGRAPHS_END 0x9FFF
  977. #define UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_START 0xF900
  978. #define UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_END 0xFAFF
  979. inline
  980. BOOL fIsHanja(WCHAR wcCh)
  981. {
  982. return (wcCh >= UNICODE_CJK_UNIFIED_IDEOGRAPHS_START &&
  983. wcCh <= UNICODE_CJK_UNIFIED_IDEOGRAPHS_END) ||
  984. (wcCh >= UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_START &&
  985. wcCh <= UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_END);
  986. }
  987. INT CHwxFE::GetTipText(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  988. {
  989. // If Hanja display the meaning and the pronounciation
  990. if ((fIsHanja(wch) && GetMeaningAndProunc(wch, lpwstrTip, cchMax)) == FALSE)
  991. {
  992. swprintf(lpwstrTip, L"U+%04X", wch, wch);
  993. }
  994. return 0;
  995. UNREFERENCED_PARAMETER(wch);
  996. UNREFERENCED_PARAMETER(lpwstrTip);
  997. UNREFERENCED_PARAMETER(cchMax);
  998. UNREFERENCED_PARAMETER(lpSkdic);
  999. }
  1000. //---FE_KOREAN CHwxFE::GetTipText() End
  1001. #else
  1002. INT CHwxFE::GetTipText(WCHAR wch, LPWSTR lpwstrTip, INT cchMax, LPVOID lpSkdic)
  1003. {
  1004. return 0;
  1005. UNREFERENCED_PARAMETER(wch);
  1006. UNREFERENCED_PARAMETER(lpwstrTip);
  1007. UNREFERENCED_PARAMETER(cchMax);
  1008. UNREFERENCED_PARAMETER(lpSkdic);
  1009. }
  1010. #endif
  1011. //////////////////////////////////////////////////////////////////
  1012. // Function : CHwxFE::Is16bitApplication
  1013. // Type : BOOL
  1014. // Purpose : Check application is 16bit or not for HtmlHelp
  1015. // Args : None
  1016. // Return :
  1017. // DATE : Mon Sep 21 13:30:56 1998
  1018. // Histroy :
  1019. //////////////////////////////////////////////////////////////////
  1020. BOOL CHwxFE::Is16bitApplication(VOID)
  1021. {
  1022. #ifndef UNDER_CE // Windows CE always Unicode
  1023. Dbg(("CHwxFE::Is16bitApplication()\n"));
  1024. if(IsWinNT()) {
  1025. //Dbg(("NT \n"));
  1026. DWORD dwType = 0;
  1027. BOOL fRet = FALSE;
  1028. LPSTR lpstrPath = (LPSTR)MemAlloc(sizeof(CHAR)*(MAX_PATH+1));
  1029. //Dbg(("lpstrPath 0x%08x\n", lpstrPath));
  1030. if(lpstrPath) {
  1031. *lpstrPath = (CHAR)0x00;
  1032. INT len = ::GetModuleFileName(NULL, lpstrPath, sizeof(CHAR)*(MAX_PATH+1));
  1033. if(len > 0) {
  1034. *(lpstrPath+len) = (CHAR)0x00;
  1035. }
  1036. //Dbg(("lpstrPath %s\n", lpstrPath));
  1037. ::GetBinaryType(lpstrPath, &dwType);
  1038. //Dbg(("dwType 0x%08x\n", dwType));
  1039. if(dwType == SCS_WOW_BINARY) {
  1040. fRet = TRUE;
  1041. }
  1042. MemFree(lpstrPath);
  1043. //Dbg(("fRet %d\n", fRet));
  1044. return fRet;
  1045. }
  1046. }
  1047. else {
  1048. HANDLE hThread;
  1049. DWORD dwId;
  1050. hThread = ::CreateThread(NULL,
  1051. 0,
  1052. NULL,
  1053. 0,
  1054. 0,
  1055. &dwId);
  1056. if(hThread) {
  1057. //Dbg(("CreateThread hThread[%d]\n", hThread));
  1058. ::CloseHandle(hThread);
  1059. return FALSE;
  1060. }
  1061. else {
  1062. INT ret = ::GetLastError();
  1063. //Dbg(("CreateThread ret %d\n",ret));
  1064. switch(ret) {
  1065. case ERROR_NOT_SUPPORTED:
  1066. return TRUE;
  1067. case ERROR_INVALID_PARAMETER:
  1068. return FALSE;
  1069. default:
  1070. return FALSE;
  1071. }
  1072. }
  1073. }
  1074. #endif // UNDER_CE
  1075. return FALSE;
  1076. }