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
10 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. icocb.cpp
  5. Abstract:
  6. This file implements the CInputContextOwnerCallBack Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "icocb.h"
  13. #include "cime.h"
  14. #include "imeapp.h"
  15. #include "mouse.h"
  16. #include "tsattrs.h"
  17. #include "imtls.h"
  18. #include "a_context.h"
  19. #include "candpos.h"
  20. CInputContextOwnerCallBack::CInputContextOwnerCallBack(LIBTHREAD *pLibTLS
  21. ) : CInputContextOwner(ICOwnerSinkCallback, NULL)
  22. {
  23. m_pMouseSink = NULL;
  24. m_pLibTLS = pLibTLS;
  25. }
  26. CInputContextOwnerCallBack::~CInputContextOwnerCallBack(
  27. )
  28. {
  29. if (m_pMouseSink) {
  30. m_pMouseSink->InternalRelease();
  31. m_pMouseSink = NULL;
  32. }
  33. }
  34. BOOL CInputContextOwnerCallBack::Init()
  35. {
  36. //
  37. // Create Mouse Sink
  38. //
  39. Assert(!m_pMouseSink);
  40. m_pMouseSink = new CMouseSink;
  41. if (m_pMouseSink == NULL)
  42. return FALSE;
  43. if (!m_pMouseSink->Init())
  44. {
  45. delete m_pMouseSink;
  46. m_pMouseSink = NULL;
  47. return FALSE;
  48. }
  49. return TRUE;
  50. }
  51. // static
  52. HRESULT
  53. CInputContextOwnerCallBack::ICOwnerSinkCallback(
  54. UINT uCode,
  55. ICOARGS *pargs,
  56. void *pv
  57. )
  58. {
  59. DebugMsg(TF_FUNC, "ICOwnerSinkCallback");
  60. POINT pt;
  61. IMTLS *ptls;
  62. CInputContextOwnerCallBack* _this = (CInputContextOwnerCallBack*)pv;
  63. switch (uCode)
  64. {
  65. case ICO_POINT_TO_ACP:
  66. Assert(0);
  67. return E_NOTIMPL;
  68. case ICO_KEYDOWN:
  69. case ICO_KEYUP:
  70. *pargs->key.pfEaten = FALSE;
  71. break;
  72. case ICO_SCREENEXT:
  73. {
  74. ptls = IMTLS_GetOrAlloc();
  75. if (ptls == NULL)
  76. break;
  77. IMCLock imc(ptls->hIMC);
  78. if (imc.Invalid())
  79. break;
  80. GetClientRect(imc->hWnd, pargs->scr_ext.prc);
  81. pt.x = pt.y = 0;
  82. ClientToScreen(imc->hWnd, &pt);
  83. pargs->scr_ext.prc->left += pt.x;
  84. pargs->scr_ext.prc->right += pt.x;
  85. pargs->scr_ext.prc->top += pt.y;
  86. pargs->scr_ext.prc->bottom += pt.y;
  87. }
  88. break;
  89. case ICO_TEXTEXT:
  90. //
  91. // consider.
  92. //
  93. // hack TextExtent from CANDIDATEFORM of HIMC.
  94. //
  95. // more hacks
  96. // - may want to send WM_OPENCANDIDATEPOS to let apps
  97. // call ImmSetCandidateWindow().
  98. // - may need to calculate the actual point from rcArea.
  99. //
  100. {
  101. CCandidatePosition cand_pos;
  102. cand_pos.GetCandidatePosition(pargs->text_ext.prc);
  103. }
  104. break;
  105. case ICO_STATUS:
  106. pargs->status.pdcs->dwDynamicFlags = 0;
  107. pargs->status.pdcs->dwStaticFlags = TF_SS_TRANSITORY;
  108. break;
  109. case ICO_WND:
  110. {
  111. ptls = IMTLS_GetOrAlloc();
  112. if (ptls == NULL)
  113. break;
  114. IMCLock imc(ptls->hIMC);
  115. *(pargs->hwnd.phwnd) = NULL;
  116. if (imc.Invalid())
  117. break;
  118. *(pargs->hwnd.phwnd) = imc->hWnd;
  119. }
  120. break;
  121. case ICO_ATTR:
  122. return _this->GetAttribute(pargs->sys_attr.pguid, pargs->sys_attr.pvar);
  123. case ICO_ADVISEMOUSE:
  124. {
  125. ptls = IMTLS_GetOrAlloc();
  126. if (ptls == NULL)
  127. break;
  128. _this->m_pMouseSink->InternalAddRef();
  129. return _this->m_pMouseSink->AdviseMouseSink(ptls->hIMC,
  130. pargs->advise_mouse.rangeACP,
  131. pargs->advise_mouse.pSink,
  132. pargs->advise_mouse.pdwCookie);
  133. }
  134. break;
  135. case ICO_UNADVISEMOUSE:
  136. {
  137. HRESULT hr = _this->m_pMouseSink->UnadviseMouseSink(pargs->unadvise_mouse.dwCookie);
  138. _this->m_pMouseSink->InternalRelease();
  139. return hr;
  140. }
  141. break;
  142. default:
  143. Assert(0); // shouldn't ever get here
  144. break;
  145. }
  146. return S_OK;
  147. }
  148. /*++
  149. Method:
  150. CInputContextOwnerCallBack::GetAttribute
  151. Routine Description:
  152. Implementation of ITfContextOwner::GetAttribute. Returns the value of a cicero
  153. app property attribute.
  154. Arguments:
  155. pguid - [in] GUID of the attrib in question.
  156. pvarValue - [out] VARIANT, receives the value. VT_EMPTY if we don't support it.
  157. Return Value:
  158. Returns S_OK if successful, or an error code otherwise.
  159. --*/
  160. HRESULT
  161. CInputContextOwnerCallBack::GetAttribute(
  162. const GUID *pguid,
  163. VARIANT *pvarValue
  164. )
  165. {
  166. TfGuidAtom ga;
  167. const GUID *pguidValue;
  168. IMTLS *ptls;
  169. QuickVariantInit(pvarValue);
  170. ptls = IMTLS_GetOrAlloc();
  171. if (ptls == NULL)
  172. return E_FAIL;
  173. if (IsEqualGUID(*pguid, GUID_PROP_MODEBIAS))
  174. {
  175. // xlate conversion mode, sentence mode to cicero mode bias
  176. IMCLock imc(ptls->hIMC);
  177. if (imc.Invalid())
  178. return E_FAIL;
  179. CAImeContext* _pAImeContext = imc->m_pAImeContext;
  180. ASSERT(_pAImeContext != NULL);
  181. if (_pAImeContext == NULL)
  182. return E_FAIL;
  183. if (_pAImeContext->lModeBias == MODEBIASMODE_FILENAME)
  184. {
  185. pguidValue = &GUID_MODEBIAS_FILENAME;
  186. }
  187. else if (_pAImeContext->lModeBias == MODEBIASMODE_DIGIT)
  188. {
  189. pguidValue = &GUID_MODEBIAS_NUMERIC;
  190. }
  191. else
  192. {
  193. if (imc->fdwConversion & IME_CMODE_GUID_NULL) {
  194. //
  195. // If extended conversion mode were set on,
  196. // returns GUID_NULL.
  197. // No returns any MODEBIAS.
  198. //
  199. pguidValue = &GUID_NULL;
  200. }
  201. else
  202. //
  203. // existing logic:
  204. //
  205. // if imcp->lModeBias == MODEBIASMODE_DEFAULT
  206. // IME_SMODE_CONVERSATION -> GUID_MODEBIAS_CONVERSATION
  207. // otherwise -> GUID_MODEBIAS_NONE
  208. // otherwise
  209. // -> MODEBIASMODE_FILENAME -> GUID_MODEBIAS_FILENAME
  210. //
  211. if (_pAImeContext->lModeBias == MODEBIASMODE_DEFAULT)
  212. {
  213. pguidValue = &GUID_MODEBIAS_NONE;
  214. if (imc->fdwConversion & IME_CMODE_KATAKANA)
  215. {
  216. if (imc->fdwConversion & IME_CMODE_FULLSHAPE)
  217. pguidValue = &GUID_MODEBIAS_KATAKANA;
  218. else
  219. pguidValue = &GUID_MODEBIAS_HALFWIDTHKATAKANA;
  220. }
  221. else if (imc->fdwConversion & IME_CMODE_NATIVE)
  222. {
  223. pguidValue = &GUID_MODEBIAS_HALFWIDTHALPHANUMERIC;
  224. LANGID langid;
  225. ptls->pAImeProfile->GetLangId(&langid);
  226. if (langid == MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT))
  227. {
  228. if (imc->fdwConversion & IME_CMODE_FULLSHAPE)
  229. pguidValue = &GUID_MODEBIAS_HIRAGANA;
  230. else
  231. pguidValue = &GUID_MODEBIAS_HALFWIDTHALPHANUMERIC;
  232. }
  233. else if (langid == MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT))
  234. {
  235. if (imc->fdwConversion & IME_CMODE_FULLSHAPE)
  236. pguidValue = &GUID_MODEBIAS_FULLWIDTHHANGUL;
  237. else
  238. pguidValue = &GUID_MODEBIAS_HANGUL;
  239. }
  240. else if (PRIMARYLANGID(langid) == LANG_CHINESE)
  241. {
  242. pguidValue = &GUID_MODEBIAS_CHINESE;
  243. }
  244. }
  245. else
  246. {
  247. if (imc->fdwConversion & IME_CMODE_FULLSHAPE)
  248. pguidValue = &GUID_MODEBIAS_FULLWIDTHALPHANUMERIC;
  249. else
  250. pguidValue = &GUID_MODEBIAS_HALFWIDTHALPHANUMERIC;
  251. }
  252. }
  253. //
  254. // We overwrite modebias here....
  255. //
  256. if (imc->fdwSentence & IME_SMODE_GUID_NULL) {
  257. //
  258. // If extended sentence mode were set on,
  259. // returns GUID_NULL.
  260. // No returns any MODEBIAS.
  261. //
  262. // Nothing to do. pguidValue might be changed with CMODE
  263. // pguidValue = &GUID_NULL;
  264. }
  265. else if (imc->fdwSentence & IME_SMODE_CONVERSATION)
  266. pguidValue = &GUID_MODEBIAS_CONVERSATION;
  267. else if (imc->fdwSentence & IME_SMODE_PLAURALCLAUSE)
  268. pguidValue = &GUID_MODEBIAS_NAME;
  269. }
  270. if (!GetGUIDATOMFromGUID(m_pLibTLS, *pguidValue, &ga))
  271. return E_FAIL;
  272. pvarValue->vt = VT_I4; // for TfGuidAtom
  273. pvarValue->lVal = ga;
  274. }
  275. if (IsEqualGUID(*pguid, TSATTRID_Text_Orientation))
  276. {
  277. // xlate conversion mode, sentence mode to cicero mode bias
  278. IMCLock imc(ptls->hIMC);
  279. if (imc.Invalid())
  280. return E_FAIL;
  281. pvarValue->vt = VT_I4;
  282. pvarValue->lVal = imc->lfFont.A.lfEscapement;
  283. }
  284. if (IsEqualGUID(*pguid, TSATTRID_Text_VerticalWriting))
  285. {
  286. // xlate conversion mode, sentence mode to cicero mode bias
  287. IMCLock imc(ptls->hIMC);
  288. if (imc.Invalid())
  289. return E_FAIL;
  290. LOGFONTW font;
  291. if (SUCCEEDED(ptls->pAImm->GetCompositionFontW(ptls->hIMC, &font))) {
  292. pvarValue->vt = VT_BOOL;
  293. pvarValue->lVal = (imc->lfFont.W.lfFaceName[0] == L'@' ? TRUE : FALSE);
  294. }
  295. }
  296. return S_OK;
  297. }
  298. LRESULT
  299. CInputContextOwnerCallBack::MsImeMouseHandler(
  300. ULONG uEdge,
  301. ULONG uQuadrant,
  302. ULONG dwBtnStatus,
  303. IMCLock& imc,
  304. ImmIfIME* ImmIfIme
  305. )
  306. {
  307. return m_pMouseSink->MsImeMouseHandler(uEdge, uQuadrant, dwBtnStatus, imc, ImmIfIme);
  308. }