Chcand.pas
资源名称:Wingb_Mz.rar [点击查看]
上传用户:wen198501
上传日期:2013-04-01
资源大小:335k
文件大小:6k
源码类别:
输入法编程
开发平台:
Delphi
- {******************************************************}
- { }
- { Copyright (c) 1990-1999 Microsoft Corporation }
- { }
- { Module Name: Chcand.c ->> Chcand.pas }
- { }
- { Translator: Liu_mazi@126.com, 2005-11-14 }
- { }
- {******************************************************}
- unit Chcand;
- {$I Define.Inc}
- interface
- uses Windows, ImmDev, ImeDefs;
- procedure SelectOneCand(lpIMC: PInputContext; lpCompStr: PCompositionString;
- lpImcP: PPrivContext; lpCandList: PCandidateList); // 选中一个Candidate
- procedure CandEscapeKey(lpIMC: PInputContext; lpImcP: PPrivContext); // Candidate取消处理
- procedure ChooseCand(wCharCode: Word; lpIMC: PInputContext;
- lpCandInfo: PCandidateInfo; lpImcP: PPrivContext); // Candidate按键处理
- implementation
- uses DDIS, Compose;
- // 选中一个Candidate
- procedure SelectOneCand(lpIMC: PInputContext; lpCompStr: PCompositionString; lpImcP: PPrivContext; lpCandList: PCandidateList);
- begin
- if (lpCompStr = nil) or (lpImcP = nil) then begin MessageBeep($FFFFFFFF); Exit; end;
- InitCompStr(lpCompStr);
- // calculate result string length
- lpCompStr.dwResultStrLen := lStrLen(PChar(DWord(lpCandList) + lpCandList.dwOffset[lpCandList.dwSelection]));
- // the result string = the selected candidate
- lStrCpy(
- PChar(DWord(lpCompStr) + lpCompStr.dwResultStrOffset),
- PChar(DWord(lpCandList) + lpCandList.dwOffset[lpCandList.dwSelection])
- );
- // tell application, there is a reslut string
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_COMPOSITION;
- lpImcP.dwCompChar := 0;
- lpImcP.fdwGcsFlag := lpImcP.fdwGcsFlag or (GCS_COMPREAD or GCS_COMP or GCS_CURSORPOS or GCS_DELTASTART or GCS_RESULTREAD or GCS_RESULT);
- if ((lpImcP.fdwImeMsg and MSG_ALREADY_OPEN) <> 0) then
- lpImcP.fdwImeMsg := (lpImcP.fdwImeMsg or MSG_CLOSE_CANDIDATE) and (not MSG_OPEN_CANDIDATE);
- // no candidate now, the right candidate string already be finalized
- lpCandList.dwCount := 0;
- lpImcP.iImeState := CST_INIT;
- // init Engine private data, **
- PDWord(@lpImcP.bSeq)^ := 0;
- end;
- // Candidate取消处理
- procedure CandEscapeKey(lpIMC: PInputContext; lpImcP: PPrivContext);
- var
- lpCompStr: PCompositionString;
- lpGuideLine: PGuideLine;
- begin
- // clean all candidate information
- if ((lpImcP.fdwImeMsg and MSG_ALREADY_OPEN) <> 0) then
- begin
- ClearCand(lpIMC);
- lpImcP.fdwImeMsg := (lpImcP.fdwImeMsg or MSG_CLOSE_CANDIDATE) and (not MSG_OPEN_CANDIDATE);
- end;
- // if it start composition, we need to clean composition
- if ((lpImcP.fdwImeMsg and MSG_ALREADY_START) = 0) then Exit;
- lpCompStr := ImmLockIMCC(lpIMC.hCompStr);
- if (lpCompStr = nil) then Exit;
- lpGuideLine := ImmLockIMCC(lpIMC.hGuideLine); // **
- if (lpGuideLine = nil) then Exit;
- CompEscapeKey(lpIMC, lpCompStr, lpGuideLine, lpImcP);
- ImmUnlockIMCC(lpIMC.hGuideLine);
- ImmUnlockIMCC(lpIMC.hCompStr);
- end;
- // Candidate按键处理
- procedure ChooseCand(wCharCode: Word; lpIMC: PInputContext; lpCandInfo: PCandidateInfo; lpImcP: PPrivContext);
- var
- lpCandList: PCandidateList;
- lpCompStr: PCompositionString;
- dwSelCand: DWord;
- begin
- if (wCharCode = VK_ESCAPE) then // 取消
- begin
- CandEscapeKey(lpIMC, lpImcP);
- Exit;
- end;
- if (lpCandInfo = nil) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- lpCandList := PCandidateList(DWord(lpCandInfo) + lpCandInfo.dwOffset[0]);
- if (wCharCode = Ord(' ')) then // 循环翻页
- begin
- Inc(lpCandList.dwSelection, lpCandList.dwPageSize);
- if (lpCandList.dwSelection >= lpCandList.dwCount) then
- begin
- lpCandList.dwSelection := 0;
- MessageBeep($FFFFFFFF);
- end;
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode = Ord('=')) then // 向下翻页
- begin
- if (lpCandList.dwSelection >= ((IME_MAXCAND - 1) div CANDPERPAGE) * lpCandList.dwPageSize) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- Inc(lpCandList.dwSelection, lpCandList.dwPageSize);
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode = Ord('-')) then // 向上翻页
- begin
- if (lpCandList.dwSelection < lpCandList.dwPageSize) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- Dec(lpCandList.dwSelection, lpCandList.dwPageSize);
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode = $23) then // 翻至尾页
- begin
- if (lpCandList.dwSelection >= ((IME_MAXCAND - 1) div CANDPERPAGE) * lpCandList.dwPageSize) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- lpCandList.dwSelection := ((IME_MAXCAND - 1) div CANDPERPAGE) * lpCandList.dwPageSize;
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode = $24) then // 翻至首页
- begin
- if (lpCandList.dwSelection < lpCandList.dwPageSize) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- lpCandList.dwSelection := 0;
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode = Ord('?')) then // 翻至home
- begin
- if (lpCandList.dwSelection = 0) then
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- lpCandList.dwSelection := 0;
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_CHANGE_CANDIDATE;
- Exit;
- end;
- if (wCharCode >= Ord('0')) and (wCharCode <= Ord('9')) then // 选择
- begin
- if (wCharCode = Ord('0')) then dwSelCand := 9 else dwSelCand := wCharCode - Ord('0') - CAND_START;
- if (dwSelCand >= CANDPERPAGE) then // out of candidate page range
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- if (lpCandList.dwSelection + dwSelCand >= lpCandList.dwCount) then // out of range
- begin
- MessageBeep($FFFFFFFF);
- Exit;
- end;
- lpCandList.dwSelection := lpCandList.dwSelection + dwSelCand;
- lpCompStr := ImmLockIMCC(lpIMC.hCompStr);
- if (lpCompStr = nil) then Exit;
- SelectOneCand(lpIMC, lpCompStr, lpImcP, lpCandList); // translate into translate buffer
- ImmUnlockIMCC(lpIMC.hCompStr);
- end;
- end;
- end.