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.

171 lines
4.4 KiB

  1. #include "stdafx.h"
  2. #include "common.h"
  3. #include "bidi.h"
  4. #ifdef _DEBUG
  5. #undef THIS_FILE
  6. static char BASED_CODE THIS_FILE[] = __FILE__;
  7. #endif
  8. #define new DEBUG_NEW
  9. /***************************************************************************\
  10. * ConvertHexStringToIntW
  11. *
  12. * Converts a hex numeric string into an integer.
  13. *
  14. * History:
  15. * 14-June-1998 msadek Created
  16. \***************************************************************************/
  17. BOOL ConvertHexStringToIntW( WCHAR *pszHexNum , int *piNum )
  18. {
  19. int n=0L;
  20. WCHAR *psz=pszHexNum;
  21. for(n=0 ; ; psz=CharNextW(psz))
  22. {
  23. if( (*psz>='0') && (*psz<='9') )
  24. n = 0x10 * n + *psz - '0';
  25. else
  26. {
  27. WCHAR ch = *psz;
  28. int n2;
  29. if(ch >= 'a')
  30. ch -= 'a' - 'A';
  31. n2 = ch - 'A' + 0xA;
  32. if (n2 >= 0xA && n2 <= 0xF)
  33. n = 0x10 * n + n2;
  34. else
  35. break;
  36. }
  37. }
  38. /*
  39. * Update results
  40. */
  41. *piNum = n;
  42. return (psz != pszHexNum);
  43. }
  44. typedef struct tagMUIINSTALLLANG {
  45. LANGID LangID;
  46. BOOL bInstalled;
  47. } MUIINSTALLLANG, *LPMUIINSTALLLANG;
  48. typedef BOOL (WINAPI *PFNENUMUILANGUAGES)(UILANGUAGE_ENUMPROC, DWORD, LONG_PTR);
  49. BOOL CALLBACK Mirror_EnumUILanguagesProc(LPTSTR lpUILanguageString, LONG_PTR lParam)
  50. {
  51. int langID = 0;
  52. ConvertHexStringToIntW(lpUILanguageString, &langID);
  53. if((LANGID)langID == ((LPMUIINSTALLLANG)lParam)->LangID)
  54. {
  55. ((LPMUIINSTALLLANG)lParam)->bInstalled = TRUE;
  56. return FALSE;
  57. }
  58. return TRUE;
  59. }
  60. /***************************************************************************\
  61. * Mirror_IsUILanguageInstalled
  62. *
  63. * Verifies that the User UI language is installed on W2k
  64. *
  65. * History:
  66. * 14-June-1999 msadek Created
  67. \***************************************************************************/
  68. BOOL Mirror_IsUILanguageInstalled( LANGID langId )
  69. {
  70. MUIINSTALLLANG MUILangInstalled = {0};
  71. MUILangInstalled.LangID = langId;
  72. static PFNENUMUILANGUAGES pfnEnumUILanguages=NULL;
  73. if( NULL == pfnEnumUILanguages )
  74. {
  75. HMODULE hmod = GetModuleHandleA("KERNEL32");
  76. if( hmod )
  77. pfnEnumUILanguages = (PFNENUMUILANGUAGES)
  78. GetProcAddress(hmod, "EnumUILanguagesW");
  79. }
  80. if( pfnEnumUILanguages )
  81. pfnEnumUILanguages(Mirror_EnumUILanguagesProc, 0, (LONG_PTR)&MUILangInstalled);
  82. return MUILangInstalled.bInstalled;
  83. }
  84. /***************************************************************************\
  85. * IsBiDiLocalizedSystemEx
  86. *
  87. * returns TRUE if running on a lozalized BiDi (Arabic/Hebrew) NT5 or Memphis.
  88. * Should be called whenever SetProcessDefaultLayout is to be called.
  89. *
  90. * History:
  91. * 02-Feb-1998 samera Created
  92. \***************************************************************************/
  93. BOOL IsBiDiLocalizedSystemEx( LANGID *pLangID )
  94. {
  95. int iLCID=0L;
  96. static BOOL bRet = (BOOL)(DWORD)-1;
  97. static LANGID langID = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
  98. if (bRet != (BOOL)(DWORD)-1)
  99. {
  100. if (bRet && pLangID)
  101. {
  102. *pLangID = langID;
  103. }
  104. return bRet;
  105. }
  106. bRet = FALSE;
  107. /*
  108. * Need to use NT5 detection method (Multiligual UI ID)
  109. */
  110. langID = GetUserDefaultUILanguage();
  111. if( langID )
  112. {
  113. WCHAR wchLCIDFontSignature[16];
  114. iLCID = MAKELCID( langID , SORT_DEFAULT );
  115. /*
  116. * Let's verify this is a RTL (BiDi) locale. Since reg value is a hex string, let's
  117. * convert to decimal value and call GetLocaleInfo afterwards.
  118. * LOCALE_FONTSIGNATURE always gives back 16 WCHARs.
  119. */
  120. if( GetLocaleInfoW( iLCID ,
  121. LOCALE_FONTSIGNATURE ,
  122. (WCHAR *) &wchLCIDFontSignature[0] ,
  123. (sizeof(wchLCIDFontSignature)/sizeof(WCHAR))) )
  124. {
  125. /* Let's verify the bits we have a BiDi UI locale */
  126. if(( wchLCIDFontSignature[7] & (WCHAR)0x0800) && Mirror_IsUILanguageInstalled(langID) )
  127. {
  128. bRet = TRUE;
  129. }
  130. }
  131. }
  132. if (bRet && pLangID)
  133. {
  134. *pLangID = langID;
  135. }
  136. return bRet;
  137. }
  138. BOOL
  139. IsBiDiLocalizedSystem( void )
  140. {
  141. return IsBiDiLocalizedSystemEx(NULL);
  142. }