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.

257 lines
9.6 KiB

  1. //
  2. // acp2anch.h
  3. //
  4. #ifndef ACP2ANCH_H
  5. #define ACP2ANCH_H
  6. #include "private.h"
  7. #include "strary.h"
  8. #include "ptrary.h"
  9. class CInputContext;
  10. class CAnchorRef;
  11. class CAnchor;
  12. class CACPWrap;
  13. extern const IID IID_PRIV_ACPWRAP;
  14. // PSEUDO_ESCB_SERIALIZE_ACP params
  15. typedef struct _SERIALIZE_ACP_PARAMS
  16. {
  17. CACPWrap *pWrap;
  18. ITfProperty *pProp;
  19. ITfRange *pRange;
  20. TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr;
  21. IStream *pStream;
  22. } SERIALIZE_ACP_PARAMS;
  23. // PSEUDO_ESCB_UNSERIALIZE_ACP params
  24. typedef struct _UNSERIALIZE_ACP_PARAMS
  25. {
  26. CACPWrap *pWrap;
  27. ITfProperty *pProp;
  28. const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr;
  29. IStream *pStream;
  30. ITfPersistentPropertyLoaderACP *pLoaderACP;
  31. } UNSERIALIZE_ACP_PARAMS;
  32. //////////////////////////////////////////////////////////////////////////////
  33. //
  34. // CLoaderACPWrap
  35. //
  36. //////////////////////////////////////////////////////////////////////////////
  37. class CLoaderACPWrap : public ITfPersistentPropertyLoaderAnchor,
  38. public CComObjectRootImmx
  39. {
  40. public:
  41. CLoaderACPWrap(ITfPersistentPropertyLoaderACP *loader);
  42. ~CLoaderACPWrap();
  43. BEGIN_COM_MAP_IMMX(CLoaderACPWrap)
  44. COM_INTERFACE_ENTRY(ITfPersistentPropertyLoaderAnchor)
  45. END_COM_MAP_IMMX()
  46. IMMX_OBJECT_IUNKNOWN_FOR_ATL()
  47. // ITfPersistentPropertyLoaderACP
  48. STDMETHODIMP LoadProperty(const TF_PERSISTENT_PROPERTY_HEADER_ANCHOR *pHdr, IStream **ppStream);
  49. private:
  50. ITfPersistentPropertyLoaderACP *_loader;
  51. DBG_ID_DECLARE;
  52. };
  53. //////////////////////////////////////////////////////////////////////////////
  54. //
  55. // CACPWrap
  56. //
  57. //////////////////////////////////////////////////////////////////////////////
  58. class CACPWrap : public ITextStoreAnchor,
  59. public ITextStoreACPSink,
  60. public ITextStoreACPServices,
  61. public ITfMouseTrackerACP,
  62. public IServiceProvider
  63. {
  64. public:
  65. CACPWrap(ITextStoreACP *ptsi);
  66. ~CACPWrap();
  67. //
  68. // IUnknown methods
  69. //
  70. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  71. STDMETHODIMP_(ULONG) AddRef(void);
  72. STDMETHODIMP_(ULONG) Release(void);
  73. // ITextStoreACPSink
  74. STDMETHODIMP OnTextChange(DWORD dwFlags, const TS_TEXTCHANGE *pChange);
  75. STDMETHODIMP OnSelectionChange();
  76. STDMETHODIMP OnLayoutChange(TsLayoutCode lcode, TsViewCookie vcView);
  77. STDMETHODIMP OnStatusChange(DWORD dwFlags);
  78. STDMETHODIMP OnAttrsChange(LONG acpStart, LONG acpEnd, ULONG cAttrs, const TS_ATTRID *paAttrs);
  79. STDMETHODIMP OnLockGranted(DWORD dwLockFlags);
  80. STDMETHODIMP OnStartEditTransaction();
  81. STDMETHODIMP OnEndEditTransaction();
  82. // ITextStoreACPServices
  83. STDMETHODIMP Serialize(ITfProperty *pProp, ITfRange *pRange, TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream);
  84. STDMETHODIMP ForceLoadProperty(ITfProperty *pProp);
  85. STDMETHODIMP Unserialize(ITfProperty *pProp, const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream, ITfPersistentPropertyLoaderACP *pLoader);
  86. STDMETHODIMP CreateRange(LONG acpStart, LONG acpEnd, ITfRangeACP **ppRange);
  87. // ITextStoreAnchor
  88. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD dwMask);
  89. STDMETHODIMP UnadviseSink(IUnknown *punk);
  90. STDMETHODIMP RequestLock(DWORD dwLockFlags, HRESULT *phrSession);
  91. STDMETHODIMP GetStatus(TS_STATUS *pdcs);
  92. STDMETHODIMP QueryInsert(IAnchor *paTestStart, IAnchor *paTestEnd, ULONG cch, IAnchor **ppaResultStart, IAnchor **ppaResultEnd);
  93. STDMETHODIMP GetSelection(ULONG ulIndex, ULONG ulCount, TS_SELECTION_ANCHOR *pSelection, ULONG *pcFetched);
  94. STDMETHODIMP SetSelection(ULONG ulCount, const TS_SELECTION_ANCHOR *pSelection);
  95. STDMETHODIMP GetText(DWORD dwFlags, IAnchor *paStart, IAnchor *paEnd, WCHAR *pchText, ULONG cchReq, ULONG *pcch, BOOL fUpdateAnchor);
  96. STDMETHODIMP SetText(DWORD dwFlags, IAnchor *paStart, IAnchor *paEnd, const WCHAR *pchText, ULONG cch);
  97. STDMETHODIMP GetFormattedText(IAnchor *paStart, IAnchor *paEnd, IDataObject **ppDataObject);
  98. STDMETHODIMP GetEmbedded(DWORD dwFlags, IAnchor *paPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk);
  99. STDMETHODIMP QueryInsertEmbedded(const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable);
  100. STDMETHODIMP InsertEmbedded(DWORD dwFlags, IAnchor *paStart, IAnchor *paEnd, IDataObject *pDataObject);
  101. STDMETHODIMP RequestSupportedAttrs (DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs);
  102. STDMETHODIMP RequestAttrsAtPosition(IAnchor *paPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags);
  103. STDMETHODIMP RequestAttrsTransitioningAtPosition(IAnchor *paPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags);
  104. STDMETHODIMP FindNextAttrTransition(IAnchor *paStart, IAnchor *paHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags, BOOL *pfFound, LONG *plFoundOffset);
  105. STDMETHODIMP RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched);
  106. STDMETHODIMP GetStart(IAnchor **ppaStart);
  107. STDMETHODIMP GetEnd(IAnchor **ppaEnd);
  108. STDMETHODIMP GetActiveView(TsViewCookie *pvcView);
  109. STDMETHODIMP GetAnchorFromPoint(TsViewCookie vcView, const POINT *pt, DWORD dwFlags, IAnchor **ppaSite);
  110. STDMETHODIMP GetTextExt(TsViewCookie vcView, IAnchor *paStart, IAnchor *paEnd, RECT *prc, BOOL *pfClipped);
  111. STDMETHODIMP GetScreenExt(TsViewCookie vcView, RECT *prc);
  112. STDMETHODIMP GetWnd(TsViewCookie vcView, HWND *phwnd);
  113. STDMETHODIMP InsertTextAtSelection(DWORD dwFlags, const WCHAR *pchText, ULONG cch, IAnchor **ppaStart, IAnchor **ppaEnd);
  114. STDMETHODIMP InsertEmbeddedAtSelection(DWORD dwFlags, IDataObject *pDataObject, IAnchor **ppaStart, IAnchor **ppaEnd);
  115. // ITfMouseTrackerACP
  116. STDMETHODIMP AdviseMouseSink(ITfRangeACP *range, ITfMouseSink *pSink, DWORD *pdwCookie);
  117. STDMETHODIMP UnadviseMouseSink(DWORD dwCookie);
  118. // IServiceProvider
  119. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  120. HRESULT _Serialize(ITfProperty *pProp, ITfRange *pRange, TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream);
  121. HRESULT _Unserialize(ITfProperty *pProp, const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream, ITfPersistentPropertyLoaderACP *pLoader);
  122. void _OnLockReleased();
  123. CAnchorRef *_CreateAnchorACP(LONG acp, TsGravity gravity);
  124. CAnchorRef *_CreateAnchorAnchor(CAnchor *pa, TsGravity gravity);
  125. ITextStoreACP *_GetTSI() { return _ptsi; }
  126. void _Dbg_AssertNoAppLock()
  127. {
  128. #ifdef DEBUG
  129. Assert(!_Dbg_fAppHasLock); // if we get here, it means the app has called OnTextChange
  130. // and someone (prob. the app) is trying to use a range object before calling
  131. // OnLockGranted (cicero will have asked for a lock inside OnTextChange).
  132. #endif
  133. }
  134. HRESULT _ACPHdrToAnchor(const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, TF_PERSISTENT_PROPERTY_HEADER_ANCHOR *phanch);
  135. void _OnAnchorRelease()
  136. {
  137. if (_cRef == 0 && _GetAnchorRef() == 0)
  138. {
  139. delete this;
  140. }
  141. }
  142. BOOL _IsDisconnected() { return (_ptsi == NULL); }
  143. CInputContext *_GetContext()
  144. {
  145. return _pic;
  146. }
  147. void _NormalizeAnchor(CAnchor *pa);
  148. BOOL _InOnTextChange()
  149. {
  150. return _fInOnTextChange;
  151. }
  152. private:
  153. friend CLoaderACPWrap;
  154. friend CAnchor;
  155. friend CAnchorRef;
  156. void _PostInsertUpdate(LONG acpStart, LONG acpEnd, ULONG cch, const TS_TEXTCHANGE *ptsTextChange);
  157. static BOOL _AnchorHdrToACP(const TF_PERSISTENT_PROPERTY_HEADER_ANCHOR *phanch, TF_PERSISTENT_PROPERTY_HEADER_ACP *phacp);
  158. LONG _GetAnchorRef() { return _GetCount(); }
  159. CAnchor *_FindWithinPendingRange(LONG acp)
  160. {
  161. int iIndex;
  162. Assert(_lPendingDelta != 0);
  163. Assert(_lPendingDeltaIndex < _rgAnchors.Count());
  164. return _FindInnerLoop(acp, _lPendingDeltaIndex+1, _rgAnchors.Count(), &iIndex);
  165. }
  166. HRESULT _Insert(CAnchorRef *par, LONG ich);
  167. HRESULT _Insert(CAnchorRef *par, CAnchor *pa);
  168. void _Remove(CAnchorRef *par);
  169. void _Update(const TS_TEXTCHANGE *pdctc);
  170. void _Renormalize(int ichStart, int ichEnd);
  171. LONG _GetCount() { return _rgAnchors.Count(); }
  172. void _DragAnchors(LONG acpFrom, LONG acpTo);
  173. LONG _GetPendingDelta()
  174. {
  175. return _lPendingDelta;
  176. }
  177. LONG _GetPendingDeltaIndex()
  178. {
  179. return _lPendingDeltaIndex;
  180. }
  181. CAnchor *_GetPendingDeltaAnchor()
  182. {
  183. return _rgAnchors.Get(_lPendingDeltaIndex);
  184. }
  185. BOOL _IsPendingDelta()
  186. {
  187. return _lPendingDelta != 0 && _lPendingDeltaIndex < _rgAnchors.Count();
  188. }
  189. CAnchor *_Find(int ich, int *piOut = NULL);
  190. CAnchor *_FindInnerLoop(LONG acp, int iMin, int iMax, int *piIndex);
  191. int _Update(CAnchor *pa, int ichNew, int iOrg, CAnchor *paInto, int iInto);
  192. void _Merge(CAnchor *paInto, CAnchor *paFrom);
  193. void _Delete(CAnchor *pa);
  194. void _AdjustIchs(int iFirst, int dSize);
  195. void _TrackDelHistory(int iEndOrg, BOOL fExactEndOrgMatch, int iEndNew, BOOL fExactEndNewMatch);
  196. #ifdef DEBUG
  197. void _Dbg_AssertAnchors();
  198. #else
  199. void _Dbg_AssertAnchors() {}
  200. #endif
  201. BOOL _fInOnTextChange : 1; // TRUE if we're inside OnTextChange
  202. CPtrArray<CAnchor> _rgAnchors;
  203. LONG _lPendingDeltaIndex;
  204. LONG _lPendingDelta;
  205. ITextStoreACP *_ptsi;
  206. ITextStoreAnchorSink *_ptss;
  207. CInputContext *_pic;
  208. LONG _cRef;
  209. #ifdef DEBUG
  210. BOOL _Dbg_fAppHasLock;
  211. #endif
  212. DBG_ID_DECLARE;
  213. };
  214. #endif // ACP2ANCH_H