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.

135 lines
4.1 KiB

  1. // unicode.h - Unicode functions that work on all 32-bit Window platform
  2. #pragma once
  3. #ifndef __UNICODE_H__
  4. #define __UNICODE_H__
  5. // C/C++ differences
  6. #ifndef INLINE
  7. #ifdef __cplusplus
  8. #define INLINE inline
  9. #else
  10. #define INLINE __inline
  11. #endif
  12. #endif
  13. #define CP_UNICODE 1200 // Unicode
  14. #define IN_RANGE(v, r1, r2) ((r1) <= (v) && (v) <= (r2))
  15. //====================
  16. // From VS6 minar.h
  17. //====================
  18. class CBufImpl
  19. {
  20. private:
  21. BYTE * m_pData;
  22. int m_cb;
  23. HRESULT _SetByteSize (int cb);
  24. public:
  25. CBufImpl() : m_pData(NULL), m_cb(0) {}
  26. ~CBufImpl() { Clear(); }
  27. void Clear ();
  28. HRESULT SetByteSize (int cb);
  29. HRESULT SetByteSizeShrink (int cb);
  30. int GetByteSize () { return m_cb; }
  31. BYTE * ByteData () { return m_pData; }
  32. };
  33. inline HRESULT CBufImpl::SetByteSize (int cb)
  34. {
  35. if (cb <= m_cb)
  36. return S_OK;
  37. return _SetByteSize(cb);
  38. }
  39. //---------------------------------------------------------------
  40. template <class T> class CMinimalArray : public CBufImpl
  41. {
  42. public:
  43. HRESULT SetSize (int cel) { return SetByteSize(cel*sizeof(T)); }
  44. HRESULT SetSizeShrink (int cel) { return SetByteSizeShrink(cel*sizeof(T)); }
  45. int Size () { return GetByteSize()/sizeof(T); }
  46. operator T* () { return (T*)ByteData(); }
  47. T* GetData () { return (T*)ByteData(); }
  48. };
  49. //====================
  50. // From VS6 intlutil.h
  51. //====================
  52. /////////////////////////////////////////////////////////////////
  53. // GetDefaultFont - Get default monospaced font for a codepage
  54. //
  55. // IN cp Codepage -- usually result of GetACP().
  56. // IN plf Address of uninitialized LOGFONT structure.
  57. // OUT plf Fully initialized LOGFONT struct.
  58. //
  59. void GetDefaultFont(UINT cp, LOGFONT * plf, BYTE *pbySize);
  60. BOOL IsStringDisplayable(const char *pszString, UINT codepage);
  61. /////////////////////////////////////////////////////////////////
  62. // locale/codepage mappings
  63. //
  64. #define LCIDCP_CURRENT (2)
  65. #define LCIDCP_GUESSED (1)
  66. #define LCIDCP_UNKNOWN (0)
  67. int WINAPI LCIDFromCodePage(UINT cp, LCID * plcid);
  68. UINT WINAPI CodePageFromLCID(LCID lcid);
  69. UINT WINAPI CodepageFromCharset(BYTE cs);
  70. BOOL WINAPI IsSupportedFontCodePage(UINT cp);
  71. BOOL WINAPI IsDbcsGdi ();
  72. BOOL WINAPI IsWin95OrLess ();
  73. BOOL WINAPI IsNT ();
  74. BOOL WINAPI WideAPIHack ();
  75. UINT WINAPI GetFontCodePage (HDC hdc);
  76. BOOL IntlGetTextExtentPoint32W (HDC hdc, LPCWSTR lpString, int cbString, LPSIZE lpSize, UINT *pCP = NULL);
  77. BOOL IntlExtTextOutW (HDC hdc, int X, int Y, UINT fuOptions, CONST RECT *lprc, LPCWSTR lpString, UINT cbCount, CONST INT *lpDx, UINT *pCP = NULL);
  78. BOOL IntlTextOutW(HDC hdc, int nXStart, int nYStart, LPCWSTR lpString, int cbString, UINT *pCP = NULL);
  79. BOOL IntlGetTextExtentExPointW(HDC hdc, LPCWSTR lpString, int cbString, int nMaxExtent, LPINT lpnFit, LPINT alpDx, LPSIZE lpSize, UINT *pCP = NULL);
  80. BOOL HxAppendMenu(HMENU hMenu, UINT uFlags, UINT uIDNewItem, LPCTSTR lpNewItem);
  81. BOOL HxSetWindowText(HWND hWnd, LPCTSTR lpString);
  82. BOOL IntlExtTextOut( HDC hdc, int X, int Y, UINT fuOptions, CONST RECT *lprc, LPCWSTR lpString, UINT cbCount, CONST INT *lpDx, UINT* pCP );
  83. inline BOOL IntlTextOutW (HDC hdc, int nXStart, int nYStart, LPCWSTR lpString, int cch, UINT *pCP)
  84. {
  85. // WARNING: this is not completely generic.
  86. // This does work for the ways we use TextOut.
  87. return IntlExtTextOutW(hdc, nXStart, nYStart, 0, NULL, lpString, cch, NULL, pCP);
  88. }
  89. inline BOOL IsImeLanguage(LANGID wLang)
  90. {
  91. wLang = PRIMARYLANGID(wLang);
  92. if (LANG_NEUTRAL == wLang) return FALSE;
  93. if (LANG_ENGLISH == wLang) return FALSE;
  94. if (LANG_JAPANESE == wLang) return TRUE;
  95. if (LANG_KOREAN == wLang) return TRUE;
  96. if (LANG_CHINESE == wLang) return TRUE;
  97. return FALSE;
  98. }
  99. inline BOOL IsImeCharSet(BYTE charset)
  100. {
  101. if (ANSI_CHARSET == charset) return FALSE;
  102. if (SHIFTJIS_CHARSET == charset) return TRUE;
  103. if (GB2312_CHARSET == charset) return TRUE;
  104. if (CHINESEBIG5_CHARSET == charset) return TRUE;
  105. if (HANGEUL_CHARSET == charset) return TRUE;
  106. if (JOHAB_CHARSET == charset) return TRUE;
  107. return FALSE;
  108. }
  109. #endif // __UNICODE_H__