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.

376 lines
13 KiB

  1. /****************************************************************************
  2. IPOINT.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. IImeIPoint1 interface
  6. History:
  7. 24-OCT-2001 cslim Branched for Cicero TIP PAD support
  8. 20-JUL-1999 cslim Created
  9. *****************************************************************************/
  10. #include "private.h"
  11. #include "korimx.h"
  12. #include "ipointcic.h"
  13. #include "editssn.h"
  14. #include "imepad.h" // IImeIPoint
  15. #include "debug.h"
  16. /*----------------------------------------------------------------------------
  17. CImeIPoint::CImeIPoint
  18. Ctor
  19. ----------------------------------------------------------------------------*/
  20. CIPointCic::CIPointCic(CKorIMX *pImx)
  21. {
  22. Assert(m_pImx != NULL);
  23. m_cRef = 0;
  24. m_pImx = pImx;
  25. m_pic = NULL;
  26. m_dwCharNo = 1;
  27. }
  28. /*----------------------------------------------------------------------------
  29. CImeIPoint::~CIPointCic
  30. Dtor
  31. ----------------------------------------------------------------------------*/
  32. CIPointCic::~CIPointCic()
  33. {
  34. SafeReleaseClear(m_pic);
  35. }
  36. /*----------------------------------------------------------------------------
  37. CImeIPoint::QueryInterface
  38. ----------------------------------------------------------------------------*/
  39. STDMETHODIMP CIPointCic::QueryInterface(REFIID riid, LPVOID * ppv)
  40. {
  41. if(riid == IID_IUnknown)
  42. {
  43. TraceMsg(DM_TRACE, TEXT("IID_IUnknown\n"));
  44. *ppv = static_cast<IImeIPoint1 *>(this);
  45. }
  46. else
  47. if(riid == IID_IImeIPoint1)
  48. {
  49. TraceMsg(DM_TRACE, TEXT("IID_IImeIPoint1\n"));
  50. *ppv = static_cast<IImeIPoint1 *>(this);
  51. }
  52. else
  53. {
  54. TraceMsg(DM_TRACE, TEXT("Unknown Interface ID\n"));
  55. *ppv = NULL;
  56. return E_NOINTERFACE;
  57. }
  58. // Increase ref counter
  59. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  60. return S_OK;
  61. }
  62. /*----------------------------------------------------------------------------
  63. CImeIPoint::AddRef
  64. ----------------------------------------------------------------------------*/
  65. STDMETHODIMP_(ULONG) CIPointCic::AddRef(VOID)
  66. {
  67. return InterlockedIncrement((LPLONG)&m_cRef);
  68. }
  69. /*----------------------------------------------------------------------------
  70. CImeIPoint::Release
  71. ----------------------------------------------------------------------------*/
  72. STDMETHODIMP_(ULONG) CIPointCic::Release(VOID)
  73. {
  74. ULONG res = InterlockedDecrement((LPLONG)&m_cRef);
  75. if (res == 0L)
  76. delete this;
  77. return res;
  78. }
  79. /*----------------------------------------------------------------------------
  80. CImeIPoint::Initialize
  81. ----------------------------------------------------------------------------*/
  82. HRESULT CIPointCic::Initialize(ITfContext *pic)
  83. {
  84. SafeReleaseClear(m_pic);
  85. m_pic = pic;
  86. if (m_pic)
  87. {
  88. m_pic->AddRef();
  89. }
  90. return (S_OK);
  91. }
  92. #ifndef DEBUG
  93. #define DumpFEInfo /##/
  94. #else
  95. /*----------------------------------------------------------------------------
  96. DumpFEInfo
  97. Dump LPIMEFAREASTINFO. Debug only
  98. ----------------------------------------------------------------------------*/
  99. VOID DumpFEInfo(LPIMEFAREASTINFO lpInfo, INT count)
  100. {
  101. TraceMsg(DM_TRACE, TEXT("DumpFEInfo Start\n"));
  102. TraceMsg(DM_TRACE, TEXT("lpInfo [0x%08x]\n"), lpInfo);
  103. TraceMsg(DM_TRACE, TEXT("lpInfo->dwSize [%d]\n"), lpInfo->dwSize);
  104. TraceMsg(DM_TRACE, TEXT("lpInfo->dwType [0x%08x]\n"), lpInfo->dwType);
  105. LPWSTR lpwstr;
  106. switch(lpInfo->dwType)
  107. {
  108. case IMEFAREASTINFO_TYPE_COMMENT:
  109. TraceMsg(DM_TRACE, TEXT("-->dwType is IMEFAREASTINFO_TYPE_COMMENT\n"));
  110. lpwstr = (LPWSTR)lpInfo->dwData;
  111. for(int i=0;i < count; i++)
  112. {
  113. //DbgW(DBGID_IMEPAD, L"%d [%s]\n", i, lpwstr);
  114. lpwstr = lpwstr + lstrlenW(lpwstr)+1;
  115. }
  116. break;
  117. }
  118. TraceMsg(DM_TRACE, TEXT("DumpFEInfo End\n"));
  119. }
  120. #endif // _DEBUG
  121. /*----------------------------------------------------------------------------
  122. CImeIPoint::InsertImeItem
  123. Multibox input call this method
  124. ----------------------------------------------------------------------------*/
  125. STDMETHODIMP CIPointCic::InsertImeItem(IPCANDIDATE* pImeItem, INT iPos, DWORD *lpdwCharId)
  126. {
  127. DWORD dwCharId;
  128. CEditSession2 *pes;
  129. ESSTRUCT ess;
  130. HRESULT hr;
  131. // Check Parameters
  132. Assert(pImeItem != NULL && pImeItem->dwSize > 0);
  133. if (pImeItem == NULL || pImeItem->dwSize <= 0 || m_pImx == NULL || m_pic == NULL)
  134. return S_FALSE;
  135. TraceMsg(DM_TRACE, TEXT("CImeIPoint::InsertImeItem\n"));
  136. TraceMsg(DM_TRACE, TEXT("pImeItem [0x%08x]\n"), pImeItem);
  137. TraceMsg(DM_TRACE, TEXT("pImeItem->dwSize [%d]\n"), pImeItem->dwSize);
  138. TraceMsg(DM_TRACE, TEXT("pImeItem->iSelIndex [%d]\n"), pImeItem->iSelIndex);
  139. TraceMsg(DM_TRACE, TEXT("pImeItem->nCandidate[%d]\n"), pImeItem->nCandidate);
  140. TraceMsg(DM_TRACE, TEXT("pImeItem->dwPrivateDataOffset[%d]\n"), pImeItem->dwPrivateDataOffset);
  141. TraceMsg(DM_TRACE, TEXT("pImeItem->dwPrivateDataSize [%d]\n"), pImeItem->dwPrivateDataSize);
  142. DumpFEInfo((LPIMEFAREASTINFO)((LPBYTE)pImeItem + pImeItem->dwPrivateDataOffset), pImeItem->nCandidate);
  143. TraceMsg(DM_TRACE, TEXT("lpdwCharId [0x%08x] [%d]\n"), lpdwCharId, lpdwCharId ? *lpdwCharId : 0xFFFFF);
  144. // Finalize current comp string
  145. ESStructInit(&ess, ESCB_COMPLETE);
  146. if ((pes = new CEditSession2(m_pic, m_pImx, &ess, CKorIMX::_EditSessionCallback2)))
  147. {
  148. pes->Invoke(ES2_READWRITE | ES2_SYNCASYNC, &hr);
  149. pes->Release();
  150. }
  151. ESStructInit(&ess, ESCB_INSERT_PAD_STRING);
  152. ess.wParam = *(LPWSTR)((PBYTE)pImeItem + pImeItem->dwOffset[0]);
  153. if ((pes = new CEditSession2(m_pic, m_pImx, &ess, CKorIMX::_EditSessionCallback2)))
  154. {
  155. pes->Invoke(ES2_READWRITE | ES2_SYNCASYNC, &hr);
  156. pes->Release();
  157. }
  158. // Increase Char serial number
  159. m_dwCharNo++;
  160. dwCharId = m_dwCharNo;
  161. if (lpdwCharId)
  162. {
  163. dwCharId |= ((*lpdwCharId) & (~ IPCHARID_CHARNO_MASK));
  164. *lpdwCharId = dwCharId;
  165. }
  166. return (S_OK);
  167. }
  168. /*----------------------------------------------------------------------------
  169. CImeIPoint::ReplaceImeItem
  170. ----------------------------------------------------------------------------*/
  171. STDMETHODIMP CIPointCic::ReplaceImeItem(
  172. INT iPos, // = IPINS_CURRENT:use current IP position and
  173. // set IP to the end of insert chars.
  174. // = 0-n: The offset of all composition string to set
  175. // IP position, before insert chars.
  176. // and IP back to original position.
  177. INT iTargetLen,
  178. IPCANDIDATE* pImeItem,
  179. DWORD *lpdwCharId)
  180. {
  181. return (E_NOTIMPL);
  182. }
  183. /*----------------------------------------------------------------------------
  184. CImeIPoint::InsertStringEx
  185. ----------------------------------------------------------------------------*/
  186. STDMETHODIMP CIPointCic::InsertStringEx(WCHAR* pwSzInsert, INT cchSzInsert, DWORD *lpdwCharId)
  187. {
  188. DWORD dwCharId;
  189. CEditSession2 *pes;
  190. ESSTRUCT ess;
  191. HRESULT hr;
  192. TraceMsg(DM_TRACE, TEXT("CIPointCic::InsertStringEx : *pwSzInsert=0x%04X, cchSzInsert=%d, *lpdwCharId = 0x%04X"), *pwSzInsert, cchSzInsert, *lpdwCharId);
  193. // Check Parameters
  194. Assert(pwSzInsert != NULL && cchSzInsert > 0);
  195. if (pwSzInsert == NULL || cchSzInsert <= 0 || m_pImx == NULL || m_pic == NULL)
  196. return S_FALSE;
  197. // Finalize current comp string
  198. ESStructInit(&ess, ESCB_COMPLETE);
  199. if ((pes = new CEditSession2(m_pic, m_pImx, &ess, CKorIMX::_EditSessionCallback2)))
  200. {
  201. pes->Invoke(ES2_READWRITE | ES2_SYNCASYNC, &hr);
  202. pes->Release();
  203. }
  204. // Add all chars in string as finalized string
  205. for (INT i=0; i<cchSzInsert; i++)
  206. {
  207. ESStructInit(&ess, ESCB_INSERT_PAD_STRING);
  208. ess.wParam = *(pwSzInsert + i);
  209. if ((pes = new CEditSession2(m_pic, m_pImx, &ess, CKorIMX::_EditSessionCallback2)))
  210. {
  211. pes->Invoke(ES2_READWRITE | ES2_SYNCASYNC, &hr);
  212. pes->Release();
  213. }
  214. // Increase Char serial number
  215. m_dwCharNo++;
  216. dwCharId = m_dwCharNo;
  217. if (lpdwCharId)
  218. {
  219. dwCharId |= ((*lpdwCharId) & (~ IPCHARID_CHARNO_MASK));
  220. *lpdwCharId = dwCharId;
  221. }
  222. }
  223. return (S_OK);
  224. }
  225. /*----------------------------------------------------------------------------
  226. CImeIPoint::DeleteCompString
  227. ----------------------------------------------------------------------------*/
  228. STDMETHODIMP CIPointCic::DeleteCompString(INT iPos,
  229. INT cchSzDel)
  230. {
  231. TraceMsg(DM_TRACE, TEXT("CImeIPoint::DeleteCompString\n"));
  232. return (E_NOTIMPL);
  233. }
  234. /*----------------------------------------------------------------------------
  235. CImeIPoint::ReplaceCompString
  236. ----------------------------------------------------------------------------*/
  237. STDMETHODIMP CIPointCic::ReplaceCompString(INT iPos,
  238. INT iTargetLen,
  239. WCHAR *pwSzInsert,
  240. INT cchSzInsert,
  241. DWORD *lpdwCharId)
  242. {
  243. TraceMsg(DM_TRACE, TEXT("CImeIPoint::ReplaceCompString\n"));
  244. return (E_NOTIMPL);
  245. }
  246. /*----------------------------------------------------------------------------
  247. CImeIPoint::ControlIME
  248. ----------------------------------------------------------------------------*/
  249. STDMETHODIMP CIPointCic::ControlIME(DWORD dwIMEFuncID, LPARAM lpara)
  250. {
  251. TraceMsg(DM_TRACE, TEXT("CImeIPoint::ControlIME, dwIMEFuncID=0x%04X, lpara=0x%08lX\n"), dwIMEFuncID, lpara);
  252. // TODO:
  253. return (E_NOTIMPL);
  254. }
  255. /*----------------------------------------------------------------------------
  256. CImeIPoint::GetAllCompositionInfo
  257. ----------------------------------------------------------------------------*/
  258. STDMETHODIMP CIPointCic::GetAllCompositionInfo(WCHAR** ppwSzCompStr,
  259. DWORD** ppdwCharID,
  260. INT *pcchCompStr,
  261. INT *piIPPos,
  262. INT *piStartUndetStrPos,
  263. INT *pcchUndetStr,
  264. INT *piEditStart,
  265. INT *piEditLen)
  266. {
  267. TraceMsg(DM_TRACE, TEXT("CImeIPoint::GetAllCompositionInfo START\n"));
  268. // Return nothing for now.
  269. if(ppwSzCompStr)
  270. {
  271. *ppwSzCompStr = NULL;
  272. }
  273. if(ppdwCharID)
  274. {
  275. *ppdwCharID = NULL;
  276. }
  277. *pcchCompStr = 0;
  278. *piIPPos = 0;
  279. *piStartUndetStrPos = 0;
  280. *pcchUndetStr =0;
  281. *piEditStart = 0;
  282. *piEditLen = 0;
  283. TraceMsg(DM_TRACE, TEXT("CImeIPoint::GetAllCompositionInfo END\n"));
  284. return (S_OK);
  285. }
  286. /*----------------------------------------------------------------------------
  287. CImeIPoint::GetIpCandidate
  288. ----------------------------------------------------------------------------*/
  289. STDMETHODIMP CIPointCic::GetIpCandidate(DWORD dwCharId,
  290. IPCANDIDATE **ppImeItem,
  291. INT * piColumn,
  292. INT * piCount)
  293. {
  294. TraceMsg(DM_TRACE, TEXT("CImeIPoint::GetIpCandidate\n"));
  295. return (E_NOTIMPL);
  296. }
  297. /*----------------------------------------------------------------------------
  298. CImeIPoint::SelectIpCandidate
  299. ----------------------------------------------------------------------------*/
  300. STDMETHODIMP CIPointCic::SelectIpCandidate(DWORD dwCharId, INT iselno)
  301. {
  302. TraceMsg(DM_TRACE, TEXT("CImeIPoint::SetIpCandidate\n"));
  303. return (E_NOTIMPL);
  304. }
  305. /*----------------------------------------------------------------------------
  306. CImeIPoint::UpdateContext
  307. Update IME context and send it to the application
  308. ----------------------------------------------------------------------------*/
  309. STDMETHODIMP CIPointCic::UpdateContext(BOOL fGenerateMessage)
  310. {
  311. TraceMsg(DM_TRACE, TEXT("CImeIPoint::UpdateContext\n"));
  312. // TODO:
  313. return (S_OK);
  314. }