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.

737 lines
24 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #ifdef UNDER_CE // stub for CE
  4. #include "stub_ce.h"
  5. #endif // UNDER_CE
  6. #include "imepadsv.h"
  7. #include "cpadcbu.h"
  8. #include "cpaddbg.h"
  9. #include "ipoint1.h"
  10. #include "iimecb.h"
  11. #include "imepad.h"
  12. #define Unref(a) UNREFERENCED_PARAMETER(a)
  13. //990812:ToshiaK For Win64. Use Global Alloc/Free Ptr.
  14. #include <windowsx.h>
  15. #define MemAlloc(a) GlobalAllocPtr(GMEM_FIXED, a)
  16. #define MemFree(a) GlobalFreePtr(a)
  17. BOOL IsBadVtblUIM(IUnkDummy *lpIUnk)
  18. {
  19. #ifdef _DEBUG
  20. BOOL fBad = ::IsBadReadPtr(lpIUnk, sizeof(VOID*)) ||
  21. ::IsBadReadPtr(lpIUnk->lpVtbl, sizeof(VOID*)) ||
  22. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->QueryInterface) ||
  23. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->AddRef) ||
  24. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->Release);
  25. if(fBad) {
  26. DBG(("--> IsBadVtbl HIT HIT HIT\n"));
  27. }
  28. return fBad;
  29. #else
  30. return ::IsBadReadPtr(lpIUnk, sizeof(VOID*)) ||
  31. ::IsBadReadPtr(lpIUnk->lpVtbl, sizeof(VOID*)) ||
  32. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->QueryInterface) ||
  33. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->AddRef) ||
  34. ::IsBadCodePtr((FARPROC)lpIUnk->lpVtbl->Release);
  35. #endif
  36. }
  37. HRESULT __stdcall
  38. CImePadCallbackUIM::QueryInterface(REFIID riid, void**ppv)
  39. {
  40. if(riid == IID_IUnknown) {
  41. *ppv = static_cast<IImePadCallback *>(this);
  42. }
  43. else if (riid == IID_IImePadCallback) {
  44. *ppv = static_cast<IImePadCallback *>(this);
  45. }
  46. else {
  47. return (*ppv = 0), E_NOINTERFACE;
  48. }
  49. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  50. return S_OK;
  51. }
  52. ULONG __stdcall
  53. CImePadCallbackUIM::AddRef(void)
  54. {
  55. //DBG(("CImePadCallbackUIM::AddRef Always return 2\n"));
  56. DBG(("CImePadCallbackUIM::AddRef m_cRef[%d] -> [%d]\n", m_cRef, m_cRef+1));
  57. return ::InterlockedIncrement(&m_cRef);
  58. }
  59. ULONG __stdcall
  60. CImePadCallbackUIM::Release(void)
  61. {
  62. //Never call delete in it.
  63. DBG(("CImePadCallbackUIM::Release (Never Delete) m_cRef[%d] -> [%d]\n", m_cRef, m_cRef-1));
  64. ::InterlockedDecrement(&m_cRef);
  65. return m_cRef;
  66. }
  67. //////////////////////////////////////////////////////////////////
  68. // Function : CImePadCallbackUIM::OnStart
  69. // Type : HRESULT __stdcall
  70. // Purpose :
  71. // Args :
  72. // : DWORD dwParam
  73. // Return :
  74. // DATE : Tue Aug 31 16:49:37 1999
  75. // Histroy :
  76. //////////////////////////////////////////////////////////////////
  77. HRESULT __stdcall
  78. CImePadCallbackUIM::OnStart(DWORD dwParam)
  79. {
  80. DBG(("OnClose come dwParam[%d]\n", dwParam));
  81. IUnknown *lpUnk;
  82. IImeCallback *lp = NULL;
  83. if(!m_lpCImePadSvrUIM) {
  84. DBG(("-->m_lpCImePadSvrUIM is NULL ?\n"));
  85. return -1;
  86. }
  87. lpUnk = m_lpCImePadSvrUIM->GetIUnkIImeCallback();
  88. if(!lpUnk) {
  89. DBG(("-->IImeCallback does not set\n"));
  90. return -1;
  91. }
  92. if(IsBadVtblUIM((IUnkDummy*)lpUnk)) {
  93. DBG(("lpIUnk is BAD Pointer \n"));
  94. return E_FAIL;
  95. }
  96. lpUnk->QueryInterface(IID_IImeCallback, (LPVOID *)&lp);
  97. if(!lp) {
  98. DBG(("-->QuertyInterface Failed\n"));
  99. }
  100. lp->Notify(IMECBNOTIFY_IMEPADOPENED, 0, 0);
  101. lp->Release();
  102. return S_OK;
  103. Unref(dwParam);
  104. }
  105. HRESULT __stdcall CImePadCallbackUIM::OnClose(DWORD dwParam)
  106. {
  107. DBG(("OnClose come dwParam[%d]\n", dwParam));
  108. IUnknown *lpUnk;
  109. IImeCallback *lp = NULL;
  110. if(!m_lpCImePadSvrUIM) {
  111. DBG(("-->m_lpCImePadSvrUIM is NULL ?\n"));
  112. return -1;
  113. }
  114. m_lpCImePadSvrUIM->OnIMEPadClose();
  115. lpUnk = m_lpCImePadSvrUIM->GetIUnkIImeCallback();
  116. if(!lpUnk) {
  117. DBG(("-->IImeCallback does not set\n"));
  118. return -1;
  119. }
  120. if(IsBadVtblUIM((IUnkDummy*)lpUnk)) {
  121. DBG(("lpIUnk is BAD Pointer \n"));
  122. return E_FAIL;
  123. }
  124. lpUnk->QueryInterface(IID_IImeCallback, (LPVOID *)&lp);
  125. if(!lp) {
  126. DBG(("-->QuertyInterface Failed\n"));
  127. }
  128. lp->Notify(IMECBNOTIFY_IMEPADCLOSED, 0, 0);
  129. lp->Release();
  130. return S_OK;
  131. Unref(dwParam);
  132. }
  133. HRESULT __stdcall
  134. CImePadCallbackUIM::OnPing(DWORD dwParam)
  135. {
  136. return S_OK;
  137. Unref(dwParam);
  138. }
  139. typedef struct tagPADCTRL2IPCTRL {
  140. DWORD dwImePadCtrl;
  141. DWORD dwIPointCtrl;
  142. }PADCTL2IPCTRL;
  143. static PADCTL2IPCTRL padCtrl2Ip[]= {
  144. { IMEPADCTRL_CONVERTALL, IPCTRL_CONVERTALL, },
  145. { IMEPADCTRL_DETERMINALL, IPCTRL_DETERMINALL, },
  146. { IMEPADCTRL_DETERMINCHAR, IPCTRL_DETERMINCHAR, },
  147. { IMEPADCTRL_CLEARALL, IPCTRL_CLEARALL, },
  148. { IMEPADCTRL_CARETSET, IPCTRL_CARETSET, },
  149. { IMEPADCTRL_CARETLEFT, IPCTRL_CARETLEFT, },
  150. { IMEPADCTRL_CARETRIGHT, IPCTRL_CARETRIGHT, },
  151. { IMEPADCTRL_CARETTOP, IPCTRL_CARETTOP, },
  152. { IMEPADCTRL_CARETBOTTOM, IPCTRL_CARETBOTTOM, },
  153. { IMEPADCTRL_CARETBACKSPACE, IPCTRL_CARETBACKSPACE, },
  154. { IMEPADCTRL_CARETDELETE, IPCTRL_CARETDELETE, },
  155. { IMEPADCTRL_PHRASEDELETE, IPCTRL_PHRASEDELETE, },
  156. { IMEPADCTRL_INSERTSPACE, IPCTRL_INSERTSPACE, },
  157. { IMEPADCTRL_INSERTFULLSPACE, IPCTRL_INSERTFULLSPACE, },
  158. { IMEPADCTRL_INSERTHALFSPACE, IPCTRL_INSERTHALFSPACE, },
  159. { IMEPADCTRL_ONIME, IPCTRL_ONIME, },
  160. { IMEPADCTRL_OFFIME, IPCTRL_OFFIME, },
  161. { IMEPADCTRL_ONPRECONVERSION, IPCTRL_PRECONVERSION, },
  162. { IMEPADCTRL_PHONETICCANDIDATE, IPCTRL_PHONETICCANDIDATE, },
  163. };
  164. HRESULT __stdcall
  165. CImePadCallbackUIM::PassData(long nSize, byte *pByte, DWORD *pdwCharID)
  166. {
  167. DBG(("CImePadCallbackUIM::PassData START\n"));
  168. LPIMEDATAHEADER lpImeDataHeader = (LPIMEDATAHEADER)pByte;
  169. HRESULT hr = S_OK;
  170. IUnknown *lpIUnk = NULL;
  171. IImeIPoint1 *lpIImeIPoint = NULL;
  172. DWORD dwCharID = 0;
  173. if(!m_lpCImePadSvrUIM) {
  174. DBG(("m_lpCImePadSvrUIM is NULL Error\n"));
  175. return E_FAIL;
  176. }
  177. lpIUnk = m_lpCImePadSvrUIM->GetIUnkIImeIPoint();
  178. if(!lpIUnk) {
  179. DBG(("lpIUnk is NULL\n"));
  180. return E_FAIL;
  181. }
  182. if(IsBadVtblUIM((IUnkDummy*)lpIUnk)) {
  183. return E_FAIL;
  184. }
  185. hr = lpIUnk->QueryInterface(IID_IImeIPoint1, (VOID **)&lpIImeIPoint);
  186. if(hr != S_OK) {
  187. DBG(("QuertyInterface Failed\n"));
  188. return E_FAIL;
  189. }
  190. if(!lpIImeIPoint) {
  191. DBG(("QuertyInterface failed\n"));
  192. return E_FAIL;
  193. }
  194. DBG(("m_hwndIF [0x%08x]\n", m_hwndIF));
  195. switch(lpImeDataHeader->dwDataID) {
  196. case IMEDATAID_CONTROL:
  197. {
  198. LPIMEDATACONTROL lpImeDataCtrl = (LPIMEDATACONTROL)lpImeDataHeader;
  199. for(int i = 0; i < sizeof(padCtrl2Ip)/sizeof(padCtrl2Ip[0]); i++) {
  200. if(lpImeDataCtrl->dwControl == padCtrl2Ip[i].dwImePadCtrl) {
  201. hr = lpIImeIPoint->ControlIME((WORD)padCtrl2Ip[i].dwIPointCtrl,
  202. IPCTRLPARAM_DEFAULT);
  203. //hr = lpIImeIPoint->UpdateContext(TRUE);
  204. break;
  205. }
  206. }
  207. }
  208. break;
  209. case IMEDATAID_STRING:
  210. {
  211. DBG(("--> IMEDATAID_STRING\n"));
  212. LPIMEDATASTRING lpImeDataStr = (LPIMEDATASTRING)lpImeDataHeader;
  213. switch(lpImeDataHeader->dwCmdID) {
  214. case IMECMDID_INSERTSTRING:
  215. {
  216. DBG(("--> IMECMDID_INSERTSTRING START\n"));
  217. LPWSTR lpwstr = (LPWSTR)((LPIMEDATASTRING)lpImeDataHeader)->wChar;
  218. INT len = lpwstr ? lstrlenW(lpwstr) : 0;
  219. DBGW((L"lpwstr [%s] len[%d]\n", lpwstr, len));
  220. BOOL fPreConv = lpImeDataStr->fPreConv;
  221. //990818:ToshiaK for KOTAE #1775.
  222. dwCharID = lpImeDataStr->dwCharID;
  223. hr = lpIImeIPoint->ControlIME(IPCTRL_ONIME, IPCTRLPARAM_DEFAULT);
  224. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION,
  225. fPreConv ? IPCTRLPARAM_ON : IPCTRLPARAM_OFF);
  226. hr = lpIImeIPoint->InsertStringEx(lpwstr,
  227. len,
  228. &dwCharID);
  229. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  230. if(pdwCharID) {
  231. *pdwCharID = dwCharID;
  232. }
  233. fPreConv = 0;
  234. DBG(("--> IMECMDID_INSERTSTRING END\n"));
  235. }
  236. break;
  237. case IMECMDID_CHANGESTRING:
  238. {
  239. DBG(("--> IMECMDID_CHANGESTRING\n"));
  240. LPWSTR lpwstr = (LPWSTR)((LPIMEDATASTRING)lpImeDataHeader)->wChar;
  241. INT len = lpwstr ? lstrlenW(lpwstr) : 0;
  242. dwCharID = ((LPIMEDATASTRING)lpImeDataHeader)->dwCharID;
  243. BOOL fPreConv = lpImeDataStr->fPreConv;
  244. hr = lpIImeIPoint->ControlIME(IPCTRL_ONIME, IPCTRLPARAM_DEFAULT);
  245. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION,
  246. fPreConv ? IPCTRLPARAM_ON : IPCTRLPARAM_OFF);
  247. hr = lpIImeIPoint->ReplaceCompString(lpImeDataStr->dwStartPos,
  248. lpImeDataStr->dwDeleteLength,
  249. lpwstr,
  250. len,
  251. &dwCharID);
  252. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  253. //hr = lpIImeIPoint->UpdateContext(TRUE);
  254. if(pdwCharID) {
  255. *pdwCharID = dwCharID;
  256. }
  257. hr = (HRESULT)dwCharID;
  258. }
  259. break;
  260. case IMECMDID_DELETESTRING:
  261. {
  262. DBG(("--> IMECMDID_DELETESTRING\n"));
  263. hr = lpIImeIPoint->ControlIME(IPCTRL_ONIME, IPCTRLPARAM_DEFAULT);
  264. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  265. hr = lpIImeIPoint->DeleteCompString((DWORD)lpImeDataStr->dwStartPos,
  266. (DWORD)lpImeDataStr->dwDeleteLength);
  267. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  268. //hr = lpIImeIPoint->UpdateContext(TRUE);
  269. }
  270. break;
  271. case IMECMDID_INSERTSTRINGINFO:
  272. case IMECMDID_CHANGESTRINGINFO:
  273. {
  274. DBG(("--> IMECMDID_INSERT(Change)STRINGINFO\n"));
  275. LPWSTR lpwstr = (LPWSTR)((LPIMEDATASTRING)lpImeDataHeader)->wChar;
  276. INT len = lpwstr ? lstrlenW(lpwstr) : 0;
  277. dwCharID = ((LPIMEDATASTRING)lpImeDataHeader)->dwCharID;
  278. BOOL fPreConv = lpImeDataStr->fPreConv;
  279. hr = lpIImeIPoint->ControlIME(IPCTRL_ONIME, IPCTRLPARAM_DEFAULT);
  280. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION,
  281. fPreConv ? IPCTRLPARAM_ON : IPCTRLPARAM_OFF);
  282. hr = lpIImeIPoint->ReplaceCompString(lpImeDataStr->dwStartPos,
  283. lpImeDataStr->dwDeleteLength,
  284. lpwstr,
  285. len,
  286. &dwCharID);
  287. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  288. if(pdwCharID) {
  289. *pdwCharID = dwCharID;
  290. }
  291. hr = (HRESULT)dwCharID;
  292. }
  293. break;
  294. default:
  295. break;
  296. }
  297. }
  298. break;
  299. case IMEDATAID_STRINGCAND:
  300. {
  301. DBG(("Data ID is IMEDATAID_STRINGCAND\n"));
  302. HRESULT hr;
  303. LPIMEDATASTRINGCAND lpStrCand = (LPIMEDATASTRINGCAND)lpImeDataHeader;
  304. PIPCANDIDATE lpIpCand;
  305. INT textCount, byteCount, i, nSize;
  306. PBYTE p;
  307. textCount = byteCount = 0;
  308. DBG(("--> dwStringCount %d\n", lpStrCand->dwStringCount));
  309. for(i = 0; i < (INT)lpStrCand->dwStringCount; i++) {
  310. DBG(("--> %d offset [%d]\n", i, lpStrCand->dwOffsetString[i]));
  311. textCount++;
  312. LPWSTR lpwstr = (LPWSTR)(((LPBYTE)lpStrCand) + lpStrCand->dwOffsetString[i]);
  313. DBGW((L"--> %d %s\n", i, lpwstr));
  314. byteCount += (lstrlenW(lpwstr)+1) * sizeof(WCHAR);
  315. }
  316. if(textCount == 0) {
  317. return S_OK;
  318. }
  319. dwCharID = lpStrCand->dwCharID;
  320. DWORD dwExInfo = lpStrCand->dwExtraInfoSize;
  321. nSize = sizeof(IPCANDIDATE) + (textCount-1) * sizeof(DWORD) + byteCount + dwExInfo;
  322. lpIpCand = (IPCANDIDATE *)MemAlloc(nSize);
  323. lpIpCand->dwSize = nSize;
  324. lpIpCand->dwFlags = lpStrCand->dwInfoMask;
  325. lpIpCand->iSelIndex = lpStrCand->dwSelIndex;
  326. lpIpCand->nCandidate = textCount;
  327. lpIpCand->dwPrivateDataOffset = 0;
  328. lpIpCand->dwPrivateDataSize = 0;
  329. DBG(("lpIpCand[0x%08x] \n", lpIpCand));
  330. DBG(("sizeof(IPCANDIDATE) [%d]\n", sizeof(IPCANDIDATE)));
  331. DBG(("size add [%d]\n", sizeof(DWORD) * (textCount -1)));
  332. DWORD dwOffset = sizeof(IPCANDIDATE)+sizeof(DWORD)*(textCount-1);
  333. p = ((PBYTE)lpIpCand) + dwOffset;
  334. for(i = 0; i < (INT)lpStrCand->dwStringCount; i++) {
  335. LPWSTR lpwstr = (LPWSTR)(((LPBYTE)lpStrCand) + lpStrCand->dwOffsetString[i]);
  336. DWORD dwStrSize = (lstrlenW(lpwstr) + 1) * sizeof(WCHAR);
  337. CopyMemory((LPWSTR)p,
  338. (WCHAR *)lpwstr,
  339. dwStrSize);
  340. lpIpCand->dwOffset[i] = dwOffset;
  341. dwOffset += dwStrSize;
  342. p += dwStrSize;
  343. }
  344. if(dwExInfo > 0) {
  345. lpIpCand->dwPrivateDataSize = dwExInfo;
  346. #ifdef _WIN64
  347. lpIpCand->dwPrivateDataOffset = (DWORD)((DWORD_PTR)p - (DWORD_PTR)lpIpCand);
  348. #else
  349. lpIpCand->dwPrivateDataOffset = (DWORD)p - (DWORD)lpIpCand;
  350. #endif
  351. CopyMemory(p,
  352. (LPBYTE)((LPBYTE)lpStrCand + lpStrCand->dwExtraInfoOffset),
  353. lpStrCand->dwExtraInfoSize);
  354. }
  355. BOOL fPreConv = lpStrCand->fPreConv;
  356. hr = lpIImeIPoint->ControlIME(IPCTRL_ONIME, IPCTRLPARAM_DEFAULT);
  357. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION,
  358. fPreConv ? IPCTRLPARAM_ON : IPCTRLPARAM_OFF);
  359. //----------------------------------------------------------------
  360. //990713: need to set Start position for IPoint.
  361. //----------------------------------------------------------------
  362. DWORD dwInsertPos; // = IPINS_CURRENT; //Default.
  363. DWORD dwLen;
  364. //990823:Toshiak for KOTAE #1779.
  365. //000825:Satori #2123
  366. if(lpStrCand->dwStartPos == IMECMDVALUE_DEFAULT_INSERT_POS) {
  367. dwInsertPos = IPINS_CURRENT; //Set IPoint's value
  368. }
  369. else {
  370. dwInsertPos = lpStrCand->dwStartPos;
  371. }
  372. dwLen = (DWORD)lpStrCand->dwDeleteLength;
  373. switch(lpStrCand->header.dwCmdID) {
  374. case IMECMDID_INSERTSTRINGCANDINFO:
  375. hr = lpIImeIPoint->InsertImeItem(lpIpCand,
  376. dwInsertPos,
  377. &dwCharID);
  378. break;
  379. case IMECMDID_CHANGESTRINGCANDINFO:
  380. hr = lpIImeIPoint->ReplaceImeItem(dwInsertPos,
  381. dwLen,
  382. lpIpCand,
  383. &dwCharID);
  384. break;
  385. default:
  386. break;
  387. }
  388. hr = lpIImeIPoint->ControlIME(IPCTRL_PRECONVERSION, IPCTRLPARAM_ON);
  389. //hr = lpIImeIPoint->UpdateContext(TRUE);
  390. MemFree(lpIpCand);
  391. if(pdwCharID) {
  392. *pdwCharID = dwCharID;
  393. }
  394. }
  395. break;
  396. default:
  397. break;
  398. }
  399. //990630:ToshiaK for #1327.
  400. //In WinWord, if call UpdateContext(TRUE) here,
  401. //Word does NOT repaint composition string.
  402. //once return the SendMessageTimeout() procedure,
  403. //and update context asynchronously.
  404. //in WM_USER_UPDATECONTEXT's lParam, set IImeIPoint interface pointer.
  405. //and message procedure, check it with current iimeipoint.
  406. ::PostMessage(m_hwndIF, WM_USER_UPDATECONTEXT, (WPARAM)0, (LPARAM)lpIImeIPoint);
  407. lpIImeIPoint->Release();
  408. return hr;
  409. Unref(nSize);
  410. }
  411. HRESULT STDMETHODCALLTYPE
  412. CImePadCallbackUIM::ReceiveData(
  413. /* [in] */ DWORD dwCmdID,
  414. /* [in] */ DWORD dwDataID,
  415. /* [out] */ long __RPC_FAR *pSize,
  416. /* [size_is][size_is][out] */ byte __RPC_FAR *__RPC_FAR *ppByte)
  417. {
  418. DBG(("CImePadCallbackUIM::ReceiveData START\n"));
  419. DBG(("-->dwCmdID [0x%08x]\n", dwCmdID));
  420. DBG(("-->dwDataID [0x%08x]\n", dwDataID));
  421. DBG(("-->pSize [0x%08x]\n", pSize));
  422. DBG(("-->ppByte [0x%08x]\n", ppByte));
  423. HRESULT hr = S_OK;
  424. IUnknown *lpIUnk = NULL;
  425. IImeIPoint1 *lpIImeIPoint = NULL;
  426. DBG(("-->Check m_lpCImePadSvrUIM\n"));
  427. if(!m_lpCImePadSvrUIM) {
  428. DBG(("m_lpCImePadSvrUIM is NULL Error\n"));
  429. return E_FAIL;
  430. }
  431. DBG(("-->Check m_fnCoTaskMemAlloc\n"));
  432. if(!m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc ||
  433. !m_lpCImePadSvrUIM->m_fnCoTaskMemFree) {
  434. DBG(("--> OLE32.DLL does NOT EXIST ? Error\n"));
  435. return E_FAIL;
  436. }
  437. lpIUnk = m_lpCImePadSvrUIM->GetIUnkIImeIPoint();
  438. DBG(("-->Check lpIUnk [0x%08x]\n", lpIUnk));
  439. if(!lpIUnk) {
  440. DBG(("lpIUnk is NULL\n"));
  441. return E_FAIL;
  442. }
  443. DBG(("-->Check lpIUnk IsBadVtblUIM[0x%08x]\n", lpIUnk));
  444. if(IsBadVtblUIM((IUnkDummy*)lpIUnk)) {
  445. DBG(("lpIUnk is BAD Pointer \n"));
  446. return E_FAIL;
  447. }
  448. DBG(("-->Call QuertyInterface\n"));
  449. hr = lpIUnk->QueryInterface(IID_IImeIPoint1, (VOID **)&lpIImeIPoint);
  450. if(hr != S_OK) {
  451. DBG(("QuertyInterface Failed\n"));
  452. return E_FAIL;
  453. }
  454. DBG(("--> QueryInterface Success \n"));
  455. if(!lpIImeIPoint) {
  456. DBG(("QuertyInterface failed\n"));
  457. return E_FAIL;
  458. }
  459. LPIMEDATACOMPOSITION lpCompoInfo;
  460. LPIMEDATACOMPOSITION lpCompoTmp;
  461. LPWSTR lpwstrCompo, lpwstr;
  462. DWORD *pdwCharID, *pdw;
  463. DWORD dwSize;
  464. switch(dwDataID) {
  465. case IMEDATAID_COMPOSITION:
  466. switch(dwCmdID) {
  467. case IMECMDID_GETCOMPOSITIONINFO:
  468. DBG(("--> IMECMDID_GETCOMPOSITIONINFO\n"));
  469. dwSize = sizeof(IMEDATACOMPOSITION);
  470. lpCompoInfo = (LPIMEDATACOMPOSITION)(*m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc)(dwSize);
  471. if(!lpCompoInfo) {
  472. lpIImeIPoint->Release();
  473. return E_OUTOFMEMORY;
  474. }
  475. hr = lpIImeIPoint->GetAllCompositionInfo(NULL,
  476. NULL,
  477. (INT *)&lpCompoInfo->dwStringCount,
  478. (INT *)&lpCompoInfo->dwCaretPos,
  479. (INT *)&lpCompoInfo->dwUndeterminedStartPos,
  480. (INT *)&lpCompoInfo->dwUndeterminedLength,
  481. (INT *)&lpCompoInfo->dwEditStartPos,
  482. (INT *)&lpCompoInfo->dwEditLength);
  483. lpCompoInfo->header.dwSize = dwSize;
  484. lpCompoInfo->header.dwCmdID = dwCmdID;
  485. lpCompoInfo->header.dwDataID= dwDataID;
  486. lpCompoInfo->dwOffsetString = 0;
  487. lpCompoInfo->dwOffsetCharID = 0;
  488. *pSize = lpCompoInfo->header.dwSize;
  489. *ppByte = (PBYTE)lpCompoInfo;
  490. DBG(("--> IMECMDID_GETCOMPOSITIONINFO END\n"));
  491. break;
  492. case IMECMDID_GETCOMPOSITIONSTRING:
  493. DBG(("--> IMECMDID_GETCOMPOSITIONSTRING START\n"));
  494. lpCompoInfo = (LPIMEDATACOMPOSITION)(*m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc)(sizeof(IMEDATACOMPOSITION));
  495. if(!lpCompoInfo) {
  496. DBG(("-->OutofMemory\n"));
  497. lpIImeIPoint->Release();
  498. return E_OUTOFMEMORY;
  499. }
  500. lpwstrCompo = NULL;
  501. pdwCharID = NULL;
  502. ZeroMemory(lpCompoInfo, sizeof(IMEDATACOMPOSITION));
  503. hr = lpIImeIPoint->GetAllCompositionInfo(&lpwstrCompo,
  504. &pdwCharID,
  505. (INT *)&lpCompoInfo->dwStringCount,
  506. (INT *)&lpCompoInfo->dwCaretPos,
  507. (INT *)&lpCompoInfo->dwUndeterminedStartPos,
  508. (INT *)&lpCompoInfo->dwUndeterminedLength,
  509. (INT *)&lpCompoInfo->dwEditStartPos,
  510. (INT *)&lpCompoInfo->dwEditLength);
  511. DBG(("-->hr [0x%08x]\n", hr));
  512. DBGW((L"-->lpwstrCompo[%s]\n", lpwstrCompo));
  513. dwSize = sizeof(IMEDATACOMPOSITION) +
  514. (lpCompoInfo->dwStringCount+1)*sizeof(WCHAR) +
  515. (lpCompoInfo->dwStringCount) * sizeof(DWORD);
  516. DBG(("-->dwSize [%d]\n", dwSize));
  517. lpCompoTmp = (LPIMEDATACOMPOSITION)(*m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc)(dwSize);
  518. if(!lpCompoTmp) {
  519. DBG(("-->OutofMemory\n"));
  520. lpIImeIPoint->Release();
  521. return E_OUTOFMEMORY;
  522. }
  523. lpCompoTmp->header.dwSize = dwSize;
  524. lpCompoTmp->header.dwCmdID = dwCmdID;
  525. lpCompoTmp->header.dwDataID= dwDataID;
  526. lpCompoTmp->dwStringCount = lpCompoInfo->dwStringCount;
  527. lpCompoTmp->dwCaretPos = lpCompoInfo->dwCaretPos;
  528. lpCompoTmp->dwUndeterminedStartPos = lpCompoInfo->dwUndeterminedStartPos;
  529. lpCompoTmp->dwUndeterminedLength = lpCompoInfo->dwUndeterminedLength;
  530. lpCompoTmp->dwEditStartPos = lpCompoInfo->dwEditStartPos;
  531. lpCompoTmp->dwEditLength = lpCompoInfo->dwEditLength;
  532. lpCompoTmp->dwOffsetString = (DWORD)sizeof(IMEDATACOMPOSITION);
  533. lpwstr = (LPWSTR)((PBYTE)lpCompoTmp + lpCompoTmp->dwOffsetString);
  534. //990928:toshiaK for KOTAE #2273
  535. //Need to check lpwstrCompo is NULL or not.
  536. if(lpwstrCompo && lpCompoTmp->dwStringCount > 0) {
  537. CopyMemory(lpwstr,
  538. (WCHAR *)lpwstrCompo,
  539. lpCompoTmp->dwStringCount * sizeof(WCHAR));
  540. }
  541. lpwstr[lpCompoTmp->dwStringCount] = (WCHAR)0x0000;
  542. lpCompoTmp->dwOffsetCharID = (DWORD)(sizeof(IMEDATACOMPOSITION) +
  543. (lpCompoTmp->dwStringCount+1)*sizeof(WCHAR));
  544. //990928:toshiaK for KOTAE #2273
  545. //Need to check pdwCharID is NULL or not.
  546. if(pdwCharID && lpCompoTmp->dwStringCount > 0) {
  547. pdw = (DWORD *)((PBYTE)lpCompoTmp + lpCompoTmp->dwOffsetCharID);
  548. CopyMemory(pdw, pdwCharID, sizeof(DWORD)*lpCompoTmp->dwStringCount);
  549. }
  550. *pSize = lpCompoTmp->header.dwSize;
  551. *ppByte = (PBYTE)lpCompoTmp;
  552. (*m_lpCImePadSvrUIM->m_fnCoTaskMemFree)(lpCompoInfo);
  553. //990928:toshiaK for KOTAE #2273
  554. if(lpwstrCompo) {
  555. (*m_lpCImePadSvrUIM->m_fnCoTaskMemFree)(lpwstrCompo);
  556. }
  557. //990928:toshiaK for KOTAE #2273
  558. if(pdwCharID) {
  559. (*m_lpCImePadSvrUIM->m_fnCoTaskMemFree)(pdwCharID);
  560. }
  561. DBG(("--> IMECMDID_GETCOMPOSITIONSTRING END\n"));
  562. break;
  563. default:
  564. break;
  565. }
  566. break;
  567. case IMEDATAID_CONVSTATUS:
  568. {
  569. if(dwCmdID != IMECMDID_GETCONVERSIONSTATUS) {
  570. DBG((" --> INVALID CMDID\n"));
  571. }
  572. DBG(("--> IMECMDID_GETCONVERSIONSTATUS\n"));
  573. dwSize = sizeof(IMEDATACONVSTATUS);
  574. LPIMEDATACONVSTATUS lpConvStat;
  575. lpConvStat = (LPIMEDATACONVSTATUS)(*m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc)(dwSize);
  576. if(!lpConvStat) {
  577. DBG(("E_OUTOFMEMORY dwSize [%d]\n", dwSize));
  578. lpIImeIPoint->Release();
  579. return E_OUTOFMEMORY;
  580. }
  581. LPARAM lConv = 0;
  582. LPARAM lSent = 0;
  583. hr = lpIImeIPoint->ControlIME((WORD)IPCTRL_GETCONVERSIONMODE,
  584. (LPARAM)&lConv);
  585. hr = lpIImeIPoint->ControlIME((WORD)IPCTRL_GETSENTENCENMODE,
  586. (LPARAM)&lSent);
  587. lpConvStat->header.dwSize = dwSize;
  588. lpConvStat->header.dwCmdID = IMECMDID_GETCONVERSIONSTATUS;
  589. lpConvStat->header.dwDataID= IMEDATAID_CONVSTATUS;
  590. lpConvStat->dwConversionMode = (DWORD)lConv;
  591. lpConvStat->dwSentenceMode = (DWORD)lSent;
  592. DBG((" --> dwConversionMode[0x%8x]\n", lpConvStat->dwConversionMode));
  593. DBG((" --> dwSentenceMode [0x%8x]\n", lpConvStat->dwSentenceMode));
  594. *pSize = dwSize;
  595. *ppByte = (PBYTE)lpConvStat;
  596. }
  597. break;
  598. case IMEDATAID_APPINFO:
  599. //990816:ToshiaK KOTAE Raid #1757
  600. if(dwCmdID != IMECMDID_GETAPPLHWND) {
  601. DBG((" --> INVALID CMDID\n"));
  602. hr = S_FALSE;
  603. }
  604. else {
  605. IImeCallback *lp = NULL;
  606. IUnknown *lpUnkCB;
  607. lpUnkCB = m_lpCImePadSvrUIM->GetIUnkIImeCallback();
  608. if(!lpUnkCB) {
  609. DBG(("-->IImeCallback does not set\n"));
  610. lpIImeIPoint->Release();
  611. return E_FAIL;
  612. }
  613. if(IsBadVtblUIM((IUnkDummy*)lpUnkCB)) {
  614. DBG(("lpIUnk is BAD Pointer \n"));
  615. lpIImeIPoint->Release();
  616. return E_FAIL;
  617. }
  618. lpUnkCB->QueryInterface(IID_IImeCallback, (LPVOID *)&lp);
  619. if(!lp) {
  620. DBG(("-->QuertyInterface Failed\n"));
  621. lpIImeIPoint->Release();
  622. return E_FAIL;
  623. }
  624. dwSize = sizeof(IMEDATAAPPLINFO);
  625. LPIMEDATAAPPLINFO lpApplInfo;
  626. lpApplInfo = (LPIMEDATAAPPLINFO)(*m_lpCImePadSvrUIM->m_fnCoTaskMemAlloc)(dwSize);
  627. if(!lpApplInfo) {
  628. DBG(("E_OUTOFMEMORY dwSize [%d]\n", dwSize));
  629. lpIImeIPoint->Release();
  630. return E_OUTOFMEMORY;
  631. }
  632. lpApplInfo->header.dwSize = dwSize;
  633. lpApplInfo->header.dwCmdID = IMECMDID_GETAPPLHWND;
  634. lpApplInfo->header.dwDataID= IMEDATAID_APPINFO;
  635. lpApplInfo->hwndApp = NULL;
  636. lp->GetApplicationHWND(&lpApplInfo->hwndApp);
  637. if(pSize && ppByte) {
  638. *pSize = dwSize;
  639. *ppByte = (PBYTE)lpApplInfo;
  640. }
  641. else {
  642. (*m_lpCImePadSvrUIM->m_fnCoTaskMemFree)(lpApplInfo);
  643. hr = E_FAIL;
  644. }
  645. lp->Release();
  646. }
  647. break;
  648. default:
  649. DBG(("UNKOWN DATAID [0x%08x]\n", dwDataID));
  650. hr = S_FALSE;
  651. break;
  652. }
  653. lpIImeIPoint->Release();
  654. DBG(("CImePadCallbackUIM::ReceiveData END hr[0x%08x]\n", hr));
  655. return hr;
  656. }
  657. //----------------------------------------------------------------
  658. CImePadCallbackUIM::CImePadCallbackUIM(HWND hwndIF, LPCImePadSvrUIM lpCImePadSvrUIM)
  659. {
  660. DBG(("######## CImePadCallbackUIM::CImePadCallbackUIM constructor START ##########\n"));
  661. m_hwndIF = hwndIF;
  662. m_lpCImePadSvrUIM = lpCImePadSvrUIM;
  663. m_cRef = 0;
  664. DBG(("######## CImePadCallbackUIM::CImePadCallbackUIM constructor END ##########\n"));
  665. }
  666. CImePadCallbackUIM::~CImePadCallbackUIM()
  667. {
  668. DBG(("######## CImePadCallbackUIM::~CImePadCallbackUIM destructor START ##########\n"));
  669. m_hwndIF = NULL;
  670. m_lpCImePadSvrUIM = NULL;
  671. DBG(("######## CImePadCallbackUIM::~CImePadCallbackUIM destructor END ##########\n"));
  672. m_cRef = 0;
  673. }
  674. VOID*
  675. CImePadCallbackUIM::operator new( size_t size )
  676. {
  677. LPVOID lp = (LPVOID)MemAlloc(size);
  678. return lp;
  679. }
  680. VOID
  681. CImePadCallbackUIM::operator delete( VOID *lp )
  682. {
  683. if(lp) {
  684. MemFree(lp);
  685. }
  686. return;
  687. }