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.

158 lines
3.5 KiB

  1. //
  2. // lpns.cpp
  3. //
  4. #include "private.h"
  5. #include "lpns.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CLanguageProfileNotifySink
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CLanguageProfileNotifySink::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_ITfLanguageProfileNotifySink))
  22. {
  23. *ppvObj = SAFECAST(this, CLanguageProfileNotifySink *);
  24. }
  25. if (*ppvObj)
  26. {
  27. AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDAPI_(ULONG) CLanguageProfileNotifySink::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CLanguageProfileNotifySink::Release()
  37. {
  38. long cr;
  39. cr = --_cRef;
  40. Assert(cr >= 0);
  41. if (cr == 0)
  42. {
  43. delete this;
  44. }
  45. return cr;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // ctor
  50. //
  51. //----------------------------------------------------------------------------
  52. CLanguageProfileNotifySink::CLanguageProfileNotifySink(LPNSCALLBACK pfn, void *pv)
  53. {
  54. Dbg_MemSetThisName(TEXT("CLanguageProfileNotifySink"));
  55. _cRef = 1;
  56. _dwCookie = LPNS_INVALID_COOKIE;
  57. _pfn = pfn;
  58. _pv = pv;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // OnLanguageChange
  63. //
  64. //----------------------------------------------------------------------------
  65. STDAPI CLanguageProfileNotifySink::OnLanguageChange(LANGID langid, BOOL *pfAccept)
  66. {
  67. return _pfn ? _pfn(FALSE, langid, pfAccept, _pv) : S_OK;
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // OnLanguageChanged
  72. //
  73. //----------------------------------------------------------------------------
  74. STDAPI CLanguageProfileNotifySink::OnLanguageChanged()
  75. {
  76. return _pfn ? _pfn(TRUE, 0, NULL, _pv) : S_OK;
  77. }
  78. //+---------------------------------------------------------------------------
  79. //
  80. // CLanguageProfileNotifySink::Advise
  81. //
  82. //----------------------------------------------------------------------------
  83. HRESULT CLanguageProfileNotifySink::_Advise(ITfInputProcessorProfiles *pipp)
  84. {
  85. HRESULT hr;
  86. ITfSource *source = NULL;
  87. _pipp = NULL;
  88. hr = E_FAIL;
  89. if (FAILED(pipp->QueryInterface(IID_ITfSource, (void **)&source)))
  90. goto Exit;
  91. if (FAILED(source->AdviseSink(IID_ITfLanguageProfileNotifySink, this, &_dwCookie)))
  92. goto Exit;
  93. _pipp = pipp;
  94. _pipp->AddRef();
  95. hr = S_OK;
  96. Exit:
  97. SafeRelease(source);
  98. return hr;
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // CLanguageProfileNotifySink::Unadvise
  103. //
  104. //----------------------------------------------------------------------------
  105. HRESULT CLanguageProfileNotifySink::_Unadvise()
  106. {
  107. HRESULT hr;
  108. ITfSource *source = NULL;
  109. hr = E_FAIL;
  110. if (_pipp == NULL)
  111. goto Exit;
  112. if (FAILED(_pipp->QueryInterface(IID_ITfSource, (void **)&source)))
  113. goto Exit;
  114. if (FAILED(source->UnadviseSink(_dwCookie)))
  115. goto Exit;
  116. hr = S_OK;
  117. Exit:
  118. SafeRelease(source);
  119. SafeReleaseClear(_pipp);
  120. return hr;
  121. }