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.

265 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. cic.cpp
  5. Abstract:
  6. This file implements the ImmIfIME Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "globals.h"
  13. #include "imeapp.h"
  14. #include "immif.h"
  15. #include "profile.h"
  16. HRESULT
  17. ImmIfIME::QueryService(
  18. REFGUID guidService,
  19. REFIID riid,
  20. void **ppv
  21. )
  22. {
  23. if (ppv == NULL) {
  24. return E_INVALIDARG;
  25. }
  26. *ppv = NULL;
  27. if (!IsEqualGUID(guidService, GUID_SERVICE_TF))
  28. return E_INVALIDARG /*SVC_E_UNKNOWNSERVICE*/; // SVC_E_UNKNOWNSERVICE is in msdn, but not any nt source/headers
  29. if (IsEqualIID(riid, IID_ITfThreadMgr)) {
  30. if (m_tim) {
  31. *ppv = SAFECAST(m_tim, ITfThreadMgr*);
  32. m_tim->AddRef();
  33. return S_OK;
  34. }
  35. }
  36. else {
  37. IMTLS *ptls = IMTLS_GetOrAlloc();
  38. if (ptls == NULL)
  39. return E_FAIL;
  40. IMCLock imc(ptls->hIMC);
  41. HRESULT hr;
  42. if (FAILED(hr=imc.GetResult()))
  43. return hr;
  44. if (IsEqualIID(riid, IID_ITfDocumentMgr)) {
  45. ITfDocumentMgr *pdim = GetDocumentManager(imc).GetPtr();
  46. if (pdim) {
  47. *ppv = SAFECAST(pdim, ITfDocumentMgr*);
  48. pdim->AddRef();
  49. return S_OK;
  50. }
  51. }
  52. else if (IsEqualIID(riid, IID_ITfContext)) {
  53. ITfContext *pic = GetInputContext(imc).GetPtr();
  54. if (pic) {
  55. *ppv = SAFECAST(pic, ITfContext*);
  56. pic->AddRef();
  57. return S_OK;
  58. }
  59. }
  60. }
  61. DebugMsg(TF_ERROR, "QueryService: cannot find the interface. riid=%p", riid);
  62. return E_NOINTERFACE;
  63. }
  64. HRESULT
  65. ImmIfIME::InitIMMX(
  66. )
  67. {
  68. ITfThreadMgr *tim;
  69. IMTLS *ptls;
  70. DebugMsg(TF_FUNC, "InitIMMX: entered. :: TID=%x", GetCurrentThreadId());
  71. HRESULT hr;
  72. if (m_fCicInit)
  73. return S_OK;
  74. Assert(m_tim == NULL);
  75. Assert(m_AImeProfile == NULL);
  76. Assert(m_pkm == NULL);
  77. Assert(m_tfClientId == TF_CLIENTID_NULL);
  78. ptls = IMTLS_GetOrAlloc();
  79. if (ptls == NULL)
  80. return E_FAIL;
  81. //
  82. // Create ITfThreadMgr instance.
  83. //
  84. if (ptls->tim == NULL)
  85. {
  86. if (FindAtom(TF_ENABLE_PROCESS_ATOM) && ! FindAtom(AIMM12_PROCESS_ATOM))
  87. {
  88. //
  89. // This is CTF aware application.
  90. //
  91. return E_NOINTERFACE;
  92. }
  93. //
  94. // This is AIMM1.2 aware application.
  95. //
  96. AddAtom(AIMM12_PROCESS_ATOM);
  97. m_fAddedProcessAtom = TRUE;
  98. //
  99. // ITfThreadMgr is per thread instance.
  100. //
  101. hr = TF_CreateThreadMgr(&tim);
  102. if (hr != S_OK)
  103. {
  104. Assert(0); // couldn't create tim!
  105. goto ExitError;
  106. }
  107. hr = tim->QueryInterface(IID_ITfThreadMgr_P, (void **)&m_tim);
  108. tim->Release();
  109. if (hr != S_OK || m_tim == NULL)
  110. {
  111. Assert(0); // couldn't find ITfThreadMgr_P
  112. m_tim = NULL;
  113. goto ExitError;
  114. }
  115. Assert(ptls->tim == NULL);
  116. ptls->tim = m_tim; // Set ITfThreadMgr instance in the TLS data.
  117. ptls->tim->AddRef();
  118. }
  119. else
  120. {
  121. m_tim = ptls->tim;
  122. m_tim->AddRef();
  123. }
  124. //
  125. // Create CAImeProfile instance.
  126. //
  127. if (ptls->pAImeProfile == NULL)
  128. {
  129. //
  130. // IAImeProfile is per thread instance.
  131. //
  132. hr = CAImeProfile::CreateInstance(NULL,
  133. IID_IAImeProfile,
  134. (void**) &m_AImeProfile);
  135. if (FAILED(hr))
  136. {
  137. Assert(0); // couldn't create profile
  138. m_AImeProfile = NULL;
  139. goto ExitError;
  140. }
  141. Assert(ptls->pAImeProfile == m_AImeProfile); // CreateInst will set tls
  142. }
  143. else
  144. {
  145. m_AImeProfile = ptls->pAImeProfile;
  146. m_AImeProfile->AddRef();
  147. }
  148. //
  149. // get the keystroke manager ready
  150. //
  151. if (FAILED(::GetService(m_tim, IID_ITfKeystrokeMgr, (IUnknown **)&m_pkm))) {
  152. Assert(0); // couldn't get ksm!
  153. goto ExitError;
  154. }
  155. // cleanup/error code assumes this is the last thing we do, doesn't call
  156. // UninitDAL on error
  157. if (FAILED(InitDisplayAttrbuteLib(&_libTLS)))
  158. {
  159. Assert(0); // couldn't init lib!
  160. goto ExitError;
  161. }
  162. m_fCicInit = TRUE;
  163. return S_OK;
  164. ExitError:
  165. UnInitIMMX();
  166. return E_FAIL;
  167. }
  168. void
  169. ImmIfIME::UnInitIMMX(
  170. )
  171. {
  172. IMTLS *ptls;
  173. DebugMsg(TF_FUNC, TEXT("ImmIfIME::UnInitIMMX :: TID=%x"), GetCurrentThreadId());
  174. // clear the display lib
  175. UninitDisplayAttrbuteLib(&_libTLS);
  176. TFUninitLib_Thread(&_libTLS);
  177. // clear the keystroke mgr
  178. SafeReleaseClear(m_pkm);
  179. ptls = IMTLS_GetOrAlloc();
  180. // clear the profile
  181. if (m_AImeProfile != NULL)
  182. {
  183. SafeReleaseClear(m_AImeProfile);
  184. if (ptls != NULL)
  185. {
  186. SafeReleaseClear(ptls->pAImeProfile);
  187. }
  188. }
  189. // clear empty dim.
  190. SafeReleaseClear(m_dimEmpty);
  191. // clear the thread mgr
  192. if (m_tim != NULL)
  193. {
  194. SafeReleaseClear(m_tim);
  195. if (ptls != NULL)
  196. {
  197. SafeReleaseClear(ptls->tim);
  198. }
  199. //
  200. // Remove AIMM1.2 aware application ATOM.
  201. //
  202. ATOM atom;
  203. if (m_fAddedProcessAtom &&
  204. (atom = FindAtom(AIMM12_PROCESS_ATOM)))
  205. {
  206. DeleteAtom(atom);
  207. m_fAddedProcessAtom = FALSE;
  208. }
  209. }
  210. m_fCicInit = FALSE;
  211. }