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.

609 lines
14 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dbcs.c
  5. Abstract:
  6. This module contains the code for console DBCS font dialog
  7. Author:
  8. kazum Feb-27-1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #if defined(FE_SB)
  14. SINGLE_LIST_ENTRY gTTFontList; // This list contain TTFONTLIST data.
  15. UINT OEMCP;
  16. BOOL gfFESystem;
  17. WORD
  18. ConvertStringToDec(
  19. LPTSTR lpch,
  20. LPTSTR *endptr
  21. )
  22. {
  23. TCHAR ch;
  24. WORD val = 0;
  25. while ( (ch=*lpch) != TEXT('\0'))
  26. {
  27. if (TEXT('0') <= ch && ch <= TEXT('9'))
  28. val = (val * 10) + (ch - TEXT('0'));
  29. else
  30. break;
  31. lpch++;
  32. }
  33. if (endptr)
  34. *endptr = lpch;
  35. return val;
  36. }
  37. WORD
  38. ConvertStringToHex(
  39. LPTSTR lpch,
  40. LPTSTR *endptr
  41. )
  42. {
  43. TCHAR ch;
  44. WORD val = 0;
  45. while ( (ch=*lpch) != TEXT('\0'))
  46. {
  47. if (TEXT('0') <= ch && ch <= TEXT('9'))
  48. val = (val << 4) + (ch - TEXT('0'));
  49. else if (TEXT('A') <= ch && ch <= TEXT('F'))
  50. val = (val << 4) + (ch - TEXT('A') + 10);
  51. else if (TEXT('a') <= ch && ch <= TEXT('f'))
  52. val = (val << 4) + (ch - TEXT('a') + 10);
  53. else
  54. break;
  55. lpch++;
  56. }
  57. if (endptr)
  58. *endptr = lpch;
  59. return val;
  60. }
  61. NTSTATUS
  62. MakeAltRasterFont(
  63. UINT CodePage,
  64. COORD *AltFontSize,
  65. BYTE *AltFontFamily,
  66. ULONG *AltFontIndex,
  67. LPTSTR AltFaceName
  68. )
  69. {
  70. DWORD i;
  71. DWORD Find;
  72. ULONG FontIndex;
  73. COORD FontSize = FontInfo[DefaultFontIndex].Size;
  74. COORD FontDelta;
  75. BOOL fDbcsCharSet = IS_ANY_DBCS_CHARSET( CodePageToCharSet( CodePage ) );
  76. FontIndex = 0;
  77. Find = (DWORD)-1;
  78. for (i=0; i < NumberOfFonts; i++)
  79. {
  80. if (!TM_IS_TT_FONT(FontInfo[i].Family) &&
  81. IS_ANY_DBCS_CHARSET(FontInfo[i].tmCharSet) == fDbcsCharSet
  82. )
  83. {
  84. FontDelta.X = (SHORT)abs(FontSize.X - FontInfo[i].Size.X);
  85. FontDelta.Y = (SHORT)abs(FontSize.Y - FontInfo[i].Size.Y);
  86. if (Find > (DWORD)(FontDelta.X + FontDelta.Y))
  87. {
  88. Find = (DWORD)(FontDelta.X + FontDelta.Y);
  89. FontIndex = i;
  90. }
  91. }
  92. }
  93. *AltFontIndex = FontIndex;
  94. _tcscpy(AltFaceName, FontInfo[*AltFontIndex].FaceName);
  95. *AltFontSize = FontInfo[*AltFontIndex].Size;
  96. *AltFontFamily = FontInfo[*AltFontIndex].Family;
  97. DBGFONTS(("MakeAltRasterFont : AltFontIndex = %ld\n", *AltFontIndex));
  98. return STATUS_SUCCESS;
  99. }
  100. NTSTATUS
  101. InitializeDbcsMisc(
  102. VOID
  103. )
  104. {
  105. HANDLE hkRegistry = NULL;
  106. NTSTATUS Status;
  107. WCHAR awchValue[ 512 ];
  108. WCHAR awchData[ 512 ];
  109. DWORD dwIndex;
  110. LPWSTR pwsz;
  111. gTTFontList.Next = NULL;
  112. Status = MyRegOpenKey(NULL,
  113. MACHINE_REGISTRY_CONSOLE_TTFONT,
  114. &hkRegistry);
  115. if (!NT_SUCCESS( Status )) {
  116. DBGPRINT(("CONSRV: NtOpenKey failed %ws\n", MACHINE_REGISTRY_CONSOLE));
  117. }
  118. else {
  119. LPTTFONTLIST pTTFontList;
  120. for( dwIndex = 0; ; dwIndex++) {
  121. Status = MyRegEnumValue(hkRegistry,
  122. dwIndex,
  123. sizeof(awchValue), (LPWSTR)&awchValue,
  124. sizeof(awchData), (PBYTE)&awchData);
  125. if (!NT_SUCCESS( Status )) {
  126. break;
  127. }
  128. pTTFontList = LocalAlloc(LPTR, sizeof(TTFONTLIST));
  129. if (pTTFontList == NULL) {
  130. break;
  131. }
  132. pTTFontList->List.Next = NULL;
  133. pTTFontList->CodePage = ConvertStringToDec(awchValue, NULL);
  134. pwsz = awchData;
  135. if (*pwsz == BOLD_MARK) {
  136. pTTFontList->fDisableBold = TRUE;
  137. pwsz++;
  138. }
  139. else
  140. pTTFontList->fDisableBold = FALSE;
  141. _tcscpy(pTTFontList->FaceName1, pwsz);
  142. pwsz += _tcslen(pwsz) + 1;
  143. if (*pwsz == BOLD_MARK) {
  144. pTTFontList->fDisableBold = TRUE;
  145. pwsz++;
  146. }
  147. _tcscpy(pTTFontList->FaceName2, pwsz);
  148. PushEntryList(&gTTFontList, &(pTTFontList->List));
  149. }
  150. NtClose(hkRegistry);
  151. }
  152. ASSERT(OEMCP != 0); // OEMCP must be initialized so far by CPL_INIT
  153. ASSERT(IsFarEastCP(OEMCP) == gfFESystem);
  154. return STATUS_SUCCESS;
  155. }
  156. BYTE
  157. CodePageToCharSet(
  158. UINT CodePage
  159. )
  160. {
  161. CHARSETINFO csi;
  162. if (!TranslateCharsetInfo((DWORD *)IntToPtr(CodePage), &csi, TCI_SRCCODEPAGE))
  163. csi.ciCharset = OEM_CHARSET;
  164. return (BYTE)csi.ciCharset;
  165. }
  166. LPTTFONTLIST
  167. SearchTTFont(
  168. LPTSTR ptszFace,
  169. BOOL fCodePage,
  170. UINT CodePage
  171. )
  172. {
  173. PSINGLE_LIST_ENTRY pTemp = gTTFontList.Next;
  174. if (ptszFace) {
  175. while (pTemp != NULL) {
  176. LPTTFONTLIST pTTFontList = (LPTTFONTLIST)pTemp;
  177. if (wcscmp(ptszFace, pTTFontList->FaceName1) == 0 ||
  178. wcscmp(ptszFace, pTTFontList->FaceName2) == 0 ) {
  179. if (fCodePage)
  180. if (pTTFontList->CodePage == CodePage )
  181. return pTTFontList;
  182. else
  183. return NULL;
  184. else
  185. return pTTFontList;
  186. }
  187. pTemp = pTemp->Next;
  188. }
  189. }
  190. return NULL;
  191. }
  192. BOOL
  193. IsAvailableTTFont(
  194. LPTSTR ptszFace
  195. )
  196. {
  197. if (SearchTTFont(ptszFace, FALSE, 0))
  198. return TRUE;
  199. else
  200. return FALSE;
  201. }
  202. BOOL
  203. IsAvailableTTFontCP(
  204. LPTSTR ptszFace,
  205. UINT CodePage
  206. )
  207. {
  208. if (SearchTTFont(ptszFace, TRUE, CodePage))
  209. return TRUE;
  210. else
  211. return FALSE;
  212. }
  213. BOOL
  214. IsDisableBoldTTFont(
  215. LPTSTR ptszFace
  216. )
  217. {
  218. LPTTFONTLIST pTTFontList;
  219. pTTFontList = SearchTTFont(ptszFace, FALSE, 0);
  220. if (pTTFontList != NULL)
  221. return pTTFontList->fDisableBold;
  222. else
  223. return FALSE;
  224. }
  225. LPTSTR
  226. GetAltFaceName(
  227. LPTSTR ptszFace
  228. )
  229. {
  230. LPTTFONTLIST pTTFontList;
  231. pTTFontList = SearchTTFont(ptszFace, FALSE, 0);
  232. if (pTTFontList != NULL) {
  233. if (wcscmp(ptszFace, pTTFontList->FaceName1) == 0) {
  234. return pTTFontList->FaceName2;
  235. }
  236. if (wcscmp(ptszFace, pTTFontList->FaceName2) == 0) {
  237. return pTTFontList->FaceName1;
  238. }
  239. return NULL;
  240. }
  241. else
  242. return NULL;
  243. }
  244. NTSTATUS
  245. DestroyDbcsMisc(
  246. VOID
  247. )
  248. {
  249. while (gTTFontList.Next != NULL) {
  250. LPTTFONTLIST pTTFontList = (LPTTFONTLIST)PopEntryList(&gTTFontList);
  251. if (pTTFontList != NULL)
  252. LocalFree(pTTFontList);
  253. }
  254. return STATUS_SUCCESS;
  255. }
  256. typedef struct _LC_List {
  257. struct _LC_List* Next;
  258. BOOL FindFlag;
  259. TCHAR LC_String[9];
  260. } LC_List, *PLC_List;
  261. static PLC_List LocaleList = NULL;
  262. BOOL CALLBACK
  263. EnumProc(
  264. LPTSTR LC_String
  265. )
  266. {
  267. PLC_List TmpList;
  268. if (_tcslen(LC_String) <= (sizeof(LocaleList->LC_String)/sizeof(TCHAR))-1)
  269. {
  270. TmpList = (PLC_List)&LocaleList;
  271. while(TmpList->Next != NULL)
  272. TmpList = TmpList->Next;
  273. TmpList->Next = LocalAlloc(LPTR, sizeof(LC_List));
  274. if (TmpList->Next != NULL)
  275. {
  276. TmpList = TmpList->Next;
  277. _tcscpy(TmpList->LC_String, LC_String);
  278. }
  279. }
  280. return TRUE;
  281. }
  282. int
  283. LanguageListCreate(
  284. HWND hDlg,
  285. UINT CodePage
  286. )
  287. /*++
  288. Initializes the Language list by enumerating all Locale Information.
  289. Returns
  290. --*/
  291. {
  292. HWND hWndLanguageCombo;
  293. HANDLE hkRegistry = NULL;
  294. NTSTATUS Status;
  295. WCHAR awchValue[ 512 ];
  296. WCHAR awchData[ 512 ];
  297. DWORD dwIndex;
  298. PLC_List TmpList;
  299. WORD LangID;
  300. LCID Locale;
  301. int cchData;
  302. LONG lListIndex;
  303. UINT cp;
  304. BOOL fRet;
  305. CPINFOEX cpinfo;
  306. /*
  307. * Enumrate system locale information
  308. */
  309. EnumSystemLocales( EnumProc, CP_INSTALLED );
  310. /*
  311. * Enumrate registory key
  312. */
  313. Status = MyRegOpenKey(NULL,
  314. MACHINE_REGISTRY_CONSOLE_NLS,
  315. &hkRegistry);
  316. if (!NT_SUCCESS( Status )) {
  317. DBGPRINT(("CONSRV: NtOpenKey failed %ws\n", MACHINE_REGISTRY_CONSOLE));
  318. }
  319. else {
  320. for( dwIndex = 0; ; dwIndex++)
  321. {
  322. Status = MyRegEnumValue(hkRegistry,
  323. dwIndex,
  324. sizeof(awchValue), (LPWSTR)&awchValue,
  325. sizeof(awchData), (PBYTE)&awchData);
  326. if (!NT_SUCCESS( Status ))
  327. {
  328. break;
  329. }
  330. TmpList = (PLC_List)&LocaleList;
  331. while(TmpList->Next != NULL)
  332. {
  333. TmpList = TmpList->Next;
  334. if (_tcscmp(awchValue, TmpList->LC_String) == 0)
  335. {
  336. TmpList->FindFlag = TRUE;
  337. break;
  338. }
  339. }
  340. }
  341. NtClose(hkRegistry);
  342. }
  343. /*
  344. * Create ComboBox items
  345. */
  346. hWndLanguageCombo = GetDlgItem(hDlg, IDD_LANGUAGELIST);
  347. SendMessage(hWndLanguageCombo, CB_RESETCONTENT, 0, 0L);
  348. TmpList = (PLC_List)&LocaleList;
  349. while(TmpList->Next != NULL)
  350. {
  351. TmpList = TmpList->Next;
  352. if (TmpList->FindFlag)
  353. {
  354. LangID = ConvertStringToHex(TmpList->LC_String, NULL);
  355. Locale = MAKELCID( LangID, SORT_DEFAULT );
  356. cchData = GetLocaleInfo(Locale, LOCALE_IDEFAULTCODEPAGE,
  357. awchData, sizeof(awchData)/sizeof(TCHAR));
  358. if (cchData)
  359. {
  360. awchData[cchData] = TEXT('\0');
  361. cp = ConvertStringToDec(awchData, NULL);
  362. if ( (IS_ANY_DBCS_CHARSET(CodePageToCharSet(cp)) && GetOEMCP() == cp) ||
  363. (!IS_ANY_DBCS_CHARSET(CodePageToCharSet(cp))) ) {
  364. fRet = GetCPInfoEx(cp, 0, &cpinfo);
  365. if (fRet) {
  366. lListIndex = (LONG)SendMessage(hWndLanguageCombo, CB_ADDSTRING, 0, (LPARAM)cpinfo.CodePageName);
  367. SendMessage(hWndLanguageCombo, CB_SETITEMDATA, (DWORD)lListIndex, cp);
  368. if (CodePage == cp) {
  369. SendMessage(hWndLanguageCombo, CB_SETCURSEL, lListIndex, 0L);
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }
  376. {
  377. PLC_List Tmp;
  378. TmpList = (PLC_List)&LocaleList;
  379. while(TmpList->Next != NULL)
  380. {
  381. Tmp = TmpList;
  382. TmpList = TmpList->Next;
  383. if (Tmp != (PLC_List)&LocaleList)
  384. LocalFree(Tmp);
  385. }
  386. LocaleList = NULL;
  387. }
  388. /*
  389. * Get the LocaleIndex from the currently selected item.
  390. * (i will be LB_ERR if no currently selected item).
  391. */
  392. lListIndex = (LONG)SendMessage(hWndLanguageCombo, CB_GETCURSEL, 0, 0L);
  393. return (LONG)SendMessage(hWndLanguageCombo, CB_GETITEMDATA, lListIndex, 0L);
  394. }
  395. // v-HirShi Nov.20.1996
  396. int
  397. LanguageDisplay(
  398. HWND hDlg,
  399. UINT CodePage
  400. )
  401. /*++
  402. Display the Language .
  403. Returns
  404. --*/
  405. {
  406. HWND hWndLanguageDisp;
  407. HANDLE hkRegistry = NULL;
  408. NTSTATUS Status;
  409. WCHAR awchValue[ 512 ];
  410. WCHAR awchData[ 512 ];
  411. DWORD dwIndex;
  412. PLC_List TmpList;
  413. WORD LangID;
  414. LCID Locale;
  415. int cchData;
  416. LONG lListIndex;
  417. UINT cp;
  418. BOOL fRet;
  419. CPINFOEX cpinfo;
  420. /*
  421. * Enumrate system locale information
  422. */
  423. EnumSystemLocales( EnumProc, CP_INSTALLED );
  424. /*
  425. * Enumrate registory key
  426. */
  427. Status = MyRegOpenKey(NULL,
  428. MACHINE_REGISTRY_CONSOLE_NLS,
  429. &hkRegistry);
  430. if (!NT_SUCCESS( Status )) {
  431. DBGPRINT(("CONSRV: NtOpenKey failed %ws\n", MACHINE_REGISTRY_CONSOLE));
  432. }
  433. else {
  434. for( dwIndex = 0; ; dwIndex++)
  435. {
  436. Status = MyRegEnumValue(hkRegistry,
  437. dwIndex,
  438. sizeof(awchValue), (LPWSTR)&awchValue,
  439. sizeof(awchData), (PBYTE)&awchData);
  440. if (!NT_SUCCESS( Status ))
  441. {
  442. break;
  443. }
  444. TmpList = (PLC_List)&LocaleList;
  445. while(TmpList->Next != NULL)
  446. {
  447. TmpList = TmpList->Next;
  448. if (_tcscmp(awchValue, TmpList->LC_String) == 0)
  449. {
  450. TmpList->FindFlag = TRUE;
  451. break;
  452. }
  453. }
  454. }
  455. NtClose(hkRegistry);
  456. }
  457. /*
  458. * Display Language
  459. */
  460. TmpList = (PLC_List)&LocaleList;
  461. while(TmpList->Next != NULL)
  462. {
  463. TmpList = TmpList->Next;
  464. if (TmpList->FindFlag)
  465. {
  466. LangID = ConvertStringToHex(TmpList->LC_String, NULL);
  467. Locale = MAKELCID( LangID, SORT_DEFAULT );
  468. cchData = GetLocaleInfo(Locale, LOCALE_IDEFAULTCODEPAGE,
  469. awchData, sizeof(awchData)/sizeof(TCHAR));
  470. if (cchData)
  471. {
  472. awchData[cchData] = TEXT('\0');
  473. cp = ConvertStringToDec(awchData, NULL);
  474. fRet = GetCPInfoEx(cp, 0, &cpinfo);
  475. if (fRet) {
  476. if (CodePage == cp) {
  477. hWndLanguageDisp = GetDlgItem(hDlg, IDD_LANGUAGE);
  478. SetWindowText(hWndLanguageDisp, cpinfo.CodePageName);
  479. }
  480. }
  481. }
  482. }
  483. }
  484. {
  485. PLC_List Tmp;
  486. TmpList = (PLC_List)&LocaleList;
  487. while(TmpList->Next != NULL)
  488. {
  489. Tmp = TmpList;
  490. TmpList = TmpList->Next;
  491. if (Tmp != (PLC_List)&LocaleList)
  492. LocalFree(Tmp);
  493. }
  494. LocaleList = NULL;
  495. }
  496. return TRUE;
  497. }
  498. #endif // FE_SB