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.

190 lines
6.8 KiB

  1. //
  2. // mark.h
  3. //
  4. // CMarkTextService declaration.
  5. //
  6. #ifndef MARK_H
  7. #define MARK_H
  8. class CLangBarItemButton;
  9. class CMarkTextService : public ITfTextInputProcessor,
  10. public ITfDisplayAttributeProvider,
  11. public ITfCreatePropertyStore,
  12. public ITfThreadMgrEventSink,
  13. public ITfTextEditSink,
  14. public ITfCompositionSink,
  15. public ITfCleanupContextDurationSink,
  16. public ITfCleanupContextSink,
  17. public ITfCompartmentEventSink,
  18. public ITfKeyEventSink
  19. {
  20. public:
  21. CMarkTextService();
  22. ~CMarkTextService();
  23. // IUnknown
  24. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  25. STDMETHODIMP_(ULONG) AddRef(void);
  26. STDMETHODIMP_(ULONG) Release(void);
  27. // ITfTextInputProcessor
  28. STDMETHODIMP Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClientId);
  29. STDMETHODIMP Deactivate();
  30. // ITfDisplayAttributeProvider
  31. STDMETHODIMP EnumDisplayAttributeInfo(IEnumTfDisplayAttributeInfo **ppEnum);
  32. STDMETHODIMP GetDisplayAttributeInfo(REFGUID guidInfo, ITfDisplayAttributeInfo **ppInfo);
  33. // ITfCreatePropertyStore
  34. STDMETHODIMP IsStoreSerializable(REFGUID guidProperty, ITfRange *pRange, ITfPropertyStore *pPropertyStore, BOOL *pfSerializable);
  35. STDMETHODIMP CreatePropertyStore(REFGUID guidProperty, ITfRange *pRange, ULONG cb, IStream *pStream, ITfPropertyStore **ppStore);
  36. // ITfThreadMgrEventSink
  37. STDMETHODIMP OnInitDocumentMgr(ITfDocumentMgr *pDocMgr);
  38. STDMETHODIMP OnUninitDocumentMgr(ITfDocumentMgr *pDocMgr);
  39. STDMETHODIMP OnSetFocus(ITfDocumentMgr *pDocMgrFocus, ITfDocumentMgr *pDocMgrPrevFocus);
  40. STDMETHODIMP OnPushContext(ITfContext *pContext);
  41. STDMETHODIMP OnPopContext(ITfContext *pContext);
  42. // ITfTextEditSink
  43. STDMETHODIMP OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord);
  44. // ITfCompositionSink
  45. STDMETHODIMP OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition *pComposition);
  46. // ITfCleanupContextDurationSink
  47. STDMETHODIMP OnStartCleanupContext();
  48. STDMETHODIMP OnEndCleanupContext();
  49. // ITfCleanupContextSink
  50. STDMETHODIMP OnCleanupContext(TfEditCookie ecWrite, ITfContext *pContext);
  51. // ITfCompartmentEventSink
  52. STDMETHODIMP OnChange(REFGUID rguidCompartment);
  53. // ITfKeyEventSink
  54. STDMETHODIMP OnSetFocus(BOOL fForeground);
  55. STDMETHODIMP OnTestKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  56. STDMETHODIMP OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  57. STDMETHODIMP OnTestKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  58. STDMETHODIMP OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  59. STDMETHODIMP OnPreservedKey(ITfContext *pContext, REFGUID rguid, BOOL *pfEaten);
  60. // CClassFactory factory callback
  61. static HRESULT CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj);
  62. // server registration
  63. static BOOL RegisterProfiles();
  64. static void UnregisterProfiles();
  65. static BOOL RegisterCategories(BOOL fRegister);
  66. static BOOL RegisterServer();
  67. static void UnregisterServer();
  68. // language bar menu handlers
  69. static void _Menu_OnComposition(CMarkTextService *_this);
  70. static void _Menu_OnSetGlobalCompartment(CMarkTextService *_this);
  71. static void _Menu_OnSetCaseProperty(CMarkTextService *_this);
  72. static void _Menu_OnViewCaseProperty(CMarkTextService *_this);
  73. static void _Menu_OnViewCustomProperty(CMarkTextService *_this);
  74. static void _Menu_OnSetCustomProperty(CMarkTextService *_this);
  75. // keystroke handlers
  76. HRESULT _HandleKeyDown(TfEditCookie ec, ITfContext *pContext, WPARAM wParam);
  77. HRESULT _HandleArrowKey(TfEditCookie ec, ITfContext *pContext, WPARAM wParam);
  78. HRESULT _HandleReturn(TfEditCookie ec, ITfContext *pContext);
  79. // callbacks for CCompositionEditSession
  80. BOOL _IsComposing()
  81. {
  82. return _pComposition != NULL;
  83. }
  84. ITfComposition *_GetComposition()
  85. {
  86. return _pComposition;
  87. }
  88. void _SetComposition(ITfComposition *pComposition)
  89. {
  90. _pComposition = pComposition;
  91. }
  92. void _TerminateComposition(TfEditCookie ec)
  93. {
  94. if (_pComposition != NULL)
  95. {
  96. _ClearCompositionDisplayAttributes(ec);
  97. _pComposition->EndComposition(ec);
  98. SafeReleaseClear(_pComposition);
  99. }
  100. }
  101. void _TerminateCompositionInContext(ITfContext *pContext);
  102. void _ClearCompositionDisplayAttributes(TfEditCookie ec);
  103. BOOL _SetCompositionDisplayAttributes(TfEditCookie ec);
  104. // messages for the worker wnd
  105. enum { WM_DISPLAY_PROPERTY = WM_USER + 1 };
  106. // property methods
  107. void _ViewCaseProperty(TfEditCookie ec, ITfContext *pContext);
  108. void _SetCaseProperty(TfEditCookie ec, ITfContext *pContext);
  109. void _ViewCustomProperty(TfEditCookie ec, ITfContext *pContext);
  110. void _SetCustomProperty(TfEditCookie ec, ITfContext *pContext);
  111. private:
  112. // init methods
  113. BOOL _InitLanguageBar();
  114. BOOL _InitThreadMgrSink();
  115. BOOL _InitTextEditSink(ITfDocumentMgr *pDocMgr);
  116. BOOL _InitDisplayAttributeGuidAtom();
  117. BOOL _InitCleanupContextDurationSink();
  118. BOOL _InitCleanupContextSink(ITfContext *pContext);
  119. BOOL _InitContextCompartment(ITfContext *pContext);
  120. BOOL _InitGlobalCompartment();
  121. BOOL _InitWorkerWnd();
  122. BOOL _InitKeystrokeSink();
  123. // uninit methods
  124. void _UninitLanguageBar();
  125. void _UninitThreadMgrSink();
  126. void _UninitCleanupContextDurationSink();
  127. void _UninitCleanupContextSink(ITfContext *pContext);
  128. void _UninitCompartment(ITfContext *pContext);
  129. void _UninitGlobalCompartment();
  130. void _UninitWorkerWnd();
  131. void _UninitKeystrokeSink();
  132. // property methods
  133. void _RequestPropertyEditSession(ULONG ulCallback);
  134. static LRESULT CALLBACK _WorkerWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  135. //
  136. // state
  137. //
  138. ITfThreadMgr *_pThreadMgr;
  139. TfClientId _tfClientId;
  140. ITfComposition *_pComposition; // pointer to an ongoing composition, or NULL if there is none
  141. BOOL _fCleaningUp;
  142. TfGuidAtom _gaDisplayAttribute;
  143. CLangBarItemButton *_pLangBarItem;
  144. DWORD _dwThreadMgrEventSinkCookie;
  145. DWORD _dwThreadFocusSinkCookie;
  146. DWORD _dwTextEditSinkCookie;
  147. DWORD _dwGlobalCompartmentEventSinkCookie;
  148. ITfContext *_pTextEditSinkContext;
  149. HWND _hWorkerWnd;
  150. // buffers for the popup property displays
  151. WCHAR _achDisplayText[64];
  152. WCHAR _achDisplayPropertyText[64];
  153. LONG _cRef; // COM ref count
  154. };
  155. #endif // MARK_H