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.

302 lines
8.9 KiB

  1. /****************************************************************************
  2. ACTIVATE.CPP : Init/Uninit Cicero services on the thread
  3. History:
  4. 24-JAN-2000 CSLim Created
  5. ****************************************************************************/
  6. #include "private.h"
  7. #include "korimx.h"
  8. #include "immxutil.h"
  9. #include "globals.h"
  10. #include "kes.h"
  11. #include "timsink.h"
  12. #include "funcprv.h"
  13. #include "insert.h"
  14. #include "pad.h"
  15. #include "helpers.h"
  16. #include "osver.h"
  17. // Hangul and Hanja key simulation for Non-Korean Win9x and NT4
  18. static const KESPRESERVEDKEY g_prekeyList[] =
  19. {
  20. { &GUID_KOREAN_HANGULSIMULATE, { VK_MENU, TF_MOD_RALT }, L"Hangul" },
  21. { &GUID_KOREAN_HANJASIMULATE, { VK_CONTROL, TF_MOD_RCONTROL }, L"Hanja" },
  22. { NULL, { 0, 0}, NULL }
  23. };
  24. /*---------------------------------------------------------------------------
  25. CKorIMX::Activate
  26. Initialize Cicero services on the thread
  27. ---------------------------------------------------------------------------*/
  28. STDAPI CKorIMX::Activate(ITfThreadMgr *ptim, TfClientId tid)
  29. {
  30. ITfKeystrokeMgr *pIksm = NULL;
  31. ITfSource *pISource;
  32. ITfSourceSingle *pISourceSingle;
  33. BOOL fThreadFocus;
  34. HRESULT hr = E_FAIL;
  35. // Keep current Thread ID
  36. m_tid = tid;
  37. // Get ITfThreadMgr and ITfDocumentMgr
  38. Assert(GetTIM() == NULL);
  39. m_ptim = ptim;
  40. m_ptim->AddRef();
  41. //////////////////////////////////////////////////////////////////////////
  42. // Get key stroke manager(ITfKeystrokeMgr) in current TIM
  43. if (FAILED(hr = GetService(GetTIM(), IID_ITfKeystrokeMgr, (IUnknown **)&pIksm)))
  44. goto Exit;
  45. //////////////////////////////////////////////////////////////////////////
  46. // Create ITfThreadMgrEventSink and set Call back function as _DocInputMgrCallback
  47. if ((m_ptimEventSink = new CThreadMgrEventSink(_DIMCallback, _ICCallback, this)) == NULL)
  48. {
  49. Assert(0); // bugbug
  50. hr = E_OUTOFMEMORY;
  51. goto Exit;
  52. }
  53. m_ptimEventSink->_Advise(GetTIM());
  54. //////////////////////////////////////////////////////////////////////////
  55. // Get IID_ITfThreadFocusSink cookie
  56. if (GetTIM()->QueryInterface(IID_ITfSource, (void **)&pISource) == S_OK)
  57. {
  58. pISource->AdviseSink(IID_ITfThreadFocusSink, (ITfThreadFocusSink *)this, &m_dwThreadFocusCookie);
  59. pISource->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, (ITfActiveLanguageProfileNotifySink *)this, &m_dwProfileNotifyCookie);
  60. pISource->Release();
  61. }
  62. // ITfCleanupContextDurationSink
  63. if (GetTIM()->QueryInterface(IID_ITfSourceSingle, (void **)&pISourceSingle) == S_OK)
  64. {
  65. pISourceSingle->AdviseSingleSink(m_tid, IID_ITfCleanupContextDurationSink, (ITfCleanupContextDurationSink *)this);
  66. pISourceSingle->Release();
  67. }
  68. // Set conversion mode compartment to null status.
  69. SetCompartmentDWORD(m_tid, m_ptim, GUID_COMPARTMENT_KORIMX_CONVMODE, TIP_NULL_CONV_MODE, fFalse);
  70. // Korean Kbd driver does not exist in system(Non Korean NT4, Non Korean WIN9X)
  71. m_fNoKorKbd = (g_uACP != 949) && (IsOn95() || IsOn98() || (IsOnNT() && !IsOnNT5()));
  72. //////////////////////////////////////////////////////////////////////////
  73. // Create Keyboard Sink(ITfKeyEventSink)
  74. // From Cicero Doc: Keyboard TIP must provide this KeyEventSink interface to get the key event.
  75. // Using this sink, TIPs can get the notification of getting or losing keyboard focus
  76. if (m_fNoKorKbd)
  77. m_pkes = new CKeyEventSink(_KeyEventCallback, _PreKeyCallback, this);
  78. else
  79. m_pkes = new CKeyEventSink(_KeyEventCallback, this);
  80. if (m_pkes == NULL)
  81. {
  82. hr = E_OUTOFMEMORY;
  83. goto Exit;
  84. }
  85. hr = pIksm->AdviseKeyEventSink(GetTID(), m_pkes, fTrue);
  86. if (FAILED(hr))
  87. goto Exit;
  88. if (m_fNoKorKbd)
  89. {
  90. hr = m_pkes->_Register(GetTIM(), GetTID(), g_prekeyList);
  91. if (FAILED(hr))
  92. {
  93. goto Exit;
  94. }
  95. }
  96. //////////////////////////////////////////////////////////////////////////
  97. // Create status window
  98. m_hOwnerWnd = CreateWindowEx(0, c_szOwnerWndClass, TEXT(""), WS_DISABLED, 0, 0, 0, 0, NULL, 0, g_hInst, this);
  99. //////////////////////////////////////////////////////////////////////////
  100. // Register Function Provider. Reconversion etc.
  101. m_pFuncPrv = new CFunctionProvider(this);
  102. if (m_pFuncPrv == NULL)
  103. {
  104. hr = E_OUTOFMEMORY;
  105. goto Exit;
  106. }
  107. m_pFuncPrv->_Advise(GetTIM());
  108. // Create Pad Core
  109. m_pPadCore = new CPadCore(this);
  110. if (m_pPadCore == NULL)
  111. {
  112. hr = E_OUTOFMEMORY;
  113. goto Exit;
  114. }
  115. //////////////////////////////////////////////////////////////////////////
  116. // Create Toolbar
  117. m_pToolBar = new CToolBar(this);
  118. if (m_pToolBar == NULL)
  119. {
  120. hr = E_OUTOFMEMORY;
  121. goto Exit;
  122. }
  123. if (!m_pToolBar->Initialize())
  124. {
  125. hr = E_OUTOFMEMORY;
  126. goto Exit;
  127. }
  128. hr = m_ptimEventSink->_InitDIMs(fTrue);
  129. if (FAILED(hr))
  130. {
  131. goto Exit;
  132. }
  133. //////////////////////////////////////////////////////////////////////////
  134. // Init UI
  135. if (GetTIM()->IsThreadFocus(&fThreadFocus) == S_OK && fThreadFocus)
  136. {
  137. // init any UI
  138. OnSetThreadFocus();
  139. }
  140. if (m_pInsertHelper = new CCompositionInsertHelper)
  141. {
  142. // optional, default is DEF_MAX_OVERTYPE_CCH in insert.h
  143. // use 0 to avoid allocating any memory
  144. // set the limit on number of overtype chars that
  145. // the helper will backup
  146. m_pInsertHelper->Configure(0);
  147. }
  148. else
  149. {
  150. hr = E_OUTOFMEMORY;
  151. goto Exit;
  152. }
  153. m_pToolBar->CheckEnable(); // update toolbar
  154. // Clear SoftKbd On/Off status backup
  155. // m_fSoftKbdOnOffSave = fFalse;
  156. // Clear SoftKbd On/Off status backup
  157. // m_fSoftKbdOnOffSave = GetSoftKBDOnOff();
  158. if (m_fSoftKbdOnOffSave)
  159. {
  160. SetSoftKBDOnOff(fTrue);
  161. }
  162. hr = S_OK;
  163. Exit:
  164. SafeRelease(pIksm);
  165. return hr;
  166. }
  167. /*---------------------------------------------------------------------------
  168. CKorIMX::Deactivate
  169. Uninitialize Cicero services on the thread
  170. ---------------------------------------------------------------------------*/
  171. STDAPI CKorIMX::Deactivate()
  172. {
  173. ITfKeystrokeMgr *pksm = NULL;
  174. ITfSource *pISource;
  175. ITfSourceSingle *pISourceSingle = NULL;
  176. BOOL fThreadFocus;
  177. HRESULT hr = E_FAIL;
  178. // close candidate UI
  179. if (m_pCandUI != NULL)
  180. {
  181. CloseCandidateUIProc();
  182. m_pCandUI->Release();
  183. m_pCandUI = NULL;
  184. }
  185. // pad core
  186. if (m_pPadCore)
  187. {
  188. delete m_pPadCore;
  189. m_pPadCore = NULL;
  190. }
  191. // toolbar
  192. if (m_pToolBar)
  193. {
  194. m_pToolBar->Terminate();
  195. delete m_pToolBar;
  196. m_pToolBar = NULL;
  197. }
  198. if (GetTIM()->IsThreadFocus(&fThreadFocus) == S_OK && fThreadFocus)
  199. {
  200. // shutdown any UI
  201. OnKillThreadFocus();
  202. }
  203. ///////////////////////////////////////////////////////////////////////////
  204. // Unadvise IID_ITfThreadFocusSink cookie
  205. if (GetTIM()->QueryInterface(IID_ITfSource, (void **)&pISource) == S_OK)
  206. {
  207. pISource->UnadviseSink(m_dwThreadFocusCookie);
  208. pISource->UnadviseSink(m_dwProfileNotifyCookie);
  209. pISource->Release();
  210. }
  211. if (GetTIM()->QueryInterface(IID_ITfSourceSingle, (void **)&pISourceSingle) == S_OK)
  212. {
  213. pISourceSingle->UnadviseSingleSink(m_tid, IID_ITfCleanupContextDurationSink);
  214. pISourceSingle->Release();
  215. }
  216. if (FAILED(hr = GetService(GetTIM(), IID_ITfKeystrokeMgr, (IUnknown **)&pksm)))
  217. goto Exit;
  218. // Release TIM event sink
  219. if (m_ptimEventSink != NULL)
  220. {
  221. m_ptimEventSink->_InitDIMs(fFalse);
  222. m_ptimEventSink->_Unadvise();
  223. SafeReleaseClear(m_ptimEventSink);
  224. }
  225. // Release Key event sink
  226. if (m_pkes)
  227. {
  228. if (m_fNoKorKbd)
  229. m_pkes->_Unregister(GetTIM(), GetTID(), g_prekeyList);
  230. SafeReleaseClear(m_pkes);
  231. }
  232. // Delete SoftKbd
  233. if (IsSoftKbdEnabled())
  234. TerminateSoftKbd();
  235. // Release Key Event Sink
  236. pksm->UnadviseKeyEventSink(GetTID());
  237. DestroyWindow(m_hOwnerWnd);
  238. m_pFuncPrv->_Unadvise(GetTIM());
  239. SafeReleaseClear(m_pFuncPrv);
  240. SafeReleaseClear(m_ptim);
  241. //
  242. // Free per-thread object that lib uses.
  243. //
  244. TFUninitLib_Thread(&m_libTLS);
  245. SafeReleaseClear(m_pInsertHelper);
  246. hr = S_OK;
  247. Exit:
  248. SafeRelease(pksm);
  249. return hr;
  250. }