// IMN_CHANGECANDIDATE: BOOL CImeView::ChangeCandidate(LONG CandList) { LPCANDIDATELIST lpCandList = NULL; DWORD dwIndex; DWORD dwBufLen; LPSTR lpStr; DWORD i = 1; RECT rect; int max_width = 0; DWORD dwPreferNumPerPage; if (!Enter()) return FALSE; for (dwIndex = 0; dwIndex < MAX_LISTCAND; dwIndex++) { if (CandList & i) break; else i <<= 1; } if (dwIndex == MAX_LISTCAND) goto exit_changecand; if (!(dwBufLen = ImmGetCandidateList(m_hIMC, dwIndex, lpCandList, 0))) { goto exit_changecand; } delete m_CandList[dwIndex]; m_CandList[dwIndex] = lpCandList = (LPCANDIDATELIST)new char[dwBufLen]; ImmGetCandidateList(m_hIMC, dwIndex, lpCandList, dwBufLen); dwPreferNumPerPage = (!lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; for( i = 0; i < lpCandList->dwCount; i++ ) { lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[i]; max_width = (max_width < lstrlen(lpStr)) ? lstrlen(lpStr) : max_width; } ::GetWindowRect(m_hwndCand[dwIndex], (LPRECT) &rect); ::SetWindowPos(m_hwndCand[dwIndex], m_hWnd, rect.left, rect.top, (max_width + 3) * m_charWidth + 4, (int)(dwPreferNumPerPage) * m_charHeight + 5, SWP_NOZORDER | SWP_NOACTIVATE ); DisplayCandStrings(m_hwndCand[dwIndex], lpCandList); exit_changecand: Leave(); return TRUE; }
void CImeView::CandPaint(HWND hwnd) { int index; HDC hdc; PAINTSTRUCT ps; hdc = ::BeginPaint(hwnd, (LPPAINTSTRUCT)&ps); for (index = 0; index < MAX_LISTCAND; index ++ ) if (m_hwndCand[index] == hwnd) break; if ( index != MAX_LISTCAND && m_CandList[index]) { DisplayCandStrings(hwnd, m_CandList[index]); } ::EndPaint( hwnd, (LPPAINTSTRUCT)&ps ); }
void CandUIPaint( HWND hwnd ) { int index; LPCANDIDATELIST lpCandList; HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint( hwnd, &ps ); // // Determine which candidate window needs to repaint. // for ( index = 0; index < MAX_LISTCAND; index ++ ) if ( gImeUIData.hListCand[ index ] == hwnd ) break; // // If index == MAX_LISTCAND, then something wrong, do nothing. // if ( index == MAX_LISTCAND ) goto exit; if ( !gImeUIData.hListCandMem[ index ] || (lpCandList = (LPCANDIDATELIST) GlobalLock( gImeUIData.hListCandMem[ index ] ) ) == NULL ) { goto exit; } DisplayCandStrings( hwnd, lpCandList ); GlobalUnlock( gImeUIData.hListCandMem[ index ] ); exit: EndPaint( hwnd, &ps ); }
// IMN_OPENCANDIDATE: BOOL CImeView::OpenCandidate(LONG lParam) { LPCANDIDATELIST lpCandList = NULL; // Storage for LP to candidate list. DWORD dwBufLen; // Storage for candidate strings. LPSTR lpStr; // Storage for LP to a string. int max_width = 0; // Storage for width of listCand int CurNumCandList = 0; // Storage for number of cand. lists. DWORD dwPreferNumPerPage; // Storage for PreferNumPerPage // POINT point; // Storage for caret position. if (!Enter()) return FALSE; // SetWindowText(hwnd, (LPSTR)TITLE_CAND); for (int i = 0; i < MAX_LISTCAND; i++ ) { if (m_hwndCand[i]) CurNumCandList++; } for (int index = 0; index < MAX_LISTCAND; index++ ) { if (lParam & (1 << index)) { if (!(dwBufLen = ImmGetCandidateList(m_hIMC, index, lpCandList, 0))) goto exit_opencand; if( !(m_CandList[index] = (LPCANDIDATELIST)new char[dwBufLen])) goto exit_opencand; lpCandList = m_CandList[index]; ImmGetCandidateList(m_hIMC, index, lpCandList, dwBufLen); POINT pt ; GetCaretPos(&pt); ClientToScreen(m_hWnd,&pt); dwPreferNumPerPage = ( !lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; // get the longest string length for (int i = 0; i < (int)lpCandList->dwCount; i++ ) { lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[i]; max_width = (max_width < lstrlen(lpStr)) ? lstrlen(lpStr) : max_width; } m_hwndCand[index] = CreateWindow( "HanjaCandidate", "CandWindow", WS_BORDER | WS_POPUP | WS_DISABLED, CurNumCandList * m_charWidth + pt.x, pt.y + m_charHeight + 2, (max_width + 3) * m_charWidth + 4, (int)dwPreferNumPerPage * m_charHeight + 5, m_hWnd, (HMENU)NULL, (HINSTANCE)GetWindowLong(m_hWnd, GWL_HINSTANCE ), (LPVOID)NULL ); if (m_hwndCand[index] == NULL) { delete m_CandList[index]; m_CandList[index] = NULL; goto exit_opencand; } SetWindowLong(m_hwndCand[index], 0, (LONG)this); ::ShowWindow(m_hwndCand[index], SW_SHOWNOACTIVATE); DisplayCandStrings(m_hwndCand[index], lpCandList); CurNumCandList++; } } m_nState |= IME_IN_CHOSECAND; exit_opencand: Leave(); return TRUE; }
//********************************************************************** // // void ImeUIChangeCandidate() // // This handles WM_IME_NOTIFY message with wParam = IMN_CHANGECANDIDATE. // //********************************************************************** void ImeUIChangeCandidate( HWND hwnd, LPARAM CandList ) { HIMC hIMC; LPCANDIDATELIST lpCandList = NULL; DWORD dwIndex; DWORD bufLen; LPSTR lpStr; DWORD i; RECT rect = {0}; int width = 0; DWORD dwPreferNumPerPage; // // If fail to get input context, do nothing. // if ( !( hIMC = ImmGetContext( hwnd ) ) ) return; // // Determine which candidate list should be updated. // for ( dwIndex = 0; dwIndex < MAX_LISTCAND; dwIndex++ ) if ( CandList & ( 1 << dwIndex ) ) break; // // If dwIndex == MAX_LISTCAND, then something wrong, do nothing. // if ( dwIndex == MAX_LISTCAND ) return; // // Determines how much memory space should be allocated to read in the // corresponding candidate list. // if ( !( bufLen = ImmGetCandidateList( hIMC, dwIndex, lpCandList, 0 ) ) ) goto exit2; // // Relocate memory space. // if ( !( gImeUIData.hListCandMem[ dwIndex ] = GlobalReAlloc( gImeUIData.hListCandMem[ dwIndex ], (int)bufLen, LPTR ) ) ) { goto exit2; } if ( !( lpStr = (LPSTR)GlobalLock( gImeUIData.hListCandMem[ dwIndex ] ) ) ) { GlobalFree( gImeUIData.hListCandMem[ dwIndex ] ); gImeUIData.hListCandMem[ dwIndex ] = NULL; goto exit2; } lpCandList = (LPCANDIDATELIST) lpStr; // // Reads in the corresponding candidate list. // ImmGetCandidateList( hIMC, dwIndex, lpCandList, bufLen ); // // Determines how many candidate strings per page. // dwPreferNumPerPage = ( !lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; // // Determining maximum character length the list box // will display by loopping through all candidate strings. // for( i = 0; i < lpCandList->dwCount; i++ ) { // // Get the pointer to i-th candidate string. // lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[ i ]; width = ( width < lstrlen( lpStr ) ) ? lstrlen( lpStr ) : width; } GetWindowRect( gImeUIData.hListCand[ dwIndex ] , &rect); SetWindowPos( gImeUIData.hListCand[ dwIndex ], hwnd, rect.left, rect.top, ( width ) * cxMetrics + 10, (int)(dwPreferNumPerPage) * cyMetrics + 5, SWP_NOZORDER | SWP_NOACTIVATE ); DisplayCandStrings( gImeUIData.hListCand[ dwIndex ], lpCandList ); GlobalUnlock( gImeUIData.hListCandMem[ dwIndex ] ); exit2: return; }
//********************************************************************** // // void ImeUIOpenCandidate() // // This handles WM_IME_NOTIFY message with wParam = IMN_OPENCANDIDATE. // //********************************************************************** void ImeUIOpenCandidate( HWND hwnd, LPARAM CandList ) { HIMC hIMC; // Input context handle. LPCANDIDATELIST lpCandList; // Storage for LP to candidate list. CANDIDATELIST tempCandList; // Storage for LP to candidate list. DWORD bufLen; // Storage for candidate strings. LPSTR lpStr; // Storage for LP to a string. DWORD dwIndex; // Storage for index of ListCand array DWORD i; // Loop count. int width = 0; // Storage for width of listCand int CurNumCandList = 0; // Storage for number of cand. lists. DWORD dwPreferNumPerPage; // Storage for PreferNumPerPage POINT point; // Storage for caret position. // // If fail to get input context handle, do nothing. // if ( ! (hIMC = ImmGetContext( hwnd ) ) ) return; // // Change caption title to DBCS candidate mode. // SetWindowText( hwnd, szSteCandTitle ); // // Find out how many candidate windows have already been opened. // for( i = 0; i < MAX_LISTCAND; i++ ) { if ( gImeUIData.hListCand[ i ] ) { CurNumCandList++; } } // // Check which candidate lists should be displayed by loopping // through all possible candidate lists. // for( dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) { if ( CandList & ( 1 << dwIndex ) ) { // // The dwIndex-th candidate list contains candidate strings. // So here we want to display them. // // // Determines how musch memory space should be allocated to // read in the corresponding candidate list . // if ( ! ( bufLen = ImmGetCandidateList( hIMC, dwIndex, &tempCandList, 0 ) ) ) goto exit2; // // Allocate memory space. // if( !( gImeUIData.hListCandMem[ dwIndex ] = GlobalAlloc( LPTR, (int)bufLen ) ) ) goto exit2; if( !( lpStr = (LPSTR)GlobalLock( gImeUIData.hListCandMem[ dwIndex ] ) ) ) { GlobalFree( gImeUIData.hListCandMem[ dwIndex ] ); gImeUIData.hListCandMem[ dwIndex ] = NULL; goto exit2; } lpCandList = (LPCANDIDATELIST) lpStr; // // Reads in the corresponding candidate list. // ImmGetCandidateList( hIMC, dwIndex, lpCandList, bufLen ); // // Get current caret position. // GetCaretPos( (POINT *)&point ); ClientToScreen( hwnd, &point ); // // Determines how many candidate strings per page. // dwPreferNumPerPage = ( !lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; // // Determining maximum character length the list box // will display by loopping through all candidate strings. // for( i = 0; i < lpCandList->dwCount; i++ ) { // // Get the pointer to i-th candidate string. // lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[ i ]; width = ( width < lstrlen( lpStr ) ) ? lstrlen( lpStr ) : width; } // // Create a candidate window for the candidate list. // gImeUIData.hListCand[ dwIndex ] = CreateWindow( szCandClass, NULL, WS_BORDER | WS_POPUP | WS_DISABLED, CurNumCandList * X_INDENT + point.x, CurNumCandList * Y_INDENT + point.y + cyMetrics, ( width ) * cxMetrics + 10, (int)(dwPreferNumPerPage) * cyMetrics + 5, hwnd, NULL, (HINSTANCE)GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); // // If fail to create the candidate window then do nothing. // if ( gImeUIData.hListCand[ dwIndex ] < 0 ) { GlobalUnlock( gImeUIData.hListCandMem[ dwIndex ] ); GlobalFree( gImeUIData.hListCandMem[ dwIndex ] ); goto exit2; } // // Show candidate window. // ShowWindow( gImeUIData.hListCand[ dwIndex ], SW_SHOWNOACTIVATE ); // // Display candidate strings. // DisplayCandStrings( gImeUIData.hListCand[ dwIndex ], lpCandList ); GlobalUnlock( gImeUIData.hListCandMem[ dwIndex ] ); CurNumCandList++; } } // // Reset IME state. // gImeUIData.ImeState |= IME_IN_CHOSECAND; exit2: ImmReleaseContext( hwnd, hIMC ); }