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.

349 lines
10 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* Chinese IME Batch Mode */
  5. /* (Dialogbox) */
  6. /* */
  7. /* */
  8. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  9. /**************************************************/
  10. #include "stdafx.h"
  11. #include "eudcedit.h"
  12. #if 1 // use function in imeblink.c!
  13. #include "imeblink.h"
  14. #endif
  15. #include "blinkdlg.h"
  16. #include "util.h"
  17. #define STRSAFE_LIB
  18. #include <strsafe.h>
  19. #define SIGN_CWIN 0x4E495743 /* Sign of CWin */
  20. #define SIGN__TBL 0x4C42545F /* Sign of IME Table */
  21. #if 0 // move to imeblink.c!
  22. #define UNICODE_CP 1200
  23. #define BIG5_CP 950
  24. #define ALT_BIG5_CP 938
  25. #define GB2312_CP 936
  26. typedef struct _tagCOUNTRYSETTING {
  27. UINT uCodePage;
  28. LPCTSTR szCodePage;
  29. } COUNTRYSETTING;
  30. static const COUNTRYSETTING sCountry[] = {
  31. {
  32. BIG5_CP, TEXT("BIG5")
  33. }
  34. , {
  35. ALT_BIG5_CP, TEXT("BIG5")
  36. }
  37. #if defined(UNICODE)
  38. , {
  39. UNICODE_CP, TEXT("UNICODE")
  40. }
  41. #endif
  42. , {
  43. GB2312_CP, TEXT("GB2312")
  44. }
  45. };
  46. #endif // move to imeblink.c!
  47. #ifdef _DEBUG
  48. #undef THIS_FILE
  49. static char BASED_CODE THIS_FILE[] = __FILE__;
  50. #endif
  51. /****************************************/
  52. /* */
  53. /* Constructor */
  54. /* */
  55. /****************************************/
  56. CBLinkDlg::CBLinkDlg( CWnd *pParent)
  57. : CDialog( CBLinkDlg::IDD, pParent)
  58. {
  59. //{{AFX_DATA_INIT(CBLinkDlg)
  60. //}}AFX_DATA_INIT
  61. }
  62. /****************************************/
  63. /* */
  64. /* MESSAGE "WM_INITDIALOG" */
  65. /* */
  66. /****************************************/
  67. BOOL
  68. CBLinkDlg::OnInitDialog()
  69. {
  70. CString DlgTtl;
  71. CDialog::OnInitDialog();
  72. // Increment contexthelp mark "?" in dialog caption.
  73. // LONG WindowStyle = GetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE);
  74. // WindowStyle |= WS_EX_CONTEXTHELP;
  75. // SetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE, WindowStyle);
  76. // Set dialog title name.
  77. DlgTtl.LoadString( IDS_BATCHLNK_DLGTITLE);
  78. this->SetWindowText( DlgTtl);
  79. return TRUE;
  80. }
  81. /****************************************/
  82. /* */
  83. /* COMMAND "BROWSE" */
  84. /* */
  85. /****************************************/
  86. void
  87. CBLinkDlg::OnBrowsetable()
  88. {
  89. OPENFILENAME ofn;
  90. CString DlgTtl, DlgMsg;
  91. CString sFilter;
  92. TCHAR chReplace;
  93. TCHAR szFilter[64];
  94. TCHAR szFileName[MAX_PATH];
  95. TCHAR szDirName[MAX_PATH];
  96. TCHAR szTitleName[MAX_PATH];
  97. HRESULT hresult;
  98. // Check size of IME batch table structure
  99. if( sizeof( USRDICIMHDR) != 256){
  100. OutputMessageBox( this->GetSafeHwnd(),
  101. IDS_INTERNAL_TITLE,
  102. IDS_INTERNAL_MSG, TRUE);
  103. return;
  104. }
  105. // Set filter of file( from string table)
  106. GetStringRes(szFilter, IDS_BATCHIME_FILTER, ARRAYLEN(szFilter));
  107. int StringLength = lstrlen( szFilter);
  108. chReplace = szFilter[StringLength-1];
  109. for( int i = 0; szFilter[i]; i++){
  110. if( szFilter[i] == chReplace)
  111. szFilter[i] = '\0';
  112. }
  113. GetSystemWindowsDirectory( szDirName, sizeof(szDirName)/sizeof(TCHAR));
  114. //*STRSAFE* lstrcpy( szFileName, TEXT("*.TBL"));
  115. hresult = StringCchCopy(szFileName , ARRAYLEN(szFileName), TEXT("*.TBL"));
  116. if (!SUCCEEDED(hresult))
  117. {
  118. return ;
  119. }
  120. DlgTtl.LoadString( IDS_BROWSETABLE_DLGTITLE);
  121. // Set data in structure of OPENFILENAME
  122. ofn.lStructSize = sizeof( OPENFILENAME);
  123. ofn.hwndOwner = this->GetSafeHwnd();
  124. ofn.lpstrFilter = szFilter;
  125. ofn.lpstrCustomFilter = NULL;
  126. ofn.nMaxCustFilter = 0;
  127. ofn.nFilterIndex = 0;
  128. ofn.lpstrFileTitle = szTitleName;
  129. ofn.nMaxFileTitle = sizeof( szTitleName) / sizeof(TCHAR);
  130. ofn.lpstrFile = szFileName;
  131. ofn.nMaxFile = sizeof( szFileName) / sizeof(TCHAR);
  132. ofn.lpstrInitialDir = szDirName;
  133. ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR
  134. | OFN_CREATEPROMPT | OFN_PATHMUSTEXIST;
  135. ofn.lpstrDefExt = NULL;
  136. ofn.lpstrTitle = DlgTtl;
  137. if( !GetOpenFileName( &ofn))
  138. return;
  139. this->SetDlgItemText( IDC_IMETABLE, ofn.lpstrFile);
  140. CWnd *cWnd = GetDlgItem( IDOK);
  141. GotoDlgCtrl( cWnd);
  142. }
  143. /****************************************/
  144. /* */
  145. /* COMMAND "IDOK" */
  146. /* */
  147. /****************************************/
  148. void
  149. CBLinkDlg::OnOK()
  150. {
  151. if( !RegistStringTable())
  152. return;
  153. CDialog::OnOK();
  154. }
  155. /****************************************/
  156. /* */
  157. /* Register reading string */
  158. /* */
  159. /****************************************/
  160. BOOL
  161. CBLinkDlg::RegistStringTable()
  162. {
  163. LPUSRDICIMHDR lpIsvUsrDic;
  164. HANDLE hIsvUsrDicFile, hIsvUsrDic;
  165. DWORD dwSize, dwFileSize;
  166. BOOL stFunc;
  167. TCHAR szTableFile[MAX_PATH];
  168. TCHAR szFileName[MAX_PATH];
  169. CString DlgMsg, DlgTtl;
  170. HRESULT hresult;
  171. this->GetDlgItemText( IDC_IMETABLE, szTableFile, sizeof( szTableFile)/sizeof(TCHAR));
  172. //*STRSAFE* lstrcpy( szFileName, TEXT("*.TBL"));
  173. hresult = StringCchCopy(szFileName , ARRAYLEN(szFileName), TEXT("*.TBL"));
  174. if (!SUCCEEDED(hresult))
  175. {
  176. return FALSE;
  177. }
  178. // Create file( to read)
  179. hIsvUsrDicFile = CreateFile( szTableFile, GENERIC_READ, 0, NULL,
  180. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  181. if( hIsvUsrDicFile == INVALID_HANDLE_VALUE){
  182. DlgTtl.LoadString( IDS_NOTOPEN_TITLE);
  183. DlgMsg.LoadString( IDS_NOTOPEN_MSG);
  184. this->MessageBox( DlgMsg, DlgTtl, MB_OK | MB_ICONHAND |
  185. MB_TASKMODAL | MB_TOPMOST);
  186. return FALSE;
  187. }
  188. #if 0
  189. for( i = 0; i < sizeof( szFileName); i++){
  190. if( szFileName[i] == '\\'){
  191. szFileName[i] = ' ';
  192. }
  193. }
  194. #endif
  195. // Create file mapping( read only)
  196. hIsvUsrDic = CreateFileMapping((HANDLE)hIsvUsrDicFile, NULL,
  197. PAGE_READONLY, 0, 0, NULL);
  198. if( !hIsvUsrDic){
  199. stFunc = FALSE;
  200. DlgTtl.LoadString( IDS_NOTOPEN_TITLE);
  201. DlgMsg.LoadString( IDS_NOTOPEN_MSG);
  202. this->MessageBox( DlgMsg, DlgTtl, MB_OK | MB_ICONHAND |
  203. MB_TASKMODAL | MB_TOPMOST);
  204. goto BatchCloseUsrDicFile;
  205. }
  206. // Set view file
  207. lpIsvUsrDic = (LPUSRDICIMHDR)MapViewOfFile( hIsvUsrDic,
  208. FILE_MAP_READ, 0, 0, 0);
  209. if( !lpIsvUsrDic){
  210. stFunc = FALSE;
  211. DlgTtl.LoadString( IDS_NOTOPEN_TITLE);
  212. DlgMsg.LoadString( IDS_NOTOPEN_MSG);
  213. this->MessageBox( DlgMsg, DlgTtl, MB_OK | MB_ICONHAND |
  214. MB_TASKMODAL | MB_TOPMOST);
  215. goto BatchCloseUsrDic;
  216. }
  217. dwSize = lpIsvUsrDic->ulTableCount * ( sizeof(WORD) + sizeof(WORD)
  218. + lpIsvUsrDic->cMethodKeySize) + 256;
  219. dwFileSize = GetFileSize( hIsvUsrDicFile, (LPDWORD)NULL);
  220. #if 0
  221. dwSize = dwFileSize;
  222. #endif
  223. // Check table file data
  224. if( dwSize != dwFileSize){
  225. stFunc = FALSE;
  226. OutputMessageBox( this->GetSafeHwnd(),
  227. IDS_FILESIZE_MSGTITLE,
  228. IDS_FILESIZE_MSG, TRUE);
  229. }else if( lpIsvUsrDic->uHeaderSize != 256){
  230. stFunc = FALSE;
  231. OutputMessageBox( this->GetSafeHwnd(),
  232. IDS_FILEHEADER_MSGTITLE,
  233. IDS_FILEHEADER_MSG, TRUE);
  234. }else if( lpIsvUsrDic->uInfoSize != 13){
  235. stFunc = FALSE;
  236. OutputMessageBox( this->GetSafeHwnd(),
  237. IDS_INMETHOD_MSGTITLE,
  238. IDS_INMETHOD_MSG, TRUE);
  239. }else if( CodePageInfo( lpIsvUsrDic->idCP) == -1){
  240. stFunc = FALSE;
  241. OutputMessageBox( this->GetSafeHwnd(),
  242. IDS_CODEPAGE_MSGTITLE,
  243. IDS_CODEPAGE_MSG, TRUE);
  244. }else if( *(DWORD UNALIGNED *)lpIsvUsrDic->idUserCharInfoSign != SIGN_CWIN){
  245. stFunc = FALSE;
  246. OutputMessageBox( this->GetSafeHwnd(),
  247. IDS_SIGN_MSGTITLE,
  248. IDS_SIGN_MSG, TRUE);
  249. }else if( *(DWORD UNALIGNED *)((LPBYTE)lpIsvUsrDic->idUserCharInfoSign +
  250. sizeof(DWORD)) != SIGN__TBL){
  251. stFunc = FALSE;
  252. OutputMessageBox( this->GetSafeHwnd(),
  253. IDS_SIGN_MSGTITLE,
  254. IDS_SIGN_MSG, TRUE);
  255. }else{
  256. stFunc = TRUE;
  257. if( !RegisterTable( this->GetSafeHwnd(),
  258. lpIsvUsrDic, dwFileSize, lpIsvUsrDic->idCP)){
  259. OutputMessageBox( this->GetSafeHwnd(),
  260. IDS_UNMATCHED_TITLE,
  261. IDS_UNMATCHED_MSG, TRUE);
  262. stFunc = FALSE;
  263. }
  264. }
  265. UnmapViewOfFile( lpIsvUsrDic);
  266. BatchCloseUsrDic:
  267. CloseHandle( hIsvUsrDic);
  268. BatchCloseUsrDicFile:
  269. CloseHandle( hIsvUsrDicFile);
  270. return stFunc;
  271. }
  272. static DWORD aIds[] =
  273. {
  274. IDC_STATICIMETBL, IDH_EUDC_BLINK_EDITTBL,
  275. IDC_IMETABLE, IDH_EUDC_BLINK_EDITTBL,
  276. IDC_BROWSETABLE, IDH_EUDC_BROWSE,
  277. 0, 0
  278. };
  279. /****************************************/
  280. /* */
  281. /* Window Procedure */
  282. /* */
  283. /****************************************/
  284. LRESULT
  285. CBLinkDlg::WindowProc(
  286. UINT message,
  287. WPARAM wParam,
  288. LPARAM lParam)
  289. {/*
  290. if( message == WM_HELP){
  291. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  292. HelpPath, HELP_WM_HELP, (DWORD_PTR)(LPDWORD)aIds);
  293. return(0);
  294. }
  295. if( message == WM_CONTEXTMENU){
  296. ::WinHelp((HWND)wParam, HelpPath,
  297. HELP_CONTEXTMENU, (DWORD_PTR)(LPDWORD)aIds);
  298. return(0);
  299. }
  300. */
  301. return CDialog::WindowProc(message, wParam, lParam);
  302. }
  303. BEGIN_MESSAGE_MAP(CBLinkDlg, CDialog)
  304. //{{AFX_MSG_MAP(CBLinkDlg)
  305. ON_BN_CLICKED(IDC_BROWSETABLE, OnBrowsetable)
  306. //}}AFX_MSG_MAP
  307. END_MESSAGE_MAP()