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.

555 lines
15 KiB

  1. /********************************************************/
  2. /* */
  3. /* */
  4. /* EUDC EDITOR ( Windows 95) */
  5. /* */
  6. /* * Japanese Version */
  7. /* * Korea Version */
  8. /* * Chinese Version */
  9. /* */
  10. /* */
  11. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  12. /********************************************************/
  13. #include "stdafx.h"
  14. #include <afxpriv.h>
  15. #include "eudcedit.h"
  16. #include "mainfrm.h"
  17. #include "registry.h"
  18. #include "util.h"
  19. #include "assocdlg.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24. BEGIN_MESSAGE_MAP(CEudcApp, CWinApp)
  25. //{{AFX_MSG_MAP(CEudcApp)
  26. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  27. //}}AFX_MSG_MAP
  28. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  29. END_MESSAGE_MAP()
  30. /* Global parameter */
  31. INT CAPTION_HEIGHT; // height of caption
  32. INT BITMAP_WIDTH; // width of bitmap
  33. INT BITMAP_HEIGHT; // height of bitmap
  34. TCHAR HelpPath[MAX_PATH]; // help file path
  35. TCHAR ChmHelpPath[MAX_PATH]; // help file path for HtmlHelp
  36. TCHAR FontPath[MAX_PATH]; // font file path
  37. DWORD COLOR_GRID; // grid color
  38. DWORD COLOR_FITTING; // bitmap color on show outline
  39. DWORD COLOR_CURVE; // color of outline
  40. DWORD COLOR_FACE; // Win95 3D Face SystemColor
  41. DWORD COLOR_HLIGHT; // Win95 3D HighLight System Color
  42. DWORD COLOR_SHADOW; // Win95 3D Shadow SystemColor
  43. DWORD COLOR_WIN; // Win95 Window System Color
  44. CString NotMemTtl;
  45. CString NotMemMsg;
  46. HCURSOR ToolCursor[NUMTOOL]; // cursor for tool
  47. HCURSOR ArrowCursor[NUMRESIZE]; // cursor for resize
  48. COUNTRYINFO CountryInfo; // country information structure
  49. /* Global function */
  50. extern BOOL SetCountryInfo( UINT LocalCP);
  51. BOOL g_bKeepEUDCLink = TRUE;
  52. extern "C" BOOL AnyLinkedFonts();
  53. CEudcApp NEAR theApp;
  54. /************************************************/
  55. /* */
  56. /* Default Constructor */
  57. /* */
  58. /************************************************/
  59. CEudcApp::CEudcApp()
  60. {
  61. }
  62. /************************************************/
  63. /* */
  64. /* Initialize Instance */
  65. /* */
  66. /************************************************/
  67. BOOL
  68. CEudcApp::InitInstance()
  69. {
  70. CString MainWndTitle;
  71. CRect MainWndRect;
  72. UINT MaxWndFlag;
  73. // Check whether EUDC editor can open or not
  74. if( !CheckPrevInstance())
  75. return FALSE;
  76. //
  77. // Cicero and Cicero TIP currently does not support EUDC mode.
  78. // Use IMM32's IMEs on eudcedit.exe.
  79. //
  80. DisableCUAS();
  81. /*------------------------------------------------
  82. * check if it's Administrator
  83. *------------------------------------------------*/
  84. TCHAR winpath[MAX_PATH];
  85. HANDLE nfh;
  86. GetSystemWindowsDirectory( winpath, MAX_PATH);
  87. #ifdef IN_FONTS_DIR // CAssocDlg::OnOK()
  88. lstrcat( winpath, TEXT("\\FONTS\\"));
  89. #else
  90. lstrcat( winpath, TEXT("\\"));
  91. #endif // IN_FONTS_DIR
  92. lstrcat(winpath, _T("eudcadm.tte"));
  93. nfh = CreateFile(winpath,
  94. GENERIC_WRITE,
  95. FILE_SHARE_DELETE,
  96. NULL,
  97. CREATE_ALWAYS,
  98. FILE_ATTRIBUTE_NORMAL,
  99. NULL);
  100. if ( nfh == INVALID_HANDLE_VALUE)
  101. {
  102. HINSTANCE hInst = AfxGetInstanceHandle();
  103. TCHAR szMessage[256];
  104. LoadString(hInst, IDS_ACCESSDENIED, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  105. AfxMessageBox(szMessage, MB_OK, 0);
  106. return FALSE;
  107. }
  108. else
  109. {
  110. CloseHandle(nfh);
  111. DeleteFile(winpath);
  112. }
  113. // Set background color for dialog
  114. COLOR_FACE = ::GetSysColor( COLOR_3DFACE);
  115. COLOR_HLIGHT = ::GetSysColor( COLOR_3DHILIGHT);
  116. COLOR_SHADOW = ::GetSysColor( COLOR_3DSHADOW);
  117. COLOR_WIN = ::GetSysColor( COLOR_WINDOW);
  118. // SetDialogBkColor( COLOR_FACE);
  119. // Set 3d controls
  120. Enable3dControls();
  121. // Create registry subkey
  122. if( !CreateRegistrySubkey())
  123. return FALSE;
  124. // Open "EUDCEDIT.INI", read data
  125. if( !GetProfileText( &MainWndRect, &MaxWndFlag))
  126. return FALSE;
  127. // Get Language ID with GetSystemDefaultLCID()
  128. // Get area of EUDC from registry and WideCharToMultiByte().
  129. if( !GetCountryInfo())
  130. return FALSE;
  131. #if WINVER >= 0x0500
  132. // Remember original font link status before we do anything
  133. //pliu g_bKeepEUDCLink = AnyLinkedFonts();
  134. #endif
  135. // Get Cursor from resource
  136. if( !GetCursorRes())
  137. return FALSE;
  138. // Get font and help file path
  139. if( !GetFilePath())
  140. return FALSE;
  141. // Create MDI mainFrame window
  142. MainWndTitle.LoadString( IDS_MAINFRAMETITLE);
  143. CMainFrame* pMainFrame = new CMainFrame;
  144. if (!pMainFrame->Create( MainWndTitle,
  145. WS_OVERLAPPEDWINDOW , MainWndRect,
  146. MAKEINTRESOURCE( IDR_MAINFRAME))){
  147. return FALSE;
  148. }
  149. pMainFrame->ShowWindow( m_nCmdShow);
  150. if( MaxWndFlag){
  151. pMainFrame->ShowWindow( SW_SHOWMAXIMIZED);
  152. }
  153. pMainFrame->UpdateWindow();
  154. m_pMainWnd = pMainFrame;
  155. CAssocDlg dlg(m_pMainWnd);
  156. if (!dlg.InitSystemFontAssoc())
  157. {
  158. return FALSE;
  159. }
  160. pMainFrame->m_wndGuideBar.PositionStatusPane();
  161. pMainFrame->SendMessage(WM_COMMAND, ID_READ_CHAR, NULL);
  162. return TRUE;
  163. }
  164. BOOL
  165. CEudcApp::ExitInstance()
  166. {
  167. if (!g_bKeepEUDCLink && CountryInfo.bOnlyUnicode)
  168. {
  169. // The code is to fix the related bug #421829 & #438677
  170. // It delays 1 second to call EnabelEUDC(FALSE).
  171. DWORD dwStart = GetTickCount();
  172. // Stop if this has taken too long
  173. while (1)
  174. {
  175. if( GetTickCount() - dwStart >= 1000 )
  176. break;
  177. }
  178. EnableEUDC(FALSE);
  179. TCHAR szDefaultFace[LF_FACESIZE];
  180. TCHAR szFontPath[MAX_PATH];
  181. TCHAR *Ptr;
  182. GetStringRes(szDefaultFace, IDS_SYSTEMEUDCFONT_STR);
  183. if (InqTypeFace(szDefaultFace, szFontPath,MAX_PATH))
  184. {
  185. //
  186. // delete file eudc.tte
  187. //
  188. DeleteFile(szFontPath);
  189. if(( Ptr = Mytcsrchr( szFontPath, '.')) != NULL)
  190. {
  191. *Ptr = '\0';
  192. lstrcat( szFontPath, TEXT(".EUF"));
  193. //
  194. // delete file eudc.euf
  195. //
  196. DeleteFile(szFontPath);
  197. }
  198. }
  199. DeleteRegistrySubkey();
  200. EnableEUDC(TRUE);
  201. }
  202. return CWinApp::ExitInstance();
  203. }
  204. /************************************************/
  205. /* */
  206. /* Check whether editor can open or not */
  207. /* */
  208. /************************************************/
  209. BOOL
  210. CEudcApp::CheckPrevInstance()
  211. {
  212. HWND hWnd;
  213. TCHAR TitleBuf[50];
  214. GetStringRes(TitleBuf, IDS_MAINFRAMETITLE);
  215. // Search previous eudcedit mainframe.
  216. hWnd = ::FindWindow( NULL, TitleBuf);
  217. if( hWnd == NULL)
  218. return TRUE;
  219. else ::SetForegroundWindow( hWnd);
  220. return FALSE;
  221. }
  222. /************************************************/
  223. /* */
  224. /* disable CUAS */
  225. /* */
  226. /************************************************/
  227. void
  228. CEudcApp::DisableCUAS()
  229. {
  230. typedef BOOL (*PFNIMMDISABLETEXTFRAMESERVICE)(DWORD);
  231. PFNIMMDISABLETEXTFRAMESERVICE pfn;
  232. HMODULE hMod = LoadLibrary(TEXT("imm32.dll"));
  233. if (hMod)
  234. {
  235. pfn = (PFNIMMDISABLETEXTFRAMESERVICE)GetProcAddress(hMod,
  236. "ImmDisableTextFrameService");
  237. if (pfn)
  238. pfn(-1);
  239. }
  240. }
  241. /************************************************/
  242. /* */
  243. /* Correspond to waitting for Input */
  244. /* */
  245. /************************************************/
  246. BOOL
  247. CEudcApp::OnIdle(
  248. LONG lCount)
  249. {
  250. CWnd *pWnd;
  251. if( !lCount){
  252. for( pWnd = m_pMainWnd->GetWindow( GW_HWNDFIRST); pWnd != NULL;
  253. pWnd = pWnd->GetNextWindow( GW_HWNDNEXT)){
  254. if( m_pMainWnd == pWnd->GetParent()){
  255. if( pWnd == m_pMainWnd->GetActiveWindow() &&
  256. ( ::GetCapture() == NULL))
  257. m_pMainWnd->SetActiveWindow();
  258. pWnd->SendMessage( WM_IDLEUPDATECMDUI,
  259. (WPARAM)TRUE, 0L);
  260. }
  261. }
  262. }
  263. return CWinApp::OnIdle( lCount);
  264. }
  265. /************************************************/
  266. /* */
  267. /* Open "EUDCEDIT.INI" */
  268. /* Set parameter of EUDC Editor */
  269. /* */
  270. /************************************************/
  271. BOOL
  272. CEudcApp::GetProfileText(
  273. LPRECT MainWndRect,
  274. UINT *MaxWndFlag)
  275. {
  276. TCHAR ProfileBuf[MAX_PATH], *pString;
  277. TCHAR Separation[] = TEXT(" ,");
  278. INT xScreen , yScreen;
  279. UINT BitmapSiz;
  280. BYTE Rcolor, Gcolor, Bcolor;
  281. CString GridColor, CurvColor, FittColor, MainWnd;
  282. // Get system metrics
  283. CAPTION_HEIGHT = ::GetSystemMetrics( SM_CYCAPTION);
  284. xScreen = ::GetSystemMetrics( SM_CXSCREEN);
  285. yScreen = ::GetSystemMetrics( SM_CYSCREEN);
  286. // Read bitmapsize and maxflag
  287. BitmapSiz = this->GetProfileInt(TEXT("Bitmap"), TEXT("BitmapSize"), DEF_BITMAPSIZE);
  288. if( BitmapSiz <= 0)
  289. BitmapSiz = DEF_BITMAPSIZE;
  290. if( BitmapSiz > MAX_BITMAPSIZE)
  291. BitmapSiz = DEF_BITMAPSIZE;
  292. BitmapSiz = ((BitmapSiz + sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
  293. if( BitmapSiz > MAX_BITMAPSIZE)
  294. BitmapSiz = MAX_BITMAPSIZE;
  295. if( BitmapSiz < MIN_BITMAPSIZE)
  296. BitmapSiz = MIN_BITMAPSIZE;
  297. BITMAP_WIDTH = BitmapSiz;
  298. BITMAP_HEIGHT = BitmapSiz;
  299. *MaxWndFlag = this->GetProfileInt(TEXT("WindowSize"), TEXT("MinMaxFlag"), 0);
  300. // Read color
  301. GridColor = this->GetProfileString(TEXT("Color"), TEXT("Grid"), TEXT("128 128 128"));
  302. CurvColor = this->GetProfileString(TEXT("Color"), TEXT("Curve"), TEXT("255 0 0"));
  303. FittColor = this->GetProfileString(TEXT("Color"), TEXT("Fitting"), TEXT("128 128 128"));
  304. // Read grid color
  305. ConvStringRes((TCHAR *)ProfileBuf, GridColor);
  306. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  307. Rcolor = 0;
  308. else Rcolor = (BYTE)Myttoi( pString);
  309. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  310. Gcolor = 0;
  311. else Gcolor = (BYTE)Myttoi( pString);
  312. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  313. Bcolor = 0;
  314. else Bcolor = (BYTE)Myttoi( pString);
  315. COLOR_GRID = RGB( Rcolor, Gcolor, Bcolor);
  316. // Read outline color
  317. ConvStringRes(ProfileBuf, CurvColor);
  318. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  319. Rcolor = 0;
  320. else Rcolor = (BYTE)Myttoi( pString);
  321. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  322. Gcolor = 0;
  323. else Gcolor = (BYTE)Myttoi( pString);
  324. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  325. Bcolor = 0;
  326. else Bcolor = (BYTE)Myttoi( pString);
  327. COLOR_CURVE = RGB( Rcolor, Gcolor, Bcolor);
  328. // Read bitmap color in show outline
  329. ConvStringRes(ProfileBuf, FittColor);
  330. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  331. Rcolor = 0;
  332. else Rcolor = (BYTE)Myttoi( pString);
  333. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  334. Gcolor = 0;
  335. else Gcolor = (BYTE)Myttoi( pString);
  336. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  337. Bcolor = 0;
  338. else Bcolor = (BYTE)Myttoi( pString);
  339. COLOR_FITTING = RGB( Rcolor, Gcolor, Bcolor);
  340. // Read main window size
  341. MainWnd = this->GetProfileString(TEXT("WindowSize"),TEXT("MainWindowSize"), TEXT(""));
  342. if( *MainWnd == '\0'){
  343. MainWndRect->left = 0;
  344. MainWndRect->top = 0;
  345. MainWndRect->right = (xScreen/5)*4;
  346. MainWndRect->bottom =(yScreen/5)*4;
  347. }else{
  348. ConvStringRes(ProfileBuf, MainWnd);
  349. pString = Mytcstok( ProfileBuf, Separation);
  350. MainWndRect->left = Myttoi( pString);
  351. pString = Mytcstok( NULL, Separation);
  352. MainWndRect->top = Myttoi( pString);
  353. pString = Mytcstok( NULL, Separation);
  354. MainWndRect->right = Myttoi( pString);
  355. pString = Mytcstok( NULL, Separation);
  356. MainWndRect->bottom = Myttoi( pString);
  357. }
  358. return TRUE;
  359. }
  360. /************************************************/
  361. /* */
  362. /* Get country information */
  363. /* */
  364. /************************************************/
  365. BOOL
  366. CEudcApp::GetCountryInfo()
  367. {
  368. UINT LocalCP;
  369. CountryInfo.CurrentRange = 0;
  370. CountryInfo.LangID = (int)GetSystemDefaultLCID();
  371. LocalCP = GetACP();
  372. CountryInfo.bUnicodeMode = FALSE;
  373. CountryInfo.bOnlyUnicode = FALSE;
  374. switch( CountryInfo.LangID){
  375. case EUDC_JPN:
  376. CountryInfo.CharacterSet = SHIFTJIS_CHARSET;
  377. break;
  378. case EUDC_HKG:
  379. CountryInfo.LangID = EUDC_CHT;
  380. //
  381. // fall through
  382. //
  383. case EUDC_CHT:
  384. CountryInfo.CharacterSet = CHINESEBIG5_CHARSET;
  385. break;
  386. case EUDC_KRW:
  387. CountryInfo.CharacterSet = HANGEUL_CHARSET;
  388. break;
  389. case EUDC_SIN:
  390. CountryInfo.LangID = EUDC_CHS;
  391. //
  392. // Fall through
  393. //
  394. case EUDC_CHS:
  395. CountryInfo.CharacterSet = GB2312_CHARSET;
  396. break;
  397. default:
  398. CHARSETINFO csi;
  399. if (TranslateCharsetInfo((DWORD*)IntToPtr(LocalCP), &csi, TCI_SRCCODEPAGE))
  400. CountryInfo.CharacterSet = csi.ciCharset;
  401. CountryInfo.bOnlyUnicode = TRUE;
  402. CountryInfo.bUnicodeMode = TRUE;
  403. lstrcpy(CountryInfo.szForceFont, _T("Microsoft Sans Serif"));
  404. break;
  405. }
  406. if( !SetCountryInfo( LocalCP))
  407. return FALSE;
  408. else return TRUE;
  409. }
  410. /************************************************/
  411. /* */
  412. /* Get Cursor resource file */
  413. /* */
  414. /************************************************/
  415. BOOL
  416. CEudcApp::GetCursorRes()
  417. {
  418. int i;
  419. // For tool cursor
  420. ToolCursor[PEN] = this->LoadCursor(IDC_PENCIL);
  421. ToolCursor[BRUSH] = this->LoadCursor(IDC_BRUSH);
  422. ToolCursor[CIRCLE] = this->LoadStandardCursor(IDC_CROSS);
  423. ToolCursor[CIRCLEFILL] = this->LoadStandardCursor(IDC_CROSS);
  424. ToolCursor[SLOPE] = this->LoadStandardCursor(IDC_CROSS);
  425. ToolCursor[RECTBAND] = this->LoadStandardCursor(IDC_CROSS);
  426. ToolCursor[RECTFILL] = this->LoadStandardCursor(IDC_CROSS);
  427. ToolCursor[FREEFORM] = this->LoadStandardCursor(IDC_CROSS);
  428. ToolCursor[RECTCLIP] = this->LoadStandardCursor(IDC_CROSS);
  429. ToolCursor[ERASER] = this->LoadCursor(IDC_ERASER);
  430. for( i = PEN; i <= ERASER; i++){
  431. if( ToolCursor[i] == NULL){
  432. return FALSE;
  433. }
  434. }
  435. // For select rectangle cursur
  436. ArrowCursor[VERTICAL] = this->LoadStandardCursor(
  437. MAKEINTRESOURCE(IDC_SIZEWE));
  438. ArrowCursor[RIGHTSLOPE]= this->LoadStandardCursor(
  439. MAKEINTRESOURCE(IDC_SIZENESW));
  440. ArrowCursor[LEFTSLOPE] = this->LoadStandardCursor(
  441. MAKEINTRESOURCE(IDC_SIZENWSE));
  442. ArrowCursor[HORIZONTAL]= this->LoadStandardCursor(
  443. MAKEINTRESOURCE(IDC_SIZENS));
  444. ArrowCursor[ALLDIRECT] = this->LoadStandardCursor(
  445. MAKEINTRESOURCE(IDC_SIZEALL));
  446. for( i = VERTICAL; i <= ALLDIRECT; i++){
  447. if( ArrowCursor[i] == NULL){
  448. return FALSE;
  449. }
  450. }
  451. return TRUE;
  452. }
  453. /************************************************/
  454. /* */
  455. /* Get help file path */
  456. /* */
  457. /************************************************/
  458. BOOL
  459. CEudcApp::GetFilePath()
  460. {
  461. if( !GetSystemWindowsDirectory( FontPath, MAX_PATH))
  462. return FALSE;
  463. lstrcat(FontPath, TEXT("\\"));
  464. lstrcpy(HelpPath, FontPath);
  465. lstrcpy(ChmHelpPath, FontPath);
  466. lstrcat(HelpPath, TEXT("Help\\EUDCEDIT.HLP"));
  467. lstrcat(ChmHelpPath, TEXT("Help\\EUDCEDIT.CHM"));
  468. NotMemTtl.LoadString( IDS_MAINFRAMETITLE);
  469. NotMemMsg.LoadString( IDS_NOTENOUGHMEMORY_ERROR);
  470. return TRUE;
  471. }
  472. /************************************************/
  473. /* */
  474. /* COMMAND "About" */
  475. /* */
  476. /************************************************/
  477. void
  478. CEudcApp::OnAppAbout()
  479. {
  480. HICON hIcon;
  481. TCHAR TitleBuf[50];
  482. hIcon = LoadIcon( IDR_MAINFRAME);
  483. GetStringRes((TCHAR *)TitleBuf, IDS_MAINFRAMETITLE);
  484. ShellAbout( m_pMainWnd->GetSafeHwnd(), TitleBuf, TEXT(""), hIcon);
  485. }