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.

114 lines
3.2 KiB

  1. //
  2. // editsink.cpp
  3. //
  4. // ITfTextEditSink implementation.
  5. //
  6. #include "globals.h"
  7. #include "case.h"
  8. #include "snoop.h"
  9. //+---------------------------------------------------------------------------
  10. //
  11. // OnEndEdit
  12. //
  13. // Called by the system whenever anyone releases a write-access document lock.
  14. //----------------------------------------------------------------------------
  15. STDAPI CCaseTextService::OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
  16. {
  17. BOOL fSelectionChanged;
  18. IEnumTfRanges *pEnumTextChanges;
  19. ITfRange *pRange;
  20. // we'll use the endedit notification to update the snoop window
  21. // did the selection change?
  22. if (pEditRecord->GetSelectionStatus(&fSelectionChanged) == S_OK &&
  23. fSelectionChanged)
  24. {
  25. _pSnoopWnd->_UpdateText(ecReadOnly, pContext, NULL);
  26. return S_OK;
  27. }
  28. // text modification?
  29. if (pEditRecord->GetTextAndPropertyUpdates(TF_GTP_INCL_TEXT, NULL, 0, &pEnumTextChanges) == S_OK)
  30. {
  31. if (pEnumTextChanges->Next(1, &pRange, NULL) == S_OK)
  32. {
  33. // arbitrary update the snoop window with the first change
  34. // there may be more than one in the enumerator, but we don't care here
  35. _pSnoopWnd->_UpdateText(ecReadOnly, pContext, pRange);
  36. pRange->Release();
  37. }
  38. pEnumTextChanges->Release();
  39. }
  40. // if we get here, only property values changed
  41. return S_OK;
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // _InitTextEditSink
  46. //
  47. // Init a text edit sink on the topmost context of the document.
  48. // Always release any previous sink.
  49. //----------------------------------------------------------------------------
  50. BOOL CCaseTextService::_InitTextEditSink(ITfDocumentMgr *pDocMgr)
  51. {
  52. ITfSource *pSource;
  53. BOOL fRet;
  54. // clear out any previous sink first
  55. if (_dwTextEditSinkCookie != TF_INVALID_COOKIE)
  56. {
  57. if (_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
  58. {
  59. pSource->UnadviseSink(_dwTextEditSinkCookie);
  60. pSource->Release();
  61. }
  62. _pTextEditSinkContext->Release();
  63. _pTextEditSinkContext = NULL;
  64. _dwTextEditSinkCookie = TF_INVALID_COOKIE;
  65. }
  66. if (pDocMgr == NULL)
  67. return TRUE; // caller just wanted to clear the previous sink
  68. // setup a new sink advised to the topmost context of the document
  69. if (pDocMgr->GetTop(&_pTextEditSinkContext) != S_OK)
  70. return FALSE;
  71. if (_pTextEditSinkContext == NULL)
  72. return TRUE; // empty document, no sink possible
  73. fRet = FALSE;
  74. if (_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
  75. {
  76. if (pSource->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &_dwTextEditSinkCookie) == S_OK)
  77. {
  78. fRet = TRUE;
  79. }
  80. else
  81. {
  82. _dwTextEditSinkCookie = TF_INVALID_COOKIE;
  83. }
  84. pSource->Release();
  85. }
  86. if (fRet == FALSE)
  87. {
  88. _pTextEditSinkContext->Release();
  89. _pTextEditSinkContext = NULL;
  90. }
  91. return fRet;
  92. }