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.

312 lines
7.6 KiB

  1. //
  2. // range.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "korimx.h"
  7. #include "xstring.h"
  8. #include "immxutil.h"
  9. #include "helpers.h"
  10. #include "kes.h"
  11. #include "mes.h"
  12. #include "editcb.h"
  13. #if 0
  14. void CKorIMX::BackupRange(TfEditCookie ec, ITfContext *pic, ITfRange* pRange)
  15. {
  16. CICPriv *picp = GetICPriv(pic);
  17. if (pic && picp && pRange)
  18. {
  19. ITfRangeBackup* pBackupRange = NULL;
  20. //
  21. // release previuos
  22. //
  23. pBackupRange = picp->GetBackupRange();
  24. if (pBackupRange)
  25. SafeReleaseClear(pBackupRange);
  26. //
  27. // create new backup range
  28. //
  29. pic->CreateRangeBackup(ec, pRange, &pBackupRange);
  30. picp->SetBackupRange(pBackupRange);
  31. if (pBackupRange == NULL)
  32. return;
  33. }
  34. }
  35. VOID CKorIMX::RestoreRange(TfEditCookie ec, ITfContext *pic)
  36. {
  37. CICPriv *picp = GetICPriv(pic);
  38. if (pic && picp)
  39. {
  40. ITfRangeBackup *pBackupRange = picp->GetBackupRange();
  41. ITfRange *pRange;
  42. if (pBackupRange == NULL)
  43. return; // no backup is exist
  44. pBackupRange->GetRange(&pRange);
  45. pBackupRange->Restore(ec, pRange); // restore to original
  46. pRange->Release();
  47. }
  48. }
  49. VOID CKorIMX::SetIPRange(TfEditCookie ec, ITfContext *pic, ITfRange* pRange)
  50. {
  51. CICPriv *picp = GetInputContextPriv(pic);
  52. if (picp)
  53. {
  54. ITfRange* pClone = NULL;
  55. // delete previous IPRange
  56. SafeRelease(picp->GetActiveRange());
  57. if (pRange)
  58. {
  59. Assert(m_ptim != NULL);
  60. pRange->Clone(&pClone);
  61. pClone->SetGravity(ec, TF_GRAVITY_FORWARD, TF_GRAVITY_BACKWARD);
  62. }
  63. else
  64. {
  65. // delete property store
  66. // ResetDiscard();
  67. }
  68. picp->SetActiveRange(pClone);
  69. }
  70. }
  71. ITfRange* CKorIMX::GetIPRange(TfEditCookie ec, ITfContext *pic)
  72. {
  73. CICPriv *picp = GetInputContextPriv(pic);
  74. if (picp)
  75. {
  76. ITfRange* pRange;
  77. ITfRange* pClone = NULL;
  78. pRange = picp->GetActiveRange();
  79. if (pRange)
  80. {
  81. pRange->Clone(&pClone);
  82. pClone->SetGravity(ec, TF_GRAVITY_BACKWARD, TF_GRAVITY_FORWARD);
  83. }
  84. return pClone;
  85. }
  86. return NULL;
  87. }
  88. ITfRange* CKorIMX::CreateIPRange(TfEditCookie ec, ITfContext *pic, ITfRange* pRangeOrg)
  89. {
  90. ITfRange* pRangeIP;
  91. if (pRangeOrg == NULL)
  92. return NULL;
  93. Assert(m_ptim != NULL);
  94. pRangeOrg->Clone(&pRangeIP);
  95. SetIPRange(ec, pic, pRangeIP); // register
  96. pRangeIP->SetGravity(ec, TF_GRAVITY_BACKWARD, TF_GRAVITY_FORWARD);
  97. return pRangeIP;
  98. }
  99. BOOL CKorIMX::FlushIPRange(TfEditCookie ec, ITfContext *pic)
  100. {
  101. // reset range
  102. SetIPRange(ec, pic, NULL); // reset
  103. // clear attribute range
  104. // ClearAttr(ec, pic, pIPRange);
  105. return FALSE;
  106. }
  107. #endif
  108. //+---------------------------------------------------------------------------
  109. //
  110. // OnCompositionTerminated
  111. //
  112. // Cicero calls this method when one of our compositions is terminated.
  113. //----------------------------------------------------------------------------
  114. STDAPI CKorIMX::OnCompositionTerminated(TfEditCookie ec, ITfComposition *pComposition)
  115. {
  116. ITfRange *pRange;
  117. ITfContext *pic;
  118. CEditSession2 *pes;
  119. ESSTRUCT ess;
  120. HRESULT hr;
  121. // finalize the covered text.
  122. // nb: there are no rules about what a tip has to do when it recevies this
  123. // callback. We will clear out the display attributes arbirarily and because
  124. // it provides visual feedback for testing.
  125. pComposition->GetRange(&pRange);
  126. pRange->GetContext(&pic);
  127. hr = E_OUTOFMEMORY;
  128. ESStructInit(&ess, ESCB_COMPLETE);
  129. ess.pRange = pRange;
  130. if (pes = new CEditSession2(pic, this, &ess, CKorIMX::_EditSessionCallback2))
  131. {
  132. // Word will not allow synchronous lock at this point.
  133. pes->Invoke(ES2_READWRITE | ES2_SYNC, &hr);
  134. pes->Release();
  135. }
  136. pRange->Release();
  137. pic->Release();
  138. return S_OK;
  139. }
  140. ITfComposition * CKorIMX::GetIPComposition(ITfContext *pic)
  141. {
  142. CICPriv *picp = GetInputContextPriv(pic);
  143. if (picp)
  144. return picp->GetActiveComposition();
  145. return NULL;
  146. }
  147. ITfComposition * CKorIMX::CreateIPComposition(TfEditCookie ec, ITfContext *pic, ITfRange* pRangeComp)
  148. {
  149. ITfContextComposition *picc;
  150. ITfComposition *pComposition;
  151. CICPriv *pICPriv;
  152. HRESULT hr;
  153. if (pRangeComp == NULL)
  154. return NULL;
  155. hr = pic->QueryInterface(IID_ITfContextComposition, (void **)&picc);
  156. Assert(hr == S_OK);
  157. if (picc->StartComposition(ec, pRangeComp, this, &pComposition) == S_OK)
  158. {
  159. if (pComposition != NULL) // NULL if the app rejects the composition
  160. {
  161. CICPriv *picp = GetInputContextPriv(pic);
  162. if (picp)
  163. SetIPComposition(pic, pComposition);
  164. else
  165. {
  166. pComposition->Release();
  167. pComposition = NULL;
  168. }
  169. }
  170. }
  171. picc->Release();
  172. // Create Mouse sink only for AIMM
  173. if (GetAIMM(pic) && (pICPriv = GetInputContextPriv(pic)) != NULL)
  174. {
  175. CMouseSink *pMouseSink;
  176. // Create Mouse sink
  177. if ((pMouseSink = pICPriv->GetMouseSink()) != NULL)
  178. {
  179. pMouseSink->_Unadvise();
  180. pMouseSink->Release();
  181. pICPriv->SetMouseSink(NULL);
  182. }
  183. if (pMouseSink = new CMouseSink(CICPriv::_MouseCallback, pICPriv))
  184. {
  185. pICPriv->SetMouseSink(pMouseSink);
  186. // set inward gravity to hug the text
  187. pRangeComp->SetGravity(ec, TF_GRAVITY_FORWARD, TF_GRAVITY_BACKWARD);
  188. pMouseSink->_Advise(pRangeComp, pic);
  189. }
  190. }
  191. return pComposition;
  192. }
  193. void CKorIMX::SetIPComposition(ITfContext *pic, ITfComposition *pComposition)
  194. {
  195. CICPriv *picp = GetInputContextPriv(pic);
  196. if (picp)
  197. picp->SetActiveComposition(pComposition);
  198. }
  199. BOOL CKorIMX::EndIPComposition(TfEditCookie ec, ITfContext *pic)
  200. {
  201. ITfComposition *pComposition;
  202. pComposition = GetIPComposition(pic);
  203. if (pComposition)
  204. {
  205. CICPriv *pICPriv;
  206. SetIPComposition(pic, NULL);
  207. pComposition->EndComposition(ec);
  208. pComposition->Release();
  209. // kill any mouse sinks
  210. if (GetAIMM(pic) && (pICPriv = GetInputContextPriv(pic)) != NULL)
  211. {
  212. CMouseSink *pMouseSink;
  213. if ((pMouseSink = pICPriv->GetMouseSink()) != NULL)
  214. {
  215. pMouseSink->_Unadvise();
  216. pMouseSink->Release();
  217. pICPriv->SetMouseSink(NULL);
  218. }
  219. }
  220. return TRUE;
  221. }
  222. return FALSE;
  223. }
  224. #if 0
  225. VOID CKorIMX::RestoreRangeRequest(ITfContext* pic)
  226. {
  227. CEditSession *pes;
  228. HRESULT hr;
  229. if (pic == NULL)
  230. return;
  231. if (pes = new CEditSession(_EditSessionCallback))
  232. {
  233. pes->_state.u = ESCB_RESTORERANGE;
  234. pes->_state.pv = (VOID*)this;
  235. pes->_state.wParam = (WPARAM)0;
  236. pes->_state.pRange = NULL;
  237. pes->_state.pic = pic;
  238. pic->EditSession( m_tid, pes, TF_ES_READWRITE | TF_ES_SYNC, &hr);
  239. SafeRelease(pes);
  240. }
  241. }
  242. #endif