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.

692 lines
21 KiB

  1. /****************************************************************************
  2. IMC.H
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. IME Context abstraction class
  6. History:
  7. 21-JUL-1999 cslim Created
  8. *****************************************************************************/
  9. #include "precomp.h"
  10. #include "hanja.h"
  11. #include "imc.h"
  12. #include "debug.h"
  13. /*----------------------------------------------------------------------------
  14. CIMECtx::CIMECtx
  15. Ctor
  16. ----------------------------------------------------------------------------*/
  17. CIMECtx::CIMECtx(HIMC hIMC)
  18. {
  19. m_fUnicode = fTrue; // default is UNICODE
  20. m_dwMessageSize = 0;
  21. m_dwCandInfoSize = 0;
  22. // Init Context variables
  23. m_hIMC = hIMC;
  24. m_pIMC = OurImmLockIMC(m_hIMC);
  25. //m_hCandInfo = m_pIMC->hCandInfo;
  26. m_pCandInfo = (LPCANDIDATEINFO)OurImmLockIMCC(GetHCandInfo());
  27. //m_hCompStr = m_pIMC->hCompStr;
  28. InitCompStrStruct();
  29. //m_hMessage = m_pIMC->hMsgBuf;
  30. m_pMessage = (LPTRANSMSG)OurImmLockIMCC(GetHMsgBuf());
  31. // Reset composition info.
  32. ResetComposition();
  33. // Reset candidate infos
  34. m_pCandStr = NULL;
  35. m_rgpCandMeaningStr = NULL;
  36. ResetCandidate();
  37. // Reset GCS flag to zero
  38. ResetGCS();
  39. // initialize message buffer
  40. ResetMessage();
  41. // clear hCompStr
  42. ClearCompositionStrBuffer();
  43. //////////////////////////////////////////////////////////////////////
  44. // initialize Shared memory. If this is only IME in the system
  45. // Shared memory will be created as file mapping object.
  46. //////////////////////////////////////////////////////////////////////
  47. m_pCIMEData = new CIMEData;
  48. DbgAssert(m_pCIMEData != 0);
  49. // Initialize IME shared memory to default value and set reg value if avaliable
  50. // Read registry: Do not call it in the DllMain
  51. if (m_pCIMEData)
  52. {
  53. m_pCIMEData->InitImeData();
  54. }
  55. // Initialize Hangul Automata
  56. //GetAutomata()->InitState();
  57. //////////////////////////////////////////////////////////////////////////
  58. // Create All three IME Automata instances
  59. m_rgpHangulAutomata[KL_2BEOLSIK] = new CHangulAutomata2;
  60. m_rgpHangulAutomata[KL_3BEOLSIK_390] = new CHangulAutomata3;
  61. m_rgpHangulAutomata[KL_3BEOLSIK_FINAL] = new CHangulAutomata3Final;
  62. }
  63. /*----------------------------------------------------------------------------
  64. CIMECtx::CIMECtx
  65. Dtor
  66. ----------------------------------------------------------------------------*/
  67. CIMECtx::~CIMECtx()
  68. {
  69. if (m_pCIMEData)
  70. {
  71. delete m_pCIMEData;
  72. m_pCIMEData = NULL;
  73. }
  74. // Release Cand info
  75. if (GetHCandInfo())
  76. OurImmUnlockIMCC(GetHCandInfo());
  77. m_pCandInfo = NULL;
  78. // Release Comp str
  79. if (GetHCompStr())
  80. OurImmUnlockIMCC(GetHCompStr());
  81. m_pCompStr = NULL;
  82. // Release Msg buffer
  83. ResetMessage();
  84. if (GetHMsgBuf())
  85. OurImmUnlockIMCC(GetHMsgBuf());
  86. m_pMessage = NULL;
  87. // Reset hIMC
  88. OurImmUnlockIMC(m_hIMC);
  89. m_pIMC = NULL;
  90. m_hIMC = NULL;
  91. // Free candidate private buffer
  92. if (m_pCandStr)
  93. {
  94. GlobalFree(m_pCandStr);
  95. m_pCandStr = NULL;
  96. }
  97. if (m_rgpCandMeaningStr)
  98. {
  99. ClearCandMeaningArray();
  100. GlobalFree(m_rgpCandMeaningStr);
  101. m_rgpCandMeaningStr = NULL;
  102. }
  103. // delete Automata
  104. for (INT i=0; i<NUM_OF_IME_KL; i++)
  105. if (m_rgpHangulAutomata[i])
  106. delete m_rgpHangulAutomata[i];
  107. }
  108. /*----------------------------------------------------------------------------
  109. CIMECtx::InitCompStrStruct
  110. Initialize and reallocater composition string buffer
  111. ----------------------------------------------------------------------------*/
  112. VOID CIMECtx::InitCompStrStruct()
  113. {
  114. INT iAllocSize;
  115. if (m_pIMC == NULL)
  116. return;
  117. // Calc COMPOSITIONSTRING buffer size.
  118. iAllocSize = sizeof(COMPOSITIONSTRING) +
  119. // composition string plus NULL terminator
  120. nMaxCompStrLen * sizeof(WCHAR) + sizeof(WCHAR) +
  121. // composition attribute
  122. nMaxCompStrLen * sizeof(WORD) +
  123. // result string plus NULL terminator
  124. nMaxResultStrLen * sizeof(WCHAR) + sizeof(WCHAR);
  125. // For avoiding miss alignment
  126. iAllocSize += 2;
  127. // Reallocation COMPOSITION buffer
  128. m_pIMC->hCompStr = OurImmReSizeIMCC(GetHCompStr(), iAllocSize);
  129. AST_EX(m_pIMC->hCompStr != (HIMCC)0);
  130. if (m_pIMC->hCompStr == (HIMCC)0)
  131. {
  132. DbgAssert(0);
  133. return;
  134. }
  135. if (m_pCompStr = (LPCOMPOSITIONSTRING)OurImmLockIMCC(GetHCompStr()))
  136. {
  137. // CONFIRM: Need to clear memory??
  138. ZeroMemory(m_pCompStr, iAllocSize);
  139. // Store total size
  140. m_pCompStr->dwSize = iAllocSize;
  141. // REVIEW: Does we need Null termination??
  142. // Store offset. All offset is static which will be calculated in compile time
  143. m_pCompStr->dwCompStrOffset = sizeof(COMPOSITIONSTRING);
  144. m_pCompStr->dwCompAttrOffset = sizeof(COMPOSITIONSTRING) +
  145. nMaxCompStrLen * sizeof(WCHAR) + sizeof(WCHAR); // length of comp str
  146. m_pCompStr->dwResultStrOffset = sizeof(COMPOSITIONSTRING) +
  147. nMaxCompStrLen * sizeof(WCHAR) + sizeof(WCHAR) + // length of comp str
  148. nMaxCompStrLen * sizeof(WORD) + 2; // length of comp str attr
  149. }
  150. Dbg(DBGID_CompChar, "InitCompStrStruct m_pIMC->hCompStr = 0x%x, m_pCompStr = 0x%x", m_pIMC->hCompStr, m_pCompStr);
  151. }
  152. /*----------------------------------------------------------------------------
  153. CIMECtx::StoreComposition
  154. Store all composition result to IME context buffer
  155. ----------------------------------------------------------------------------*/
  156. VOID CIMECtx::StoreComposition()
  157. {
  158. LPWSTR pwsz;
  159. LPSTR psz;
  160. Dbg(DBGID_Key, "StoreComposition GCS = 0x%x", GetGCS());
  161. // Check composition handle validity
  162. if (GetHCompStr() == NULL || m_pCompStr == NULL)
  163. return ;
  164. //////////////////////////////////////////////////////////////////////////
  165. // Comp Str
  166. if (GetGCS() & GCS_COMPSTR)
  167. {
  168. Dbg(DBGID_Key, "StoreComposition - GCS_COMPSTR comp str = 0x%04X", m_wcComp);
  169. DbgAssert(m_wcComp != 0);
  170. // Composition string. dw*StrLen contains character count
  171. if (IsUnicodeEnv())
  172. {
  173. m_pCompStr->dwCompStrLen = 1;
  174. pwsz = (LPWSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwCompStrOffset);
  175. *pwsz++ = m_wcComp; // Store composition char
  176. *pwsz = L'\0';
  177. }
  178. else
  179. {
  180. // Byte length
  181. m_pCompStr->dwCompStrLen = 2;
  182. // Convert to ANSI
  183. WideCharToMultiByte(CP_KOREA, 0,
  184. &m_wcComp, 1, (LPSTR)m_szComp, sizeof(m_szComp),
  185. NULL, NULL );
  186. psz = (LPSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwCompStrOffset);
  187. *psz++ = m_szComp[0];
  188. *psz++ = m_szComp[1];
  189. *psz = '\0';
  190. }
  191. // Composition attribute. Always set
  192. m_pCompStr->dwCompAttrLen = 1;
  193. *((LPBYTE)m_pCompStr + m_pCompStr->dwCompAttrOffset) = ATTR_INPUT;
  194. }
  195. else
  196. {
  197. // Reset length
  198. m_pCompStr->dwCompStrLen = 0;
  199. m_pCompStr->dwCompAttrLen = 0;
  200. }
  201. //////////////////////////////////////////////////////////////////////////
  202. // Result Str
  203. if (GetGCS() & GCS_RESULTSTR)
  204. {
  205. Dbg(DBGID_Key, "StoreComposition - GCS_RESULTSTR comp str = 0x%04x, 0x%04X", m_wzResult[0], m_wzResult[1]);
  206. // Composition string. dw*StrLen contains character count
  207. if (IsUnicodeEnv())
  208. {
  209. // Result string length 1 or 2
  210. m_pCompStr->dwResultStrLen = m_wzResult[1] ? 2 : 1; // lstrlenW(m_wzResult);
  211. pwsz = (LPWSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwResultStrOffset);
  212. *pwsz++ = m_wzResult[0]; // Store composition result string
  213. if (m_wzResult[1])
  214. *pwsz++ = m_wzResult[1]; // Store composition result string
  215. *pwsz = L'\0';
  216. }
  217. else
  218. {
  219. // Result string length 2 or 3
  220. m_pCompStr->dwResultStrLen = m_wzResult[1] ? 3 : 2; // lstrlenW(m_wzResult);
  221. // Convert to ANSI
  222. WideCharToMultiByte(CP_KOREA, 0,
  223. m_wzResult, (m_wzResult[1] ? 2 : 1),
  224. (LPSTR)m_szResult, sizeof(m_szResult),
  225. NULL, NULL );
  226. psz = (LPSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwResultStrOffset);
  227. *psz++ = m_szResult[0];
  228. *psz++ = m_szResult[1];
  229. if (m_wzResult[1])
  230. *psz++ = m_szResult[2];
  231. *psz = '\0';
  232. }
  233. }
  234. else
  235. {
  236. m_pCompStr->dwResultStrLen = 0;
  237. }
  238. }
  239. /////////////////////////////////////////////////
  240. // CANDIDATEINFO STRUCTURE SUPPORT
  241. /////////////////////////////////////////////////
  242. VOID CIMECtx::AppendCandidateStr(WCHAR wcCand, LPWSTR wszMeaning)
  243. {
  244. Dbg(DBGID_Hanja, "AppendCandidateStr");
  245. // Alocate cand string and meaning buffer
  246. if (m_pCandStr == NULL)
  247. {
  248. m_pCandStr =(LPWSTR)GlobalAlloc(GPTR, sizeof(WCHAR)*MAX_CANDSTR);
  249. DbgAssert(m_pCandStr != NULL);
  250. }
  251. if (m_rgpCandMeaningStr == NULL)
  252. {
  253. m_rgpCandMeaningStr = (LPWSTR*)GlobalAlloc(GPTR, sizeof(LPWSTR)*MAX_CANDSTR);
  254. DbgAssert(m_rgpCandMeaningStr != NULL);
  255. }
  256. if (m_pCandStr == NULL || m_rgpCandMeaningStr == NULL)
  257. return;
  258. // Append candidate char
  259. DbgAssert(m_iciCandidate < MAX_CANDSTR);
  260. if (m_iciCandidate >= MAX_CANDSTR)
  261. return;
  262. m_pCandStr[m_iciCandidate] = wcCand;
  263. // Append candidate meaning
  264. if (wszMeaning[0])
  265. {
  266. m_rgpCandMeaningStr[m_iciCandidate] = (LPWSTR)GlobalAlloc(GPTR, sizeof(WCHAR)*(lstrlenW(wszMeaning)+1));
  267. if (m_rgpCandMeaningStr[m_iciCandidate] == NULL)
  268. return;
  269. StrCopyW(m_rgpCandMeaningStr[m_iciCandidate], wszMeaning);
  270. }
  271. else
  272. m_rgpCandMeaningStr[m_iciCandidate] = NULL;
  273. m_iciCandidate++;
  274. }
  275. WCHAR CIMECtx::GetCandidateStr(INT iIdx)
  276. {
  277. if (iIdx < 0 || iIdx >= MAX_CANDSTR)
  278. {
  279. DbgAssert(0);
  280. return L'\0';
  281. }
  282. if (iIdx >= m_iciCandidate)
  283. {
  284. DbgAssert(0);
  285. return L'\0';
  286. }
  287. return m_pCandStr[iIdx];
  288. }
  289. LPWSTR CIMECtx::GetCandidateMeaningStr(INT iIdx)
  290. {
  291. if (m_rgpCandMeaningStr == NULL ||
  292. m_rgpCandMeaningStr[iIdx] == NULL ||
  293. iIdx >= MAX_CANDSTR || iIdx < 0)
  294. {
  295. // DbgAssert(0); It happen for symbol mapping
  296. return NULL;
  297. }
  298. else
  299. return m_rgpCandMeaningStr[iIdx];
  300. }
  301. VOID CIMECtx::StoreCandidate()
  302. {
  303. INT iAllocSize;
  304. LPCANDIDATELIST lpCandList;
  305. Dbg(DBGID_Key, "StoreCandidate");
  306. if (GetHCandInfo() == NULL)
  307. return ; // do nothing
  308. // Calc CANDIDATEINFO buffer size
  309. iAllocSize = sizeof(CANDIDATEINFO) +
  310. sizeof(CANDIDATELIST) + // candlist struct
  311. m_iciCandidate * sizeof(DWORD) + // cand index
  312. m_iciCandidate * sizeof(WCHAR) * 2; // cand strings with null termination
  313. // Alllocate buffer
  314. if (m_dwCandInfoSize < (DWORD)iAllocSize) // need to re-allocate
  315. {
  316. // reallocation COMPOSITION buffer
  317. OurImmUnlockIMCC(GetHCandInfo());
  318. m_pIMC->hCandInfo = OurImmReSizeIMCC(GetHCandInfo(), iAllocSize);
  319. AST_EX(m_pIMC->hCandInfo != (HIMCC)0);
  320. if (m_pIMC->hCandInfo == (HIMCC)0)
  321. return;
  322. m_pCandInfo = (CANDIDATEINFO*)OurImmLockIMCC(GetHCandInfo());
  323. m_dwCandInfoSize = (DWORD)iAllocSize;
  324. }
  325. // Check if m_pCandInfo is valid
  326. if (m_pCandInfo == NULL)
  327. return;
  328. // Fill cand info
  329. m_pCandInfo->dwSize = iAllocSize;
  330. m_pCandInfo->dwCount = 1;
  331. m_pCandInfo->dwOffset[0] = sizeof(CANDIDATEINFO);
  332. // Fill cand list
  333. lpCandList = (LPCANDIDATELIST)((LPBYTE)m_pCandInfo + m_pCandInfo->dwOffset[0]);
  334. lpCandList->dwSize = iAllocSize - sizeof(CANDIDATEINFO);
  335. lpCandList->dwStyle = IME_CAND_READ;
  336. lpCandList->dwCount = m_iciCandidate;
  337. lpCandList->dwPageStart = lpCandList->dwSelection = 0;
  338. lpCandList->dwPageSize = CAND_PAGE_SIZE;
  339. INT iOffset = sizeof(CANDIDATELIST)
  340. + sizeof(DWORD) * (m_iciCandidate); // for dwOffset array
  341. for (INT i = 0; i < m_iciCandidate; i++)
  342. {
  343. LPWSTR wszCandStr;
  344. LPSTR szCandStr;
  345. CHAR szCand[4] = "\0\0"; // Cand string always 1 char(2 bytes) + extra one byte
  346. lpCandList->dwOffset[i] = iOffset;
  347. if (IsUnicodeEnv())
  348. {
  349. wszCandStr = (LPWSTR)((LPSTR)lpCandList + iOffset);
  350. *wszCandStr++ = m_pCandStr[i];
  351. *wszCandStr++ = L'\0';
  352. iOffset += sizeof(WCHAR) * 2;
  353. }
  354. else
  355. {
  356. // Convert to ANSI
  357. WideCharToMultiByte(CP_KOREA, 0,
  358. &m_pCandStr[m_iciCandidate], 1, (LPSTR)szCand, sizeof(szCand),
  359. NULL, NULL );
  360. szCandStr = (LPSTR)((LPSTR)lpCandList + iOffset);
  361. *szCandStr++ = szCand[0];
  362. *szCandStr++ = szCand[1];
  363. *szCandStr = '\0';
  364. iOffset += 3; // DBCS + NULL
  365. }
  366. }
  367. }
  368. /////////////////////////////////////////////////
  369. // MSGBUF STRUCTURE SUPPORT
  370. BOOL CIMECtx::FinalizeMessage()
  371. {
  372. DWORD dwCurrentGCS;
  373. WPARAM wParam;
  374. Dbg(DBGID_Key, "FinalizeMessage");
  375. // support WM_IME_STARTCOMPOSITION
  376. if (m_fStartComposition == fTrue)
  377. {
  378. Dbg(DBGID_Key, "FinalizeMessage - WM_IME_STARTCOMPOSITION");
  379. AddMessage(WM_IME_STARTCOMPOSITION);
  380. }
  381. // support WM_IME_ENDCOMPOSITION
  382. if (m_fEndComposition == fTrue)
  383. {
  384. Dbg(DBGID_Key, "FinalizeMessage - WM_IME_ENDCOMPOSITION");
  385. AddMessage(WM_IME_ENDCOMPOSITION);
  386. // Clear all automata states
  387. if (GetAutomata() != NULL)
  388. {
  389. GetAutomata()->InitState();
  390. }
  391. }
  392. // GCS validation before set to IMC
  393. dwCurrentGCS = ValidateGCS();
  394. if (dwCurrentGCS & GCS_RESULTSTR)
  395. {
  396. Dbg(DBGID_Key, "FinalizeMessage - WM_IME_COMPOSITION - GCS_RESULTSTR 0x%04x", m_wzResult[0]);
  397. if (IsUnicodeEnv())
  398. AddMessage(WM_IME_COMPOSITION, m_wzResult[0], GCS_RESULTSTR);
  399. else
  400. {
  401. // Set ANSI code
  402. wParam = ((WPARAM)m_szResult[0] << 8) | m_szResult[1];
  403. AddMessage(WM_IME_COMPOSITION, wParam, GCS_RESULTSTR);
  404. }
  405. }
  406. if (dwCurrentGCS & GCS_COMP_KOR)
  407. {
  408. Dbg(DBGID_Key, "FinalizeMessage - WM_IME_COMPOSITION - GCS_COMP_KOR 0x%04x", m_wcComp);
  409. if (IsUnicodeEnv())
  410. AddMessage(WM_IME_COMPOSITION, m_wcComp, (GCS_COMP_KOR|GCS_COMPATTR|CS_INSERTCHAR|CS_NOMOVECARET));
  411. else
  412. {
  413. // Set ANSI code
  414. wParam = ((WPARAM)m_szComp[0] << 8) | m_szComp[1];
  415. AddMessage(WM_IME_COMPOSITION, wParam, (GCS_COMP_KOR|GCS_COMPATTR|CS_INSERTCHAR|CS_NOMOVECARET));
  416. }
  417. }
  418. ResetGCS(); // reset now
  419. // O10 Bug #150012
  420. // support WM_IME_ENDCOMPOSITION
  421. if (m_fEndComposition == fTrue)
  422. {
  423. ResetComposition();
  424. ResetCandidate();
  425. }
  426. FlushCandMessage();
  427. //////////////////////////////////////////////////////////////////////////
  428. // WM_IME_KEYDOWN: This should be added after all composition message
  429. if (m_fKeyDown)
  430. AddMessage(WM_IME_KEYDOWN, m_wParamKeyDown, (m_lParamKeyDown << 16) | 1UL);
  431. return TRUE;
  432. }
  433. VOID CIMECtx::FlushCandMessage()
  434. {
  435. switch (m_uiSendCand)
  436. {
  437. case MSG_NONE: // Do nothing
  438. break;
  439. case MSG_OPENCAND:
  440. AddMessage(WM_IME_NOTIFY, IMN_OPENCANDIDATE, 1);
  441. break;
  442. case MSG_CLOSECAND:
  443. AddMessage(WM_IME_NOTIFY, IMN_CLOSECANDIDATE, 1);
  444. ResetCandidate();
  445. break;
  446. case MSG_CHANGECAND:
  447. AddMessage(WM_IME_NOTIFY, IMN_CHANGECANDIDATE, 1);
  448. break;
  449. default:
  450. DbgAssert(0); // Error
  451. break;
  452. }
  453. m_uiSendCand = MSG_NONE;
  454. }
  455. BOOL CIMECtx::GenerateMessage()
  456. {
  457. BOOL fResult = fFalse;
  458. INT iMsgCount;
  459. Dbg(DBGID_Key, "GenerateMessage");
  460. if (IsProcessKeyStatus())
  461. return fFalse; // Do nothing
  462. FinalizeMessage();
  463. iMsgCount = GetMessageCount();
  464. ResetMessage();
  465. if (iMsgCount > 0)
  466. fResult = OurImmGenerateMessage(m_hIMC);
  467. return fResult;
  468. }
  469. INT CIMECtx::AddMessage(UINT uiMessage, WPARAM wParam, LPARAM lParam)
  470. {
  471. LPTRANSMSG pImeMsg;
  472. Dbg(DBGID_Key, "AddMessage uiMessage=0x%X, wParam=0x%04X, lParam=0x%08lX", uiMessage, wParam, lParam);
  473. if (GetHMsgBuf() == NULL)
  474. return m_uiMsgCount;
  475. m_uiMsgCount++;
  476. //////////////////////////////////////////////////////////////////////////
  477. // Check if this data stream created by ImeToAsciiEx()
  478. if (m_pTransMessage)
  479. {
  480. Dbg(DBGID_Key, "AddMessage - use Transbuffer(ImeToAscii)");
  481. // Check if need reallocate message buffer
  482. if (m_pTransMessage->uMsgCount >= m_uiMsgCount)
  483. {
  484. // Fill msg buffer
  485. pImeMsg = &m_pTransMessage->TransMsg[m_uiMsgCount - 1];
  486. pImeMsg->message = uiMessage;
  487. pImeMsg->wParam = wParam;
  488. pImeMsg->lParam = lParam;
  489. }
  490. else
  491. {
  492. DbgAssert(0);
  493. // pre-allocated buffer is full - use hMsgBuf instead.
  494. UINT uiMsgCountOrg = m_uiMsgCount; // backup
  495. m_uiMsgCount = 0; // reset anyway
  496. LPTRANSMSGLIST pHeader = m_pTransMessage; // backup
  497. SetTransMessage(NULL); // use hMsgBuf
  498. for (UINT i=0; i<uiMsgCountOrg; i++)
  499. AddMessage(pHeader->TransMsg[i].message, pHeader->TransMsg[i].wParam, pHeader->TransMsg[i].lParam);
  500. // finally adds current message
  501. AddMessage(uiMessage, wParam, lParam);
  502. }
  503. }
  504. else // m_pTransMessage. Not called from ImeToAsciiEx()
  505. {
  506. UINT iMaxMsg = m_dwMessageSize / sizeof(TRANSMSG);
  507. DWORD dwNewSize;
  508. Dbg(DBGID_Key, "AddMessage - use hMsgBuf");
  509. if (m_uiMsgCount > iMaxMsg)
  510. {
  511. Dbg(DBGID_Key, "AddMessage - Reallocate");
  512. // Reallocation message buffer
  513. OurImmUnlockIMCC(GetHMsgBuf());
  514. dwNewSize = max(16, m_uiMsgCount) * sizeof(TRANSMSG); // At least 16 cand list
  515. m_pIMC->hMsgBuf = OurImmReSizeIMCC(GetHMsgBuf(), dwNewSize);
  516. AST_EX(m_pIMC->hMsgBuf != (HIMCC)0);
  517. if (m_pIMC->hMsgBuf == (HIMCC)0)
  518. return m_uiMsgCount;
  519. m_pMessage = (LPTRANSMSG)OurImmLockIMCC(GetHMsgBuf());
  520. m_dwMessageSize = dwNewSize;
  521. }
  522. // Fill msg buffer
  523. pImeMsg = m_pMessage + m_uiMsgCount - 1;
  524. pImeMsg->message = uiMessage;
  525. pImeMsg->wParam = wParam;
  526. pImeMsg->lParam = lParam;
  527. // set message count
  528. m_pIMC->dwNumMsgBuf = m_uiMsgCount;
  529. }
  530. return m_uiMsgCount;
  531. }
  532. /*----------------------------------------------------------------------------
  533. CIMECtx::GetCompBufStr
  534. Get current hCompStr comp str. If Win95, convert it to Unicode
  535. ----------------------------------------------------------------------------*/
  536. WCHAR CIMECtx::GetCompBufStr()
  537. {
  538. WCHAR wch;
  539. if (GetHCompStr() == NULL || m_pCompStr == NULL)
  540. return L'\0';
  541. if (IsUnicodeEnv())
  542. return *(LPWSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwCompStrOffset);
  543. else
  544. {
  545. if (MultiByteToWideChar(CP_KOREA, MB_PRECOMPOSED,
  546. (LPSTR)((LPBYTE)m_pCompStr + m_pCompStr->dwCompStrOffset),
  547. 2,
  548. &wch,
  549. 1))
  550. return wch;
  551. else
  552. return L'\0';
  553. }
  554. }
  555. /*----------------------------------------------------------------------------
  556. CIMECtx::ClearCandMeaningArray
  557. ----------------------------------------------------------------------------*/
  558. void CIMECtx::ClearCandMeaningArray()
  559. {
  560. if (m_rgpCandMeaningStr == NULL)
  561. return;
  562. for (int i=0; i<MAX_CANDSTR; i++)
  563. {
  564. if (m_rgpCandMeaningStr[i] == NULL)
  565. break;
  566. GlobalFree(m_rgpCandMeaningStr[i]);
  567. m_rgpCandMeaningStr[i] = 0;
  568. }
  569. }