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.

375 lines
7.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: dimmcom.cpp
  4. //
  5. // Contents: CActiveIMM COM methods without win32 mappings.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "private.h"
  9. #include "cdimm.h"
  10. #include "globals.h"
  11. #include "defs.h"
  12. #include "util.h"
  13. //+---------------------------------------------------------------------------
  14. //
  15. // QueryInterface
  16. //
  17. //----------------------------------------------------------------------------
  18. STDAPI CActiveIMM::QueryInterface(REFIID riid, void **ppvObj)
  19. {
  20. if (ppvObj == NULL)
  21. return E_INVALIDARG;
  22. *ppvObj = NULL;
  23. if (IsEqualIID(riid, IID_IUnknown) ||
  24. IsEqualIID(riid, IID_IActiveIMMIME_Private))
  25. {
  26. *ppvObj = SAFECAST(this, IActiveIMMIME_Private *);
  27. }
  28. if (*ppvObj)
  29. {
  30. AddRef();
  31. return S_OK;
  32. }
  33. return E_NOINTERFACE;
  34. }
  35. //+---------------------------------------------------------------------------
  36. //
  37. // AddRef
  38. //
  39. //----------------------------------------------------------------------------
  40. STDAPI_(ULONG) CActiveIMM::AddRef()
  41. {
  42. return ++_cRef;
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Release
  47. //
  48. //----------------------------------------------------------------------------
  49. STDAPI_(ULONG) CActiveIMM::Release()
  50. {
  51. LONG cr = --_cRef;
  52. Assert(_cRef >= 0);
  53. if (_cRef == 0)
  54. {
  55. delete this;
  56. }
  57. return cr;
  58. }
  59. HRESULT CActiveIMM::Activate(BOOL fRestoreLayout)
  60. /*++
  61. Method:
  62. IActiveIMMApp::Activate
  63. Routine Description:
  64. Starts the Active IMM service and sets the status of Active IMEs for the thread.
  65. Arguments:
  66. fRestoreLayout - [in] Boolean value that determines wherher Active IMEs are enabled
  67. for the thread. If TRUE, the method enables Active IMEs.
  68. Otherwise it disables Active IMEs.
  69. Return Value:
  70. Returns S_OK if successful, or an error code otherwise.
  71. --*/
  72. {
  73. HKL hKL;
  74. TraceMsg(TF_GENERAL, "Activate called for %x", GetCurrentThreadId());
  75. //
  76. // If target thread doesn't activate the IActiveIME, then calls _ActivateIME.
  77. // Otherwise, if already activated then add reference count and returns S_OK.
  78. //
  79. //
  80. // Increment activate reference count.
  81. //
  82. if (_AddActivate() > 1)
  83. {
  84. return S_OK;
  85. }
  86. // init the thread focus wnd
  87. _hFocusWnd = GetFocus();
  88. if (_CreateActiveIME()) {
  89. //
  90. // setup the hooks
  91. //
  92. if (!_InitHooks()) {
  93. _ReleaseActivate();
  94. return E_UNEXPECTED;
  95. }
  96. /*
  97. * If hKL were regacy IME, then we should not call WM_IME_SELCT to Default IME window.
  98. * The wrapapi.h should check hKL.
  99. * The user32!ImeSelectHandler would like create new pimeui.
  100. */
  101. _GetKeyboardLayout(&hKL);
  102. _ActivateLayout(hKL, NULL);
  103. /*
  104. * If hKL were Cicero IME and IsOnImm() is true,
  105. * then we should call WM_IME_SELECT to Default IME window.
  106. * SendIMEMessage() doesn't send WM_IME_SELECT message when IsOnImm() is true
  107. * because imm32 also send it message to Default IME window.
  108. * However, when start new application, imm32 doesn't send message so in this case
  109. * win32 layer can not create UI window.
  110. */
  111. if ( (! _IsRealIme() && IsOnImm()) || ! IsOnImm()) {
  112. _OnImeSelect(hKL);
  113. }
  114. }
  115. _OnSetFocus(_hFocusWnd, _IsRealIme());
  116. // if everything went ok, and this is the first call on this thread
  117. // need to AddRef this
  118. AddRef();
  119. return S_OK;
  120. }
  121. HRESULT
  122. CActiveIMM::Deactivate(
  123. )
  124. /*++
  125. Method:
  126. IActiveIMMApp::Deactivate
  127. Routine Description:
  128. Stops the Activate IMM service.
  129. Arguments:
  130. Return Value:
  131. Returns S_OK if successful, or an error code otherwise.
  132. --*/
  133. {
  134. HRESULT hr;
  135. HKL hUnSelKL;
  136. TraceMsg(TF_GENERAL, "Deactivate called for %x", GetCurrentThreadId());
  137. if (!_IsAlreadyActivate())
  138. return E_UNEXPECTED;
  139. hr = S_OK;
  140. if (_ReleaseActivate() == 0)
  141. {
  142. _OnKillFocus(_hFocusWnd, _IsRealIme());
  143. //hr = _pCiceroIME->Deactivate(_hFocusWnd, _IsRealIme());
  144. hr = _GetKeyboardLayout(&hUnSelKL);
  145. if (FAILED(hr))
  146. return hr;
  147. //
  148. // unload the hooks
  149. //
  150. _UninitHooks();
  151. _DeactivateLayout(NULL, hUnSelKL);
  152. if ( (! _IsRealIme() && IsOnImm()) || ! IsOnImm()) {
  153. _OnImeUnselect(hUnSelKL);
  154. }
  155. _DestroyActiveIME();
  156. SafeReleaseClear(_AImeProfile);
  157. // last call on this thread, delete this
  158. // NB: no this pointer after the following Release!
  159. Release();
  160. }
  161. return hr;
  162. }
  163. HRESULT
  164. CActiveIMM::FilterClientWindows(
  165. ATOM *aaWindowClasses,
  166. UINT uSize,
  167. BOOL *aaGuidMap
  168. )
  169. /*++
  170. Method:
  171. IActiveIMMAppEx::FilterClientWindows
  172. Routine Description:
  173. Creates a list of registered window class that support Active IMM.
  174. Arguments:
  175. aaWindowClasses - [in] Address of a list of window classes.
  176. uSize - [in] Unsigned integer that contains the number of window classes in the list.
  177. aaGuidMap - [in] Address of a list of GUID map enable/disable flag.
  178. Return Value:
  179. Returns S_OK if successful, or an error code otherwise.
  180. --*/
  181. {
  182. HRESULT hr;
  183. if (g_ProcessIMM)
  184. {
  185. hr = g_ProcessIMM->_FilterList._Update(aaWindowClasses, uSize, aaGuidMap);
  186. }
  187. else
  188. {
  189. hr = E_FAIL;
  190. }
  191. HWND hwndFocus = GetFocus();
  192. if (hwndFocus)
  193. {
  194. ATOM aClass = (ATOM)GetClassLong(hwndFocus, GCW_ATOM);
  195. UINT u = 0;
  196. while (u < uSize)
  197. {
  198. if (aClass == aaWindowClasses[u])
  199. {
  200. _OnSetFocus(hwndFocus, _IsRealIme());
  201. break;
  202. }
  203. u++;
  204. }
  205. }
  206. return hr;
  207. }
  208. HRESULT
  209. CActiveIMM::FilterClientWindowsEx(
  210. HWND hWnd,
  211. BOOL fGuidMap
  212. )
  213. /*++
  214. Method:
  215. IActiveIMMAppEx::FilterClientWindowsEx
  216. Routine Description:
  217. Register window handle that support Active IMM.
  218. Arguments:
  219. hWnd - [in] Handle to the window.
  220. fGuidMap - [in] Boolean value that contains the GUID map flag.
  221. If TRUE, the hIMC's attribute field contains GUID map attribute and application should get GUID atom by IActiveIMMAppEx::GetGuidMap method.
  222. Return Value:
  223. Returns S_OK if successful, or an error code otherwise.
  224. --*/
  225. {
  226. _mapFilterWndEx.SetAt(hWnd, fGuidMap);
  227. HWND hwndFocus = GetFocus();
  228. if (hwndFocus == hWnd)
  229. _OnSetFocus(hWnd, _IsRealIme());
  230. return S_OK;
  231. }
  232. HRESULT
  233. CActiveIMM::UnfilterClientWindowsEx(
  234. HWND hWnd
  235. )
  236. /*++
  237. Method:
  238. IActiveIMMAppEx::UnfilterClientWindowsEx
  239. Routine Description:
  240. Unregister window handle that support Active IMM.
  241. Arguments:
  242. hWnd - [in] Handle to the window.
  243. Return Value:
  244. Returns S_OK if successful, or an error code otherwise.
  245. --*/
  246. {
  247. _mapFilterWndEx.RemoveKey(hWnd);
  248. HWND hwndFocus = GetFocus();
  249. if (hwndFocus == hWnd)
  250. _OnKillFocus(hWnd, _IsRealIme());
  251. return S_OK;
  252. }