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.

261 lines
4.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1999
  3. All rights reserved.
  4. Module Name:
  5. rtlmir.cxx
  6. Abstract:
  7. RTL (right-to-left) mirroring &
  8. BIDI localized support
  9. Author:
  10. Lazar Ivanov (LazarI)
  11. Revision History:
  12. Jul-29-1999 - Created.
  13. --*/
  14. #include "precomp.hxx"
  15. #pragma hdrstop
  16. #include "rtlmir.hxx"
  17. BOOL
  18. bConvertHexStringToInt(
  19. TCHAR *pszHexNum,
  20. int *piNum
  21. )
  22. /*++
  23. Routine Description:
  24. Converts a hex numeric string into an integer.
  25. Arguments:
  26. pszHexNum - thre string that needs to be converted to a number
  27. piNum - where to put the output number after the convertion
  28. Return Value:
  29. TRUE on sucess, FALSE otherwise
  30. --*/
  31. {
  32. int n=0L;
  33. TCHAR *psz=pszHexNum;
  34. for(n=0 ; ; psz=CharNext(psz))
  35. {
  36. if( (*psz >= TEXT('0')) && (*psz <= TEXT('9')) )
  37. n = 0x10 * n + *psz - TEXT('0');
  38. else
  39. {
  40. TCHAR ch = *psz;
  41. int n2;
  42. if(ch >= TEXT('a'))
  43. ch -= TEXT('a') - TEXT('A');
  44. n2 = ch - TEXT('A') + 0xA;
  45. if (n2 >= 0xA && n2 <= 0xF)
  46. n = 0x10 * n + n2;
  47. else
  48. break;
  49. }
  50. }
  51. /*
  52. * Update results
  53. */
  54. *piNum = n;
  55. return (psz != pszHexNum);
  56. }
  57. BOOL
  58. bIsBiDiLocalizedSystemEx(
  59. LANGID *pLangID
  60. )
  61. /*++
  62. Routine Description:
  63. returns TRUE if running on a lozalized BiDi (Arabic/Hebrew) NT5.
  64. Arguments:
  65. pLangID - where to return the user default UI language
  66. Return Value:
  67. TRUE on sucess, FALSE otherwise
  68. --*/
  69. {
  70. HKEY hKey;
  71. DWORD dwType;
  72. CHAR szResourceLocale[12];
  73. DWORD dwSize = sizeof(szResourceLocale)/sizeof(CHAR);
  74. int iLCID=0L;
  75. BOOL bRet = FALSE;
  76. LANGID langID = GetUserDefaultUILanguage();
  77. /*
  78. * Need to use NT5 detection method (Multiligual UI ID)
  79. */
  80. if( langID )
  81. {
  82. WCHAR wchLCIDFontSignature[16];
  83. iLCID = MAKELCID( langID , SORT_DEFAULT );
  84. /*
  85. * Let's verify this is a RTL (BiDi) locale. Since reg value is a hex string, let's
  86. * convert to decimal value and call GetLocaleInfo afterwards.
  87. * LOCALE_FONTSIGNATURE always gives back 16 WCHARs.
  88. */
  89. if( GetLocaleInfoW( iLCID ,
  90. LOCALE_FONTSIGNATURE ,
  91. (WCHAR *) &wchLCIDFontSignature[0] ,
  92. (sizeof(wchLCIDFontSignature)/sizeof(WCHAR))) )
  93. {
  94. /* Let's verify the bits we have a BiDi UI locale */
  95. if( ( wchLCIDFontSignature[7] & (WCHAR)0x0800) && bIsUILanguageInstalled( langID ) )
  96. {
  97. bRet = TRUE;
  98. }
  99. }
  100. }
  101. if( bRet && pLangID )
  102. {
  103. *pLangID = langID;
  104. }
  105. return bRet;
  106. }
  107. BOOL
  108. bIsBiDiLocalizedSystem(
  109. VOID
  110. )
  111. /*++
  112. Routine Description:
  113. returns TRUE if running on a lozalized BiDi (Arabic/Hebrew) NT5.
  114. Arguments:
  115. None
  116. Return Value:
  117. TRUE on sucess, FALSE otherwise
  118. --*/
  119. {
  120. return bIsBiDiLocalizedSystemEx( NULL );
  121. }
  122. typedef struct tagMUIINSTALLLANG {
  123. LANGID LangID;
  124. BOOL bInstalled;
  125. } MUIINSTALLLANG, *LPMUIINSTALLLANG;
  126. BOOL CALLBACK
  127. EnumUILanguagesProc(
  128. LPTSTR lpUILanguageString,
  129. LONG_PTR lParam
  130. )
  131. /*++
  132. Routine Description:
  133. standard EnumUILanguagesProc
  134. Arguments:
  135. standard - see the SDK
  136. Return Value:
  137. standard - see the SDK
  138. --*/
  139. {
  140. int langID = 0;
  141. bConvertHexStringToInt(lpUILanguageString, &langID);
  142. if((LANGID)langID == ((LPMUIINSTALLLANG)lParam)->LangID)
  143. {
  144. ((LPMUIINSTALLLANG)lParam)->bInstalled = TRUE;
  145. return FALSE;
  146. }
  147. return TRUE;
  148. }
  149. BOOL
  150. bIsUILanguageInstalled(
  151. LANGID langId
  152. )
  153. /*++
  154. Routine Description:
  155. Verifies that a particular User UI language is installed on W2k
  156. Arguments:
  157. langId - language to check for
  158. Return Value:
  159. TRUE if installed, FALSE otherwise
  160. --*/
  161. {
  162. MUIINSTALLLANG MUILangInstalled = {0};
  163. MUILangInstalled.LangID = langId;
  164. EnumUILanguages(EnumUILanguagesProc, 0, (LONG_PTR)&MUILangInstalled);
  165. return MUILangInstalled.bInstalled;
  166. }
  167. BOOL
  168. bIsWindowMirroredRTL(
  169. HWND hWnd
  170. )
  171. /*++
  172. Routine Description:
  173. Verifies whether a particular window is right-to-left mirrored.
  174. Arguments:
  175. hWnd - window to check for
  176. Return Value:
  177. TRUE if mirrored, FALSE otherwise
  178. --*/
  179. {
  180. return (GetWindowLongA( hWnd , GWL_EXSTYLE ) & WS_EX_LAYOUTRTL );
  181. }