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.

133 lines
3.7 KiB

  1. //
  2. // tmgrsink.cpp
  3. //
  4. // ITfThreadMgrEventSink implementation.
  5. //
  6. #include "globals.h"
  7. #include "case.h"
  8. #include "snoop.h"
  9. //+---------------------------------------------------------------------------
  10. //
  11. // OnInitDocumentMgr
  12. //
  13. // Sink called by the framework just before the first context is pushed onto
  14. // a document.
  15. //----------------------------------------------------------------------------
  16. STDAPI CCaseTextService::OnInitDocumentMgr(ITfDocumentMgr *pDocMgr)
  17. {
  18. return S_OK;
  19. }
  20. //+---------------------------------------------------------------------------
  21. //
  22. // OnUninitDocumentMgr
  23. //
  24. // Sink called by the framework just after the last context is popped off a
  25. // document.
  26. //----------------------------------------------------------------------------
  27. STDAPI CCaseTextService::OnUninitDocumentMgr(ITfDocumentMgr *pDocMgr)
  28. {
  29. return S_OK;
  30. }
  31. //+---------------------------------------------------------------------------
  32. //
  33. // OnSetFocus
  34. //
  35. // Sink called by the framework when focus changes from one document to
  36. // another. Either document may be NULL, meaning previously there was no
  37. // focus document, or now no document holds the input focus.
  38. //----------------------------------------------------------------------------
  39. STDAPI CCaseTextService::OnSetFocus(ITfDocumentMgr *pDocMgrFocus, ITfDocumentMgr *pDocMgrPrevFocus)
  40. {
  41. // track text changes on the focus doc
  42. // we are guarenteed a final OnSetFocus(NULL, ..) which we use for cleanup
  43. _InitTextEditSink(pDocMgrFocus);
  44. // let's update the snoop window with text from the new focus context
  45. _pSnoopWnd->_UpdateText(NULL);
  46. return S_OK;
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // OnPushContext
  51. //
  52. // Sink called by the framework when a context is pushed.
  53. //----------------------------------------------------------------------------
  54. STDAPI CCaseTextService::OnPushContext(ITfContext *pContext)
  55. {
  56. return S_OK;
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // OnPopContext
  61. //
  62. // Sink called by the framework when a context is popped.
  63. //----------------------------------------------------------------------------
  64. STDAPI CCaseTextService::OnPopContext(ITfContext *pContext)
  65. {
  66. return S_OK;
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // _InitThreadMgrSink
  71. //
  72. // Advise our sink.
  73. //----------------------------------------------------------------------------
  74. BOOL CCaseTextService::_InitThreadMgrSink()
  75. {
  76. ITfSource *pSource;
  77. BOOL fRet;
  78. if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
  79. return FALSE;
  80. fRet = FALSE;
  81. if (pSource->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *)this, &_dwThreadMgrEventSinkCookie) != S_OK)
  82. {
  83. // make sure we don't try to Unadvise _dwThreadMgrEventSinkCookie later
  84. _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
  85. goto Exit;
  86. }
  87. fRet = TRUE;
  88. Exit:
  89. pSource->Release();
  90. return fRet;
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // _UninitThreadMgrSink
  95. //
  96. // Unadvise our sink.
  97. //----------------------------------------------------------------------------
  98. void CCaseTextService::_UninitThreadMgrSink()
  99. {
  100. ITfSource *pSource;
  101. if (_dwThreadMgrEventSinkCookie == TF_INVALID_COOKIE)
  102. return; // never Advised
  103. if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
  104. {
  105. pSource->UnadviseSink(_dwThreadMgrEventSinkCookie);
  106. pSource->Release();
  107. }
  108. _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
  109. }