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.

385 lines
13 KiB

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