#include #include "PCMan.h" #include "DotNETHeader.h" //#define ITEMS_PER_ROW 4 LRESULT APIENTRY CandWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: //murmur("WM_PAINT, candidate window"); // // Uses the managed UI function instead //PaintCandWindow(hWnd); // break; case WM_SETCURSOR: case WM_MOUSEMOVE: case WM_LBUTTONUP: case WM_RBUTTONUP: // // Uses the managed UI function instead /* DragUI(hWnd, NULL, msg, wParam, lParam, FALSE); if ((msg == WM_SETCURSOR) && (HIWORD(lParam) != WM_LBUTTONDOWN) && (HIWORD(lParam) != WM_RBUTTONDOWN)) return DefWindowProc(hWnd, msg, wParam, lParam); if ((msg == WM_LBUTTONUP) || (msg == WM_RBUTTONUP)) SetWindowLong(hWnd, FIGWL_MOUSE, 0L); */ // break; default: if (!MyIsIMEMessage(msg)){ return DefWindowProc(hWnd, msg, wParam, lParam); } break; } return 0L; } void UICreateCandWindow(HWND hUIWnd) { if (!IsWindow(uiCand.hWnd)) { //SIZE sz; sz.cx = sz.cy = 0; /* // CreateWindowEx is not equivalent to SetParent. // Set WS_POPUP in each C# widget instead. uiCand.hWnd = CreateWindowEx(0, UICANDCLASSNAME ,NULL, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, hUIWnd,NULL,hInst,NULL); SetWindowLong(uiCand.hWnd, FIGWL_SVRWND, (DWORD)hUIWnd); //changes an attribute of the specified window.The function also sets the 32-bit (long) value at the specified offset into the extra window memory. */ // //uiCand.hWnd = _CreateCandiPage(); uiCand.hWnd = _CreateCandiPageWithHandle(hUIWnd); //uiCand.sz.cx = sz.cx + 2; //uiCand.sz.cy = sz.cy + 4; } //ShowWindow(uiCand.hWnd, SW_HIDE); //UIHideCandWindow(); // by b6s return; } int CompIndexToXPos( int i ); BOOL GetCandPosFromCompWnd(LPSIZE lpsz) { if (IsWindow(uiComp.hWnd)) { RECT rc, screenrc; POINT pt; GetWindowRect(uiComp.hWnd, &rc); pt.x = rc.left; pt.y = rc.bottom + 2; pt.x += CompIndexToXPos( CompCursorPos ); GetWindowRect(uiCand.hWnd, &rc); pt.x -= 16; if( pt.x < 0 ) pt.x = 0; SystemParametersInfo(SPI_GETWORKAREA, 0, &screenrc, 0); if( (pt.x + lpsz->cx) > screenrc.right) pt.x = screenrc.right - lpsz->cx - 5;//rc.left - lpsz->cx - 5; if( (pt.y + lpsz->cy) > screenrc.bottom) pt.y = screenrc.bottom - lpsz->cy; uiCand.pt.x = pt.x; uiCand.pt.y = pt.y; return TRUE; } return FALSE; } void UISetCandStr(wchar_t* lpStr) { _ClearCandiPage(); /* lpCandStr = wcsdup(lpStr); std::wstring wsCandStr(lpCandStr); watch.start(); _SetCandString(wsCandStr); watch.stop(); murmur("%1.3f sec:\tC# candidate window, set string", watch.getSec()); Watch watch; watch.start(); _ClearCompPage(); watch.stop();*/ // murmur("%1.3f sec:\tC# comp window, clear", watch.getSec()); if(wcslen(lpStr)) { lpCandStr = wcsdup(lpStr); _SetCandiString(lpCandStr); } else { _ClearCandiPage(); } } void UIMoveCandWindow(int X, int Y) { // if(lpStr!=NULL) { //int newX=X+(CompCursorPos-1)*((int)lpStr); //int newY=Y+((int)lpStr); //int newX=X+(CompCursorPos)*21 ; int newX = X; int newY = Y; //if (IsWindow(uiCand.hWnd)) { RECT screenrc; SystemParametersInfo(SPI_GETWORKAREA,0,&screenrc,0); if( newX+100 > screenrc.right ) newX=screenrc.right-100; if( newY+200 > screenrc.bottom ) newY=Y-190; _MoveCandiPage(newX,newY); //uiCand.pt.x=newX; //uiCand.pt.y=newY; } } } //Deprecated. /* void UIMoveCandWindow_OLD(HWND hUIWnd, int X, int Y, wchar_t* lpStr) { murmur("UIMoveCandWindow_OLD"); //James free(lpCandStr); lpCandStr = wcsdup(lpStr); if(lpStr) { if( !*lpStr ) { UIHideCandWindow(); return; } } // FIXME: UIMoveCandWindow will be called twice almost at the same time. // The first call cause some problems. // This should be fixed in the future. // It's impossible to have lpStr != NULL and lpCompStr ==NULL. // Since there is no composition string, is candidate window needed? if( !lpCompStr || !*lpCompStr ) return; if (!IsWindow(uiCand.hWnd)) UICreateCandWindow(hUIWnd); if (IsWindow(uiCand.hWnd)) { HDC hDC; HFONT oldFont; SIZE sz; SIZE candsz; sz.cx = 0; sz.cy = 0; AVConfig cfg; AVDictionary *dict = AVDictionary::getDict(cfg.getUserDir(), "OVIMEUI"); int items_per_row = dict->keyExist("items_per_row") ? dict->getInteger("items_per_row") : ITEMS_PER_ROW; // No Cand if(lpStr == NULL) { //ShowWindow(uiCand.hWnd, SW_HIDE); UIHideCandWindow(); return; } _SetCandiString(lpCandStr); // //UIShowCandWindow(); // hDC = GetDC(uiCand.hWnd); oldFont = (HFONT)SelectObject(hDC, hUIFont); LPCTSTR cand = wcstok( lpCandStr, L" "); // strtok, delimited by space int num = 0; int width = 0; numCand = 0; while( cand ) { ++numCand; int len = (int)wcslen( cand ); GetTextExtentPoint32(hDC, cand, len, &candsz); candsz.cx += 4; candsz.cy += 2; width += candsz.cx; ++num; if( num >= items_per_row ) { sz.cy += candsz.cy; if( width > sz.cx ) sz.cx = width; width = 0; num = 0; } cand = wcstok( NULL, L" " ); } if( width > sz.cx ) sz.cx = width; if( num > 0 && num < items_per_row ) sz.cy += candsz.cy; sz.cy += 2; sz.cx += 2; SelectObject(hDC, oldFont); ReleaseDC(uiCand.hWnd,hDC); if( X > 0 && Y > 0) { RECT screenrc; SystemParametersInfo(SPI_GETWORKAREA, 0, &screenrc, 0); if( (X + sz.cx) > screenrc.right) X = screenrc.right - sz.cx - 5;//rc.left - lpsz->cx - 5; if( (Y + sz.cy) > screenrc.bottom) Y = screenrc.bottom - sz.cy; uiCand.pt.x = X; uiCand.pt.y = Y; //MoveWindow(uiCand.hWnd, // uiCand.pt.x, // uiCand.pt.y, // sz.cx, // sz.cy, // TRUE); _MoveCandiPage(uiCand.pt.x,uiCand.pt.y); // // Test //UIShowCandWindow(); // //InvalidateRect(uiCand.hWnd, NULL, FALSE); } else if( GetCandPosFromCompWnd(&sz) ) { //MoveWindow(uiCand.hWnd, // uiCand.pt.x, // uiCand.pt.y, // sz.cx, // sz.cy, // TRUE); _MoveCandiPage(uiCand.pt.x,uiCand.pt.y); // // Test //UIShowCandWindow(); // //InvalidateRect(uiCand.hWnd, NULL, FALSE); } //James test if(lpStr) UIShowCandWindow(); } } */ // // // Uses the managed UI function instead /* void PaintCandWindow(HWND hCandWnd) { murmur("PaintCandWindow"); #if 0 PAINTSTRUCT ps; HDC hDC; HFONT oldFont; RECT rc; //DWORD i; hDC = BeginPaint(hCandWnd,&ps); oldFont = (HFONT)SelectObject(hDC, hUIFont); GetClientRect(hCandWnd,&rc); if(lpCandStr) { SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) ); SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) ); AVConfig cfg; AVDictionary *dict = AVDictionary::getDict(cfg.getBaseDir(), "OVIMEUI"); int items_per_row = dict->keyExist("items_per_row") ? dict->getInteger("items_per_row") : ITEMS_PER_ROW; RECT cand_rc; cand_rc.left = 1; cand_rc.top = 1; LPCTSTR cand = lpCandStr; //Array foo = cand.split(new char[]{' '}); int num = 0; for( int i = 0; i < numCand; ++i ) { ++num; int len = (int)wcslen( cand ); SIZE candsz; GetTextExtentPoint32(hDC, cand, len, &candsz); candsz.cx += 4; candsz.cy += 2; cand_rc.right = cand_rc.left + candsz.cx; cand_rc.bottom = cand_rc.top + candsz.cy; if( (i + 1) == numCand ) SetTextColor( hDC, RGB(0, 0, 192) ); ExtTextOut( hDC, cand_rc.left + 2, cand_rc.top, ETO_OPAQUE, &cand_rc, cand, len, NULL); if( num >= items_per_row && (i + 1) < numCand ) { cand_rc.left = 1; cand_rc.top += candsz.cy; num = 0; } else cand_rc.left = cand_rc.right; cand = cand + wcslen(cand) + 1; } cand_rc.left = cand_rc.right; cand_rc.right = rc.right; ExtTextOut( hDC, cand_rc.left, cand_rc.top, ETO_OPAQUE, &cand_rc, NULL, 0, NULL); } Draw3DBorder( hDC, &rc, GetSysColor(COLOR_3DFACE), 0 //,GetSysColor(COLOR_3DDKSHADOW) ); SelectObject(hDC, oldFont); EndPaint(hCandWnd,&ps); #endif if(lpCandStr) { UIShowCandWindow(); //James comments return; } } */ // void UIShowCandWindow() { murmur("UIShowCandWindow"); if (IsWindow(uiCand.hWnd)) { _ShowCandiPage(); } } void UIHideCandWindow() { murmur("UIHideCandWindow"); if (IsWindow(uiCand.hWnd)) { _HideCandiPage(); } } void UIExpandCandi() { _ExpandCandi(); }