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.

832 lines
23 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : cpadsvrs.cpp
  3. // Purpose : CImePadServerUIM for Shared Memory version.
  4. //
  5. //
  6. // Date : Fri Apr 16 15:39:33 1999
  7. // Author : ToshiaK
  8. //
  9. // Copyright(c) 1995-1999, Microsoft Corp. All rights reserved
  10. //////////////////////////////////////////////////////////////////
  11. #include <windows.h>
  12. #include "imepadsv.h"
  13. #include "cpadsvus.h"
  14. #include "cpadcbu.h"
  15. #include "cpaddbg.h"
  16. #include "iimecb.h"
  17. #include "ipoint1.h"
  18. //----------------------------------------------------------------
  19. //misc definition
  20. //----------------------------------------------------------------
  21. #define Unref(a) UNREFERENCED_PARAMETER(a)
  22. //990812:ToshiaK For Win64. Use Global Alloc/Free Ptr.
  23. #include <windowsx.h>
  24. #define MemAlloc(a) GlobalAllocPtr(GMEM_FIXED, a)
  25. #define MemFree(a) GlobalFreePtr(a)
  26. #define SZ_IMEPADIFCLASS TEXT("msimepad8UIMIFClass")
  27. //----------------------------------------------------------------
  28. //TIMER id definition
  29. //----------------------------------------------------------------
  30. #define TIMERID_NOTIFY_ACTIVATECONTEXT 0x0010
  31. #define TIMERID_NOTIFY_APPLYCANDIDATE 0x0011
  32. #define TIMERID_NOTIFY_QUERYCANDIDATE 0x0012
  33. #define TIMERID_NOTIFY_APPLYCANDIDATEEX 0x0013
  34. #define TIMERELAPS_ACTIVATE 200 //milisec
  35. #define TIMERELAPS_INACTIVATE 100
  36. #define TIMERELAPS_NOTIFY 200
  37. inline LPVOID
  38. WinSetUserPtr(HWND hwnd, LPVOID lpVoid)
  39. {
  40. #ifdef _WIN64
  41. return (LPVOID)SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lpVoid);
  42. #else
  43. return (LPVOID)SetWindowLong(hwnd, GWL_USERDATA, (LONG)lpVoid);
  44. #endif
  45. }
  46. inline LPVOID
  47. WinGetUserPtr(HWND hwnd)
  48. {
  49. #ifdef _WIN64
  50. return (LPVOID)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  51. #else
  52. return (LPVOID)GetWindowLong(hwnd, GWL_USERDATA);
  53. #endif
  54. }
  55. static LPWSTR
  56. StrdupW(LPWSTR lpwstr)
  57. {
  58. LPWSTR lpwstrRet;
  59. if(!lpwstr) {
  60. return NULL;
  61. }
  62. INT len = lstrlenW(lpwstr);
  63. if(len == 0) {
  64. return NULL;
  65. }
  66. lpwstrRet = (LPWSTR)MemAlloc((len+1) * sizeof(WCHAR));
  67. if(!lpwstrRet) {
  68. return NULL;
  69. }
  70. CopyMemory(lpwstrRet, lpwstr, sizeof(WCHAR)*len);
  71. lpwstrRet[len] = (WCHAR)0x0000;
  72. return lpwstrRet;
  73. }
  74. //----------------------------------------------------------------
  75. //
  76. //public method decalre
  77. //
  78. //----------------------------------------------------------------
  79. //////////////////////////////////////////////////////////////////
  80. // Function : CImePadSvrSharemem::CImePadSvrSharemem
  81. // Type : None
  82. // Purpose : Constructor of CImePadSvrSharemem class
  83. // Args : None
  84. // Return :
  85. // DATE : Mon May 17 23:04:01 1999
  86. // Histroy :
  87. //////////////////////////////////////////////////////////////////
  88. CImePadSvrUIM_Sharemem::CImePadSvrUIM_Sharemem(HINSTANCE hInst):CImePadSvrUIM(hInst)
  89. {
  90. DBG(("CImePadSvrUIM_Sharemem::CImePadSvrUIM_Sharemem() constructor START\n"));
  91. m_imeLangID = 0; //Save Initialized data.
  92. m_dwImeInputID = 0; //Save Initialized data.
  93. m_fShowReqStatus = FALSE; //Save ShowUI()'s bool value.
  94. m_fLastActiveCtx = FALSE; //Save IMEPADNOTIFY_ACTIVATECONTEXT
  95. m_hwndIF = NULL; //Internal I/F Window handle.
  96. m_lpIUnkIImeIPoint = NULL; //IImeIPoint I/F pointer as IUnknown.
  97. m_lpIUnkIImeCallback = NULL; //IImeCallback I/F pointer as IUnknown.
  98. m_lpCImePadCallbackUIM = NULL; //CImePadCallbackUIM instance pointer.
  99. m_lpIImePadServer = NULL; //IImePadServer I/F pointer.
  100. m_dwRegAdvise = 0;
  101. m_hModuleProxyStub = NULL;
  102. //Initialize Candidate data
  103. ZeroMemory(&m_ntfyDataApplyCand, sizeof(m_ntfyDataApplyCand));
  104. ZeroMemory(&m_ntfyDataQueryCand, sizeof(m_ntfyDataQueryCand));
  105. ZeroMemory(&m_ntfyDataApplyCandEx, sizeof(m_ntfyDataApplyCandEx));
  106. DBG(("CImePadSvrUIM_Sharemem::CImePadSvrUIM_Sharemem() constructor END\n"));
  107. }
  108. //////////////////////////////////////////////////////////////////
  109. // Function : CImePadSvrUIM_Sharemem::~CImePadSvrUIM_Sharemem
  110. // Type : INT
  111. // Purpose : Destructor of CImePadSvrUIM_Sharemem Class.
  112. // Args : None
  113. // Return :
  114. // DATE : Mon May 17 23:04:29 1999
  115. // Histroy :
  116. //////////////////////////////////////////////////////////////////
  117. CImePadSvrUIM_Sharemem::~CImePadSvrUIM_Sharemem(VOID)
  118. {
  119. DBG(("CImePadSvrUIM_Sharemem::CImePadSvrUIM_Sharemem() Destructor START\n"));
  120. this->DestroyIFHWND(TRUE);
  121. m_imeLangID = 0; //Save Initialized data.
  122. m_dwImeInputID = 0; //Save Initialized data.
  123. m_fShowReqStatus = FALSE; //Save ShowUI()'s bool value.
  124. m_fLastActiveCtx = FALSE; //Save IMEPADNOTIFY_ACTIVATECONTEXT
  125. m_hwndIF = NULL; //Internal I/F Window handle.
  126. m_lpIUnkIImeIPoint = NULL; //IImeIPoint I/F pointer as IUnknown.
  127. m_lpIUnkIImeCallback = NULL; //IImeCallback I/F pointer as IUnknown.
  128. m_lpIImePadServer = NULL; //IImePadServer I/F pointer.
  129. //990813:ToshiaK. Memory leak.
  130. if(m_lpCImePadCallbackUIM) {
  131. delete m_lpCImePadCallbackUIM;
  132. m_lpCImePadCallbackUIM = NULL;
  133. }
  134. if(m_hModuleProxyStub) {
  135. ::FreeLibrary(m_hModuleProxyStub);
  136. m_hModuleProxyStub = 0;
  137. }
  138. DBG(("CImePadSvrUIM_Sharemem::CImePadSvrUIM_Sharemem() Destructor END\n"));
  139. }
  140. BOOL
  141. CImePadSvrUIM_Sharemem::IsAvailable(VOID)
  142. {
  143. LPTSTR lpPath = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  144. if(!lpPath) {
  145. DBG(("-->Outof Memory ??\n"));
  146. return FALSE;
  147. }
  148. if(0 == this->CLSID2ModuleName(IID_IImePadServerSHM,
  149. FALSE,
  150. lpPath,
  151. sizeof(TCHAR)*MAX_PATH)) {
  152. MemFree(lpPath);
  153. return TRUE;
  154. }
  155. MemFree(lpPath);
  156. return FALSE;
  157. }
  158. BOOL
  159. CImePadSvrUIM_Sharemem::OnIMEPadClose(VOID)
  160. {
  161. m_fShowReqStatus = FALSE;
  162. return 0;
  163. }
  164. INT
  165. CImePadSvrUIM_Sharemem::Initialize(LANGID imeLangID,
  166. DWORD dwImeInputID,
  167. LPVOID lpVoid)
  168. {
  169. DBG(("CImePadSvrUIM_Sharemem::Initialize() START\n"));
  170. DBG(("--> imeLangID [0x%08x]\n", imeLangID));
  171. DBG(("--> dwImeInputID[0x%08x]\n", dwImeInputID));
  172. if(m_lpIImePadServer) {
  173. DBG(("-->Already Initialized\n"));
  174. return 0;
  175. }
  176. HRESULT hr;
  177. this->CreateIFHWND(); //Create internal Interface Window.
  178. m_imeLangID = imeLangID;
  179. m_dwImeInputID = dwImeInputID;
  180. if(!m_lpCImePadCallbackUIM) {
  181. m_lpCImePadCallbackUIM = new CImePadCallbackUIM(m_hwndIF, this);
  182. }
  183. this->InitOleAPI();
  184. m_lpIImePadServer = (IImePadServer *)this->CreateObject();
  185. if(!m_lpIImePadServer) {
  186. return -1;
  187. }
  188. m_lpIImePadServer->Initialize(::GetCurrentProcessId(),
  189. ::GetCurrentThreadId(),
  190. (DWORD)imeLangID,
  191. (DWORD)dwImeInputID,
  192. TRUE, //fUIM,
  193. m_lpCImePadCallbackUIM,
  194. NULL,
  195. 0,
  196. 0);
  197. DBG(("CImePadSvrUIM_Sharemem::Initialize() END\n"));
  198. return 0;
  199. Unref(lpVoid);
  200. Unref(hr);
  201. }
  202. INT
  203. CImePadSvrUIM_Sharemem::Terminate(LPVOID lpVoid)
  204. {
  205. DBG(("CImePadSvrUIM_Sharemem::::Terminate() START \n"));
  206. if(!m_lpIImePadServer) {
  207. return -1;
  208. }
  209. m_lpIImePadServer->Terminate(0, 0);
  210. m_lpIImePadServer = NULL;
  211. //990813:ToshiaK memory leak;
  212. if(m_lpCImePadCallbackUIM) {
  213. delete m_lpCImePadCallbackUIM;
  214. m_lpCImePadCallbackUIM = NULL;
  215. }
  216. DBG(("CImePadSvrUIM_Sharemem::Terminate() End\n"));
  217. return 0;
  218. Unref(lpVoid);
  219. }
  220. INT
  221. CImePadSvrUIM_Sharemem::ForceDisConnect(VOID)
  222. {
  223. DBG(("CImePadSvrUIM_Sharemem::ForceDisConnect START\n"));
  224. if(m_lpIImePadServer) {
  225. m_lpIImePadServer = NULL;
  226. }
  227. DBG(("CImePadSvrUIM_Sharemem::ForceDisConnect END\n"));
  228. return 0;
  229. }
  230. INT
  231. CImePadSvrUIM_Sharemem::ShowUI(BOOL fShow)
  232. {
  233. DBG(("CImePadSvrUIM_Sharemem::ShowUI() START fShow [%d]\n"));
  234. m_fShowReqStatus = fShow;
  235. if(!m_lpIImePadServer) {
  236. return -1;
  237. }
  238. m_lpIImePadServer->ShowUI(fShow);
  239. DBG(("CImePadSvrUIM_Sharemem::ShowUI() END\n"));
  240. return 0;
  241. }
  242. INT
  243. CImePadSvrUIM_Sharemem::IsVisible(BOOL *pfVisible)
  244. {
  245. if(pfVisible) {
  246. *pfVisible = m_fShowReqStatus;
  247. }
  248. return 0;
  249. }
  250. INT
  251. CImePadSvrUIM_Sharemem::ActivateApplet(UINT activateID,
  252. LPARAM dwActivateParam,
  253. LPWSTR lpwstr1,
  254. LPWSTR lpwstr2)
  255. {
  256. DBG(("CImePadSvrUIM_Sharemem::ActivateApplet START\n"));
  257. DBG(("-->activateID [0x%08x][%s]\n",
  258. activateID,
  259. activateID == IMEPADACTID_ACTIVATEBYCATID ? "IMEPADACTID_ACTIVATEBYCATID" :
  260. activateID == IMEPADACTID_ACTIVATEBYIID ? "IMEPADACTID_ACTIVATEBYIID" :
  261. activateID == IMEPADACTID_ACTIVATEBYNAME ? "IMEPADACTID_ACTIVATEBYNAME" :
  262. "Unknown"));
  263. DBG(("-->dwActivateParam [0x%08x]\n", dwActivateParam));
  264. DBG(("-->lpwstr1 [0x%08x]\n", lpwstr1));
  265. DBG(("-->lpwstr2 [0x%08x]\n", lpwstr2));
  266. if(!m_lpIImePadServer) {
  267. DBG(("-->m_lpIImePadServer is NULL\n"));
  268. DBG(("CImePadSvrUIM_Sharemem::ActivateApplet END\n"));
  269. return -1;
  270. }
  271. m_lpIImePadServer->ActivateApplet(activateID,
  272. dwActivateParam,
  273. lpwstr1,
  274. lpwstr2);
  275. DBG(("CImePadSvrUIM_Sharemem::ActivateApplet END\n"));
  276. return 0;
  277. Unref(activateID);
  278. Unref(dwActivateParam);
  279. Unref(lpwstr1);
  280. Unref(lpwstr2);
  281. }
  282. INT
  283. CImePadSvrUIM_Sharemem::Notify(INT id, WPARAM wParam, LPARAM lParam)
  284. {
  285. HRESULT hr;
  286. switch(id) {
  287. case IMEPADNOTIFY_ACTIVATECONTEXT:
  288. DBG(("CImePadSvrUIM_Sharemem::Notify: ActivateContext\n"));
  289. //990608:KOTAE #1121. if ImePad is not shown in this application,
  290. //Do not send IMEPADNOTIFY_ACTIVATECONTEXT
  291. if(!m_fShowReqStatus) {
  292. return 0;
  293. }
  294. m_fLastActiveCtx = (BOOL)wParam;
  295. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_ACTIVATECONTEXT);
  296. if(m_fLastActiveCtx) {
  297. ::SetTimer(m_hwndIF,
  298. TIMERID_NOTIFY_ACTIVATECONTEXT,
  299. TIMERELAPS_ACTIVATE,
  300. NULL);
  301. }
  302. else {
  303. ::SetTimer(m_hwndIF,
  304. TIMERID_NOTIFY_ACTIVATECONTEXT,
  305. TIMERELAPS_INACTIVATE,
  306. NULL);
  307. }
  308. break;
  309. case IMEPADNOTIFY_APPLYCANDIDATE:
  310. //----------------------------------------------------------------
  311. // Notify for Candidate Applied
  312. // WPARAM wParam: dwCharId = (DWORD)wParam;
  313. // LPARAM lParam: iSelIndex = (INT)lParam;
  314. //----------------------------------------------------------------
  315. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATE);
  316. m_ntfyDataApplyCand.dwCharID = (DWORD)wParam;
  317. m_ntfyDataApplyCand.dwSelIndex = (DWORD)lParam;
  318. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATE, TIMERELAPS_NOTIFY, NULL);
  319. break;
  320. case IMEPADNOTIFY_QUERYCANDIDATE:
  321. //----------------------------------------------------------------
  322. // Notify for Querying Candidate
  323. // WPARAM wParam: dwCharId = (DWORD)wParam;
  324. // LPARAM lParam: 0. not used.
  325. //----------------------------------------------------------------
  326. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_QUERYCANDIDATE);
  327. m_ntfyDataQueryCand.dwCharID = (DWORD)wParam;
  328. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_QUERYCANDIDATE, TIMERELAPS_NOTIFY, NULL);
  329. break;
  330. case IMEPADNOTIFY_APPLYCANDIDATE_EX:
  331. //----------------------------------------------------------------
  332. // Notify for Candidate Applied
  333. // WPARAM wParam: dwCharId = (DWORD)wParam;
  334. // LPARAM lParam: lpApplyCandEx = (LPIMEPADAPPLYCANDEX)lParam;
  335. //----------------------------------------------------------------
  336. {
  337. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATEEX);
  338. m_ntfyDataApplyCandEx.dwCharID = (DWORD)wParam;
  339. LPIMEPADAPPLYCANDINFO lpApplyCandInfo = (LPIMEPADAPPLYCANDINFO)lParam;
  340. if(m_ntfyDataApplyCandEx.lpwstrCreated1) {
  341. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated1);
  342. }
  343. if(m_ntfyDataApplyCandEx.lpwstrCreated2) {
  344. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated2);
  345. }
  346. m_ntfyDataApplyCandEx.lpwstrCreated1 = NULL;
  347. m_ntfyDataApplyCandEx.lpwstrCreated2 = NULL;
  348. if(lpApplyCandInfo) {
  349. if(lpApplyCandInfo->lpwstrDisplay) {
  350. m_ntfyDataApplyCandEx.lpwstrCreated1 = StrdupW(lpApplyCandInfo->lpwstrDisplay);
  351. }
  352. if(lpApplyCandInfo->lpwstrReading) {
  353. m_ntfyDataApplyCandEx.lpwstrCreated2 = StrdupW(lpApplyCandInfo->lpwstrReading);
  354. }
  355. }
  356. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATEEX, TIMERELAPS_NOTIFY, NULL);
  357. }
  358. break;
  359. case IMEPADNOTIFY_MODECHANGED:
  360. break;
  361. case IMEPADNOTIFY_STARTCOMPOSITION:
  362. break;
  363. case IMEPADNOTIFY_COMPOSITION:
  364. break;
  365. case IMEPADNOTIFY_ENDCOMPOSITION:
  366. break;
  367. case IMEPADNOTIFY_OPENCANDIDATE:
  368. break;
  369. case IMEPADNOTIFY_CLOSECANDIDATE:
  370. break;
  371. default:
  372. break;
  373. }
  374. return 0;
  375. Unref(hr);
  376. Unref(wParam);
  377. Unref(lParam);
  378. }
  379. INT
  380. CImePadSvrUIM_Sharemem::GetAppletConfigList(DWORD dwMask,
  381. INT *pCountApplet,
  382. IMEPADAPPLETCONFIG **ppList)
  383. {
  384. DBG(("CImePadSvrUIM_Sharemem::GetAppletConfigList START\n"));
  385. if(!m_lpIImePadServer) {
  386. DBG(("-->m_lpIImePadServer is NULL\n"));
  387. return -1;
  388. }
  389. HRESULT hr;
  390. hr = m_lpIImePadServer->GetAppletConfigList(dwMask,
  391. (UINT *)pCountApplet,
  392. ppList);
  393. DBG(("CImePadSvrUIM_Sharemem::GetAppletConfigList END\n"));
  394. return hr;
  395. }
  396. IUnknown *
  397. CImePadSvrUIM_Sharemem::SetIUnkIImeIPoint(IUnknown *pIUnkIImeIPoint)
  398. {
  399. return m_lpIUnkIImeIPoint = pIUnkIImeIPoint;
  400. }
  401. IUnknown *
  402. CImePadSvrUIM_Sharemem::SetIUnkIImeCallback(IUnknown *pIUnkIImeCallback)
  403. {
  404. return m_lpIUnkIImeCallback = pIUnkIImeCallback;
  405. }
  406. IUnknown*
  407. CImePadSvrUIM_Sharemem::GetIUnkIImeIPoint(VOID)
  408. {
  409. return m_lpIUnkIImeIPoint;
  410. }
  411. IUnknown*
  412. CImePadSvrUIM_Sharemem::GetIUnkIImeCallback(VOID)
  413. {
  414. return m_lpIUnkIImeCallback;
  415. }
  416. //----------------------------------------------------------------
  417. //
  418. //private static method
  419. //
  420. //----------------------------------------------------------------
  421. IImePadServer*
  422. CImePadSvrUIM_Sharemem::CreateObject(VOID)
  423. {
  424. DBG(("CImePadSvrUIM_Sharemem::CreateObject START\n"));
  425. typedef LPVOID (WINAPI * LPFN_CREATEOBJECT2)(DWORD dwIntanceID, DWORD *pdwTLS);
  426. LPTSTR lpPath = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  427. if(!lpPath) {
  428. DBG(("-->Outof Memory ??\n"));
  429. return NULL;
  430. }
  431. if(0 != this->CLSID2ModuleName(IID_IImePadServerSHM,
  432. FALSE,
  433. lpPath,
  434. sizeof(TCHAR)*MAX_PATH)) {
  435. DBG(("-->Cannot found proxy\n"));
  436. goto LError;
  437. }
  438. if(!m_hModuleProxyStub) {
  439. m_hModuleProxyStub= ::LoadLibrary(lpPath);
  440. }
  441. DBG(("-->lpPath [%s]\n", lpPath));
  442. if(!m_hModuleProxyStub) {
  443. DBG(("CImePadSvrUIM_Sharemem::CreateObject START\n"));
  444. goto LError;
  445. }
  446. LPFN_CREATEOBJECT2 lpfn;
  447. lpfn = (LPFN_CREATEOBJECT2)::GetProcAddress(m_hModuleProxyStub, "CreateObject2");
  448. if(!lpfn) {
  449. DBG(("-->GetProcAddress Error \n"));
  450. goto LError;
  451. }
  452. m_lpIImePadServer = (IImePadServer *)(*lpfn)(0, NULL);
  453. DBG(("CImePadSvrUIM_Sharemem::CreateObject m_lpIImePadServer[0x%08x]\n", m_lpIImePadServer));
  454. return m_lpIImePadServer;
  455. LError:
  456. if(lpPath) {
  457. MemFree(lpPath);
  458. }
  459. DBG(("CImePadSvrUIM_Sharemem::CreateObject Error END\n"));
  460. return NULL;
  461. }
  462. LRESULT CALLBACK
  463. CImePadSvrUIM_Sharemem::ClientWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  464. {
  465. LPCImePadSvrUIM_Sharemem lpCImePadSvr = NULL;
  466. switch(uMsg) {
  467. #ifdef UNDER_CE
  468. case WM_CREATE:
  469. lpCImePadSvr = (LPCImePadSvrUIM_Sharemem)((LPCREATESTRUCT)lParam)->lpCreateParams;
  470. WinSetUserPtr(hwnd, (LPVOID)lpCImePadSvr);
  471. if(lpCImePadSvr) {
  472. return lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  473. }
  474. break;
  475. case WM_DESTROY:
  476. lpCImePadSvr = (LPCImePadSvrUIM_Sharemem)WinGetUserPtr(hwnd);
  477. if(lpCImePadSvr) {
  478. lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  479. }
  480. WinSetUserPtr(hwnd, (LPVOID)NULL);
  481. break;
  482. #else //!UNDER_CE
  483. case WM_NCCREATE:
  484. lpCImePadSvr = (LPCImePadSvrUIM_Sharemem)((LPCREATESTRUCT)lParam)->lpCreateParams;
  485. WinSetUserPtr(hwnd, (LPVOID)lpCImePadSvr);
  486. break;
  487. case WM_NCDESTROY:
  488. WinSetUserPtr(hwnd, (LPVOID)NULL);
  489. break;
  490. #endif //UNDER_CE
  491. default:
  492. lpCImePadSvr = (LPCImePadSvrUIM_Sharemem)WinGetUserPtr(hwnd);
  493. if(lpCImePadSvr) {
  494. return lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  495. }
  496. break;
  497. }
  498. return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
  499. }
  500. LRESULT
  501. CImePadSvrUIM_Sharemem::RealWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  502. {
  503. switch(uMsg) {
  504. case WM_CREATE:
  505. DBG(("CImePadSvrUIM_Sharemem::WM_CREATE\n"));
  506. return 1;
  507. case WM_TIMER:
  508. return MsgTimer(hwnd, wParam, lParam);
  509. case WM_USER_UPDATECONTEXT:
  510. {
  511. IImeIPoint1 *lpIImeIPoint = NULL;
  512. if(!m_lpIUnkIImeIPoint) {
  513. DBG(("--> m_lpIUnkIImeIPoint is NULL\n"));
  514. return E_FAIL;
  515. }
  516. if(IsBadVtblUIM((IUnkDummy *)m_lpIUnkIImeIPoint)) {
  517. return E_FAIL;
  518. }
  519. HRESULT hr = m_lpIUnkIImeIPoint->QueryInterface(IID_IImeIPoint1,
  520. (VOID **)&lpIImeIPoint);
  521. if(hr != S_OK) {
  522. DBG(("QuertyInterface Failed\n"));
  523. return E_FAIL;
  524. }
  525. if(!lpIImeIPoint) {
  526. DBG(("lpIImeIPoint is NULL\n"));
  527. return 0;
  528. }
  529. //Check current IImeIPoint is same with lParam's IImeIPoint.
  530. //990715:Fixed KOTAE #1563.
  531. //In 16bit application wParam's HIWORD is always 0x0000 !!!!!
  532. //So, Use LParam.
  533. if((IImeIPoint1 *)lParam == lpIImeIPoint) {
  534. DBG(("Call UpdateContext\n"));
  535. lpIImeIPoint->UpdateContext(TRUE);
  536. }
  537. else {
  538. DBG(("lpIImeIPoint is different lParam[0x%08x]\n", lParam));
  539. }
  540. lpIImeIPoint->Release();
  541. }
  542. break;
  543. default:
  544. break;
  545. }
  546. return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
  547. }
  548. LRESULT
  549. CImePadSvrUIM_Sharemem::MsgTimer(HWND hwnd, WPARAM wParam, LPARAM lParam)
  550. {
  551. HRESULT hr;
  552. switch(wParam) {
  553. case TIMERID_NOTIFY_ACTIVATECONTEXT:
  554. ::KillTimer(hwnd, wParam);
  555. if(!m_lpIImePadServer) {
  556. return -1;
  557. }
  558. m_lpIImePadServer->Notify(IMEPADNOTIFY_ACTIVATECONTEXT,
  559. (WPARAM)m_fLastActiveCtx,
  560. (LPARAM)0);
  561. break;
  562. case TIMERID_NOTIFY_APPLYCANDIDATE:
  563. ::KillTimer(hwnd, wParam);
  564. if(!m_lpIImePadServer) {
  565. return -1;
  566. }
  567. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_APPLYCANDIDATE,
  568. m_ntfyDataApplyCand.dwCharID,
  569. 0,
  570. 0,
  571. 0);
  572. m_ntfyDataApplyCand.dwCharID = 0;
  573. break;
  574. case TIMERID_NOTIFY_QUERYCANDIDATE:
  575. ::KillTimer(hwnd, wParam);
  576. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_QUERYCANDIDATE,
  577. m_ntfyDataQueryCand.dwCharID,
  578. m_ntfyDataQueryCand.dwSelIndex,
  579. 0,
  580. 0);
  581. m_ntfyDataQueryCand.dwCharID = 0;
  582. m_ntfyDataQueryCand.dwSelIndex = 0;
  583. break;
  584. case TIMERID_NOTIFY_APPLYCANDIDATEEX:
  585. ::KillTimer(hwnd, wParam);
  586. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_APPLYCANDIDATE_EX,
  587. m_ntfyDataApplyCandEx.dwCharID,
  588. 0,
  589. m_ntfyDataApplyCandEx.lpwstrCreated1,
  590. m_ntfyDataApplyCandEx.lpwstrCreated2);
  591. if(m_ntfyDataApplyCandEx.lpwstrCreated1) {
  592. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated1);
  593. }
  594. if(m_ntfyDataApplyCandEx.lpwstrCreated2) {
  595. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated2);
  596. }
  597. m_ntfyDataApplyCandEx.lpwstrCreated1 = NULL;
  598. m_ntfyDataApplyCandEx.lpwstrCreated2 = NULL;
  599. break;
  600. default:
  601. ::KillTimer(hwnd, wParam);
  602. break;
  603. }
  604. return 0;
  605. Unref(hr);
  606. Unref(hwnd);
  607. Unref(wParam);
  608. Unref(lParam);
  609. }
  610. //////////////////////////////////////////////////////////////////
  611. // Function : CImePadSvrUIM_Sharemem::CreateIFHWND
  612. // Type : HWND
  613. // Purpose : Create interface size 0 window.
  614. // Args : None
  615. // Return :
  616. // DATE : Mon May 17 23:01:19 1999
  617. // Histroy :
  618. //////////////////////////////////////////////////////////////////
  619. HWND
  620. CImePadSvrUIM_Sharemem::CreateIFHWND(VOID)
  621. {
  622. DBG(("CImePadSvrUIM_Sharemem::CreateIFHWND START\n"));
  623. if(m_hwndIF && ::IsWindow(m_hwndIF)) {
  624. return m_hwndIF;
  625. }
  626. ATOM atom;
  627. HWND hwnd;
  628. #ifndef UNDER_CE // No Ex
  629. WNDCLASSEX wc;
  630. #else // UNDER_CE
  631. WNDCLASS wc;
  632. #endif // UNDER_CE
  633. #ifndef UNDER_CE // No Ex
  634. wc.cbSize = sizeof(wc);
  635. #endif // UNDER_CE
  636. wc.style = 0;
  637. wc.lpfnWndProc = (WNDPROC)CImePadSvrUIM_Sharemem::ClientWndProc;
  638. wc.cbClsExtra = 0;
  639. wc.cbWndExtra = 0;
  640. wc.hInstance = m_hModClient;
  641. wc.hIcon = (HICON)NULL;
  642. wc.hCursor = (HCURSOR)NULL;
  643. wc.hbrBackground = (HBRUSH)NULL;
  644. wc.lpszMenuName = NULL;
  645. wc.lpszClassName = SZ_IMEPADIFCLASS;
  646. #ifndef UNDER_CE // No Ex
  647. wc.hIconSm = NULL;
  648. atom = ::RegisterClassEx(&wc);
  649. #else // UNDER_CE
  650. atom = ::RegisterClass(&wc);
  651. #endif // UNDER_CE
  652. hwnd = ::CreateWindowEx(0,
  653. SZ_IMEPADIFCLASS,
  654. NULL,
  655. WS_POPUP | WS_DISABLED,
  656. 0,0,0,0,
  657. NULL,
  658. NULL,
  659. m_hModClient,
  660. (LPVOID)this);
  661. if(!hwnd) {
  662. DBG(("CreateWindowEx Error %d\n", GetLastError()));
  663. }
  664. m_hwndIF = hwnd;
  665. DBG(("CImePadSvrUIM_Sharemem::CreateIFHWND END\n"));
  666. return hwnd;
  667. }
  668. //////////////////////////////////////////////////////////////////
  669. // Function : CImePadSvrUIM_Sharemem::DestroyIFHWND
  670. // Type : BOOL
  671. // Purpose : Destroy interface window.
  672. // Args :
  673. // : BOOL fReserved
  674. // Return :
  675. // DATE : Mon May 17 23:02:43 1999
  676. // Histroy :
  677. //////////////////////////////////////////////////////////////////
  678. BOOL
  679. CImePadSvrUIM_Sharemem::DestroyIFHWND(BOOL fReserved)
  680. {
  681. //DBG(("CImePadSvrUIM_Sharemem::DestroyIFHWND() START\n"));
  682. if(m_hwndIF && ::IsWindow(m_hwndIF)) {
  683. ::DestroyWindow(m_hwndIF);
  684. m_hwndIF = NULL;
  685. }
  686. //Must Unregister class.
  687. BOOL fRet = ::UnregisterClass(SZ_IMEPADIFCLASS, m_hModClient);
  688. if(!fRet) {
  689. if(::GetLastError() != ERROR_CLASS_DOES_NOT_EXIST) {
  690. DBG(("UnregisterClass Unknown error [%d]\n", GetLastError()));
  691. }
  692. }
  693. //DBG(("CImePadSvrUIM_Sharemem::DestroyIFHWND() END\n"));
  694. return TRUE;
  695. Unref(fReserved);
  696. }
  697. INT
  698. CImePadSvrUIM_Sharemem::CLSID2Str(REFCLSID refclsid, TCHAR *szBuf)
  699. {
  700. wsprintf(szBuf, TEXT("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
  701. refclsid.Data1,
  702. refclsid.Data2,
  703. refclsid.Data3,
  704. refclsid.Data4[0],
  705. refclsid.Data4[1],
  706. refclsid.Data4[2],
  707. refclsid.Data4[3],
  708. refclsid.Data4[4],
  709. refclsid.Data4[5],
  710. refclsid.Data4[6],
  711. refclsid.Data4[7]);
  712. return 0;
  713. }
  714. //////////////////////////////////////////////////////////////////
  715. // Function : CLSID2ModuleName
  716. // Type : INT
  717. // Purpose : Get module path from CLSID. only gets InprocServer32
  718. // : Path.
  719. // Args :
  720. // : REFCLSID refclsid
  721. // : BOOL fLocalSvr;
  722. // : TCHAR szPath
  723. // : INT cbSize
  724. // Return :
  725. // DATE : Thu Apr 16 02:48:05 1998
  726. // Author :
  727. //////////////////////////////////////////////////////////////////
  728. #define MAX_CLSIDNAME 64
  729. INT
  730. CImePadSvrUIM_Sharemem::CLSID2ModuleName(REFCLSID refclsid, BOOL fLocalSvr, TCHAR *szPath, INT cbSize)
  731. {
  732. //DBG(("CImePadSvrUIM_Sharemem::CLSID2ModuleName START\n"));
  733. static TCHAR szCLSID[MAX_CLSIDNAME];
  734. static TCHAR szServerKey[256];
  735. CLSID2Str(refclsid, szCLSID);
  736. DBG(("-->szCLSID [%s]\n", szCLSID));
  737. if(fLocalSvr) {
  738. wsprintf(szServerKey, TEXT("CLSID\\%s\\LocalServer32"), szCLSID);
  739. }
  740. else {
  741. wsprintf(szServerKey, TEXT("CLSID\\%s\\InprocServer32"), szCLSID);
  742. }
  743. INT ret;
  744. HKEY hKey;
  745. ret = ::RegOpenKeyEx(HKEY_CLASSES_ROOT,
  746. szServerKey,
  747. 0,
  748. KEY_READ, //ALL_ACCESS,
  749. &hKey);
  750. if(ret != ERROR_SUCCESS) {
  751. DBG(("-->RegOpenKeyEx Failed\n", ret));
  752. return ret;
  753. }
  754. ULONG size = cbSize;
  755. ret = ::RegQueryValueEx(hKey,
  756. NULL,
  757. NULL,
  758. NULL,
  759. (LPBYTE)szPath, &size);
  760. if(ret != ERROR_SUCCESS) {
  761. DBG(("-->RegQueryValueEx Failed\n", ret));
  762. ::RegCloseKey(hKey);
  763. return ret;
  764. }
  765. ::RegCloseKey(hKey);
  766. return 0;
  767. }