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.

230 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. CHCAND.C
  5. ++*/
  6. #include <windows.h>
  7. #include <immdev.h>
  8. #include <imedefs.h>
  9. /**********************************************************************/
  10. /* SelectOneCand() */
  11. /**********************************************************************/
  12. void PASCAL SelectOneCand(
  13. LPINPUTCONTEXT lpIMC,
  14. LPCOMPOSITIONSTRING lpCompStr,
  15. LPPRIVCONTEXT lpImcP,
  16. LPCANDIDATELIST lpCandList)
  17. {
  18. if (!lpCompStr) {
  19. MessageBeep((UINT)-1);
  20. return;
  21. }
  22. if (!lpImcP) {
  23. MessageBeep((UINT)-1);
  24. return;
  25. }
  26. InitCompStr(lpCompStr);
  27. // online create word
  28. if(lpImcP->PrivateArea.Comp_Status.OnLineCreWord) {
  29. UINT i, j;
  30. for(i=lstrlen(CWDBCSStr), j=0; i<MAXINPUTWORD; i++, j++) {
  31. CWDBCSStr[i] = lpImcP->PrivateArea.Comp_Context.CKBBuf[j];
  32. }
  33. }
  34. // calculate result string length
  35. if(MBIndex.IMEChara[0].IC_INSSPC) {
  36. int i,j, ilen;
  37. ilen = lstrlen(lpImcP->PrivateArea.Comp_Context.CKBBuf);
  38. lpImcP->PrivateArea.Comp_Context.CKBBuf[ilen + ilen/2] = 0;
  39. for(i = ilen, j=3*ilen/2; i>2; i-=2, j-=3) {
  40. lpImcP->PrivateArea.Comp_Context.CKBBuf[j-1] = 0x20;
  41. lpImcP->PrivateArea.Comp_Context.CKBBuf[j-2] =
  42. lpImcP->PrivateArea.Comp_Context.CKBBuf[i-1];
  43. lpImcP->PrivateArea.Comp_Context.CKBBuf[j-3] =
  44. lpImcP->PrivateArea.Comp_Context.CKBBuf[i-2];
  45. }
  46. lpImcP->PrivateArea.Comp_Context.CKBBuf[i] = 0x20;
  47. }
  48. lstrcpy((LPTSTR)((LPBYTE)lpCompStr + lpCompStr->dwResultStrOffset),
  49. (LPTSTR)lpImcP->PrivateArea.Comp_Context.CKBBuf);
  50. // calculate result string length
  51. lpCompStr->dwResultStrLen =
  52. lstrlen(lpImcP->PrivateArea.Comp_Context.CKBBuf);
  53. // tell application, there is a reslut string
  54. lpImcP->fdwImeMsg |= MSG_COMPOSITION;
  55. lpImcP->dwCompChar = (DWORD) 0;
  56. lpImcP->fdwGcsFlag |= GCS_COMPREAD|GCS_COMP|GCS_CURSORPOS|
  57. GCS_DELTASTART|GCS_RESULTREAD|GCS_RESULT;
  58. lpImcP->iImeState = CST_INIT;
  59. if(!(MBIndex.IMEChara[0].IC_LX)
  60. ||!(lpImcP->PrivateArea.Comp_Status.dwSTLX)) {
  61. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  62. lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &
  63. ~(MSG_OPEN_CANDIDATE);
  64. }
  65. // no candidate now, the right candidate string already be finalized
  66. lpCandList->dwCount = 0;
  67. lpCandList->dwSelection = 0;
  68. } else {
  69. // chang candidate by LX state
  70. lpImcP->fdwImeMsg =
  71. (lpImcP->fdwImeMsg | MSG_OPEN_CANDIDATE | MSG_CHANGE_CANDIDATE) &
  72. ~(MSG_CLOSE_CANDIDATE);
  73. lpCandList->dwSelection = 0;
  74. }
  75. #ifdef CROSSREF
  76. if (!CrossReverseConv(lpIMC, lpCompStr, lpImcP, lpCandList))
  77. // CHP
  78. // No refence code, not a fussy char
  79. #ifdef FUSSYMODE
  80. MBIndex.IsFussyCharFlag =0;
  81. #endif FUSSYMODE
  82. #endif
  83. return;
  84. }
  85. /**********************************************************************/
  86. /* CandEscapeKey() */
  87. /**********************************************************************/
  88. void PASCAL CandEscapeKey(
  89. LPINPUTCONTEXT lpIMC,
  90. LPPRIVCONTEXT lpImcP)
  91. {
  92. LPCOMPOSITIONSTRING lpCompStr;
  93. LPGUIDELINE lpGuideLine;
  94. // clean all candidate information
  95. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  96. ClearCand(lpIMC);
  97. lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &
  98. ~(MSG_OPEN_CANDIDATE);
  99. }
  100. // if it start composition, we need to clean composition
  101. if (!(lpImcP->fdwImeMsg & MSG_ALREADY_START)) {
  102. return;
  103. }
  104. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  105. if(!lpCompStr){
  106. return;
  107. }
  108. lpGuideLine = (LPGUIDELINE)ImmLockIMCC(lpIMC->hGuideLine);
  109. if(!lpGuideLine){
  110. return;
  111. }
  112. CompEscapeKey(lpIMC, lpCompStr, lpGuideLine, lpImcP);
  113. ImmUnlockIMCC(lpIMC->hGuideLine);
  114. ImmUnlockIMCC(lpIMC->hCompStr);
  115. return;
  116. }
  117. /**********************************************************************/
  118. /* ChooseCand() */
  119. /**********************************************************************/
  120. void PASCAL ChooseCand( // choose one of candidate strings by
  121. // input char
  122. WORD wCharCode,
  123. LPINPUTCONTEXT lpIMC,
  124. LPCANDIDATEINFO lpCandInfo,
  125. LPPRIVCONTEXT lpImcP)
  126. {
  127. LPCANDIDATELIST lpCandList;
  128. LPCOMPOSITIONSTRING lpCompStr;
  129. if ((wCharCode == VK_ESCAPE)
  130. || (wCharCode == VK_RETURN)) { // escape key or return key
  131. CandEscapeKey(lpIMC, lpImcP);
  132. return;
  133. }
  134. if (wCharCode == VK_NEXT) { // next selection
  135. lpImcP->fdwImeMsg |= MSG_CHANGE_CANDIDATE;
  136. return;
  137. }
  138. if (wCharCode == VK_PRIOR) { // previous selection
  139. lpImcP->fdwImeMsg |= MSG_CHANGE_CANDIDATE;
  140. return;
  141. }
  142. if (wCharCode == VK_HOME) { // Home selection
  143. lpImcP->fdwImeMsg |= MSG_CHANGE_CANDIDATE;
  144. return;
  145. }
  146. if (wCharCode == VK_END) { // End selection
  147. lpImcP->fdwImeMsg |= MSG_CHANGE_CANDIDATE;
  148. return;
  149. }
  150. if (!lpCandInfo) {
  151. MessageBeep((UINT)-1);
  152. return;
  153. }
  154. lpCandList = (LPCANDIDATELIST)
  155. ((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);
  156. if ((wCharCode >= TEXT('0')) && wCharCode <= TEXT('9')) {
  157. DWORD dwSelCand;
  158. dwSelCand = wCharCode - TEXT('0');
  159. if(wCharCode == TEXT('0')) {
  160. dwSelCand = 10;
  161. }
  162. if(!(MBIndex.IMEChara[0].IC_LX)
  163. ||!(lpImcP->PrivateArea.Comp_Status.dwSTLX)) {
  164. if ((lpCandList->dwSelection + dwSelCand) >
  165. lpCandList->dwCount) {
  166. // out of range
  167. return;
  168. }
  169. } else {
  170. if ((lpCandList->dwSelection + dwSelCand) >
  171. lpImcP->dwOldCandCnt) {
  172. // out of range
  173. return;
  174. }
  175. }
  176. lpCandList->dwSelection = lpCandList->dwSelection + dwSelCand;
  177. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  178. if(!lpCompStr){
  179. return;
  180. }
  181. // translate into translate buffer
  182. SelectOneCand(lpIMC, lpCompStr, lpImcP, lpCandList);
  183. ImmUnlockIMCC(lpIMC->hCompStr);
  184. return;
  185. }
  186. return;
  187. }