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.

289 lines
8.3 KiB

  1. //
  2. // fnrecon.h
  3. //
  4. #ifndef FNRECON_H
  5. #define FNRECON_H
  6. #include "private.h"
  7. #include "ctffunc.h"
  8. #include "sapilayr.h"
  9. #include "candlist.h"
  10. #include "mscandui.h"
  11. #include "ptrary.h"
  12. #include "lmobj.h"
  13. #include "propstor.h"
  14. #include "strary.h"
  15. #include "TabletTip.h"
  16. #define OPTION_REPLAY 0
  17. #define OPTION_DELETE 1
  18. #define OPTION_REDO 2
  19. class CSapiIMX;
  20. class CCandUIFilterEventSink;
  21. class CCandUIExtButtonEventSink;
  22. class CSapiAlternativeList ;
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // CFunction
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28. class CFunction
  29. {
  30. public:
  31. CFunction(CSapiIMX *pImx);
  32. ~CFunction();
  33. protected:
  34. BOOL GetFocusedTarget(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, BOOL bAdjust, ITfRange **ppRangeTmp);
  35. HRESULT _GetLangIdFromRange(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, LANGID *plangid);
  36. friend CSapiIMX;
  37. CSapiIMX *m_pImx;
  38. long m_cRef;
  39. };
  40. //
  41. // The member functions in this class are extracted from CFnReconversion,
  42. // We create this new class for a separate functionality that computes best prop range
  43. // for the given selected range.
  44. // This Class could be inherited by CFnReconversion and CSapiPlayBack.
  45. //
  46. class __declspec(novtable) CBestPropRange
  47. {
  48. public:
  49. CBestPropRange( )
  50. {
  51. m_MaxCandChars = 0;
  52. }
  53. ~CBestPropRange( )
  54. {
  55. }
  56. HRESULT _ComputeBestFitPropRange(TfEditCookie ec, ITfProperty *pProp, ITfRange *pRange, ITfRange **ppBestPropRange, ULONG *pulStart, ULONG *pulcElem);
  57. ULONG _GetMaxCandidateChars( );
  58. private:
  59. ULONG m_MaxCandChars;
  60. };
  61. class CFnReconversion : public ITfFnReconversion,
  62. public CFunction,
  63. public CMasterLMWrap,
  64. public CBestPropRange
  65. {
  66. public:
  67. CFnReconversion(CSapiIMX *psi);
  68. ~CFnReconversion();
  69. //
  70. // IUnknown methods
  71. //
  72. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  73. STDMETHODIMP_(ULONG) AddRef(void);
  74. STDMETHODIMP_(ULONG) Release(void);
  75. //
  76. // ITfFunction
  77. //
  78. STDMETHODIMP GetDisplayName(BSTR *pbstrCand);
  79. //
  80. // ITfFnReconversion
  81. //
  82. STDMETHODIMP QueryRange(ITfRange *pRange, ITfRange **ppNewRange, BOOL *pfConvertable);
  83. STDMETHODIMP GetReconversion(ITfRange *pRange, ITfCandidateList **ppCandList);
  84. STDMETHODIMP Reconvert(ITfRange *pRange);
  85. static HRESULT SetResult(ITfContext *pic, ITfRange *pRange, CCandidateString *pCand, TfCandidateResult imcr);
  86. static HRESULT SetOption(ITfContext *pic, ITfRange *pRange, CCandidateString *pCand, TfCandidateResult imcr);
  87. HRESULT _Reconvert(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, BOOL *pfCallLMReconvert);
  88. HRESULT _GetReconversion(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, ITfCandidateList **ppCandList, BOOL fDisableEngine = FALSE);
  89. HRESULT _QueryReconversion(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, ITfRange **ppNewRange);
  90. void _SetCurrentLangID(LANGID langid) { m_langid = langid;}
  91. HRESULT GetCandidateForRange(CSapiAlternativeList *psal, ITfContext *pic, ITfRange *pRange, ITfCandidateList **ppCandList) ;
  92. void _Commit(CCandidateString *pcand);
  93. CSapiAlternativeList *GetCSapiAlternativeList( ) { return m_psal; }
  94. HRESULT CFnReconversion::_GetSapilayrEngineInstance(ISpRecognizer **ppRecoEngine);
  95. friend CCandUIFilterEventSink;
  96. friend CCandUIExtButtonEventSink;
  97. // TABLET PC
  98. HRESULT GetTabletTip(void);
  99. CComPtr<ITipWindow> m_cpTabletTip;
  100. private:
  101. HRESULT ShowCandidateList(TfEditCookie ec, ITfContext *pic, ITfRange *pRange, ITfCandidateList *pCandList);
  102. LANGID m_langid;
  103. CSapiAlternativeList *m_psal;
  104. CComPtr<ISpRecoResult> m_cpRecoResult;
  105. };
  106. class CCandUIFilterEventSink : public ITfCandUIAutoFilterEventSink
  107. {
  108. public:
  109. CCandUIFilterEventSink(CFnReconversion *pfnReconv, ITfContext *pic, ITfCandidateUI *pCandUI)
  110. {
  111. m_pic = pic;
  112. m_pic->AddRef();
  113. m_pfnReconv = pfnReconv;
  114. m_pfnReconv->AddRef();
  115. m_pCandUI = pCandUI;
  116. m_cRef = 1;
  117. }
  118. ~CCandUIFilterEventSink()
  119. {
  120. SafeRelease(m_pic);
  121. SafeRelease(m_pfnReconv);
  122. }
  123. //
  124. // IUnknown methods
  125. //
  126. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  127. STDMETHODIMP_(ULONG) AddRef(void);
  128. STDMETHODIMP_(ULONG) Release(void);
  129. //
  130. // ITfCandUIAutoFilterEventSink
  131. //
  132. STDMETHODIMP OnFilterEvent(CANDUIFILTEREVENT ev);
  133. // STDMETHODIMP OnAddCharToFilterStringEvent(CANDUIFILTEREVENT ev, WCHAR wch, int nItemVisible, BOOL *bEten);
  134. ITfContext *m_pic;
  135. private:
  136. CFnReconversion *m_pfnReconv;
  137. ITfCandidateUI *m_pCandUI;
  138. long m_cRef;
  139. };
  140. class CSapiAlternativeList
  141. {
  142. public:
  143. CSapiAlternativeList(LANGID langid, ITfRange *pRange, ULONG ulMaxCandChars);
  144. ~CSapiAlternativeList();
  145. int GetNumItem();
  146. HRESULT SetPhraseAlt(CRecoResultWrap *pResWrap, ISpPhraseAlt **ppAlt, ULONG cAlt, ULONG ulStart, ULONG ulcElem, WCHAR *pwszParent);
  147. HRESULT GetCachedAltInfo(ULONG nId, ULONG *pulParentStart, ULONG *pulcParentElements, ULONG *pulcElements, WCHAR **ppwszText, ULONG *pulLeadSpaceRemoved=NULL);
  148. HRESULT GetAlternativeText(ISpPhraseAlt *pAlt, SPPHRASE *pPhrases, BOOL fFirstAlt, ULONG ulStartElem, ULONG ulNumElems, WCHAR *pwszAlt, int cchAlt, ULONG *pulLeadSpaceRemoved);
  149. HRESULT GetProbability(int nId, int * nProb);
  150. HRESULT AddLMAlternates(CLMAlternates *pLMAlt);
  151. BOOL IsSameRange(ITfRange *pRange, TfEditCookie ec)
  152. {
  153. Assert(m_cpRange);
  154. BOOL fEq = FALSE;
  155. HRESULT hr = pRange->IsEqualStart(ec,
  156. m_cpRange,
  157. TF_ANCHOR_START,
  158. &fEq);
  159. if (S_OK == hr )
  160. {
  161. if (fEq)
  162. {
  163. hr = pRange->IsEqualEnd(ec,
  164. m_cpRange,
  165. TF_ANCHOR_END,
  166. &fEq);
  167. }
  168. }
  169. return S_OK == hr && fEq;
  170. }
  171. void _Commit(ULONG nIdx, ISpRecoResult *pRecoResult);
  172. // Keep the current selection index
  173. //
  174. void _SaveCurrentSelectionIndex(ULONG ulIndexSelect)
  175. {
  176. m_ulIndexSelect = ulIndexSelect;
  177. }
  178. void _Speak(void)
  179. {
  180. if( m_cpwrp )
  181. {
  182. ULONG ulParentStart=0, ulParentNumElems=0;
  183. if ( S_OK == GetCachedAltInfo(m_ulIndexSelect, &ulParentStart, &ulParentNumElems, NULL, NULL) )
  184. {
  185. m_cpwrp->_SpeakAudio(ulParentStart, ulParentNumElems);
  186. }
  187. }
  188. }
  189. HRESULT _ProcessTrailingSpaces(SPPHRASE *pPhrases, ULONG ulNextElem, WCHAR *pwszAlt);
  190. CRecoResultWrap *GetResultWrap() { return m_cpwrp; }
  191. BOOL _GetUIFont(BOOL fVerticalWriting, LOGFONTW * plf);
  192. BOOL _IsFirstAltInCandidate( ) { return m_fFirstAltInCandidate; }
  193. BOOL _IsNoAlternate( ) { return m_fNoAlternate; }
  194. int _GetFakeAltIndex( ) { return m_iFakeAlternate; }
  195. private:
  196. int m_nItem;
  197. ULONG m_ulStart;
  198. ULONG m_ulcElem;
  199. ISpPhraseAlt **m_ppAlt;
  200. ULONG m_cAlt;
  201. CComPtr<ITfRange> m_cpRange;
  202. CPtrArray<CLMAlternates> *m_prgLMAlternates;
  203. typedef struct
  204. {
  205. ULONG ulParentStart;
  206. ULONG ulcParentElements;
  207. ULONG ulcElements;
  208. ULONG ulLeadSpaceRemoved; // the number of leading space to remove.
  209. WCHAR *pwszAltText;
  210. } SPELEMENTUSED;
  211. CStructArray<SPELEMENTUSED> m_rgElemUsed;
  212. LANGID m_langid;
  213. CComPtr<CRecoResultWrap> m_cpwrp;
  214. BOOL m_fFirstAltInCandidate;
  215. BOOL m_fNoAlternate;
  216. int m_iFakeAlternate;
  217. ULONG m_MaxCandChars;
  218. ULONG m_ulIndexSelect; // keep the index of the current selection in the candidate Window.
  219. };
  220. #define NO_FAKEALT -1
  221. #endif // FNRECON_H