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.

936 lines
25 KiB

  1. // NewProject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "minidev.h"
  5. #include "codepage.h"
  6. #include <wingdi.h>
  7. #include <winddi.h>
  8. #include <prntfont.h>
  9. #include <uni16res.h>
  10. #include "gtt.h"
  11. #include "nconvert.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CConvPfmDlg property page
  19. IMPLEMENT_DYNCREATE(CConvPfmDlg, CPropertyPage)
  20. CConvPfmDlg::CConvPfmDlg() : CPropertyPage(CConvPfmDlg::IDD)
  21. {
  22. //{{AFX_DATA_INIT(CConvPfmDlg)
  23. m_csGttPath = _T("");
  24. m_csPfmPath = _T("");
  25. m_csUfmDir = _T("");
  26. //}}AFX_DATA_INIT
  27. }
  28. CConvPfmDlg::~CConvPfmDlg()
  29. {
  30. }
  31. void CConvPfmDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CPropertyPage::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CConvPfmDlg)
  35. DDX_Control(pDX, IDC_ComboCodePage, m_ccbCodepages);
  36. DDX_Text(pDX, IDC_GttPath, m_csGttPath);
  37. DDX_Text(pDX, IDC_PfmFiles, m_csPfmPath);
  38. DDX_Text(pDX, IDC_UfmDir, m_csUfmDir);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CConvPfmDlg, CPropertyPage)
  42. //{{AFX_MSG_MAP(CConvPfmDlg)
  43. ON_BN_CLICKED(IDC_GTTBrowser, OnGTTBrowser)
  44. ON_BN_CLICKED(IDC_PFMBrowser, OnPFMBrowsers)
  45. ON_CBN_SELCHANGE(IDC_ComboCodePage, OnSelchangeComboCodePage)
  46. ON_BN_CLICKED(IDC_UfmDirBrowser, OnUfmDirBrowser)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CConvPfmDlg message handlers
  51. BOOL CConvPfmDlg::OnWizardFinish()
  52. {
  53. CString csErr ;
  54. if( ConvPFMToUFM() ) {
  55. csErr.Format(IDS_NewUFM,m_csUfmDir) ;
  56. AfxMessageBox(csErr,MB_ICONINFORMATION) ;
  57. }
  58. else
  59. {
  60. csErr.LoadString(IDS_NewUFMError);
  61. AfxMessageBox(csErr,MB_ICONEXCLAMATION) ;
  62. }
  63. return CPropertyPage::OnWizardFinish();
  64. }
  65. LRESULT CConvPfmDlg::OnWizardBack()
  66. {
  67. // restore the parent propertysheet dialog.
  68. EndDialog(IDD_ConvertPFM) ;
  69. return CPropertyPage::OnWizardBack();
  70. }
  71. BOOL CConvPfmDlg::OnSetActive()
  72. {
  73. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  74. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_DISABLEDFINISH) ;
  75. ((CPropertySheet*)GetParent())->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE) ;
  76. CCodePageInformation ccpi ;
  77. unsigned unumcps = ccpi.InstalledCount() ;
  78. // Get the installed code page numbers and load them into the code page
  79. // list box.
  80. DWORD dwcp, dwdefcp ;
  81. dwdefcp = GetACP() ;
  82. TCHAR accp[32] ;
  83. int n ; ;
  84. for (unsigned u = 0 ; u < unumcps ; u++) {
  85. dwcp = ccpi.Installed(u) ;
  86. // There are 3 code pages that seem to make MultiByteToWideChar() to
  87. // fail. Don't let the user choose one of those code pages unless
  88. // he knows the secret password (ie, undocument command line switch
  89. // 'CP').
  90. if (ThisApp().m_bExcludeBadCodePages)
  91. if (dwcp == 1361 || dwcp == 28595 || dwcp == 28597)
  92. continue ;
  93. wsprintf(accp, "%5d", dwcp) ;
  94. n = m_ccbCodepages.AddString(accp) ;
  95. if (dwcp == 1252) // change dwdefcp to 1252 due to not support DBCS.
  96. m_ccbCodepages.SetCurSel(n) ;
  97. } ;
  98. return CPropertyPage::OnSetActive();
  99. }
  100. void CConvPfmDlg::OnGTTBrowser()
  101. {
  102. UpdateData() ;
  103. CString csFilter = _T("GTT File(*.gtt)|*.gtt||") ;
  104. CString csExtension = _T(".GTT") ;
  105. CFileDialog cfd(TRUE, csExtension, NULL,
  106. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST ,csFilter);
  107. if (cfd.DoModal() == IDOK) {
  108. m_csGttPath = cfd.GetPathName() ;
  109. UpdateData(FALSE) ;
  110. } ;
  111. }
  112. void CConvPfmDlg::OnPFMBrowsers()
  113. {
  114. UpdateData() ;
  115. CString csFilter( _T("PFM Files (*.pfm)|*.pfm||") ) ;
  116. CFileDialog cfd(TRUE, _T(".ctt"), NULL,
  117. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT, csFilter,
  118. this);
  119. cfd.m_ofn.lpstrFile = new char[4096];
  120. memset(cfd.m_ofn.lpstrFile,0,4096);
  121. cfd.m_ofn.nMaxFile = 4096;
  122. if (cfd.DoModal() != IDOK) {
  123. delete cfd.m_ofn.lpstrFile ;
  124. return;
  125. }
  126. // save the file path to member string array
  127. for (POSITION pos = cfd.GetStartPosition(); pos; ) {
  128. m_csaPfmFiles.Add(cfd.GetNextPathName(pos)) ;
  129. }
  130. m_csPfmPath = m_csaPfmFiles[0] ;
  131. // GTT directory is same with the CTT directory as default.
  132. m_csUfmDir = m_csPfmPath.Left(m_csPfmPath.ReverseFind(_T('\\') ) );
  133. SetCurrentDirectory(m_csUfmDir) ;
  134. UpdateData(FALSE) ;
  135. if(m_csPfmPath.GetLength() )
  136. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH) ;
  137. }
  138. /**************************************************************************************
  139. bool CConvPfmDlg::OnUfmDirBrowser()
  140. Do ; just directory browser
  141. Args
  142. Ret.
  143. ***************************************************************************************/
  144. void CConvPfmDlg::OnUfmDirBrowser()
  145. {
  146. OPENFILENAME ofn ; // Used to send/get info to/from common dlg
  147. char acpath[_MAX_PATH] ; // Path is saved here (or an error message)
  148. // char acidir[_MAX_PATH] ; // Initial directory is built here
  149. BOOL brc = FALSE ; // Return code
  150. // Update the contents of csinitdir
  151. UpdateData(TRUE) ;
  152. // Load the open file name structure
  153. ofn.lStructSize = sizeof(ofn) ;
  154. ofn.hwndOwner = m_hWnd ;
  155. ofn.hInstance = GetModuleHandle(_T("MINIDEV.EXE")) ;
  156. ofn.lpstrFilter = ofn.lpstrCustomFilter = NULL ;
  157. ofn.nMaxCustFilter = ofn.nFilterIndex = 0 ;
  158. strcpy(acpath, _T("JUNK")) ; // No need to localize this string
  159. ofn.lpstrFile = acpath ;
  160. ofn.nMaxFile = _MAX_PATH ;
  161. ofn.lpstrFileTitle = NULL ;
  162. ofn.nMaxFileTitle = 0 ;
  163. ofn.lpstrInitialDir = m_csUfmDir ; // in parent dialog box
  164. ofn.lpstrTitle = NULL ;
  165. ofn.Flags = OFN_HIDEREADONLY /*| OFN_ENABLEHOOK */| OFN_NOCHANGEDIR
  166. | OFN_NOTESTFILECREATE | OFN_ENABLETEMPLATE | OFN_NONETWORKBUTTON ;
  167. ofn.lpstrDefExt = NULL ;
  168. ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEOPENORD) ;
  169. ofn.lpfnHook = NULL ;// BrowseDlgProc ;
  170. // Display the dialog box. If the user cancels, just return.
  171. if (!GetOpenFileName(&ofn))
  172. return ;
  173. // Take the bogus file name off the path and put the path into the page's
  174. // edit box.
  175. acpath[ofn.nFileOffset - 1] = 0 ;
  176. m_csUfmDir = (LPCTSTR) acpath ;
  177. UpdateData(FALSE) ;
  178. }
  179. /**************************************************************************************
  180. bool CConvPfmDlg::OnSelchangeComboCodePage()
  181. Do ;DBCS code page convert does not supported in this version. so we have to show exclamtion
  182. messag to the user when they select DBCS code page; the reason of showing DBCS in the list
  183. although they are not supported is that it cann't less confusing to the user.
  184. Args
  185. Ret.
  186. ***************************************************************************************/
  187. //
  188. void CConvPfmDlg::OnSelchangeComboCodePage()
  189. {
  190. CString csCodepage ;
  191. DWORD dwCodepage ;
  192. m_ccbCodepages.GetLBText(m_ccbCodepages.GetCurSel(),csCodepage) ;
  193. dwCodepage = atoi(csCodepage) ;
  194. if (dwCodepage == 932 || dwCodepage == 936 || dwCodepage == 949 || dwCodepage == 950 ) {
  195. AfxMessageBox(_T("DBCS conversion is not supported in this version"),MB_ICONINFORMATION) ;
  196. DWORD dwacp = GetACP() ;
  197. TCHAR acp[16] ;
  198. wsprintf(acp, "%5d",dwacp) ;
  199. int nI = m_ccbCodepages.FindString(-1,acp ) ;
  200. m_ccbCodepages.SetCurSel(nI ) ;
  201. } ;
  202. } ;
  203. struct sGTTHeader {
  204. DWORD m_dwcbImage;
  205. enum {Version1Point0 = 0x10000};
  206. DWORD m_dwVersion;
  207. DWORD m_dwfControl; // Any flags defined?
  208. long m_lidPredefined;
  209. DWORD m_dwcGlyphs;
  210. DWORD m_dwcRuns;
  211. DWORD m_dwofRuns;
  212. DWORD m_dwcCodePages;
  213. DWORD m_dwofCodePages;
  214. DWORD m_dwofMapTable;
  215. DWORD m_dwReserved[2];
  216. sGTTHeader() {
  217. memset(this, 0, sizeof *this);
  218. m_dwVersion = Version1Point0;
  219. m_lidPredefined = CGlyphMap::NoPredefined;
  220. m_dwcbImage = sizeof *this;
  221. }
  222. };
  223. extern "C" {
  224. BOOL BConvertPFM(LPBYTE lpbPFM, DWORD dwCodePage, LPBYTE lpbGTT,
  225. PWSTR pwstrUnique, LPCTSTR lpstrUFM, int iGTTID);
  226. PUNI_GLYPHSETDATA PGetDefaultGlyphset(
  227. IN HANDLE hHeap,
  228. IN WORD wFirstChar,
  229. IN WORD wLastChar,
  230. IN DWORD dwCodePage) ;
  231. }
  232. /**************************************************************************************
  233. bool CConvPfmDlg::ConvPFMToUFM()
  234. Do ; this is workhorse. untimately, all routine exist for BConvertPFM; correct codepage
  235. inside gtt file, ufm directory, gtt files or resource gtt or default. new UFM files
  236. are created inside BConvertPFM function. just set correct UFM path.
  237. Args .
  238. Ret.
  239. ***************************************************************************************/
  240. bool CConvPfmDlg::ConvPFMToUFM()
  241. {
  242. // Call BConvertPFM for each PFM data with codepage, gtt data if exist,
  243. // ufm file path and name,
  244. CByteArray cbaGTT ;
  245. // loading the GTT
  246. // change the codepage value of GTT(
  247. CString csCodePage ;
  248. DWORD dwCodePage ;
  249. m_ccbCodepages.GetLBText(m_ccbCodepages.GetCurSel(),csCodePage) ;
  250. dwCodePage = atoi(csCodePage) ;
  251. // loading the GTT file when there is gtt file or we have to use resource file or
  252. // default GTT file instead of real GTT file
  253. if (m_csGttPath.GetLength() ) {
  254. try {
  255. CFile cfLoad(m_csGttPath, CFile::modeRead | CFile::shareDenyWrite);
  256. cbaGTT.SetSize(cfLoad.GetLength());
  257. cfLoad.Read(cbaGTT.GetData(), cfLoad.GetLength());
  258. }
  259. catch (CException *pce) {
  260. pce -> ReportError();
  261. pce -> Delete();
  262. cbaGTT.RemoveAll();
  263. return false;
  264. }
  265. }
  266. else
  267. {
  268. short sid = (short)dwCodePage ;
  269. if(MAKEINTRESOURCE((sid < 0) ? -sid : sid) == NULL)
  270. return false ;
  271. HRSRC hrsrc = FindResource(AfxGetResourceHandle(),
  272. MAKEINTRESOURCE((sid < 0) ? -sid : sid),
  273. MAKEINTRESOURCE(IDR_GLYPHMAP));
  274. if (hrsrc) {
  275. HGLOBAL hg = LoadResource(AfxGetResourceHandle(), hrsrc) ;
  276. if (!hg)
  277. return false;
  278. LPVOID lpv = LockResource(hg) ;
  279. if (!lpv)
  280. return false ;
  281. cbaGTT.SetSize(SizeofResource(AfxGetResourceHandle(), hrsrc)) ;
  282. memcpy(cbaGTT.GetData(), lpv, (size_t)cbaGTT.GetSize()) ;
  283. return false ;
  284. } ;
  285. //AfxMessageBox("GTT building code reached.") ;
  286. // If all else fails, try to generate a GTT based on the code page ID
  287. // that should be in m_wID if this point is reached.
  288. HANDLE hheap ;
  289. UNI_GLYPHSETDATA *pGTT ;
  290. if (!(hheap = HeapCreate(HEAP_NO_SERIALIZE, 10 * 1024, 256 * 1024))) {
  291. AfxMessageBox(IDS_HeapInGLoad) ;
  292. return false ;
  293. } ;
  294. pGTT = PGetDefaultGlyphset(hheap, 0x20, 0xff,
  295. (DWORD) sid) ;
  296. if (pGTT == NULL) {
  297. HeapDestroy(hheap) ; //raid 116600 Prefix
  298. AfxMessageBox(IDS_PGetFailedInGLoad) ;
  299. return false ;
  300. } ;
  301. cbaGTT.SetSize(pGTT->dwSize) ;
  302. memcpy(cbaGTT.GetData(), pGTT, (size_t)cbaGTT.GetSize()) ;
  303. HeapDestroy(hheap) ;
  304. }
  305. // Creating the UFM Path
  306. UpdateData() ;
  307. SECURITY_ATTRIBUTES st;
  308. st.nLength = sizeof(SECURITY_ATTRIBUTES);
  309. st.lpSecurityDescriptor = NULL;
  310. st.bInheritHandle = FALSE ;
  311. WIN32_FIND_DATA wfd32 ;
  312. HANDLE hDir = FindFirstFile(m_csUfmDir,&wfd32) ;
  313. if (hDir == INVALID_HANDLE_VALUE) {
  314. if (!CreateDirectory(m_csUfmDir,&st) ) {
  315. CString csmsg ;
  316. csmsg = _T("Fail to create the template directory") ;
  317. AfxMessageBox(csmsg) ;
  318. return false ;
  319. }
  320. } ;
  321. //Set the GTT codepage with selected code page by user
  322. union {
  323. BYTE* pbGTT ;
  324. sGTTHeader* psGTTH ;
  325. } ;
  326. pbGTT = cbaGTT.GetData() ;
  327. if (!pbGTT)
  328. return false ;
  329. PUNI_CODEPAGEINFO pCodepage = (PUNI_CODEPAGEINFO)(pbGTT + psGTTH->m_dwofCodePages );
  330. CopyMemory(&pCodepage->dwCodePage,&dwCodePage,sizeof(DWORD) ) ;
  331. // Convert the PFM to UFM: calling the BConvertPFM for every selected PFM files
  332. CCodePageInformation ccpi ;
  333. for ( int i = 0 ; i < m_csaPfmFiles.GetSize() ; i++ ) {
  334. // loading the PFM
  335. CString csPFMPath = m_csaPfmFiles[i] ;
  336. CByteArray cbaPFM ;
  337. try {
  338. CFile cfLoad(csPFMPath, CFile::modeRead | CFile::shareDenyWrite);
  339. cbaPFM.SetSize(cfLoad.GetLength());
  340. cfLoad.Read(cbaPFM.GetData(), cfLoad.GetLength());
  341. cfLoad.Close() ;
  342. }
  343. catch (CException *pce) {
  344. pce -> ReportError();
  345. pce -> Delete();
  346. cbaPFM.RemoveAll();
  347. return false ;
  348. }
  349. CString csUFMName = csPFMPath.Mid(csPFMPath.ReverseFind(_T('\\') )+1 ) ;
  350. csUFMName = csUFMName.Left(csUFMName.ReverseFind(('.')) ) ;
  351. csUFMName.MakeUpper() ;
  352. CString csUFMPath = m_csUfmDir + _T("\\") + csUFMName + _T(".UFM") ;
  353. // convert ansi unique name to unicode.
  354. CByteArray cbaIn;
  355. CWordArray cwaOut;
  356. cbaIn.SetSize(1 + csUFMName.GetLength());
  357. lstrcpy((LPSTR) cbaIn.GetData(), (LPCTSTR) csUFMName);
  358. ccpi.Convert(cbaIn, cwaOut, GetACP());
  359. // Call the global function BConvertPFM, BConvertPFM creat the UFM file under the
  360. // specified path.
  361. if(!BConvertPFM(cbaPFM.GetData(), dwCodePage, cbaGTT.GetData(),
  362. cwaOut.GetData(), csUFMPath, (short) 0 ) )
  363. return false;
  364. // clear the data field
  365. // cbaPFM.RemoveAll() ;
  366. // cwaOut.RemoveAll() ;
  367. }
  368. return true ;
  369. }
  370. /////////////////////////////////////////////////////////////////////////////
  371. // CConverPFM
  372. IMPLEMENT_DYNAMIC(CConvertPFM, CPropertySheet)
  373. CConvertPFM::CConvertPFM(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  374. :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  375. {
  376. }
  377. CConvertPFM::CConvertPFM(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  378. :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  379. {
  380. AddPage(&m_ccpd) ;
  381. SetWizardMode() ;
  382. }
  383. CConvertPFM::~CConvertPFM()
  384. {
  385. }
  386. BEGIN_MESSAGE_MAP(CConvertPFM, CPropertySheet)
  387. //{{AFX_MSG_MAP(CConverPFM)
  388. // NOTE - the ClassWizard will add and remove mapping macros here.
  389. //}}AFX_MSG_MAP
  390. END_MESSAGE_MAP()
  391. /////////////////////////////////////////////////////////////////////////////
  392. // CConverPFM message handlers
  393. /////////////////////////////////////////////////////////////////////////////
  394. // CConvCttDlg property page
  395. IMPLEMENT_DYNCREATE(CConvCttDlg, CPropertyPage)
  396. CConvCttDlg::CConvCttDlg() : CPropertyPage(CConvCttDlg::IDD)
  397. {
  398. //{{AFX_DATA_INIT(CConvCttDlg)
  399. m_csCttPath = _T("");
  400. m_csGttDir = _T("");
  401. //}}AFX_DATA_INIT
  402. }
  403. CConvCttDlg::~CConvCttDlg()
  404. {
  405. }
  406. void CConvCttDlg::DoDataExchange(CDataExchange* pDX)
  407. {
  408. CPropertyPage::DoDataExchange(pDX);
  409. //{{AFX_DATA_MAP(CConvCttDlg)
  410. DDX_Control(pDX, IDC_COMBO_Codepage, m_ccbCodepages);
  411. DDX_Text(pDX, IDC_EDIT_CTTFile, m_csCttPath);
  412. DDX_Text(pDX, IDC_GttDirectory, m_csGttDir);
  413. //}}AFX_DATA_MAP
  414. }
  415. BEGIN_MESSAGE_MAP(CConvCttDlg, CPropertyPage)
  416. //{{AFX_MSG_MAP(CConvCttDlg)
  417. ON_BN_CLICKED(IDC_CTTBrowser, OnCTTBrowser)
  418. //}}AFX_MSG_MAP
  419. END_MESSAGE_MAP()
  420. /////////////////////////////////////////////////////////////////////////////
  421. // CConvCttDlg message handlers
  422. BOOL CConvCttDlg::OnWizardFinish()
  423. {
  424. CString csErr ;
  425. if(ConvCTTToGTT() ) {
  426. csErr.Format(IDS_NewGTT,m_csGttDir) ;
  427. AfxMessageBox(csErr,MB_ICONINFORMATION) ;
  428. }
  429. else
  430. {
  431. csErr.LoadString(IDS_NewGTTError);
  432. AfxMessageBox(csErr,MB_ICONEXCLAMATION) ;
  433. }
  434. return CPropertyPage::OnWizardFinish();
  435. }
  436. LRESULT CConvCttDlg::OnWizardBack()
  437. {
  438. EndDialog(IDD_ConvertCTT) ;
  439. return CPropertyPage::OnWizardBack();
  440. }
  441. void CConvCttDlg::OnCTTBrowser()
  442. {
  443. UpdateData() ;
  444. CString csFilter( _T("CTT Files (*.ctt)|*.ctt||") ) ;
  445. CFileDialog cfd(TRUE, _T(".ctt"), NULL,
  446. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT, csFilter,
  447. this);
  448. cfd.m_ofn.lpstrFile = new char[4096];
  449. memset(cfd.m_ofn.lpstrFile,0,4096);
  450. cfd.m_ofn.nMaxFile = 4096;
  451. if (cfd.DoModal() != IDOK) {
  452. delete cfd.m_ofn.lpstrFile ;
  453. return;
  454. }
  455. // save the file path to member string array
  456. for (POSITION pos = cfd.GetStartPosition(); pos; ) {
  457. m_csaCttFiles.Add(cfd.GetNextPathName(pos)) ;
  458. }
  459. m_csCttPath = m_csaCttFiles[0] ;
  460. // GTT directory is same with the CTT directory as default.
  461. m_csGttDir = m_csCttPath.Left(m_csCttPath.ReverseFind(_T('\\') ) );
  462. SetCurrentDirectory(m_csGttDir) ;
  463. UpdateData(FALSE) ;
  464. if(m_csCttPath.GetLength() )
  465. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH) ;
  466. }
  467. //DEL BOOL CConvCttDlg::OnInitDialog()
  468. //DEL {
  469. //DEL CPropertyPage::OnInitDialog();
  470. //DEL
  471. //DEL //Fill the list with installed codepage rather than supported code page.
  472. //DEL
  473. //DEL CCodePageInformation ccpi ;
  474. //DEL
  475. //DEL // ccpi.
  476. //DEL
  477. //DEL return TRUE; // return TRUE unless you set the focus to a control
  478. //DEL // EXCEPTION: OCX Property Pages should return FALSE
  479. //DEL }
  480. BOOL CConvCttDlg::OnSetActive()
  481. {
  482. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  483. ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_DISABLEDFINISH) ;
  484. ((CPropertySheet*)GetParent())->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE) ;
  485. CCodePageInformation ccpi ;
  486. unsigned unumcps = ccpi.InstalledCount() ;
  487. // Get the installed code page numbers and load them into the code page
  488. // list box.
  489. DWORD dwcp, dwdefcp ;
  490. dwdefcp = GetACP() ;
  491. TCHAR accp[32] ;
  492. int n ; ;
  493. for (unsigned u = 0 ; u < unumcps ; u++) {
  494. dwcp = ccpi.Installed(u) ;
  495. // There are 3 code pages that seem to make MultiByteToWideChar() to
  496. // fail. Don't let the user choose one of those code pages unless
  497. // he knows the secret password (ie, undocument command line switch
  498. // 'CP').
  499. if (dwcp == 1361 || dwcp == 28595 || dwcp == 28597)
  500. continue ;
  501. wsprintf(accp, "%5d", dwcp) ;
  502. n = m_ccbCodepages.AddString(accp) ;
  503. if (dwcp == 1252) // change dwdefcp to 1252 due to not support DBCS.
  504. m_ccbCodepages.SetCurSel(n) ;
  505. } ;
  506. return CPropertyPage::OnSetActive();
  507. }
  508. extern "C"
  509. BOOL
  510. BConvertCTT2GTT(
  511. IN HANDLE hHeap,
  512. IN PTRANSTAB pCTTData,
  513. IN DWORD dwCodePage,
  514. IN WCHAR wchFirst,
  515. IN WCHAR wchLast,
  516. IN PBYTE pCPSel,
  517. IN PBYTE pCPUnSel,
  518. IN OUT PUNI_GLYPHSETDATA *ppGlyphSetData,
  519. IN DWORD dwGlySize);
  520. extern "C"
  521. PUNI_GLYPHSETDATA
  522. PGetDefaultGlyphset(
  523. IN HANDLE hHeap,
  524. IN WORD wFirstChar,
  525. IN WORD wLastChar,
  526. IN DWORD dwCodePage) ;
  527. bool CConvCttDlg::ConvCTTToGTT()
  528. {
  529. CString csCodePage ;
  530. DWORD dwCodePage ;
  531. m_ccbCodepages.GetLBText(m_ccbCodepages.GetCurSel(),csCodePage) ;
  532. dwCodePage = atoi(csCodePage) ;
  533. // Creating the UFM Path
  534. UpdateData() ;
  535. SECURITY_ATTRIBUTES st;
  536. st.nLength = sizeof(SECURITY_ATTRIBUTES);
  537. st.lpSecurityDescriptor = NULL;
  538. st.bInheritHandle = FALSE ;
  539. WIN32_FIND_DATA wfd32 ;
  540. HANDLE hDir = FindFirstFile(m_csGttDir,&wfd32) ;
  541. if (hDir == INVALID_HANDLE_VALUE) {
  542. if (!CreateDirectory(m_csGttDir,&st) ) {
  543. CString csmsg ;
  544. csmsg = _T("Fail to create the template directory") ;
  545. AfxMessageBox(csmsg) ;
  546. return false ;
  547. }
  548. } ;
  549. for (int i = 0 ; i < m_csaCttFiles.GetSize() ; i ++ ) {
  550. // load the cTT files
  551. CString csCTTPath = m_csaCttFiles[i] ;
  552. CByteArray cbaCTT ;
  553. try {
  554. CFile cfLoad(csCTTPath, CFile::modeRead | CFile::shareDenyWrite);
  555. cbaCTT.SetSize(cfLoad.GetLength());
  556. cfLoad.Read(cbaCTT.GetData(), cfLoad.GetLength());
  557. }
  558. catch (CException *pce) {
  559. pce -> ReportError();
  560. pce -> Delete();
  561. cbaCTT.RemoveAll();
  562. return false ;
  563. }
  564. PBYTE pbCTT = cbaCTT.GetData() ;
  565. HANDLE hheap ;
  566. if( !(hheap = HeapCreate(HEAP_NO_SERIALIZE, 10 * 1024, 256 * 1024 )))
  567. {
  568. CString csErr ;
  569. csErr.Format(IDS_HeapCFailed,csCTTPath) ;
  570. AfxMessageBox(csErr ,MB_ICONEXCLAMATION);
  571. return false ;
  572. }
  573. // call the convert extern function
  574. UNI_GLYPHSETDATA *pGTT = new UNI_GLYPHSETDATA ;
  575. if(NULL == pGTT){
  576. HeapDestroy(hheap);
  577. return false;
  578. }
  579. if (!BConvertCTT2GTT(hheap, (PTRANSTAB)pbCTT, dwCodePage, 0x20, 0xff, NULL,
  580. NULL, &pGTT, 0)){
  581. delete pGTT; // raid fix 692536 prefix
  582. HeapDestroy(hheap); // raid 116619 prefix
  583. return false ;
  584. }
  585. // store the GTT files
  586. CString csGTTName = csCTTPath.Mid(csCTTPath.ReverseFind(_T('\\') )+1 ) ;
  587. csGTTName = csGTTName.Left(csGTTName.ReverseFind(('.')) ) ;
  588. CString csGTTPath = m_csGttDir + _T("\\") + csGTTName + _T(".GTT") ;
  589. csGTTName.MakeUpper() ;
  590. try {
  591. CFile cfGTT;
  592. if (!cfGTT.Open(csGTTPath, CFile::modeCreate | CFile::modeWrite |
  593. CFile::shareExclusive))
  594. return false;
  595. cfGTT.Write(pGTT, pGTT->dwSize);
  596. cfGTT.Close() ;
  597. }
  598. catch (CException *pce) {
  599. pce -> ReportError();
  600. pce -> Delete();
  601. delete pGTT;
  602. HeapDestroy(hheap);
  603. return false ;
  604. }
  605. if (pGTT )
  606. delete pGTT ;
  607. HeapDestroy(hheap);
  608. }
  609. return true ;
  610. }
  611. /////////////////////////////////////////////////////////////////////////////
  612. // CConvertCTT
  613. IMPLEMENT_DYNAMIC(CConvertCTT, CPropertySheet)
  614. CConvertCTT::CConvertCTT(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  615. :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  616. {
  617. }
  618. CConvertCTT::CConvertCTT(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  619. :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  620. {
  621. AddPage(&m_cccd) ;
  622. SetWizardMode() ;
  623. }
  624. CConvertCTT::~CConvertCTT()
  625. {
  626. }
  627. BEGIN_MESSAGE_MAP(CConvertCTT, CPropertySheet)
  628. //{{AFX_MSG_MAP(CConvertCTT)
  629. // NOTE - the ClassWizard will add and remove mapping macros here.
  630. //}}AFX_MSG_MAP
  631. END_MESSAGE_MAP()
  632. /////////////////////////////////////////////////////////////////////////////
  633. // CConvertCTT message handlers
  634. /////////////////////////////////////////////////////////////////////////////
  635. // CNewConvert property page
  636. IMPLEMENT_DYNCREATE(CNewConvert, CPropertyPage)
  637. CNewConvert::CNewConvert() : CPropertyPage(CNewConvert::IDD)
  638. {
  639. //{{AFX_DATA_INIT(CNewConvert)
  640. // NOTE: the ClassWizard will add member initialization here
  641. //}}AFX_DATA_INIT
  642. }
  643. CNewConvert::~CNewConvert()
  644. {
  645. }
  646. void CNewConvert::DoDataExchange(CDataExchange* pDX)
  647. {
  648. CPropertyPage::DoDataExchange(pDX);
  649. //{{AFX_DATA_MAP(CNewConvert)
  650. // NOTE: the ClassWizard will add DDX and DDV calls here
  651. //}}AFX_DATA_MAP
  652. }
  653. BEGIN_MESSAGE_MAP(CNewConvert, CPropertyPage)
  654. //{{AFX_MSG_MAP(CNewConvert)
  655. ON_BN_CLICKED(IDC_CONVERT, OnPrjConvert)
  656. ON_BN_CLICKED(IDC_CONV_PFM, OnPFMConvert)
  657. ON_BN_CLICKED(IDC_CONV_CTT, OnCTTConvert)
  658. //}}AFX_MSG_MAP
  659. END_MESSAGE_MAP()
  660. /////////////////////////////////////////////////////////////////////////////
  661. // CNewConvert message handlers
  662. /*************************************************************************************
  663. void CNewConvert::OnPrjConvert()
  664. Creat Doc-> call Convert Wizard -> Creat frame -> Create View by updatefram
  665. **************************************************************************************/
  666. void CNewConvert::OnPrjConvert()
  667. {
  668. // Invoke the wizard.
  669. m_pcps->ShowWindow(SW_HIDE) ;
  670. CMultiDocTemplate* pcmdt = ThisApp().WorkspaceTemplate() ;
  671. CDocument* pcdWS = pcmdt->CreateNewDocument() ;
  672. if (!pcdWS || !pcdWS -> OnNewDocument()) {
  673. if (pcdWS) {
  674. delete pcdWS;
  675. m_pcps->EndDialog(1) ;
  676. }
  677. return;
  678. }
  679. pcmdt->SetDefaultTitle(pcdWS) ;
  680. CFrameWnd* pcfw = pcmdt->CreateNewFrame(pcdWS,NULL) ;
  681. if (pcfw)
  682. pcmdt->InitialUpdateFrame(pcfw,pcdWS) ;
  683. m_pcps->EndDialog(1) ;
  684. }
  685. /*************************************************************************************
  686. void CNewConvert::OnPFMConvert()
  687. **************************************************************************************/
  688. void CNewConvert::OnPFMConvert()
  689. {
  690. CConvertPFM cnp ( _T("PFM Convert To UFM ") ) ;
  691. m_pcps->ShowWindow(SW_HIDE) ;
  692. INT_PTR ret = cnp.DoModal() ;
  693. if (ret == (INT_PTR)IDD_ConvertPFM )
  694. m_pcps->ShowWindow(SW_RESTORE) ;
  695. else
  696. m_pcps->EndDialog(1) ;
  697. }
  698. /*************************************************************************************
  699. void CNewConvert::OnCTTConvert()
  700. **************************************************************************************/
  701. void CNewConvert::OnCTTConvert()
  702. {
  703. CConvertCTT ccc ( _T("GTT Converter ") ) ;
  704. m_pcps->ShowWindow(SW_HIDE) ;
  705. INT_PTR ret = ccc.DoModal() ;
  706. if (ret == (INT_PTR)IDD_ConvertCTT )
  707. m_pcps->ShowWindow(SW_RESTORE) ;
  708. else
  709. m_pcps->EndDialog(1) ;
  710. }
  711. /***************************************************************************************
  712. BOOL CNewConvert::OnSetActive()
  713. Do.
  714. ****************************************************************************************/
  715. BOOL CNewConvert::OnSetActive()
  716. {
  717. return CPropertyPage::OnSetActive();
  718. }
  719. /***************************************************************************************
  720. BOOL CNewConvert::OnInitDialog()
  721. Do; Getting perent pointer
  722. ****************************************************************************************/
  723. BOOL CNewConvert::OnInitDialog()
  724. {
  725. CPropertyPage::OnInitDialog();
  726. m_pcps = DYNAMIC_DOWNCAST(CPropertySheet,GetOwner() ) ;
  727. return TRUE; // return TRUE unless you set the focus to a control
  728. // EXCEPTION: OCX Property Pages should return FALSE
  729. }