📄 compui.cpp
字号:
}
rcWorkArea = sImeG.rcWorkArea;
if (pt.x < rcWorkArea.left) {
pt.x = rcWorkArea.left;
} else if (pt.x + lpImeL->xCompWi > rcWorkArea.right) {
pt.x = rcWorkArea.right - lpImeL->xCompWi;
}
if (pt.y < rcWorkArea.top) {
pt.y = rcWorkArea.top;
} else if (pt.y + lpImeL->yCompHi > rcWorkArea.bottom) {
pt.y = rcWorkArea.bottom - lpImeL->yCompHi;
}
lpIMC->cfCompForm.dwStyle = CFS_FORCE_POSITION;
lpIMC->cfCompForm.ptCurrentPos.x = pt.x + lpImeL->cxCompBorder;
lpIMC->cfCompForm.ptCurrentPos.y = pt.y + lpImeL->cyCompBorder;
ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
ImmUnlockIMC(hIMC);
// set composition window to the new poosition
PostMessage(hCompWnd, WM_IME_NOTIFY, IMN_SETCOMPOSITIONWINDOW, 0);
return (TRUE);
}
int GetWideCharNum(TCHAR *Src)
{
int num = 0 ;
if(Src==NULL) return 0;
while((*Src) != 0) {
if((*Src) >0xFF)
num +=2;
else
num ++;
Src++;
}
return num;
}
int FindFirstStr(TCHAR *Src, TCHAR *Des )
{
TCHAR *pdest;
int num = 0;
if(Src==NULL|| Des == NULL) return 0;
pdest = wcsstr(Src,Des);
if(pdest == NULL) return 0;
//count char num
while(Src<pdest ) {
if((*Src) >0xFF)
num +=2;
else
num ++;
Src++;
}
return (num +1) ;
}
/**********************************************************************/
/* PaintCompWindow() */
/**********************************************************************/
void PASCAL PaintCompWindow(
HWND hUIWnd,
HWND hCompWnd,
HDC hDC)
{
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
HGDIOBJ hOldFont;
LPCOMPOSITIONSTRING lpCompStr;
RECT TempRC;
RECT rcWnd;
hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWLP_IMC);
if (!hIMC) {
return;
}
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return;
}
if (sImeG.fDiffSysCharSet) {
LOGFONT lfFont;
ZeroMemory(&lfFont, sizeof(lfFont));
hOldFont = GetCurrentObject(hDC, OBJ_FONT);
lfFont.lfHeight = -((12*GetDeviceCaps(hDC, LOGPIXELSY))/72);
lfFont.lfCharSet = NATIVE_CHARSET;
lstrcpy(lfFont.lfFaceName, TEXT("Simsun"));
SelectObject(hDC, CreateFontIndirect(&lfFont));
}
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
if (!lpCompStr) {
return;
}
// draw CompWnd Layout
GetClientRect(hCompWnd, &rcWnd);
DrawConcaveRect(hDC,
rcWnd.left,
rcWnd.top,
lpImeL->xComSelWi-1,
rcWnd.bottom - 1);
SetBkColor(hDC, RGB(0xC0, 0xC0, 0xC0));
TempRC.left = lpImeL->rcCompText.left -lpImeL->xComSelWi;
TempRC.right = lpImeL->rcCompText.left -2 ;
TempRC.top = lpImeL->rcCompText.top+lpImeL->cyCompBorder;
TempRC.bottom = lpImeL->rcCompText.bottom;
if (lpCompStr->dwCompStrLen > 0) {
ExtTextOut(hDC,
TempRC.left,
TempRC.top,
ETO_OPAQUE, &TempRC ,
(LPTSTR)NULL,0, NULL);
DrawText(hDC,
lpImeL->tComCurItem,
lstrlen(lpImeL->tComCurItem),
&TempRC,
DT_LEFT | DT_VCENTER | DT_SINGLELINE);
ExtTextOut(hDC,
lpImeL->rcCompText.left,
lpImeL->rcCompText.top,
ETO_OPAQUE, &lpImeL->rcCompText,
(LPTSTR)NULL, 0, NULL);
DrawText(hDC,
(LPTSTR)((LPBYTE)lpCompStr + lpCompStr->dwCompStrOffset),
(int)lpCompStr->dwCompStrLen,
&lpImeL->rcCompText,
DT_LEFT | DT_VCENTER | DT_SINGLELINE);
if(!sImeG.bGetFocus){
int retVal = FindFirstStr((LPTSTR)((LPBYTE)lpCompStr + lpCompStr->dwCompStrOffset),lpImeL->tComSelItem);
if(retVal>0) {
TempRC.left = lpImeL->rcCompText.left + (retVal-1) *(sImeG.xChiCharWi/2);
retVal = GetWideCharNum(lpImeL->tComSelItem);
TempRC.right = TempRC.left + retVal*(sImeG.xChiCharWi/2);
SetTextColor(hDC,RGB(0,0,0xFF));
DrawText(hDC,
lpImeL->tComSelItem,
retVal,
&TempRC,
DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
}
} else {
ExtTextOut(hDC,
TempRC.left,
TempRC.top,
ETO_OPAQUE,
&TempRC ,
(LPTSTR)NULL,0, NULL);
ExtTextOut(hDC,
lpImeL->rcCompText.left,
lpImeL->rcCompText.top,
ETO_OPAQUE, &lpImeL->rcCompText,
(LPTSTR)NULL, 0, NULL);
}
if (sImeG.fDiffSysCharSet) {
DeleteObject(SelectObject(hDC, hOldFont));
}
{
HBITMAP hComDBmp, hComUBmp,hOldBmp;
HDC hMemDC;
hComDBmp = LoadBitmap(hInst, TEXT("CandU"));
hComUBmp = LoadBitmap(hInst, TEXT("CandD"));
hMemDC = CreateCompatibleDC(hDC);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hComDBmp);
if(hComDBmp) {
SelectObject(hMemDC, hComDBmp);
BitBlt(hDC,
lpImeL->rcCompText.right+1,
lpImeL->rcCompText.top +lpImeL->cyCompBorder+2,
UI_CANDBTW,
UI_CANDBTH,
hMemDC,
0, 0,
SRCCOPY);
}
if(hComUBmp) {
SelectObject(hMemDC, hComUBmp);
BitBlt(hDC,
lpImeL->rcCompText.right+UI_CANDBTW+2,
lpImeL->rcCompText.top+lpImeL->cyCompBorder+2,
UI_CANDBTW,
UI_CANDBTH,
hMemDC,
0, 0,
SRCCOPY);
}
SelectObject(hMemDC, hOldBmp);
DeleteDC(hMemDC);
DeleteObject(hComDBmp);
DeleteObject(hComUBmp);
}
ImmUnlockIMCC(lpIMC->hCompStr);
ImmUnlockIMC(hIMC);
return;
}
/**********************************************************************/
/* CompWndProc() */
/**********************************************************************/
LRESULT CALLBACK CompWndProc( // composition window proc
HWND hCompWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_DESTROY:
DestroyCompWindow(hCompWnd);
break;
case WM_SETCURSOR:
{
POINT ptCursor;
RECT rcComBTD,rcComBTU;
if (GetWindowLong(hCompWnd, UI_MOVE_OFFSET) != WINDOW_NOT_DRAG) {
SetCursor(LoadCursor(hInst, szHandCursor));
break;
}
GetCursorPos(&ptCursor);
ScreenToClient(hCompWnd, &ptCursor);
rcComBTU.top = lpImeL->cxCompBorder;
rcComBTU.left = lpImeL->rcCompText.right;
rcComBTU.bottom = rcComBTU.top + UI_CANDBTH;
rcComBTU.right = rcComBTU.left +UI_CANDBTW;
rcComBTD.top = rcComBTU.top;
rcComBTD.left = rcComBTU.left + UI_CANDBTW;
rcComBTD.bottom = rcComBTD.top + UI_CANDBTH;
rcComBTD.right = rcComBTD.left +UI_CANDBTW;
if (PtInRect(&lpImeL->rcCompText, ptCursor)) {
SetCursor(LoadCursor(hInst, szHandCursor));
} else if (PtInRect(&rcComBTD, ptCursor)) {
SetCursor(LoadCursor(hInst, szHandCursor));
} else if (PtInRect(&rcComBTU, ptCursor)){
SetCursor(LoadCursor(hInst, szHandCursor));
} else {
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
}
}
break;
case WM_LBUTTONDOWN:
{
POINT ptCursor;
RECT rcComBTD,rcComBTU;
ptCursor.x = LOWORD(lParam);
ptCursor.y = HIWORD(lParam);
rcComBTU.top = lpImeL->rcCompText.top + lpImeL->cxCompBorder+2;
rcComBTU.left = lpImeL->rcCompText.right+1;
rcComBTU.bottom = rcComBTU.top + UI_CANDBTH;
rcComBTU.right = rcComBTU.left +UI_CANDBTW;
rcComBTD.top = rcComBTU.top;
rcComBTD.left = rcComBTU.left + UI_CANDBTW+2;
rcComBTD.bottom = rcComBTD.top + UI_CANDBTH;
rcComBTD.right = rcComBTD.left +UI_CANDBTW;
if(PtInRect(&lpImeL->rcCompText, ptCursor)){
MouseSelCompingyin(hCompWnd,&ptCursor);
//pingyin page Down
}else if (PtInRect(&rcComBTD, ptCursor)){
ComLoadBmp(hCompWnd,TEXT("CandDp"),&rcComBTD);
//pingyin page Up
}else if(PtInRect(&rcComBTU, ptCursor)){
ComLoadBmp(hCompWnd,TEXT("CandUp"),&rcComBTU);
}
}
break;
case WM_MOUSEMOVE:
if (GetWindowLong(hCompWnd, UI_MOVE_OFFSET) != WINDOW_NOT_DRAG) {
POINT ptCursor;
DrawDragBorder(hCompWnd,
GetWindowLong(hCompWnd, UI_MOVE_XY),
GetWindowLong(hCompWnd, UI_MOVE_OFFSET));
ptCursor.x = LOWORD(lParam);
ptCursor.y = HIWORD(lParam);
SetWindowLong(hCompWnd, UI_MOVE_XY,
MAKELONG(ptCursor.x, ptCursor.y));
DrawDragBorder(hCompWnd, MAKELONG(ptCursor.x, ptCursor.y),
GetWindowLong(hCompWnd, UI_MOVE_OFFSET));
} else {
return DefWindowProc(hCompWnd, uMsg, wParam, lParam);
}
break;
case WM_LBUTTONUP:
{
POINT ptCursor;
RECT rcComBTD,rcComBTU;
ptCursor.x = LOWORD(lParam);
ptCursor.y = HIWORD(lParam);
rcComBTU.top = lpImeL->rcCompText.top + lpImeL->cxCompBorder+2;
rcComBTU.left = lpImeL->rcCompText.right+1;
rcComBTU.bottom = rcComBTU.top + UI_CANDBTH;
rcComBTU.right = rcComBTU.left +UI_CANDBTW;
rcComBTD.top = rcComBTU.top;
rcComBTD.left = rcComBTU.left + UI_CANDBTW+2;
rcComBTD.bottom = rcComBTD.top + UI_CANDBTH;
rcComBTD.right = rcComBTD.left +UI_CANDBTW;
if (PtInRect(&rcComBTD, ptCursor)) {
ComLoadBmp(hCompWnd,TEXT("CandD"),&rcComBTD);
ComNextPingyinPage( hCompWnd,FALSE);
} else if(PtInRect(&rcComBTU, ptCursor)) {
ComLoadBmp(hCompWnd,TEXT("CandU"),&rcComBTU);
ComNextPingyinPage( hCompWnd,TRUE);
}
if (!CompButtonUp(hCompWnd)) {
return DefWindowProc(hCompWnd, uMsg, wParam, lParam);
}
ReleaseCapture();
}
break;
case WM_IME_NOTIFY:
if (wParam == IMN_SETCOMPOSITIONWINDOW) {
// 9.8.add
SetCompWindow(hCompWnd);
}
break;
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hCompWnd, &ps);
PaintCompWindow(GetWindow(hCompWnd, GW_OWNER), hCompWnd, hDC);
EndPaint(hCompWnd, &ps);
}
break;
case WM_MOUSEACTIVATE:
return (MA_NOACTIVATE);
default:
return DefWindowProc(hCompWnd, uMsg, wParam, lParam);
}
return (0L);
}
void ComNextPingyinPage( HWND hCompWnd , BOOL pagedown)
{
HIMC hIMC;
LPINPUTCONTEXT lpIMC;
LPCOMPOSITIONSTRING lpCompStr;
HWND hUIWnd;
int i;
if( lpImeL->iTotalItem <COMP_MAX_ITEM) return;
hUIWnd = GetWindow(hCompWnd, GW_OWNER);
hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWLP_IMC);
if (!hIMC) {
return ;
}
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return ;
}
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC ->hCompStr);
if (!lpCompStr) {
ImmUnlockIMC(hIMC);
return ;
}
if(lpCompStr->dwCompStrLen<1){
ImmUnlockIMC(hIMC);
return ;
}
{
int j ,MaxCount,StartItem ,iTotalLen =0 ;
TCHAR *pDes ;
if(pagedown) {
if(lpImeL->iStartItem<1) return ; //first page
if(lpImeL->iStartItem > lpImeL->iTotalItem)
lpImeL->iStartItem = lpImeL->iTotalItem ;
MaxCount = lpImeL->iStartItem%COMP_MAX_ITEM ;
if(MaxCount == 0) MaxCount = COMP_MAX_ITEM;
StartItem = lpImeL->iStartItem - MaxCount-COMP_MAX_ITEM;
if(StartItem<0) return ;
MaxCount = COMP_MAX_ITEM ;
lpImeL->iStartItem = StartItem;
} else{
if(lpImeL->iStartItem >= lpImeL->iTotalItem) return;//last page
if(lpImeL->iStartItem<1) lpImeL->iStartItem = 0;
if(lpImeL->iTotalItem -lpImeL->iStartItem <(COMP_MAX_ITEM-1)) {
MaxCount = lpImeL->iTotalItem%COMP_MAX_ITEM ;
} else {
MaxCount = COMP_MAX_ITEM;
}
StartItem = lpImeL->iStartItem;
}
i = 0;
j = MultiByteToWideChar( GetACP(),
0,
&(CurrentPy[StartItem][0]),
-1,
lpImeL->tComCurItem,
COMP_MAX_PYLEN);
pDes = lpImeL->tComSelItem;
while(i<COMP_MAX_PYLEN && i<j) {
*pDes++ = lpImeL->tComCurItem[i];
i++;
}
pDes = ((LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwCompReadStrOffset));
for(i=StartItem;i<StartItem+MaxCount;i++) {
j = MultiByteToWideChar( GetACP(),
0,
&(CurrentPy[i][0]),
-1,
pDes,
COMP_MAX_PYLEN);
if(j>0){
pDes += (j-1);
iTotalLen +=(j-1);
*pDes = 0x20;
pDes++;
iTotalLen++;
}
}
*((LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwCompReadAttrOffset )) =((ATTR_TARGET_CONVERTED << 8)|ATTR_TARGET_CONVERTED);
lpCompStr->dwCompReadStrLen = iTotalLen;
lpImeL->iStartItem += MaxCount;
}
// composition string is reading string for some simple IMEs
lpCompStr->dwCompStrLen = lpCompStr->dwCompReadStrLen;
// composition/reading attribute length is equal to reading string length
lpCompStr->dwCompReadAttrLen = lpCompStr->dwCompReadStrLen;
lpCompStr->dwCompAttrLen = lpCompStr->dwCompStrLen;
// delta start from previous cursor position
lpCompStr->dwDeltaStart = lpCompStr->dwCursorPos;
// set new cursor with next to the composition string
lpCompStr->dwCursorPos = lpCompStr->dwCompStrLen;
{
LPPRIVCONTEXT lpImcP;
HWND hCandWnd;
//get lpImcP
lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
if(lpImcP){
Finalize(lpIMC, lpCompStr, lpImcP);
hCandWnd = GetCandWnd(GetWindow(hCompWnd, GW_OWNER));
if(hCandWnd)
RedrawWindow(hCandWnd, &sImeG.rcCandText, NULL, RDW_INVALIDATE);
ImmUnlockIMCC(lpIMC->hPrivate);
}
}
ImmUnlockIMCC(lpIMC->hCompStr);
ImmUnlockIMC(hIMC);
{
RECT rcRect;
rcRect = lpImeL->rcCompText;
RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
rcRect.left = lpImeL->rcCompText.left -lpImeL->xComSelWi;
rcRect.right = lpImeL->rcCompText.left -2 ;
rcRect.top = lpImeL->rcCompText.top;
rcRect.bottom = lpImeL->rcCompText.bottom;
RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -