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.

343 lines
9.1 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* Convert from bmp to ttf */
  5. /* (Dialogbox) */
  6. /* */
  7. /* */
  8. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  9. /**************************************************/
  10. #include "stdafx.h"
  11. #include "eudcedit.h"
  12. #include "imprtdlg.h"
  13. #include "ttfstruc.h"
  14. #include "extfunc.h"
  15. #include "util.h"
  16. #define STRSAFE_LIB
  17. #include <strsafe.h>
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. TCHAR UserFont[MAX_PATH];
  23. TCHAR EUDCTTF[MAX_PATH];
  24. TCHAR EUDCBMP[MAX_PATH];
  25. /****************************************/
  26. /* */
  27. /* Default Constructor */
  28. /* */
  29. /****************************************/
  30. CImportDlg::CImportDlg( CWnd* pParent)
  31. : CDialog(CImportDlg::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(CImportDlg)
  34. //}}AFX_DATA_INIT
  35. }
  36. /****************************************/
  37. /* */
  38. /* MESSAGE "WM_INITDIALOG" */
  39. /* */
  40. /****************************************/
  41. BOOL
  42. CImportDlg::OnInitDialog()
  43. {
  44. CString DlgTitle;
  45. CDialog::OnInitDialog();
  46. // Implement "?" in this dialogbox.
  47. // LONG WindowStyle = GetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE);
  48. // WindowStyle |= WS_EX_CONTEXTHELP;
  49. // SetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE, WindowStyle);
  50. // Set dialog title name.
  51. DlgTitle.LoadString( IDS_IMPORT_DLGTITLE);
  52. this->SetWindowText( DlgTitle);
  53. return TRUE;
  54. }
  55. /****************************************/
  56. /* */
  57. /* COMMAND "BROWSE" */
  58. /* */
  59. /****************************************/
  60. void
  61. CImportDlg::OnFileBrowse()
  62. {
  63. OPENFILENAME ofn;
  64. CString DlgTtl, DlgMsg;
  65. CString sFilter;
  66. CWnd *cWnd;
  67. TCHAR chReplace;
  68. TCHAR szFilter[MAX_PATH];
  69. TCHAR szFileName[MAX_PATH];
  70. TCHAR szTitleName[MAX_PATH];
  71. TCHAR szDirName[MAX_PATH];
  72. HRESULT hresult;
  73. if( CountryInfo.LangID == EUDC_JPN){
  74. // Set filter of file( from string table)
  75. GetStringRes(szFilter, IDS_IMPORT_JAPAN_FILTER, ARRAYLEN(szFilter));
  76. int StringLength = lstrlen( szFilter);
  77. chReplace = szFilter[StringLength-1];
  78. for( int i = 0; szFilter[i]; i++){
  79. if( szFilter[i] == chReplace)
  80. szFilter[i] = '\0';
  81. }
  82. GetSystemWindowsDirectory( szDirName, sizeof(szDirName)/sizeof(TCHAR));
  83. //*STRSAFE* lstrcpy( szFileName, TEXT("USERFONT.FON"));
  84. hresult = StringCchCopy(szFileName , ARRAYLEN(szFileName), TEXT("USERFONT.FON"));
  85. if (!SUCCEEDED(hresult))
  86. {
  87. return ;
  88. }
  89. DlgTtl.LoadString( IDS_BROWSEUSER_DLGTITLE);
  90. // Set data in structure of OPENFILENAME
  91. ofn.lStructSize = sizeof( OPENFILENAME);
  92. ofn.hInstance = AfxGetInstanceHandle();
  93. ofn.hwndOwner = this->GetSafeHwnd();
  94. ofn.lpstrFilter = szFilter;
  95. ofn.lpstrCustomFilter = NULL;
  96. ofn.nMaxCustFilter = 0;
  97. ofn.nFilterIndex = 0;
  98. ofn.lpstrFile = szFileName;
  99. ofn.lpstrFileTitle = szTitleName;
  100. ofn.nMaxFileTitle = sizeof( szTitleName) / sizeof(TCHAR);
  101. ofn.nMaxFile = sizeof( szFileName) / sizeof(TCHAR);
  102. ofn.lpstrInitialDir = szDirName;
  103. ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR
  104. | OFN_PATHMUSTEXIST;
  105. ofn.lpstrDefExt = NULL;
  106. ofn.lpstrTitle = DlgTtl;
  107. if( !GetOpenFileName( &ofn)){
  108. return;
  109. }
  110. memcpy( UserFont, ofn.lpstrFile, sizeof( UserFont));
  111. this->SetDlgItemText( IDC_BMP_IMPUT, ofn.lpstrFile);
  112. #ifdef BUILD_ON_WINNT
  113. if( OExistUserFont( UserFont) != 1){
  114. OutputMessageBoxEx( this->GetSafeHwnd(),
  115. IDS_IMPORT_DLGTITLE,
  116. AFX_IDP_FAILED_INVALID_PATH, TRUE, UserFont);
  117. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  118. GotoDlgCtrl( cWnd);
  119. return;
  120. }
  121. #endif // BUILD_ON_WINNT
  122. if( isW31JEUDCBMP( UserFont) != 1){
  123. OutputMessageBox( this->GetSafeHwnd(),
  124. IDS_IMPORT_DLGTITLE,
  125. IDS_NOTUSERFONT_MSG, TRUE);
  126. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  127. GotoDlgCtrl( cWnd);
  128. return;
  129. }
  130. cWnd = GetDlgItem( IDOK);
  131. GotoDlgCtrl( cWnd);
  132. }else if( CountryInfo.LangID == EUDC_CHT ||
  133. CountryInfo.LangID == EUDC_CHS ){
  134. // Set filter of file( from string table)
  135. GetStringRes(szFilter, IDS_IMPORT_CHINA_FILTER, ARRAYLEN(szFilter));
  136. int StringLength = lstrlen( szFilter);
  137. chReplace = szFilter[StringLength-1];
  138. for( int i = 0; szFilter[i]; i++){
  139. if( szFilter[i] == chReplace)
  140. szFilter[i] = '\0';
  141. }
  142. GetSystemWindowsDirectory( szDirName, sizeof(szDirName)/sizeof(TCHAR));
  143. //*STRSAFE* lstrcpy( szFileName, TEXT("*.*"));
  144. hresult = StringCchCopy(szFileName , ARRAYLEN(szFileName), TEXT("*.*"));
  145. if (!SUCCEEDED(hresult))
  146. {
  147. return ;
  148. }
  149. DlgTtl.LoadString( IDS_BROWSEUSER_DLGTITLE);
  150. // Set data in structure of OPENFILENAME
  151. ofn.lStructSize = sizeof( OPENFILENAME);
  152. ofn.hwndOwner = this->GetSafeHwnd();
  153. ofn.hInstance = AfxGetInstanceHandle();
  154. ofn.lpstrFilter = szFilter;
  155. ofn.lpstrCustomFilter = NULL;
  156. ofn.nMaxCustFilter = 0;
  157. ofn.nFilterIndex = 0;
  158. ofn.lpstrFileTitle = szTitleName;
  159. ofn.nMaxFileTitle = sizeof( szTitleName) / sizeof(TCHAR);
  160. ofn.lpstrFile = szFileName;
  161. ofn.nMaxFile = sizeof( szFileName) / sizeof(TCHAR);
  162. ofn.lpstrInitialDir = szDirName;
  163. ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR
  164. | OFN_PATHMUSTEXIST;
  165. ofn.lpstrDefExt = NULL;
  166. ofn.lpstrTitle = DlgTtl;
  167. if( !GetOpenFileName( &ofn))
  168. return;
  169. memcpy( UserFont, ofn.lpstrFile, sizeof( UserFont));
  170. this->SetDlgItemText( IDC_BMP_IMPUT, ofn.lpstrFile);
  171. #ifdef BUILD_ON_WINNT
  172. if( OExistUserFont( UserFont) != 1){
  173. OutputMessageBoxEx( this->GetSafeHwnd(),
  174. IDS_IMPORT_DLGTITLE,
  175. AFX_IDP_FAILED_INVALID_PATH, TRUE, UserFont);
  176. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  177. GotoDlgCtrl( cWnd);
  178. return;
  179. }
  180. #endif // BUILD_ON_WINNT
  181. if( isETENBMP( UserFont) != 1){
  182. OutputMessageBox( this->GetSafeHwnd(),
  183. IDS_IMPORT_DLGTITLE,
  184. IDS_NOTUSERFONT_MSG, TRUE);
  185. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  186. GotoDlgCtrl( cWnd);
  187. return;
  188. }
  189. cWnd = GetDlgItem( IDOK);
  190. GotoDlgCtrl( cWnd);
  191. }
  192. }
  193. /****************************************/
  194. /* */
  195. /* COMMAND "IDOK" */
  196. /* */
  197. /****************************************/
  198. void
  199. CImportDlg::OnOK()
  200. {
  201. TCHAR *FilePtr;
  202. CWnd *cWnd;
  203. HRESULT hresult;
  204. //*STRSAFE* lstrcpy(EUDCTTF,SelectEUDC.m_File);
  205. hresult = StringCchCopy(EUDCTTF , ARRAYLEN(EUDCTTF), SelectEUDC.m_File);
  206. if (!SUCCEEDED(hresult))
  207. {
  208. goto RET ;
  209. }
  210. //*STRSAFE* lstrcpy( EUDCBMP, EUDCTTF);
  211. hresult = StringCchCopy(EUDCBMP , ARRAYLEN(EUDCBMP), EUDCTTF);
  212. if (!SUCCEEDED(hresult))
  213. {
  214. goto RET ;
  215. }
  216. if(( FilePtr = Mytcsrchr( EUDCBMP, '.')) != NULL)
  217. *FilePtr = '\0';
  218. //*STRSAFE* lstrcat( EUDCBMP, TEXT(".EUF"));
  219. hresult = StringCchCat(EUDCBMP , ARRAYLEN(EUDCBMP), TEXT(".EUF"));
  220. if (!SUCCEEDED(hresult))
  221. {
  222. goto RET ;
  223. }
  224. if( !this->GetDlgItemText(IDC_BMP_IMPUT, UserFont, MAX_PATH)){
  225. OutputMessageBox( this->GetSafeHwnd(),
  226. IDS_IMPORT_DLGTITLE,
  227. IDS_NOTUSERFONT_MSG, TRUE);
  228. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  229. GotoDlgCtrl( cWnd);
  230. return;
  231. }
  232. if( CountryInfo.LangID == EUDC_JPN){
  233. #ifdef BUILD_ON_WINNT
  234. if( OExistUserFont( UserFont) != 1){
  235. OutputMessageBoxEx( this->GetSafeHwnd(),
  236. IDS_IMPORT_DLGTITLE,
  237. AFX_IDP_FAILED_INVALID_PATH, TRUE, UserFont);
  238. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  239. GotoDlgCtrl( cWnd);
  240. return;
  241. }
  242. #endif // BUILD_ON_WINNT
  243. if( isW31JEUDCBMP( UserFont) != 1){
  244. OutputMessageBox( this->GetSafeHwnd(),
  245. IDS_IMPORT_DLGTITLE,
  246. IDS_NOTUSERFONT_MSG, TRUE);
  247. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  248. GotoDlgCtrl( cWnd);
  249. return;
  250. }
  251. }else{
  252. #ifdef BUILD_ON_WINNT
  253. if( OExistUserFont( UserFont) != 1){
  254. OutputMessageBoxEx( this->GetSafeHwnd(),
  255. IDS_IMPORT_DLGTITLE,
  256. AFX_IDP_FAILED_INVALID_PATH, TRUE, UserFont);
  257. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  258. GotoDlgCtrl( cWnd);
  259. return;
  260. }
  261. #endif // BUILD_ON_WINNT
  262. if( isETENBMP( UserFont) != 1){
  263. OutputMessageBox( this->GetSafeHwnd(),
  264. IDS_IMPORT_DLGTITLE,
  265. IDS_NOTUSERFONT_MSG, TRUE);
  266. cWnd = this->GetDlgItem( IDC_BMP_IMPUT);
  267. GotoDlgCtrl( cWnd);
  268. return;
  269. }
  270. }
  271. RET:
  272. EndDialog(IDOK);
  273. }
  274. static DWORD aIds[] =
  275. {
  276. IDC_STATICBMP, IDH_EUDC_IMPOBMP,
  277. IDC_BMP_IMPUT, IDH_EUDC_IMPOBMP,
  278. IDC_FILE_BROWSE, IDH_EUDC_BROWSE,
  279. 0,0
  280. };
  281. /****************************************/
  282. /* */
  283. /* Window procedure */
  284. /* */
  285. /****************************************/
  286. LRESULT
  287. CImportDlg::WindowProc(
  288. UINT message,
  289. WPARAM wParam,
  290. LPARAM lParam)
  291. {/*
  292. if( message == WM_HELP){
  293. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  294. HelpPath, HELP_WM_HELP, (DWORD_PTR)(LPTSTR)aIds);
  295. return(0);
  296. }
  297. if( message == WM_CONTEXTMENU){
  298. ::WinHelp((HWND)wParam, HelpPath,
  299. HELP_CONTEXTMENU, (DWORD_PTR)(LPTSTR)aIds);
  300. return(0);
  301. }
  302. */
  303. return CDialog::WindowProc(message, wParam, lParam);
  304. }
  305. BEGIN_MESSAGE_MAP(CImportDlg, CDialog)
  306. //{{AFX_MSG_MAP(CImportDlg)
  307. ON_BN_CLICKED(IDC_FILE_BROWSE, OnFileBrowse)
  308. //}}AFX_MSG_MAP
  309. END_MESSAGE_MAP()