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.

537 lines
14 KiB

  1. //
  2. //
  3. // Sapilayr Edit Sessions implementation.
  4. //
  5. //
  6. #include "private.h"
  7. #include "sapilayr.h"
  8. //
  9. // CEditSessionBase
  10. //
  11. CEditSessionBase::CEditSessionBase(ITfContext *pContext)
  12. {
  13. _cRef = 1;
  14. m_cpic = pContext;
  15. m_pData = NULL;
  16. m_lData1 = 0;
  17. m_lData2 = 0;
  18. m_fBool = FALSE;
  19. m_lRetData = 0;
  20. }
  21. CEditSessionBase::~CEditSessionBase()
  22. {
  23. if (m_pData)
  24. cicMemFree(m_pData);
  25. }
  26. // IUnknown
  27. HRESULT CEditSessionBase::QueryInterface(REFIID riid, void **ppvObj)
  28. {
  29. if (ppvObj == NULL)
  30. return E_INVALIDARG;
  31. *ppvObj = NULL;
  32. if (IsEqualIID(riid, IID_IUnknown) ||
  33. IsEqualIID(riid, IID_ITfEditSession))
  34. {
  35. *ppvObj = SAFECAST(this, CEditSessionBase *);
  36. }
  37. if (*ppvObj)
  38. {
  39. AddRef();
  40. return S_OK;
  41. }
  42. return E_NOINTERFACE;
  43. }
  44. STDMETHODIMP_(ULONG) CEditSessionBase::AddRef(void)
  45. {
  46. return ++_cRef;
  47. }
  48. STDMETHODIMP_(ULONG) CEditSessionBase::Release(void)
  49. {
  50. LONG cr = --_cRef;
  51. Assert(_cRef >= 0);
  52. if (_cRef == 0)
  53. {
  54. delete this;
  55. }
  56. return cr;
  57. }
  58. //
  59. // Set input data memeber and m_idEditSession.
  60. //
  61. HRESULT CEditSessionBase::_SetEditSessionData(UINT idEditSession, void *pData, UINT uByte, LONG_PTR lData1, LONG_PTR lData2, BOOL fBool)
  62. {
  63. HRESULT hr = S_OK;
  64. if ( uByte )
  65. {
  66. m_pData = cicMemAlloc(uByte);
  67. if ( m_pData )
  68. {
  69. if ( pData )
  70. memcpy(m_pData, pData, uByte);
  71. }
  72. else
  73. hr = E_OUTOFMEMORY;
  74. }
  75. if ( hr == S_OK )
  76. {
  77. m_idEditSession = idEditSession;
  78. m_lData1 = lData1;
  79. m_lData2 = lData2;
  80. m_fBool = fBool;
  81. }
  82. return hr;
  83. }
  84. //
  85. // CSapiEditSession
  86. //
  87. //
  88. CSapiEditSession::CSapiEditSession(CSapiIMX *pimx, ITfContext *pContext) : CEditSessionBase(pContext)
  89. {
  90. m_pimx = pimx;
  91. pimx->AddRef( );
  92. }
  93. CSapiEditSession::~CSapiEditSession( )
  94. {
  95. m_pimx->Release( );
  96. }
  97. //
  98. // Do the real Edit Session handling for CSapiIMX
  99. //
  100. HRESULT CSapiEditSession::DoEditSession(TfEditCookie ec)
  101. {
  102. HRESULT hr = S_OK;
  103. Assert(m_pimx);
  104. switch(m_idEditSession)
  105. {
  106. case ESCB_FINALIZECOMP:
  107. hr = m_pimx->_KillFocusRange(ec, m_cpic, NULL, m_pimx->_GetId( ) );
  108. break;
  109. case ESCB_FINALIZE_ALL_COMPS :
  110. hr = m_pimx->_FinalizeAllCompositions(ec, m_cpic);
  111. break;
  112. case ESCB_FEEDBACKUI:
  113. hr = m_pimx->_AddFeedbackUI(ec, m_pimx->IsFocusFullAware(m_pimx->_tim)
  114. ? DA_COLOR_AWARE : DA_COLOR_UNAWARE,
  115. (LONG)_GetData1( ));
  116. break;
  117. case ESCB_KILLFEEDBACKUI:
  118. hr = m_pimx->_KillFeedbackUI(ec, m_cpic, _GetRange( ));
  119. break;
  120. case ESCB_DETECTFEEDBACKUI:
  121. hr = m_pimx->_DetectFeedbackUI(ec, m_cpic, _GetRange( ));
  122. break;
  123. case ESCB_KILLLASTPHRASE:
  124. hr = m_pimx->_KillLastPhrase(ec, m_cpic);
  125. break;
  126. case ESCB_FEEDCURRENTIP:
  127. hr = m_pimx->_InternalFeedCurrentIPtoSR(ec, m_cpic);
  128. break;
  129. case ESCB_PROCESSCONTROLKEY:
  130. hr = m_pimx->_ProcessControlKeys(ec, m_cpic, (WCHAR *)_GetPtrData( ), (ULONG)_GetData1( ), (LANGID)_GetData2( ));
  131. break;
  132. case ESCB_PROCESS_EDIT_COMMAND :
  133. hr = m_pimx->_ProcessEditCommands(ec, m_cpic, (ULONG)_GetData1( ));
  134. break;
  135. case ESCB_PROCESS_SPELL_THAT :
  136. hr = m_pimx->_ProcessSpellThat(ec, m_cpic);
  137. break;
  138. case ESCB_PROCESS_SPELL_IT :
  139. hr = m_pimx->_ProcessSpellIt(ec, m_cpic, (WCHAR *)_GetPtrData( ), (LANGID)_GetData1( ));
  140. break;
  141. case ESCB_TTS_PLAY :
  142. hr = m_pimx->_TtsPlay(ec, m_cpic);
  143. break;
  144. case ESCB_PROCESS_CAP_COMMANDS :
  145. if ( m_pimx->GetCapCmdHandler( ))
  146. {
  147. CCapCmdHandler *pCapCmdHandler;
  148. pCapCmdHandler = m_pimx->GetCapCmdHandler( );
  149. hr = pCapCmdHandler->_ProcessCapCommands(ec,
  150. m_cpic,
  151. (CAPCOMMAND_ID)_GetData1( ),
  152. (WCHAR *)_GetPtrData( ),
  153. (ULONG)_GetData2( )
  154. );
  155. }
  156. break;
  157. case ESCB_SETREPSELECTION:
  158. // Set the selection which covers the parent phrase range to be replaced by an alternate.
  159. if (m_cpic && _GetRange( ))
  160. {
  161. // adjust selection based on the length of the alternates and the start position in the parent phrase.
  162. hr = m_pimx->_SetReplaceSelection(ec, m_cpic, _GetRange( ), (ULONG)_GetData1( ), (ULONG)_GetData2( ));
  163. }
  164. break;
  165. case ESCB_PROCESS_ALTERNATE_TEXT:
  166. // We have already set the right selection before this function is called.
  167. hr = m_pimx->_ProcessAlternateText(ec,(WCHAR *)_GetPtrData( ),(LANGID)_GetData1( ), m_cpic, _GetBool( ));
  168. break;
  169. case ESCB_RESTORE_CORRECT_ORGIP :
  170. hr = m_pimx->_RestoreCorrectOrgIP(ec, m_cpic);
  171. break;
  172. case ESCB_PROCESSTEXT:
  173. hr = m_pimx->_ProcessText(ec, (WCHAR *)_GetPtrData( ), (LANGID)_GetData1( ), m_cpic);
  174. break;
  175. /* we don't use this editsession, it is replaced by ESCB_INJECT_SPELL_TEXT
  176. case ESCB_PROCESSTEXT_NO_OWNERID:
  177. if (m_cpic)
  178. {
  179. hr = m_pimx->_ProcessTextInternal(ec,
  180. (WCHAR *)_GetPtrData( ), GUID_ATTR_SAPI_INPUT,
  181. (LANGID)_GetData1( ), m_cpic,
  182. FALSE, TRUE);
  183. }
  184. break;
  185. */
  186. case ESCB_INJECT_SPELL_TEXT :
  187. hr = m_pimx->_ProcessSpelledText(ec, m_cpic, (WCHAR *)_GetPtrData( ), (LANGID)_GetData1( ), _GetBool());
  188. break;
  189. case ESCB_PROCESS_MODEBIAS_TEXT :
  190. hr = m_pimx->_ProcessModebiasText(ec, (WCHAR *)_GetPtrData( ), (LANGID)_GetData1( ), m_cpic);
  191. break;
  192. case ESCB_ATTACHRECORESULTOBJ:
  193. // m_cpunk contains the pointer to ISpRecoResult object
  194. hr = m_pimx->_ProcessRecoObject(ec, (ISpRecoResult *)_GetUnk( ), (ULONG)_GetData1( ), (ULONG)_GetData2( ));
  195. break;
  196. case ESCB_HANDLESPACES:
  197. if (_GetRange( ) && m_cpic)
  198. hr = m_pimx->_ProcessSpaces( ec,
  199. m_cpic,
  200. _GetRange( ),
  201. _GetBool( ),
  202. (ULONG)_GetData2( ),
  203. (LANGID)_GetData1( ));
  204. break;
  205. case ESCB_COMPLETE:
  206. hr = m_pimx->MakeResultString(ec, m_cpic, _GetRange( ), m_pimx->_tid, m_pimx->m_pCSpTask);
  207. break;
  208. case ESCB_ABORT:
  209. hr = m_pimx->AbortString(ec, m_cpic, m_pimx->m_pCSpTask);
  210. break;
  211. case ESCB_RECONV_ONIP:
  212. hr = m_pimx->_CorrectThat(ec, m_cpic);
  213. break;
  214. case ESCB_UPDATEFILTERSTR:
  215. hr = m_pimx->_SetFilteringString(ec, (ITfCandidateUI *)_GetUnk( ), m_cpic);
  216. break;
  217. case ESCB_SYNCMBWITHSEL:
  218. hr = m_pimx->_SyncModeBiasWithSelectionCallback(ec, m_cpic);
  219. break;
  220. case ESCB_GETRANGETEXT:
  221. WCHAR *pText;
  222. ULONG ulSize;
  223. pText = (WCHAR *)_GetPtrData( );
  224. ulSize = (ULONG)_GetData2( );
  225. hr = _GetRange( )->GetText(ec, (ULONG)_GetData1( ), pText, ulSize, (ULONG *)&m_lRetData);
  226. break;
  227. case ESCB_ISRANGEEMPTY:
  228. hr = _GetRange( )->IsEmpty(ec, (BOOL *)&m_lRetData);
  229. break;
  230. case ESCB_HANDLE_ADDDELETE_WORD:
  231. hr = m_pimx->_HandleAddDeleteWord(ec, m_cpic);
  232. break;
  233. case ESCB_HANDLE_LEARNFROMDOC:
  234. hr = m_pimx->_HandleLearnFromDoc(ec, m_cpic, (ITfDocumentMgr *)_GetUnk( ));
  235. break;
  236. case ESCB_LEARNDOC_NEXTRANGE:
  237. hr = m_pimx->_HandleNextRange(ec, (ULONG)_GetData1( ));
  238. break;
  239. case ESCB_HANDLERECOGNITION:
  240. m_pimx->_HandleRecognition((ISpRecoResult *)_GetUnk( ), m_cpic, ec);
  241. break;
  242. case ESCB_HANDLEHYPOTHESIS:
  243. m_pimx->_HandleHypothesis((ISpRecoResult *)_GetUnk( ), m_cpic, ec);
  244. break;
  245. case ESCB_SAVECURIP_ADDDELETEUI:
  246. hr = m_pimx->_SaveCurIPAndHandleAddDeleteUI(ec, m_cpic);
  247. break;
  248. case ESCB_HANDLE_MOUSESINK:
  249. hr = m_pimx->_HandleMouseSink(ec, (ULONG)_GetData1(), (ULONG)_GetData2(), _GetBool());
  250. break;
  251. default:
  252. Assert(0);
  253. break;
  254. }
  255. return hr;
  256. }
  257. //
  258. // CSelWordEditSession
  259. //
  260. CSelWordEditSession::CSelWordEditSession(CSapiIMX *pimx, CSelectWord *pSelWord, ITfContext *pContext) : CSapiEditSession(pimx, pContext)
  261. {
  262. m_pSelWord = pSelWord;
  263. }
  264. CSelWordEditSession::~CSelWordEditSession( )
  265. {
  266. }
  267. //
  268. // Real Edit Session handling for Selection related commands.
  269. //
  270. HRESULT CSelWordEditSession::DoEditSession(TfEditCookie ec)
  271. {
  272. HRESULT hr = S_OK;
  273. Assert(m_pSelWord);
  274. switch(m_idEditSession)
  275. {
  276. case ESCB_UPDATE_TEXT_BUFFER :
  277. hr = m_pSelWord->_UpdateTextBuffer(ec, m_cpic, (ISpRecoContext *)_GetUnk(), (ISpRecoGrammar *)_GetUnk2() );
  278. break;
  279. case ESCB_PROCESSSELECTWORD :
  280. hr = m_pSelWord->_HandleSelectWord(ec, m_cpic, (WCHAR *)_GetPtrData( ),(ULONG)_GetData1( ),(SELECTWORD_OPERATION)_GetData2( ), (ULONG)_GetLenXXX( ) );
  281. break;
  282. default:
  283. Assert(0);
  284. break;
  285. }
  286. return hr;
  287. }
  288. //
  289. // CPlayBackEditSession
  290. //
  291. //
  292. CPlayBackEditSession::CPlayBackEditSession(CSapiPlayBack *pPlayBack, ITfContext *pContext) : CEditSessionBase(pContext)
  293. {
  294. m_pPlayBack = pPlayBack;
  295. m_pPlayBack->AddRef( );
  296. }
  297. CPlayBackEditSession::~CPlayBackEditSession( )
  298. {
  299. m_pPlayBack->Release( );
  300. }
  301. //
  302. // Real Edit Session handling for PlayBack.
  303. //
  304. HRESULT CPlayBackEditSession::DoEditSession(TfEditCookie ec)
  305. {
  306. HRESULT hr = S_OK;
  307. Assert(m_pPlayBack);
  308. switch(m_idEditSession)
  309. {
  310. case ESCB_PLAYBK_PLAYSND:
  311. return m_pPlayBack->_PlaySound(ec, _GetRange( ) );
  312. case ESCB_PLAYBK_PLAYSNDSELECTION:
  313. return m_pPlayBack->_PlaySoundSelection(ec, m_cpic);
  314. default:
  315. Assert(0);
  316. break;
  317. }
  318. return hr;
  319. }
  320. //
  321. // CFnRecvEditSession
  322. //
  323. CFnRecvEditSession::CFnRecvEditSession(CFnReconversion *pFnRecv, ITfRange *pRange, ITfContext *pContext) : CEditSessionBase(pContext)
  324. {
  325. m_pFnRecv = pFnRecv;
  326. m_pFnRecv->AddRef( );
  327. _SetRange(pRange);
  328. }
  329. CFnRecvEditSession::~CFnRecvEditSession( )
  330. {
  331. m_pFnRecv->Release( );
  332. }
  333. //
  334. // Real Edit Session for Reconvertion.
  335. //
  336. HRESULT CFnRecvEditSession::DoEditSession(TfEditCookie ec)
  337. {
  338. HRESULT hr = S_OK;
  339. Assert(m_pFnRecv);
  340. switch(m_idEditSession)
  341. {
  342. case ESCB_RECONV_QUERYRECONV:
  343. return m_pFnRecv->_QueryReconversion(ec, m_cpic, _GetRange( ), (ITfRange **)&m_cpRetUnk);
  344. case ESCB_RECONV_GETRECONV:
  345. return m_pFnRecv->_GetReconversion(ec, m_cpic, _GetRange( ), (ITfCandidateList **)&m_cpRetUnk, TRUE);
  346. case ESCB_RECONV_RECONV:
  347. return m_pFnRecv->_Reconvert(ec, m_cpic, _GetRange( ), (BOOL *)&m_lRetData);
  348. default:
  349. Assert(0);
  350. break;
  351. }
  352. return hr;
  353. }
  354. //
  355. // CPSRecoEditSession
  356. //
  357. CPSRecoEditSession::CPSRecoEditSession(CPropStoreRecoResultObject *pPropStoreReco, ITfRange *pRange, ITfContext *pContext) : CEditSessionBase(pContext)
  358. {
  359. m_pPropStoreReco = pPropStoreReco;
  360. m_pPropStoreReco->AddRef( );
  361. _SetRange(pRange);
  362. }
  363. CPSRecoEditSession::~CPSRecoEditSession( )
  364. {
  365. m_pPropStoreReco->Release( );
  366. }
  367. //
  368. // Real Edit Session handling for RecoResult Property Store
  369. //
  370. HRESULT CPSRecoEditSession::DoEditSession(TfEditCookie ec)
  371. {
  372. HRESULT hr = S_OK;
  373. Assert(m_pPropStoreReco);
  374. switch(m_idEditSession)
  375. {
  376. case ESCB_PROP_DIVIDE:
  377. hr = m_pPropStoreReco->_Divide(ec,_GetRange( ),(ITfRange *)_GetUnk( ),(ITfPropertyStore **)&m_cpRetUnk);
  378. break;
  379. case ESCB_PROP_SHRINK:
  380. hr = m_pPropStoreReco->_Shrink(ec,_GetRange( ), (BOOL *)&m_lRetData);
  381. break;
  382. case ESCB_PROP_TEXTUPDATE:
  383. hr = m_pPropStoreReco->_OnTextUpdated(ec, (DWORD)_GetData1( ), _GetRange( ), (BOOL *)&m_lRetData);
  384. break;
  385. default:
  386. Assert(0);
  387. break;
  388. }
  389. return hr;
  390. }
  391. //
  392. // CPSLMEditSession
  393. //
  394. CPSLMEditSession::CPSLMEditSession(CPropStoreLMLattice *pPropStoreLM, ITfRange *pRange, ITfContext *pContext) : CEditSessionBase(pContext)
  395. {
  396. m_pPropStoreLM = pPropStoreLM;
  397. m_pPropStoreLM->AddRef( );
  398. _SetRange(pRange);
  399. }
  400. CPSLMEditSession::~CPSLMEditSession( )
  401. {
  402. m_pPropStoreLM->Release( );
  403. }
  404. //
  405. // Real edit session for Language Model Property Store.
  406. //
  407. HRESULT CPSLMEditSession::DoEditSession(TfEditCookie ec)
  408. {
  409. HRESULT hr = S_OK;
  410. Assert(m_pPropStoreLM);
  411. switch(m_idEditSession)
  412. {
  413. case ESCB_PROP_DIVIDE:
  414. hr = m_pPropStoreLM->_Divide(ec,_GetRange( ),(ITfRange *)_GetUnk( ), (ITfPropertyStore **)&m_cpRetUnk);
  415. break;
  416. default:
  417. Assert(0);
  418. break;
  419. }
  420. return hr;
  421. }