void ImeUIStartComposition( HWND hwnd ) { PCONSOLE_TABLE ConTbl; ConTbl = SearchConsole(LastConsole); if (ConTbl == NULL) { DBGPRINT(("CONIME: Error! Cannot found registed Console\n")); return; } // // Set fInComposition variables. // ConTbl->fInComposition = TRUE; #ifdef DEBUG_MODE { int i ; for (i = FIRSTCOL ; i < MAXCOL ; i++) { ConvertLine[i] = UNICODE_SPACE ; ConvertLineAtr[i] = 0 ; } } #endif #ifdef DEBUG_INFO xPos = FIRSTCOL; xPosLast = FIRSTCOL; HideCaret( hwnd ); DisplayConvInformation( hwnd ) ; ResetCaret( hwnd ); #endif }
//********************************************************************** // // void ImeUIClearData() // // Handler routine of WM_IME_SELECT message. // //********************************************************************** void ImeUIClearData( HWND hwnd ) { RECT rect; int i; SetWindowText( hwnd, szSteTitle ); // // If user switches to other IME, here we destroy all candidate // windows which has been opened and erase all composition // chars if any. // for( i = 0; i < MAX_LISTCAND; i++ ) { if ( gImeUIData.hListCand[ i ] ) { // // The i-th candidate list has already been displayed, // destroy it and free memory which stores candidate // strings. // DestroyWindow( gImeUIData.hListCand[ i] ); GlobalFree( gImeUIData.hListCandMem[ i ] ); gImeUIData.hListCand[ i ] = gImeUIData.hListCandMem[ i ] = NULL; } } // // Update client area. // GetClientRect( hwnd, &rect ); InvalidateRect( hwnd, &rect, FALSE ); // // Reset IMEUI's global data. // gImeUIData.uCompLen = gImeUIData.ImeState = 0; // // Reset caret to the original position. // HideCaret( hwnd ); ResetCaret( hwnd ); ShowCaret( hwnd ); }
/************************************************************************ * * SteCommand - WM_COMMAND handler * ************************************************************************/ void SteCommand( HWND hWnd, UINT cmd, LPARAM lParam ) { switch( cmd ) { case IDC_CLEAR: // // Blank out text buffer. Return caret to home position // for ( yPos = FIRSTROW; yPos <= LASTROW; yPos++ ) for ( xPos = FIRSTCOL; xPos <= LASTCOL; xPos++ ) textbuf[yPos][xPos] = ' '; break; case IDC_ANSIFILL: /* fall through */ case IDC_DBCSFILL: // // Fill text buffer with ANSI or DBCS pattern // for ( yPos = FIRSTROW; yPos <= LASTROW; yPos++ ) for ( xPos = FIRSTCOL; xPos <= LASTCOL; xPos++ ) if ( cmd == IDC_ANSIFILL ) textbuf[yPos][xPos] = 'a'; else { textbuf[yPos][xPos] = HIBYTE(DBCSFillChar); textbuf[yPos][++xPos] = LOBYTE(DBCSFillChar); } break; // // The following messages are to control IME. // case IDC_OPENIME: SteImeOpenClose( hWnd, TRUE ); goto exit_func; case IDC_CLOSEIME: SteImeOpenClose( hWnd, FALSE ); goto exit_func; } yPos = FIRSTROW; xPos = FIRSTCOL; InvalidateRect( hWnd, (LPRECT)NULL, TRUE ); ResetCaret(hWnd); exit_func: return; }
void DisplayResultString( HWND hwnd, LPWSTR lpwStr ) { int StrLen = lstrlenW( lpwStr ); CopyMemory(ConvertLine, lpwStr, StrLen*sizeof(WCHAR)) ; HideCaret( hwnd ); DisplayConvInformation( hwnd ) ; ResetCaret( hwnd ); // gImeUIData.uCompLen = 0; }
bool TextInputHelper::SetNewText(const string &newText, unsigned int newCaretPosition) { // If we have a max pixel width and the new text will push us past that width, // then we won't do anything. if (maxPixelWidth >= 0 && pFontToCheckAgainst != NULL && pFontToCheckAgainst->GetWidth(newText) > maxPixelWidth) { return false; } currentText = newText; caretPosition = newCaretPosition; ResetCaret(); return true; }
void TextInputHelper::Reset() { ResetCaret(); currentText = ""; caretPosition = 0; keyDownForRepeat = SDLK_UNKNOWN; msSinceKeyDown = -1; isRepeating = false; userHasConfirmed = false; userHasCanceled = false; isInSession = false; }
void DisplayCompString( HWND hwnd, int Length, PWCHAR CharBuf, PUCHAR AttrBuf ) { int i; CopyMemory(ConvertLine, CharBuf, Length * sizeof(WCHAR) ) ; if ( AttrBuf == NULL ) { for ( i = 0 ; i < Length ; i++ ) ConvertLineAtr[i] = 0 ; } else { CopyMemory(ConvertLineAtr, AttrBuf, Length) ; } HideCaret( hwnd ); DisplayConvInformation( hwnd ) ; ResetCaret( hwnd ); }
void ImeUIEndComposition( HWND hwnd ) { PCONSOLE_TABLE ConTbl; ConTbl = SearchConsole(LastConsole); if (ConTbl == NULL) { DBGPRINT(("CONIME: Error! Cannot found registed Console\n")); return; } // // Reset fInComposition variables. // ConTbl->fInComposition = FALSE; if (ConTbl->lpCompStrMem) LocalFree( ConTbl->lpCompStrMem ); ConTbl->lpCompStrMem = NULL ; #ifdef DEBUG_MODE { int i ; // // Reset the length of composition string to zero. // for (i = FIRSTCOL ; i < MAXCOL ; i++) { ConvertLine[i] = UNICODE_SPACE ; ConvertLineAtr[i] = 0 ; } } #endif #ifdef DEBUG_INFO xPos = FIRSTCOL; xPosLast = FIRSTCOL; HideCaret( hwnd ); DisplayConvInformation( hwnd ) ; ResetCaret( hwnd ); #endif }
//********************************************************************* // // void DisplayResultString() // // This displays result string. // // This function supports only fixed pitch font. // //********************************************************************* void DisplayResultString( HWND hwnd, LPSTR lpStr ) { int StrLen; // Storage for string length. int i; // Loop counter. HDC hdc; // Display context handle. StrLen = lstrlen( lpStr ); // // If there is no room for compsoition string, discard it // if ( xPos == ( LASTCOL - StrLen - 1 ) ) return; // // if insert mode or during composition session, // move rest of line to the right by StrLen bytes. // if ( fInsertMode ) { for( i = LASTCOL; i > xPos; i-- ) textbuf[ yPos ][ i ] = textbuf[ yPos ][ i - StrLen ]; // // If the row ends on a lead byte, blank it out, // To do this we must first traverse the string starting // from a know character boundry until we reach the last column. // If the last column is a character boundry then the last // character is either a string byte or a lead byte. // for( i = xPos + StrLen; i < LASTCOL; ) { if ( IsDBCSLeadByte( textbuf[ yPos ][ i ] ) ) i++; i++; } if ( i == LASTCOL && IsDBCSLeadByte( textbuf[ yPos ][ i ] ) ) textbuf[ yPos ][ LASTCOL ] = ' '; } else { // // overtype mode // if ( ( StrLen % 2 ) ) { if ( IsDBCSLeadByte( textbuf[ yPos ][ xPos + StrLen - 1 ] ) ) textbuf[ yPos ][ xPos + StrLen ] = ' '; } else { if ( !IsDBCSLeadByte( textbuf[ yPos ][ xPos + StrLen - 2 ] ) ) { // // Overtyping the current byte, plus the following byte // which could be a lead byte. // if ( IsDBCSLeadByte( textbuf[ yPos ][ xPos + StrLen - 1 ] ) ) textbuf[ yPos ][ xPos + StrLen ] = ' '; } } } // // Store input character at current caret position. // for( i = 0; i <= LASTCOL && *lpStr; i++ ) textbuf[ yPos ][ xPos + i ] = *lpStr++; // // Display input character // hdc = GetDC( hwnd ); HideCaret( hwnd ); // // Displays result string with normal color. // TextOut( hdc, xPos *cxMetrics, yPos * cyMetrics, (LPCSTR)&( textbuf[ yPos][xPos] ), MAXCOL - xPos ); ShowCaret( hwnd ); ReleaseDC( hwnd, hdc ); // // Reset Caret position // xPos += StrLen; if ( xPos > LASTCOL ) xPos = LASTCOL; ResetCaret( hwnd ); gImeUIData.uCompLen = 0; }
//*********************************************************************** // // void ImeUISetOpenStatus() // // This handles WM_IME_REPORT message with wParam = IR_NOTIFY & // lParam = IMC_SETOPENSTATUS. // //********************************************************************** void ImeUISetOpenStatus( HWND hwnd ) { int i; // Lopp counter HIMC hIMC; // Storage for input context handle. // // If fail to get input context handle then do nothing // if ( !( hIMC = ImmGetContext( hwnd ) ) ) return; if ( ImmGetOpenStatus( hIMC ) ) { // // If the IME conversion engine is open, here we change // window's caption title to DBCS composition mode. // SetWindowText( hwnd, (LPSTR)szSteCompTitle ); } else { RECT rect = {0}; // // If the IME conversion engine is closed, here we // erase all already displayed composition chars if any, // change the window's caption title to normal. // GetClientRect( hwnd, &rect ); InvalidateRect( hwnd, &rect, FALSE ); SetWindowText( hwnd, (LPSTR)szSteTitle ); // // Here we close and destroy all of candidate windows // if IME conversion engine is closed. // for( i = 0; i <= MAX_LISTCAND; i++ ) { if ( gImeUIData.hListCand[ i ] ) { DestroyWindow( gImeUIData.hListCand[ i ] ); gImeUIData.hListCand[ i ] = NULL; GlobalFree( gImeUIData.hListCandMem[ i ] ); gImeUIData.hListCandMem[ i ] = NULL; } } // // Reset IMEUI's global data. // gImeUIData.uCompLen = 0; gImeUIData.ImeState = 0; ResetCaret( hwnd ); } ImmReleaseContext( hwnd, hIMC ); }
void VirtualKeyHandler( HWND hWnd, UINT wParam ) { int i; HDC hdc; static int delta = 1; if ( ( gImeUIData.ImeState & IME_IN_CHOSECAND ) || ( gImeUIData.ImeState & IME_IN_COMPOSITION && !MoveCaret( hWnd ) ) ) return; switch( wParam ) { case VK_HOME: // beginning of line xPos = FIRSTCOL; break; case VK_END: // end of line xPos = LASTCOL; goto check_for_trailbyte; case VK_RIGHT: if ( IsDBCSLeadByte( textbuf[yPos][xPos] ) ) { if (xPos==LASTCOL - 1) break; //last character don't move xPos += 2; //skip 2 for DB Character } else { xPos = min( xPos + 1, LASTCOL ); } break; case VK_LEFT: xPos = max( xPos - 1, FIRSTCOL ); check_for_trailbyte: if ( IsDBCSTrailByte( (LPSTR)textbuf[yPos], (LPSTR)&(textbuf[yPos][xPos]) ) ) xPos--; break; case VK_UP: yPos = max( yPos - 1, FIRSTROW ); goto Virtical_Check_Trail; case VK_DOWN: yPos = min( yPos + 1, LASTROW ); Virtical_Check_Trail: if ( IsDBCSTrailByte( (LPSTR)textbuf[yPos], (LPSTR)&(textbuf[yPos][xPos]) ) ) { if (xPos<LASTCOL) { xPos+=delta; delta *= -1; } else { xPos--; } } break; case VK_INSERT: // // Change caret shape to indicate insert/overtype mode // fInsertMode = !fInsertMode; CaretWidth = fInsertMode ? cxMetrics : cxOverTypeCaret; break; case VK_BACK: // backspace if ( xPos > FIRSTCOL ) { xPos--; // // DB Character so backup one more to allign on boundary // if ( IsDBCSTrailByte( (LPSTR)textbuf[yPos], (LPSTR)&(textbuf[yPos][xPos]) ) ) xPos--; // // Fall Through to VK_DELETE to adjust row // } else //FIRST COLUMN don't backup -- this would change for wrapping { break; } case VK_DELETE: if ( !IsDBCSLeadByte( textbuf[yPos][xPos] ) ) { // // Move rest of line left by one, then blank out last character // for ( i = xPos; i < LASTCOL; i++ ) { textbuf[yPos][i] = textbuf[yPos][i+1]; } textbuf[yPos][LASTCOL] = ' '; } else { // // Move line left by two bytes, blank out last two bytes // for ( i = xPos; i < LASTCOL-1; i++ ) { textbuf[yPos][i] = textbuf[yPos][i+2]; } textbuf[yPos][LASTCOL-1] = ' '; textbuf[yPos][LASTCOL] = ' '; } // // Repaint the entire line // hdc = GetDC( hWnd ); HideCaret( hWnd ); TextOut( hdc, 0, yPos*cyMetrics, (LPSTR)textbuf[yPos], MAXCOL ); ReleaseDC( hWnd, hdc ); break; case VK_TAB: // tab -- tabs are column allignment not character { int xTabMax = xPos + TABSTOP; int xPosPrev; do { xPosPrev = xPos; SendMessage( hWnd, WM_KEYDOWN, VK_RIGHT, 1L ); } while ( (xPos % TABSTOP) && (xPos < xTabMax) && (xPos != xPosPrev)); } break; case VK_RETURN: // linefeed yPos = min( yPos+1, LASTROW ); xPos = FIRSTCOL; break; } ResetCaret( hWnd ); }
void CSelection::OnFontChanged( HFONT hFont ) { ResetCaret( hFont ); }