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.

178 lines
4.8 KiB

  1. // cutil.h
  2. //
  3. // file to put misc utility classes implementation
  4. //
  5. #ifndef CUTIL_H
  6. #define CUTIL_H
  7. #include "private.h"
  8. #include "regimx.h"
  9. class CDocStatus
  10. {
  11. public:
  12. CDocStatus(ITfContext *pic)
  13. {
  14. cpic = pic;
  15. }
  16. BOOL IsReadOnly()
  17. {
  18. TF_STATUS ts;
  19. HRESULT hr = cpic->GetStatus(&ts);
  20. if (S_OK == hr)
  21. {
  22. if (TF_SD_READONLY & ts.dwDynamicFlags)
  23. return TRUE;
  24. }
  25. return FALSE;
  26. }
  27. private:
  28. CComPtr<ITfContext> cpic;
  29. };
  30. class __declspec(novtable) CLangProfileUtil : public ITfFnLangProfileUtil
  31. {
  32. public:
  33. CLangProfileUtil()
  34. {
  35. m_fProfileInit = FALSE;
  36. m_langidDefault = 0xFFFF;
  37. m_uiUseSAPIForLangDetection = 0;
  38. }
  39. virtual ~CLangProfileUtil();
  40. // ITfFnLangProfileUtil method
  41. STDMETHODIMP RegisterActiveProfiles(void);
  42. STDMETHODIMP IsProfileAvailableForLang(LANGID langid, BOOL *pfAvailable);
  43. // ITfFunction method
  44. STDMETHODIMP GetDisplayName(BSTR *pbstrName);
  45. // private APIs
  46. HRESULT _EnsureProfiles(BOOL fRegister, BOOL *pfEnabled = NULL);
  47. HRESULT _RegisterAProfile(HINSTANCE hInst, REFCLSID rclsid, const REGTIPLANGPROFILE *plp);
  48. HRESULT _GetProfileLangID(LANGID *plangid);
  49. static const REGTIPLANGPROFILE *_GetSPTIPProfileForLang(LANGID langid);
  50. virtual BOOL _DictationEnabled(LANGID *plangidRequested = NULL);
  51. BOOL _IsDictationActiveForLang(LANGID langidReq);
  52. BOOL _IsDictationEnabledForLang(LANGID langidReq, BOOL fUseDefault = FALSE);
  53. BOOL _IsDictationEnabledForLangSAPI(LANGID langidReq, BOOL fUseDefault);
  54. LONG _IsDictationEnabledForLangInReg(LANGID langidReq, BOOL fUseDefault, BOOL *pfEnabled);
  55. BOOL _IsAnyProfileEnabled();
  56. BOOL _fUseSAPIForLanguageDetection(void);
  57. BOOL _fUserRemovedProfile(void);
  58. BOOL _fUserInitializedProfile(void);
  59. BOOL _SetUserInitializedProfile(void);
  60. void _ResetDefaultLang() {m_langidDefault = 0xFFFF; }
  61. LANGID _GetLangIdFromRecognizerToken(HKEY hkeyToken);
  62. CComPtr<ITfInputProcessorProfiles> m_cpProfileMgr;
  63. typedef struct {
  64. DWORD langid;
  65. DWORD dwStat;
  66. DWORD lidOverRidden;
  67. } LANGPROFILESTAT ;
  68. BOOL m_fProfileInit;
  69. LANGID m_langidDefault;
  70. UINT m_uiUseSAPIForLangDetection;
  71. //
  72. // this is an array of installed recognizers in their langid
  73. //
  74. CStructArray<LANGID> m_langidRecognizers;
  75. };
  76. typedef enum
  77. {
  78. DA_COLOR_AWARE,
  79. DA_COLOR_UNAWARE
  80. } ColorType;
  81. class __declspec(novtable) CColorUtil
  82. {
  83. public:
  84. CColorUtil() {m_cBitsPixelScreen = 0; m_fHighContrast =0;}
  85. COLORREF col( int r1, COLORREF col1, int r2, COLORREF col2 )
  86. {
  87. int sum = r1 + r2;
  88. Assert( sum == 10 || sum == 100 || sum == 1000 );
  89. int r = (r1 * GetRValue(col1) + r2 * GetRValue(col2) + sum/2) / sum;
  90. int g = (r1 * GetGValue(col1) + r2 * GetGValue(col2) + sum/2) / sum;
  91. int b = (r1 * GetBValue(col1) + r2 * GetBValue(col2) + sum/2) / sum;
  92. return RGB( r, g, b );
  93. }
  94. COLORREF GetNewLookColor(ColorType ct = DA_COLOR_AWARE)
  95. {
  96. InitColorInfo();
  97. COLORREF cr;
  98. if (m_cBitsPixelScreen < 8 || m_fHighContrast == TRUE)
  99. {
  100. cr = GetSysColor( COLOR_HIGHLIGHT );
  101. }
  102. else if (ct == DA_COLOR_AWARE)
  103. {
  104. cr = col( 50, GetSysColor( COLOR_HIGHLIGHT ),
  105. 50, GetSysColor( COLOR_WINDOW ) );
  106. }
  107. else
  108. {
  109. cr = col( 80, GetSysColor( COLOR_INFOBK ),
  110. 20, GetSysColor(COLOR_3DSHADOW) );
  111. }
  112. return cr;
  113. }
  114. void InitColorInfo(void)
  115. {
  116. // do nothing if it's initialized already
  117. if (m_cBitsPixelScreen) return;
  118. HIGHCONTRAST hicntr = {0};
  119. HDC hDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  120. // device caps
  121. m_cBitsPixelScreen = GetDeviceCaps( hDC, BITSPIXEL );
  122. // system paramater info
  123. hicntr.cbSize = sizeof(HIGHCONTRAST);
  124. SystemParametersInfo( SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST), &hicntr, 0 );
  125. m_fHighContrast = ((hicntr.dwFlags & HCF_HIGHCONTRASTON) != 0);
  126. DeleteDC( hDC );
  127. }
  128. COLORREF GetTextColor()
  129. {
  130. return m_fHighContrast ? GetSysColor(COLOR_HIGHLIGHTTEXT) : GetSysColor(COLOR_WINDOWTEXT);
  131. }
  132. private:
  133. int m_cBitsPixelScreen;
  134. BOOL m_fHighContrast;
  135. };
  136. extern const GUID c_guidProfileBogus;
  137. extern const GUID c_guidProfile0 ;
  138. extern const GUID c_guidProfile1 ;
  139. extern const GUID c_guidProfile2 ;
  140. extern const REGTIPLANGPROFILE c_rgProfiles[];
  141. #endif // CUTIL_H