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.

259 lines
8.8 KiB

  1. //
  2. // property store class implementation
  3. //
  4. #ifndef PROPSTOR_H
  5. #define PROPSTOR_H
  6. #include "strary.h"
  7. extern const IID IID_PRIV_RESULTWRAP;
  8. typedef enum
  9. {
  10. DivideNormal = 1,
  11. DivideInsideFirstElement=2 ,
  12. DivideInDelta = 3,
  13. CurRangeNoElement = 4,
  14. } DIVIDECASE;
  15. // A Data structure to keep the ITN position and showstate.
  16. typedef struct _tagSPITNSHOWSTATE
  17. {
  18. ULONG ulITNStart;
  19. ULONG ulITNNumElem;
  20. BOOL fITNShown;
  21. } SPITNSHOWSTATE;
  22. // A Data Structure to keep the data in Reco Wrapper which will be saved during serialization.
  23. typedef struct _tagRecoWrapData
  24. {
  25. ULONG ulSize; // size of this structure + plus the size of text string in bytes.
  26. ULONG ulStartElement;
  27. ULONG ulNumElements;
  28. ULONG ulOffsetDelta;
  29. ULONG ulCharsInTrail;
  30. ULONG ulTrailSpaceRemoved;
  31. ULONG ulNumOfITN;
  32. ULONG ulOffsetNum;
  33. SPITNSHOWSTATE *pITNShowState;
  34. ULONG *pulOffset;
  35. WCHAR *pwszText;
  36. } RECOWRAPDATA;
  37. class CSapiIMX;
  38. //
  39. // A wrapper object for ISpRecoResult used to
  40. // track what portion of a phrase object is being
  41. // used for the range
  42. //
  43. class CRecoResultWrap : public IServiceProvider
  44. {
  45. public:
  46. CRecoResultWrap(CSapiIMX *pimx, ULONG ulStartElement, ULONG ulNumElements, ULONG ulNumOfITN) ;
  47. ~CRecoResultWrap();
  48. // IUnknown
  49. //
  50. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  51. STDMETHODIMP_(ULONG) AddRef(void);
  52. STDMETHODIMP_(ULONG) Release(void);
  53. // IServiceProvider
  54. STDMETHODIMP QueryService( REFGUID guidService, REFIID riid, void** ppv );
  55. // Clone this object.
  56. HRESULT Clone(CRecoResultWrap **ppRw);
  57. // APIs
  58. HRESULT Init(ISpRecoResult *pRecoResult);
  59. ULONG GetStart(void) {return m_ulStartElement;}
  60. ULONG GetNumElements(void) {return m_ulNumElements;}
  61. HRESULT GetResult(ISpRecoResult **ppRecoResult );
  62. BOOL IsElementOffsetIntialized( ) { return m_pulElementOffsets == NULL ? FALSE : TRUE; }
  63. void SetStart(ULONG ulStartElement ) { m_ulStartElement = ulStartElement; return; }
  64. void SetNumElements(ULONG ulNumElements ) { m_ulNumElements = ulNumElements; return; }
  65. void SetOffsetDelta( ULONG delta ) { m_OffsetDelta = delta; return; }
  66. ULONG _GetOffsetDelta( ) { return m_OffsetDelta; }
  67. void SetCharsInTrail( ULONG ulCharsInTrail ) { m_ulCharsInTrail = ulCharsInTrail; }
  68. ULONG GetCharsInTrail( ) { return m_ulCharsInTrail; }
  69. ULONG GetTrailSpaceRemoved( ) { return m_ulTrailSpaceRemoved; }
  70. void SetTrailSpaceRemoved( ULONG ulTrailSpaceRemoved ) { m_ulTrailSpaceRemoved = ulTrailSpaceRemoved; return; }
  71. HRESULT _SpeakAudio(ULONG ulStart, ULONG ulcElem);
  72. ULONG _GetElementOffsetCch(ULONG ulElement);
  73. void _SetElementOffsetCch(ISpPhraseAlt *pAlt);
  74. HRESULT _SetElementNewOffset(ULONG ulElement, ULONG ulNewOffset);
  75. ULONG _RangeHasITN(ULONG ulStartElement, ULONG ulNumElements);
  76. BOOL _CheckITNForElement(SPPHRASE *pPhrase, ULONG ulElement, ULONG *pulITNStart, ULONG *pulITNNumElem, CSpDynamicString *pdstrReplace);
  77. BYTE _GetElementDispAttribute(ULONG ulElement);
  78. HRESULT _InitITNShowState(BOOL fITNShown, ULONG ulITNStart, ULONG ulITNNumElements);
  79. HRESULT _InvertITNShowStateForRange( ULONG ulStartElement, ULONG ulNumElements );
  80. HRESULT _UpdateStateWithAltPhrase( ISpPhraseAlt *pSpPhraseAlt );
  81. void _UpdateInternalText(ISpPhrase *pPhrase);
  82. BOOL _CanIgnoreChange(ULONG ich, WCHAR *pszChange, int cch);
  83. ULONG m_ulNumOfITN; // the number of ITN in this range ( from start element to end element in this recowrap.
  84. CStructArray<SPITNSHOWSTATE> m_rgITNShowState;
  85. BSTR m_bstrCurrentText; // the current text for the parent pharse
  86. private:
  87. CSapiIMX *m_pimx;
  88. ULONG m_ulStartElement;
  89. ULONG m_ulNumElements;
  90. ULONG *m_pulElementOffsets;
  91. ULONG m_OffsetDelta; // This is for Divide use, if prop is divided at a middle of an element,
  92. // this element would be discarded, but we need to keep the char number of the rest in this element,
  93. // so that the next range would keep correct offsets for every element.
  94. ULONG m_ulCharsInTrail; // This will keep the number of trailing part which is at the end part of the
  95. // current parent text, and is not in any valid phrase element.
  96. // By default this value is 0.
  97. //
  98. // Now a whole parent text would be composed of following three parts:
  99. // Delta part + valid elements + Trailing Part.
  100. //
  101. // For example: the original parent text is "This is a good example for testing ".
  102. // After divided many times, it could become to the new string like:
  103. //
  104. // "s is a good example for tes"
  105. //
  106. // Here "s " is Delta part.
  107. // "a good example for " is composed of valid elements. ( and can be change by correction later)
  108. // "tes" is trailing part.
  109. //
  110. // m_OffsetDelta will keep the number of characters in Delta part.
  111. // m_ulCharsInTrail will keep the number of characters in Trailing part.
  112. //
  113. ULONG m_ulTrailSpaceRemoved; // Keep the number of trailing spaces which were
  114. // removed from the original phrase text.
  115. // The Initialize value for this data member is 0,
  116. // But after Property Divided or Shrinked, the new
  117. // property range could have some trailing spaces
  118. // removed, and this data memeber needs to update.
  119. SPSERIALIZEDRESULT *m_pSerializedRecoResult;
  120. int m_cRef;
  121. #ifdef DEBUG
  122. DWORD m_dbg_dwId;
  123. #endif // DEBUG
  124. };
  125. //
  126. // [12/21/99 - implementing propstore for non-serialized SAPI result object]
  127. //
  128. //
  129. class CPropStoreRecoResultObject: public ITfPropertyStore
  130. {
  131. public:
  132. CPropStoreRecoResultObject(CSapiIMX *pimx, ITfRange *pRange);
  133. ~CPropStoreRecoResultObject();
  134. // IUnknown
  135. //
  136. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  137. STDMETHODIMP_(ULONG) AddRef(void);
  138. STDMETHODIMP_(ULONG) Release(void);
  139. // ITfPropertyStore
  140. STDMETHODIMP GetType(GUID *pguid);
  141. STDMETHODIMP GetDataType(DWORD *pdwReserved);
  142. STDMETHODIMP GetData(VARIANT *pvarValue);
  143. STDMETHODIMP OnTextUpdated(DWORD dwFlags, ITfRange *pRange, BOOL *pfAccept);
  144. STDMETHODIMP Shrink(ITfRange *pRange, BOOL *pfFree);
  145. STDMETHODIMP Divide(ITfRange *pRangeThis, ITfRange *pRangeNew, ITfPropertyStore **ppPropStore);
  146. STDMETHODIMP Clone(ITfPropertyStore **ppPropStore);
  147. STDMETHODIMP GetPropertyRangeCreator(CLSID *pclsid);
  148. STDMETHODIMP Serialize(IStream *pStream, ULONG *pcb);
  149. // public APIs
  150. HRESULT _InitFromRecoResult(ISpRecoResult *pResult, RECOWRAPDATA *pRecoWrapData);
  151. HRESULT _InitFromIStream(IStream *pStream, int iSize, ISpRecoContext *pRecoCtxt);
  152. HRESULT _InitFromResultWrap(IUnknown *pResWrap);
  153. HRESULT _Divide(TfEditCookie ec, ITfRange *pR1, ITfRange *pR2, ITfPropertyStore **ppPs);
  154. HRESULT _Shrink(TfEditCookie ec, ITfRange *pRange,BOOL *pfFree);
  155. HRESULT _OnTextUpdated(TfEditCookie ec, DWORD dwFlags, ITfRange *pRange, BOOL *pfAccept);
  156. private:
  157. CComPtr<IUnknown> m_cpResultWrap;
  158. CComPtr<ITfRange> m_cpRange;
  159. CSapiIMX *m_pimx;
  160. int m_cRef;
  161. };
  162. class CPropStoreLMLattice: public ITfPropertyStore
  163. {
  164. public:
  165. CPropStoreLMLattice(CSapiIMX *pimx);
  166. ~CPropStoreLMLattice();
  167. // IUnknown
  168. //
  169. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  170. STDMETHODIMP_(ULONG) AddRef(void);
  171. STDMETHODIMP_(ULONG) Release(void);
  172. // ITfPropertyStore
  173. STDMETHODIMP GetType(GUID *pguid);
  174. STDMETHODIMP GetDataType(DWORD *pdwReserved);
  175. STDMETHODIMP GetData(VARIANT *pvarValue);
  176. STDMETHODIMP OnTextUpdated(DWORD dwFlags, ITfRange *pRange, BOOL *pfAccept);
  177. STDMETHODIMP Shrink(ITfRange *pRange, BOOL *pfFree);
  178. STDMETHODIMP Divide(ITfRange *pRangeThis, ITfRange *pRangeNew, ITfPropertyStore **ppPropStore);
  179. STDMETHODIMP Clone(ITfPropertyStore **ppPropStore);
  180. STDMETHODIMP GetPropertyRangeCreator(CLSID *pclsid);
  181. STDMETHODIMP Serialize(IStream *pStream, ULONG *pcb);
  182. // public APIs
  183. HRESULT _InitFromResultWrap(IUnknown *pResWrap);
  184. HRESULT _Divide(TfEditCookie ec, ITfRange *pR1, ITfRange *pR2, ITfPropertyStore **ppPs);
  185. private:
  186. CComPtr<IUnknown> m_cpResultWrap;
  187. CComPtr<ITfLMLattice> m_cpLMLattice;
  188. CSapiIMX *m_pimx;
  189. int m_cRef;
  190. };
  191. #endif