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.

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