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.

344 lines
9.3 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* SelectCode... EUDC Editor Dialog */
  5. /* */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include "stdafx.h"
  10. #include "eudcedit.h"
  11. #include "eudcdlg.h"
  12. #include "registry.h"
  13. #include "util.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18. typedef struct _tagRegistDef{
  19. TCHAR RegFont[LF_FACESIZE];
  20. TCHAR RegFile[MAX_PATH];
  21. BOOL RegFlg;
  22. } REGISTDEF;
  23. static REGISTDEF RegistDef;
  24. BEGIN_MESSAGE_MAP(CEudcDlg, CDialog)
  25. //{{AFX_MSG_MAP(CEudcDlg)
  26. ON_CBN_SELCHANGE(IDC_CHINARANGE, OnSelchangeChinarange)
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. /****************************************/
  30. /* */
  31. /* Constructor */
  32. /* */
  33. /****************************************/
  34. CEudcDlg::CEudcDlg( CWnd* pParent)
  35. : CDialog(CEudcDlg::IDD, pParent)
  36. {
  37. //{{AFX_DATA_INIT(CEudcDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. /****************************************/
  41. /* */
  42. /* MESSAGE "WM_INITDIALOG" */
  43. /* */
  44. /****************************************/
  45. BOOL
  46. CEudcDlg::OnInitDialog()
  47. {
  48. LOGFONT LogFont;
  49. CString DialogTitle;
  50. TCHAR SBuf[5], EBuf[5], CodeBuf[15];
  51. TCHAR SysFace[LF_FACESIZE];
  52. long WindowStyle;
  53. CDialog::OnInitDialog();
  54. WindowStyle = GetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE);
  55. WindowStyle |= WS_EX_CONTEXTHELP;
  56. SetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE, WindowStyle);
  57. m_EditList.SubclassDlgItem( IDC_CUSTOMEDIT, this);
  58. m_ViewChar.SubclassDlgItem( IDC_CUSTOMCHR, this);
  59. #ifdef BUILD_ON_WINNT
  60. m_ColumnHeading.SubclassDlgItem( IDC_COLUMNHEADING, this);
  61. #endif //BUILD_ON_WINNT
  62. m_Frame.SubclassDlgItem( IDC_CUSTOMFRAME, this);
  63. m_ListFrame.SubclassDlgItem( IDC_CUSTOMLISTFRAME, this);
  64. m_InfoFrame2.SubclassDlgItem( IDC_CUSTOMFRAME2, this);
  65. m_InfoFrame3.SubclassDlgItem( IDC_CUSTOMFRAME3, this);
  66. m_StaticRange.SubclassDlgItem( IDC_STATICRANGE, this);
  67. m_ComboRange.SubclassDlgItem( IDC_CHINARANGE, this);
  68. if( CountryInfo.LangID != EUDC_KRW || CountryInfo.bUnicodeMode){
  69. m_EditList.EnableScrollBar( SB_VERT, ESB_ENABLE_BOTH);
  70. }else m_EditList.ShowScrollBar( SB_VERT, FALSE);
  71. AdjustFileName();
  72. AdjustFontName();
  73. this->SetDlgItemText( IDC_SETFONTNAME, FontName);
  74. this->SetDlgItemText( IDC_SETFILENAME, FileName);
  75. if( WorRFlag)
  76. DialogTitle.LoadString( IDS_REGISTAS_DLGTITLE);
  77. else DialogTitle.LoadString( IDS_SELECTCODE_DLGTITLE);
  78. this->SetWindowText( DialogTitle);
  79. m_EditList.cRange = CountryInfo.CurrentRange;
  80. if( CountryInfo.nRange > 2 && !CountryInfo.bUnicodeMode){
  81. m_StaticRange.ShowWindow( SW_SHOWNORMAL);
  82. m_ComboRange.ShowWindow( SW_SHOWNORMAL);
  83. m_StaticRange.UpdateWindow();
  84. m_ComboRange.UpdateWindow();
  85. for( int i = 0; i < CountryInfo.nRange-1; i++){
  86. wsprintf( SBuf, TEXT("%X"), CountryInfo.sRange[i]);
  87. wsprintf( EBuf, TEXT("%X"), CountryInfo.eRange[i]);
  88. lstrcpy( CodeBuf, SBuf);
  89. lstrcat( CodeBuf, TEXT(" - "));
  90. lstrcat( CodeBuf, EBuf);
  91. m_ComboRange.InsertString( i, CodeBuf);
  92. }
  93. m_ComboRange.DeleteString( CountryInfo.nRange-1);
  94. m_ComboRange.SetCurSel( CountryInfo.CurrentRange);
  95. }
  96. // Set font for output character code
  97. GetFont()->GetObject( sizeof( LOGFONT), &LogFont);
  98. m_EditList.SysFFont.CreateFontIndirect( &LogFont);
  99. m_EditList.CalcCharSize();
  100. #ifdef BUILD_ON_WINNT
  101. // Set font for the column heading
  102. m_ColumnHeading.SysFFont.CreateFontIndirect( &LogFont);
  103. #endif //BUILD_ON_WINNT
  104. // Set font for output character
  105. memset( &LogFont, 0, sizeof( LogFont));
  106. if( m_EditList.CharSize.cx >= m_EditList.CharSize.cy)
  107. LogFont.lfHeight = m_EditList.CharSize.cy-2;
  108. else LogFont.lfHeight = m_EditList.CharSize.cx-2;
  109. LogFont.lfCharSet = (BYTE)CountryInfo.CharacterSet;
  110. GetStringRes((TCHAR *)SysFace, IDS_SYSTEMEUDCFONT_STR);
  111. if( !lstrcmp(SelectEUDC.m_Font, (const TCHAR *)SysFace) )
  112. {
  113. lstrcpy (LogFont.lfFaceName, TEXT("System"));
  114. }else{
  115. lstrcpy( LogFont.lfFaceName, SelectEUDC.m_Font);
  116. }
  117. if( !m_EditList.EUDCFont.CreateFontIndirect( &LogFont))
  118. return FALSE;
  119. //fix for 261529
  120. if( !m_ViewChar.EUDCFont.CreateFontIndirect( &LogFont))
  121. return FALSE;
  122. return TRUE;
  123. }
  124. /****************************************/
  125. /* Deal with "OK" */
  126. /****************************************/
  127. void CEudcDlg::OnOK()
  128. {
  129. if( !m_EditList.SelectCode){
  130. if( WorRFlag){
  131. OutputMessageBox( this->GetSafeHwnd(),
  132. IDS_REGISTAS_DLGTITLE,
  133. IDS_NOTSELCHARACTER_MSG, TRUE);
  134. }else{
  135. OutputMessageBox( this->GetSafeHwnd(),
  136. IDS_SELECTCODE_DLGTITLE,
  137. IDS_NOTSELCHARACTER_MSG, TRUE);
  138. }
  139. return;
  140. }
  141. RegistRegFont();
  142. EndDialog(IDOK);
  143. }
  144. void CEudcDlg::OnCancel()
  145. {
  146. RegistRegFont();
  147. CDialog::OnCancel();
  148. }
  149. /****************************************/
  150. /* Take off ".TTF" from filename */
  151. /****************************************/
  152. void CEudcDlg::AdjustFileName()
  153. {
  154. TCHAR *FilePtr;
  155. lstrcpy(FileName, SelectEUDC.m_FileTitle);
  156. if(( FilePtr = Mytcsrchr( FileName, '.')) != NULL)
  157. *FilePtr = '\0';
  158. #ifdef BUILD_ON_WINNT
  159. /*
  160. * Trim the string more better way...
  161. */
  162. CClientDC dc(this);
  163. CRect ViewFileRect;
  164. CSize FileNameSize;
  165. CWnd *cWnd = GetDlgItem( IDC_SETFILENAME);
  166. INT MaxChars;
  167. INT cchString = lstrlen(FileName);
  168. cWnd->GetClientRect( &ViewFileRect);
  169. GetTextExtentExPoint( dc.GetSafeHdc(), FileName,
  170. cchString, ViewFileRect.Width(), &MaxChars, NULL ,&FileNameSize);
  171. if( cchString > MaxChars) {
  172. INT Chars = 0;
  173. FilePtr = FileName;
  174. while (Chars < (MaxChars-3)) {
  175. FilePtr++; Chars++;
  176. }
  177. for (; Chars < MaxChars; Chars++) {
  178. FileName[Chars] = TEXT('.');
  179. }
  180. FileName[Chars] = TEXT('\0');
  181. }
  182. #else
  183. if( strlen((const char *)FileName) > 11){
  184. FileName[11] = '.';
  185. FileName[12] = '.';
  186. FileName[13] = '\0';
  187. }
  188. #endif // BUILD_ON_WINNT
  189. return;
  190. }
  191. /****************************************/
  192. /* Adjust EUDC Font name */
  193. /****************************************/
  194. void CEudcDlg::AdjustFontName()
  195. {
  196. CClientDC dc(this);
  197. CRect ViewFontRect;
  198. CSize FontNameSize, CharSize;
  199. int i;
  200. lstrcpy(FontName, SelectEUDC.m_Font);
  201. CWnd *cWnd = GetDlgItem( IDC_SETFONTNAME);
  202. cWnd->GetClientRect( &ViewFontRect);
  203. GetTextExtentPoint32( dc.GetSafeHdc(), FontName,
  204. lstrlen(FontName), &FontNameSize);
  205. if( ViewFontRect.Width() <= FontNameSize.cx){
  206. GetTextExtentPoint32( dc.GetSafeHdc(), TEXT("<<"), 2, &CharSize);
  207. i = ( ViewFontRect.Width() /CharSize.cx) * 2;
  208. FontName[i-2] = '.';
  209. FontName[i-1] = '.';
  210. FontName[i] = '\0';
  211. }
  212. }
  213. /****************************************/
  214. /* Change EUDC code range(CHINESE) */
  215. /****************************************/
  216. void CEudcDlg::OnSelchangeChinarange()
  217. {
  218. int nIndex = m_ComboRange.GetCurSel();
  219. m_EditList.cRange = nIndex;
  220. m_EditList.SetEUDCCodeRange( nIndex);
  221. this->SetDlgItemText( IDC_CUSTOMCHR, TEXT(""));
  222. this->SetDlgItemText( IDC_CODECUST, TEXT(""));
  223. m_EditList.Invalidate();
  224. m_EditList.UpdateWindow();
  225. CWnd *cWnd = this->GetDlgItem( IDC_CUSTOMEDIT);
  226. this->GotoDlgCtrl( cWnd);
  227. }
  228. void CEudcDlg::RegistRegFont()
  229. {
  230. if( RegistDef.RegFlg){
  231. // The code is to fix the related bug #421829 & #438677
  232. // It delays 1 second to call EnabelEUDC(FALSE).
  233. DWORD dwStart = GetTickCount();
  234. // Stop if this has taken too long
  235. while (1)
  236. {
  237. if( GetTickCount() - dwStart >= 1000 )
  238. break;
  239. }
  240. EnableEUDC(FALSE);
  241. RegistTypeFace( RegistDef.RegFont, RegistDef.RegFile);
  242. EnableEUDC(TRUE);
  243. }
  244. }
  245. static DWORD aIds[] =
  246. {
  247. IDC_CUSTOMEDIT, IDH_EUDC_SELLIST,
  248. IDC_COLUMNHEADING, IDH_EUDC_SELLIST,
  249. IDC_CODECUST, IDH_EUDC_SELCODE,
  250. IDC_CODE_NAME, IDH_EUDC_SELCODE,
  251. IDC_CUSTOMFRAME, IDH_EUDC_SELCODE,
  252. IDC_SETFONTNAME,IDH_EUDC_SELFONT,
  253. IDC_FONT_NAME, IDH_EUDC_SELFONT,
  254. IDC_CUSTOMFRAME3, IDH_EUDC_SELFONT,
  255. IDC_SETFILENAME,IDH_EUDC_SELFILE,
  256. IDC_FILE_NAME, IDH_EUDC_SELFILE,
  257. IDC_CUSTOMFRAME2, IDH_EUDC_SELFILE,
  258. IDC_CUSTOMCHR, IDH_EUDC_SELCHAR,
  259. IDC_STATICRANGE, IDH_EUDC_SELRANGE,
  260. IDC_CHINARANGE, IDH_EUDC_SELRANGE,
  261. 0,0
  262. };
  263. static DWORD aIdsReg[] =
  264. {
  265. IDC_CUSTOMEDIT, IDH_EUDC_REGLIST,
  266. IDC_COLUMNHEADING, IDH_EUDC_REGLIST,
  267. IDC_CODECUST, IDH_EUDC_REGCODE,
  268. IDC_CODE_NAME, IDH_EUDC_REGCODE,
  269. IDC_CUSTOMFRAME, IDH_EUDC_REGCODE,
  270. IDC_SETFONTNAME,IDH_EUDC_REGFONT,
  271. IDC_FONT_NAME, IDH_EUDC_REGFONT,
  272. IDC_CUSTOMFRAME3, IDH_EUDC_REGFONT,
  273. IDC_SETFILENAME,IDH_EUDC_REGFILE,
  274. IDC_FILE_NAME, IDH_EUDC_REGFILE,
  275. IDC_CUSTOMFRAME2, IDH_EUDC_REGFILE,
  276. IDC_CUSTOMCHR, IDH_EUDC_REGCHAR,
  277. IDC_STATICRANGE, IDH_EUDC_REGRANGE,
  278. IDC_CHINARANGE, IDH_EUDC_REGRANGE,
  279. 0,0
  280. };
  281. /****************************************/
  282. /* Customdlg Window Procedure */
  283. /****************************************/
  284. LRESULT CEudcDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  285. {
  286. if( message == WM_VIEWUPDATE){
  287. m_ViewChar.Invalidate( FALSE);
  288. m_ViewChar.UpdateWindow();
  289. return(0);
  290. }
  291. if( message == WM_HELP){
  292. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  293. HelpPath, HELP_WM_HELP, (DWORD_PTR)(LPTSTR)(WorRFlag ? aIdsReg : aIds));
  294. return(0);
  295. }
  296. if( message == WM_CONTEXTMENU){
  297. ::WinHelp((HWND)wParam, HelpPath,
  298. HELP_CONTEXTMENU, (DWORD_PTR)(LPTSTR) (WorRFlag ? aIdsReg : aIds));
  299. return(0);
  300. }
  301. return CDialog::WindowProc( message, wParam, lParam);
  302. }