uicomp.c
资源名称:大熊猫输入法原码.zip [点击查看]
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:16k
源码类别:
输入法编程
开发平台:
C/C++
- /* 大熊猫输入法(Free Chinese Input) 由YJMSIR(yjmsir@163.com)编写
- * 协议: GPL
- * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
- * Licence: GPL
- */
- #include "freepy.h"
- static HBITMAP hBmpComp;//,hBmp_forward,hBmp_next
- static int NoCompStrYjm=0;
- void UpdateCompBackBmp()
- {
- if(!IsFileExist(szStatusFileName)||
- !(hBmpComp = (HBITMAP)LoadImage(NULL, szCompFileName,
- IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION))){
- Add(InstallFromDir,_T("background\leaf.bmp"),szCompFileName);
- hBmpComp = (HBITMAP)LoadImage(NULL, szCompFileName,
- IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
- }
- }
- LRESULT WINAPI CompWndProc(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
- {
- HWND hUIWnd;
- HGLOBAL hUIExtra;
- LPUIEXTRA lpUIExtra;
- hUIWnd = (HWND)GetWindowLong(hWnd,FIGWL_SVRWND);
- hUIExtra = (HGLOBAL)GetWindowLong(hUIWnd,IMMGWL_PRIVATE);
- lpUIExtra = (LPUIEXTRA)GlobalLock(hUIExtra);
- switch (message)
- {
- case WM_PAINT:
- //DebugLog(8,(DebugLogFile,"WM_PAINTn"));
- //MessageBox(NULL,"have paint","hCompWnd",MB_OK);
- //hBmp_forward = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_forward));
- //hBmp_next = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_next));
- PaintCompWindow(hWnd);
- break;
- case WM_SETCURSOR:
- case WM_MOUSEMOVE:
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- //DragUI(hWnd,lpUIExtra->uiCand.hWnd,message,wParam,lParam,TRUE);
- if ((message == WM_SETCURSOR) &&
- (HIWORD(lParam) != WM_LBUTTONDOWN) &&
- (HIWORD(lParam) != WM_RBUTTONDOWN))
- return DefWindowProc(hWnd,message,wParam,lParam);
- if ((message == WM_LBUTTONUP) || (message == WM_RBUTTONUP))
- SetWindowLong(hWnd,FIGWL_MOUSE,0L);
- break;
- case WM_DESTROY:
- DeleteObject(hBmpComp);
- break;
- default:
- if (!MyIsIMEMessage(message)) {
- GlobalUnlock(hUIExtra);
- return DefWindowProc(hWnd,message,wParam,lParam);
- }
- break;
- }
- GlobalUnlock(hUIExtra);
- return 0;
- }
- void CreateCompWindow( HWND hUIWnd, LPUIEXTRA lpUIExtra)
- {
- UpdateCompBackBmp();
- if (!IsWindow(lpUIExtra->uiComp.hWnd))
- {
- HDC hDC;
- HFONT oldFont;
- SIZE sz;
- TCHAR szStr[100];
- RECT screenrc;
- SystemParametersInfo(SPI_GETWORKAREA,
- 0,
- &screenrc,
- 0);
- lpUIExtra->uiComp.hWnd =
- // CreateWindowEx( WS_EX_WINDOWEDGE,//WS_EX_TOPMOST
- CreateWindowEx( 0,
- COMPCLASSNAME,NULL,
- WS_DISABLED |WS_POPUP,
- //lpUIExtra->uiComp.pt.x,
- //lpUIExtra->uiComp.pt.y,
- screenrc.left+20,
- screenrc.bottom -1,
- 21,
- 11,
- hUIWnd,NULL,hInst,NULL);
- SetWindowLong(lpUIExtra->uiComp.hWnd,FIGWL_SVRWND,(DWORD)hUIWnd);
- hDC = GetDC(lpUIExtra->uiComp.hWnd);
- oldFont = SelectObject(hDC, hUIFont);
- _stprintf(szStr,_T("A"));
- GetTextExtentPoint(hDC,szStr,1,&sz);
- _stprintf(szStr,_T("AAAAAAAAAAAAA"));
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),sizeCand);
- _stprintf(szStr,_T("<< 1啊 2啊 3啊 4啊 5啊 6啊 7啊 8啊 9啊 0啊 >>"));
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),sizeCand+1);
- SelectObject(hDC, oldFont);
- ReleaseDC(lpUIExtra->uiComp.hWnd,hDC);
- lpUIExtra->uiComp.sz.cx = sz.cx*20;
- lpUIExtra->uiComp.sz.cy = sz.cy+4;
- }
- //ShowWindow(lpUIExtra->uiComp.hWnd,SW_HIDE);
- //DebugLog(8,(DebugLogFile,"CreateCompWindown"));
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_SHOWNOACTIVATE);
- InvalidateRect(lpUIExtra->uiComp.hWnd,NULL,FALSE);
- return;
- }
- void MoveCompWindow( HWND hUIWnd, LPUIEXTRA lpUIExtra, LPINPUTCONTEXT lpIMC)
- {
- //DebugLog(8,(DebugLogFile,"MoveCompWindown"));
- if (!IsWindow(lpUIExtra->uiComp.hWnd)){
- CreateCompWindow( hUIWnd, lpUIExtra);
- //DebugLog(8,(DebugLogFile,"MoveCompWindown"));
- }
- if (IsWindow(lpUIExtra->uiComp.hWnd))
- {
- HDC hDC;
- HFONT oldFont;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- POINT pt;
- RECT screenrc;
- LPTSTR lpStr;
- SIZE sz;
- int height;
- int width,maxcomplen;
- //DebugLog(8,(DebugLogFile,"IsWindown"));
- if(wConversionSet1 & C_SET1_SINGLELINE)
- height=lpUIExtra->uiComp.sz.cy+3;
- else height=lpUIExtra->uiComp.sz.cy*2+6;
- if(wConversionSet & CONVERSION_SET_HISTORYREUSE||wConversionSet1 & C_SET1_Word_Existed_Hint)
- if(_tcslen(YJMMessage))
- maxcomplen=sizeCand[0].cx;
- else maxcomplen=0;
- sz.cx = 0;
- sz.cy = 0;
- if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
- {
- if ((lpCompStr->dwSize > sizeof(COMPOSITIONSTRING))
- && (lpCompStr->dwCompStrLen > 0))
- {
- lpStr =((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- hDC = GetDC(lpUIExtra->uiComp.hWnd);
- oldFont = SelectObject(hDC, hUIFont);
- GetTextExtentPoint(hDC,lpStr,_tcslen(lpStr),&sz);
- SelectObject(hDC, oldFont);
- ReleaseDC(lpUIExtra->uiComp.hWnd,hDC);
- if(_tcslen(lpStr)) sz.cx += 2*sz.cx/_tcslen(lpStr);
- ImmUnlockIMCC(lpIMC->hCompStr);
- maxcomplen=max(sz.cx,lpUIExtra->uiComp.sz.cx);
- NoCompStrYjm=0;
- }
- else{
- NoCompStrYjm=1;
- /* if(wConversionSet & CONVERSION_SET_AUTOHIDE)
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_HIDE);
- else{
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_SHOWNOACTIVATE);
- InvalidateRect(lpUIExtra->uiComp.hWnd,NULL,FALSE);
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- return;*/
- }
- }
- if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
- {
- TCHAR szStr[10*MAXSTRHZLENGTH];
- DWORD i;
- DWORD dwMaxPaintPos;
- WORD wCount;
- LPTSTR lpstr;
- width = 2;
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- if( lpCandList->dwCount <= 0 && NoCompStrYjm) {
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_HIDE);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- return;
- }
- //hDC = GetDC(lpUIExtra->uiCand.hWnd);
- hDC = GetDC(lpUIExtra->uiComp.hWnd);
- oldFont = SelectObject(hDC, hUIFont);
- if(wConversionSet1 & C_SET1_SINGLELINE) {
- width +=maxcomplen;
- lpstr = GETLPCANDSTR(lpCandList,0);
- GetTextExtentPoint(hDC,lpstr,_tcslen(lpstr),&sz);
- if(_tcslen(lpstr)) width +=sz.cx*3/2;
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {
- lpstr = GETLPCANDSTR(lpCandList,0);
- if(_tcslen(lpstr)) width += 30;//sz.cx*3/2;
- }
- dwMaxPaintPos = lpCandList->dwPageStart +lpCandList->dwPageSize ;
- if(dwMaxPaintPos > lpCandList->dwCount + 2) dwMaxPaintPos = lpCandList->dwCount + 2;
- wCount = 0;
- for (i = lpCandList->dwPageStart; i < dwMaxPaintPos; i++)
- {
- wCount++;
- lpstr = GETLPCANDSTR(lpCandList,i);
- GetTextExtentPoint(hDC,lpstr,_tcslen(lpstr),&sz);
- if(wConversionSet1 & C_SET1_SINGLELINE) {//单行
- _stprintf(szStr,"%d%s ",wCount%10,lpstr);
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- width += sz.cx;
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {//双行
- if((wConversionMode==CONVERSION_MODE_WUBI|| wConversionMode==CONVERSION_MODE_ATTACHLIB|| wConversionMode==CONVERSION_MODE_TEMPATTACHLIB)&&
- i<12 && wConversionSet1 & C_SET1_CODE_HINT)
- _stprintf(szStr,"%d%s%s ",wCount%10,lpstr,CodeHintText[i-2]);
- else
- _stprintf(szStr,"%d%s ",wCount%10,lpstr);
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- width += sz.cx;
- }
- else {
- _stprintf(szStr,"%d %s ",wCount%10,lpstr);//多行
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- height += sz.cy;
- width=max(width,sz.cx);
- }
- }
- if(wConversionSet1 & C_SET1_SINGLELINE) {
- lpstr = GETLPCANDSTR(lpCandList,1);
- if(_tcslen(lpstr)) {
- GetTextExtentPoint(hDC,"A",1,&sz);
- width += sz.cx*3/2;
- }
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {
- lpstr = GETLPCANDSTR(lpCandList,1);
- if(_tcslen(lpstr)) {
- //GetTextExtentPoint(hDC,"A",1,&sz);
- width +=30;// sz.cx*3/2;
- }
- }
- SelectObject(hDC, oldFont);
- //ReleaseDC(lpUIExtra->uiCand.hWnd,hDC);
- ReleaseDC(lpUIExtra->uiComp.hWnd,hDC);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- }
- sz.cx =max(maxcomplen,width);
- sz.cy = height;
- if(lpUIExtra->uiComp.pt.x < 0) {
- pt.x = 15;
- pt.y = 15;
- ClientToScreen(lpIMC->hWnd, &pt);
- }
- else{
- pt.x = lpUIExtra->uiComp.pt.x;
- pt.y = lpUIExtra->uiComp.pt.y;
- }
- SystemParametersInfo(SPI_GETWORKAREA,
- 0,
- &screenrc,
- 0);
- //DebugLog(8,(DebugLogFile,"screenrc.x=%d,screenrc.y=%dn",screenrc.right,screenrc.bottom));
- if( (pt.x + sz.cx) > screenrc.right )
- pt.x = screenrc.right - sz.cx;
- if( (pt.y + sz.cy) > screenrc.bottom )
- pt.y = screenrc.bottom - sz.cy;
- //DebugLog(8,(DebugLogFile,"pt.x=%d,pt.y=%dn",pt.x,pt.y));
- MoveWindow(lpUIExtra->uiComp.hWnd,
- pt.x,
- pt.y,
- sz.cx,
- sz.cy,
- TRUE);
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_SHOWNOACTIVATE);
- InvalidateRect(lpUIExtra->uiComp.hWnd,NULL,FALSE);
- }
- }
- void PaintCompWindow( HWND hCompWnd)
- {
- PAINTSTRUCT ps;
- HIMC hIMC;
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- HDC hDC;
- HDC hMemDC;
- HBITMAP hBmpOld;
- HFONT oldFont;
- int height=2,width=2;
- RECT rc;
- HWND hSvrWnd;
- HBRUSH hBrush = (HBRUSH)NULL;
- HBRUSH hOldBrush = (HBRUSH)NULL;
- HPEN hPen = (HPEN)NULL;
- HPEN hOldPen = (HPEN)NULL;
- //DebugLog(8,(DebugLogFile,"PaintCompWindown"));
- //MessageBox(NULL,"have paint","hCompWnd",MB_OK);
- hDC = BeginPaint(hCompWnd,&ps);
- oldFont = SelectObject(hDC, hUIFont);
- hMemDC = CreateCompatibleDC(hDC);
- hBmpOld = SelectObject(hMemDC,hBmpStatus);
- GetClientRect(hCompWnd,&rc);
- if(wConversionSet &CONVERSION_SET_BACKBMP)
- hBrush = CreatePatternBrush(hBmpComp);
- else
- hBrush =CreateSolidBrush(dwBackColor&0xffffff);
- hOldBrush=SelectObject(hDC,hBrush);
- hPen = CreatePen(PS_SOLID ,0,dwPenColor&0xffffff);
- hOldPen = SelectObject(hDC,hPen);
- if(wConversionSet1 & C_SET1_RECTANGLEWINDOW)
- Rectangle(hDC,
- rc.left,
- rc.top,
- rc.right,
- rc.bottom);
- else
- RoundRect(hDC,
- rc.left,
- rc.top,
- rc.right,
- rc.bottom,10,10);
- SelectObject(hDC,hOldPen);
- DeleteObject(hPen);
- if(hBrush && hOldBrush)
- SelectObject(hDC,hOldBrush);
- hSvrWnd = (HWND)GetWindowLong(hCompWnd,FIGWL_SVRWND);
- if (hIMC = (HIMC)GetWindowLong(hSvrWnd,IMMGWL_IMC))
- {
- if( (lpIMC = ImmLockIMC(hIMC)) == NULL ){
- SelectObject(hDC, oldFont);
- EndPaint(hCompWnd,&ps);
- //MessageBox(NULL,"no lpIMC","hCompWnd",MB_OK);
- return;
- }
- if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
- {
- if ((lpCompStr->dwSize > sizeof(COMPOSITIONSTRING))
- && (lpCompStr->dwCompStrLen > 0))
- {
- LPTSTR lpStr,lpPaintStr;
- SIZE sz,sz1,sz2;
- SHORT wEditCaret;
- SHORT wCharNum,wCount;
- int i;
- wEditCaret = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret;
- lpStr = GETLPCOMPSTR(lpCompStr);
- lpPaintStr =
- ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- SetBkMode(hDC,TRANSPARENT);
- SetPaintColor(hDC, (WORD)wConversionMode);
- TextOut(hDC,2,2,lpPaintStr,_tcslen(lpPaintStr));
- if(wConversionMode == CONVERSION_MODE_WUBI){
- GetTextExtentPoint(hDC,lpStr,_tcslen(lpStr),&sz);
- }
- else{
- wCharNum = _tcslen(lpStr) - wEditCaret;
- wCount = 0;
- for(i = _tcslen(lpPaintStr);i;i--) {
- if(wCount == wCharNum) break;
- if( *(lpPaintStr + i -1 ) != _T(' ')) wCount++;
- }
- GetTextExtentPoint(hDC,lpPaintStr,i,&sz);
- }
- GetTextExtentPoint(hDC,"A",1,&sz1);
- GetTextExtentPoint(hDC,lpPaintStr,_tcslen(lpPaintStr),&sz2);
- if(_tcslen(lpPaintStr)) sz2.cx += 2*sz1.cx;
- width=max(sz2.cx,sz1.cx*4);
- height=6+sz1.cy;
- //以下画光标
- hPen = CreatePen(PS_SOLID,3,RGB(0,0,0));
- hOldPen = SelectObject(hDC,hPen);
- MoveToEx(hDC,sz.cx + sz1.cx/4,sz1.cy*11/10,NULL);
- LineTo(hDC,sz.cx + sz1.cx*2/3,sz1.cy*11/10);
- SelectObject(hDC,hOldPen);
- DeleteObject(hPen);
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- }
- if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
- {
- DWORD dwMaxPaintPos,i;
- TCHAR szStr[10*MAXSTRHZLENGTH];
- WORD wCount;
- LPTSTR lpstr;
- SIZE sz;
- if(wConversionSet1 & C_SET1_SINGLELINE)
- height = 2;
- else{
- //height = 26;
- width = 2;
- }
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- SetBkMode(hDC,TRANSPARENT);
- SetPaintColor(hDC, (WORD)wConversionMode);
- //if(wConversionSet1 & C_SET1_SINGLELINE)
- if(wConversionSet1 & C_SET1_SINGLELINE) {
- lpstr = GETLPCANDSTR(lpCandList,0);
- if(_tcslen(lpstr)) {
- TextOut(hDC,width,height,lpstr,_tcslen(lpstr));
- GetTextExtentPoint(hDC,lpstr,_tcslen(lpstr),&sz);
- width += sz.cx*3/2;//30;
- }
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {
- lpstr = GETLPCANDSTR(lpCandList,0);
- //TextOut(hDC,width,height,lpstr,_tcslen(lpstr));
- //GetTextExtentPoint(hDC,lpstr,_tcslen(lpstr),&sz);
- if(_tcslen(lpstr)) {
- BitBlt(hDC,width,height,width+20,height+20,hMemDC,180,0,SRCAND);//SRCCOPY
- width += 30;//sz.cx*3/2;
- }
- }
- dwMaxPaintPos = lpCandList->dwPageStart +lpCandList->dwPageSize ;
- if(dwMaxPaintPos > lpCandList->dwCount + 2) dwMaxPaintPos = lpCandList->dwCount + 2;
- //if(dwMaxPaintPos > CAND_PAGESIZE + 2) dwMaxPaintPos = CAND_PAGESIZE + 2;
- wCount = 0;
- for (i = lpCandList->dwPageStart; i < dwMaxPaintPos; i++)
- {
- wCount++;
- lpstr = GETLPCANDSTR(lpCandList,i);
- GetTextExtentPoint(hDC,lpstr,_tcslen(lpstr),&sz);
- if(wConversionSet1 & C_SET1_SINGLELINE) {
- _stprintf(szStr,"%d%s ",wCount%10,lpstr);
- TextOut(hDC,width,height,szStr,_tcslen(szStr));
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- width += sz.cx;
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {//双行
- if((wConversionMode==CONVERSION_MODE_WUBI|| wConversionMode==CONVERSION_MODE_ATTACHLIB|| wConversionMode==CONVERSION_MODE_TEMPATTACHLIB)&&
- i<12 && wConversionSet1 & C_SET1_CODE_HINT)
- _stprintf(szStr,"%d%s%s ",wCount%10,lpstr,CodeHintText[i-2]);
- else
- _stprintf(szStr,"%d%s ",wCount%10,lpstr);
- TextOut(hDC,width,height,szStr,_tcslen(szStr));
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- width += sz.cx;
- }
- else {
- _stprintf(szStr,"%d %s ",wCount%10,lpstr);
- TextOut(hDC,width,height,szStr,_tcslen(szStr));
- GetTextExtentPoint(hDC,szStr,_tcslen(szStr),&sz);
- height += sz.cy;
- }
- }
- if(wConversionSet1 & C_SET1_SINGLELINE) {
- lpstr = GETLPCANDSTR(lpCandList,1);
- if(_tcslen(lpstr)) {
- GetTextExtentPoint(hDC,"A",1,&sz);
- //width = sizeCand[1].cx -sz.cx*3/2;
- TextOut(hDC,width,height,lpstr,_tcslen(lpstr));
- //BitBlt(hDC,width,height,width+20,height+20,hMemDC,200,0,SRCCOPY);
- }
- }
- else if(wConversionSet & CONVERSION_SET_SHAPE) {
- lpstr = GETLPCANDSTR(lpCandList,1);
- if(_tcslen(lpstr)) {
- //GetTextExtentPoint(hDC,"A",1,&sz);
- //width = sizeCand[1].cx - 30;//sz.cx*3/2;
- //TextOut(hDC,width,height,lpstr,_tcslen(lpstr));
- BitBlt(hDC,width,height,width+20,height+20,hMemDC,200,0,SRCAND);//SRCCOPY
- }
- }
- ImmUnlockIMCC(lpIMC->hCandInfo);
- }
- ImmUnlockIMC(hIMC);
- }
- SelectObject(hMemDC,hBmpOld);
- DeleteDC(hMemDC);
- SelectObject(hDC, oldFont);
- EndPaint(hCompWnd,&ps);
- }
- void HideCompWindow(LPUIEXTRA lpUIExtra)
- {
- if (IsWindow(lpUIExtra->uiComp.hWnd))
- {
- ShowWindow(lpUIExtra->uiComp.hWnd, SW_HIDE);
- }
- }