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.

177 lines
5.2 KiB

  1. //
  2. // globals.cpp
  3. //
  4. // Global variables.
  5. //
  6. #include "globals.h"
  7. HINSTANCE g_hInst;
  8. LONG g_cRefDll = -1; // -1 /w no refs, for win95 InterlockedIncrement/Decrement compat
  9. CRITICAL_SECTION g_cs;
  10. /* 23e97bc9-f2d3-4b25-8ef3-d78391bf2150 */
  11. const CLSID c_clsidMarkTextService = { 0x23e97bc9, 0xf2d3, 0x4b25, {0x8e, 0xf3, 0xd7, 0x83, 0x91, 0xbf, 0x21, 0x50} };
  12. /* a2767f97-e735-461a-84ba-7a7ecad24827 */
  13. const GUID c_guidMarkProfile = { 0xa2767f97, 0xe735, 0x461a, {0x84, 0xba, 0x7a, 0x7e, 0xca, 0xd2, 0x48, 0x27} };
  14. /* c74a88d5-6614-439b-8880-2dd8e6cd91a7 */
  15. const GUID c_guidLangBarItemButton = { 0xc74a88d5, 0x6614, 0x439b, {0x88, 0x80, 0x2d, 0xd8, 0xe6, 0xcd, 0x91, 0xa7} };
  16. /* d81face6-845c-45e7-a2af-1c5fc7adf667 */
  17. const GUID c_guidMarkDisplayAttribute = { 0xd81face6, 0x845c, 0x45e7, {0xa2, 0xaf, 0x1c, 0x5f, 0xc7, 0xad, 0xf6, 0x67} };
  18. /* eadc084c-6130-4222-82e5-c528c1f4abbb */
  19. const GUID c_guidMarkContextCompartment = { 0xeadc084c, 0x6130, 0x4222, {0x82, 0xe5, 0xc5, 0x28, 0xc1, 0xf4, 0xab, 0xbb} };
  20. /* 947d9d1c-7a4c-4392-b37c-34017c6c7fe1 */
  21. const GUID c_guidMarkGlobalCompartment = { 0x947d9d1c, 0x7a4c, 0x4392, {0xb3, 0x7c, 0x34, 0x01, 0x7c, 0x6c, 0x7f, 0xe1} };
  22. /* 3042ae6a-4697-4f7d-acdf-20a972fee027 */
  23. const GUID c_guidCaseProperty = { 0x3042ae6a, 0x4697, 0x4f7d, {0xac, 0xdf, 0x20, 0xa9, 0x72, 0xfe, 0xe0, 0x27} };
  24. /* d05a182a-7782-4e61-a2ea-6a4794ab7aaa */
  25. const GUID c_guidCustomProperty = { 0xd05a182a, 0x7782, 0x4e61, {0xa2, 0xea, 0x6a, 0x47, 0x94, 0xab, 0x7a, 0xaa} };
  26. //+---------------------------------------------------------------------------
  27. //
  28. // AdviseSink
  29. //
  30. //----------------------------------------------------------------------------
  31. BOOL AdviseSink(IUnknown *pSourceIn, IUnknown *pSink, REFIID riid, DWORD *pdwCookie)
  32. {
  33. ITfSource *pSource;
  34. HRESULT hr;
  35. if (pSourceIn->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
  36. return FALSE;
  37. hr = pSource->AdviseSink(riid, pSink, pdwCookie);
  38. pSource->Release();
  39. if (hr != S_OK)
  40. {
  41. // make sure we don't try to Unadvise pdwCookie later
  42. *pdwCookie = TF_INVALID_COOKIE;
  43. return FALSE;
  44. }
  45. return TRUE;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // UnadviseSink
  50. //
  51. //----------------------------------------------------------------------------
  52. void UnadviseSink(IUnknown *pSourceIn, DWORD *pdwCookie)
  53. {
  54. ITfSource *pSource;
  55. if (*pdwCookie == TF_INVALID_COOKIE)
  56. return; // never Advised
  57. if (pSourceIn->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
  58. {
  59. pSource->UnadviseSink(*pdwCookie);
  60. pSource->Release();
  61. }
  62. *pdwCookie = TF_INVALID_COOKIE;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // AdviseSingleSink
  67. //
  68. //----------------------------------------------------------------------------
  69. BOOL AdviseSingleSink(TfClientId tfClientId, IUnknown *pSourceIn, IUnknown *pSink, REFIID riid)
  70. {
  71. ITfSourceSingle *pSource;
  72. HRESULT hr;
  73. if (pSourceIn->QueryInterface(IID_ITfSourceSingle, (void **)&pSource) != S_OK)
  74. return FALSE;
  75. hr = pSource->AdviseSingleSink(tfClientId, riid, pSink);
  76. pSource->Release();
  77. return (hr == S_OK);
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // UnadviseSingleSink
  82. //
  83. //----------------------------------------------------------------------------
  84. void UnadviseSingleSink(TfClientId tfClientId, IUnknown *pSourceIn, REFIID riid)
  85. {
  86. ITfSourceSingle *pSource;
  87. if (pSourceIn->QueryInterface(IID_ITfSourceSingle, (void **)&pSource) == S_OK)
  88. {
  89. pSource->UnadviseSingleSink(tfClientId, riid);
  90. pSource->Release();
  91. }
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // IsRangeCovered
  96. //
  97. // Returns TRUE if pRangeTest is entirely contained within pRangeCover.
  98. //----------------------------------------------------------------------------
  99. BOOL IsRangeCovered(TfEditCookie ec, ITfRange *pRangeTest, ITfRange *pRangeCover)
  100. {
  101. LONG lResult;
  102. if (pRangeCover->CompareStart(ec, pRangeTest, TF_ANCHOR_START, &lResult) != S_OK ||
  103. lResult > 0)
  104. {
  105. return FALSE;
  106. }
  107. if (pRangeCover->CompareEnd(ec, pRangeTest, TF_ANCHOR_END, &lResult) != S_OK ||
  108. lResult < 0)
  109. {
  110. return FALSE;
  111. }
  112. return TRUE;
  113. }
  114. //+---------------------------------------------------------------------------
  115. //
  116. // IsEqualUnknown
  117. //
  118. // Returns TRUE if punk1 and punk2 refer to the same object. We must QI for
  119. // IUnknown to be guarenteed a reliable test, per the COM rules.
  120. //----------------------------------------------------------------------------
  121. BOOL IsEqualUnknown(IUnknown *interface1, IUnknown *interface2)
  122. {
  123. IUnknown *punk1;
  124. IUnknown *punk2;
  125. if (interface1->QueryInterface(IID_IUnknown, (void **)&punk1) != S_OK)
  126. return FALSE;
  127. punk1->Release(); // we don't actually need to dereference these guys, just want to compare them
  128. if (interface2->QueryInterface(IID_IUnknown, (void **)&punk2) != S_OK)
  129. return FALSE;
  130. punk2->Release();
  131. return (punk1 == punk2);
  132. }