test: imefull.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# imefull.c

Go to the documentation of this file.

    00001 // Copyright (c) 1985 - 1999, Microsoft Corporation
    00002 //
    00003 //  MODULE:   imefull.c
    00004 //
    00005 //  PURPOSE:   Console IME control.
    00006 //
    00007 //  PLATFORMS: Windows NT-J 3.51
    00008 //
    00009 //  FUNCTIONS:
    00010 //    ImeOpenClose() - calls initialization functions, processes message loop
    00011 //
    00012 //  History:
    00013 //
    00014 //  27.Jul.1995 v-HirShi (Hirotoshi Shimizu)    created
    00015 //
    00016 //  COMMENTS:
    00017 //
    00018
    00019 #include "precomp.h"
    00020 #pragma hdrstop
    00021
    00022 //**********************************************************************
    00023 //
    00024 // IMEOpenClose()
    00025 //
    00026 // This routines calls IMM API to open or close IME.
    00027 //
    00028 //**********************************************************************
    00029
    00030 VOID ImeOpenClose( HWND hWnd, BOOL fFlag )
    00031 {
    00032     HIMC            hIMC;
    00033
    00034     //
    00035     // If fFlag is true then open IME; otherwise close it.
    00036     //
    00037
    00038     if ( !( hIMC = ImmGetContext( hWnd ) ) )
    00039         return;
    00040
    00041     ImmSetOpenStatus( hIMC, fFlag );
    00042
    00043     ImmReleaseContext( hWnd, hIMC );
    00044
    00045 }
    00046
    00047 #ifdef DEBUG_MODE
    00048 /************************************************************************
    00049 *
    00050 *   VirtualKeyHandler - WM_KEYDOWN handler
    00051 *
    00052 *
    00053 *   INPUT:  HWND - handle to the window for repainting output.
    00054 *           UINT - virtual key code.
    00055 *
    00056 ************************************************************************/
    00057
    00058 VOID VirtualKeyHandler( HWND hWnd, UINT wParam, UINT lParam )
    00059 {
    00060     PCONSOLE_TABLE ConTbl;
    00061     int i;
    00062     static int delta ;
    00063
    00064     ConTbl = SearchConsole(LastConsole);
    00065     if (ConTbl == NULL) {
    00066         DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
    00067         return;
    00068     }
    00069
    00070     if ( ConTbl->fInCandidate ||
    00071          ( ConTbl->fInComposition && !MoveCaret( hWnd ) )
    00072        )
    00073         return;
    00074
    00075     switch( wParam )
    00076     {
    00077     case VK_HOME:   // beginning of line
    00078         xPos = FIRSTCOL;
    00079         break;
    00080
    00081     case VK_END:    // end of line
    00082         xPos = xPosLast ;
    00083         break;
    00084
    00085     case VK_RIGHT:
    00086         if ( IsUnicodeFullWidth( ConvertLine[xPos] ) ){
    00087             if (xPos > xPosLast - 2 ) break;  //last character don't move
    00088             xPos += 2;                     //skip 2 for DB Character
    00089         }
    00090         else
    00091             xPos = min( xPos+1, xPosLast );
    00092         break;
    00093
    00094     case VK_LEFT:
    00095
    00096         xPos = max( xPos-1, FIRSTCOL );
    00097
    00098         if ( IsUnicodeFullWidth( ConvertLine[xPos] ) )
    00099             xPos--;
    00100         break;
    00101
    00102     case VK_BACK:   // backspace
    00103
    00104         if ( xPos > FIRSTCOL ) {
    00105             delta = 1 ;
    00106
    00107             //
    00108             // DB Character so backup one more to allign on boundary
    00109             //
    00110             if ( IsUnicodeFullWidth( ConvertLine[xPos] ) )
    00111                 delta = 2 ;
    00112             //
    00113             // Fall Through to VK_DELETE to adjust row
    00114             //
    00115             xPos -= delta ;
    00116             for ( i = xPos ; i < xPosLast+2 ; i++) {
    00117                 ConvertLine[i] = ConvertLine[i+delta] ;
    00118                 ConvertLineAtr[i] = ConvertLineAtr[i+delta] ;
    00119             }
    00120             xPosLast -= delta ;
    00121         }
    00122         else     //FIRST COLUMN  don't backup -- this would change for wrapping
    00123            break;
    00124         goto Repaint ;
    00125         break;
    00126     case VK_DELETE:
    00127         if ( !IsUnicodeFullWidth( ConvertLine[xPos] ) ) {
    00128
    00129             //
    00130             // Move rest of line left by one, then blank out last character
    00131             //
    00132
    00133             for ( i = xPos; i < xPosLast; i++ ) {
    00134                 ConvertLine[i] = ConvertLine[i+1];
    00135                 ConvertLineAtr[i] = ConvertLineAtr[i+1];
    00136             }
    00137             xPosLast-- ;
    00138
    00139         } else {
    00140
    00141             //
    00142             // Move line left by two bytes, blank out last two bytes
    00143             //
    00144
    00145             for ( i = xPos; i < xPosLast; i++ ) {
    00146                 ConvertLine[i] = ConvertLine[i+2];
    00147                 ConvertLineAtr[i] = ConvertLineAtr[i+2];
    00148             }
    00149             xPosLast -= 2 ;
    00150         }
    00151
    00152         goto Repaint ;
    00153         break;
    00154
    00155     case VK_TAB:    // tab  -- tabs are column allignment not character
    00156         {
    00157          int xTabMax = xPos + TABSTOP;
    00158          int xPosPrev;
    00159
    00160          do {
    00161              xPosPrev = xPos;
    00162             if ( IsUnicodeFullWidth( ConvertLine[xPos] ) ){
    00163                 if (xPos > xPosLast - 2 ) break;  //last character don't move
    00164                 xPos += 2;                     //skip 2 for DB Character
    00165             }
    00166             else
    00167                 xPos = min( xPos+1, xPosLast );
    00168
    00169          } while ( (xPos % TABSTOP) &&
    00170                    (xPos < xTabMax) &&
    00171                    (xPos != xPosPrev));
    00172
    00173         }
    00174         goto Repaint ;
    00175         break;
    00176
    00177     case VK_RETURN: // linefeed
    00178         for (i = FIRSTCOL ; i < MAXCOL ; i++) {
    00179             ConvertLine[i] = ' ' ;
    00180             ConvertLineAtr[i] = 0 ;
    00181         }
    00182         xPos = FIRSTCOL;
    00183         xPosLast = FIRSTCOL;
    00184 Repaint:
    00185         {
    00186         //
    00187         // Repaint the entire line
    00188         //
    00189         HDC hdc;
    00190
    00191         hdc = GetDC( hWnd );
    00192         HideCaret( hWnd );
    00193         DisplayConvInformation( hWnd ) ;
    00194         ReleaseDC( hWnd, hdc );
    00195         }
    00196         break;
    00197     }
    00198     ResetCaret( hWnd );
    00199 }
    00200 #endif
    00201
    00202 /************************************************************************
    00203 *
    00204 *   CharHandler - WM_CHAR handler
    00205 *
    00206 ************************************************************************/
    00207
    00208 VOID CharHandlerFromConsole( HWND hWnd, UINT Message, ULONG wParam, ULONG lParam)
    00209 {
    00210     UINT TmpMessage ;
    00211     DWORD dwImmRet ;
    00212     UINT uVKey ;
    00213     UINT wParamSave ;
    00214
    00215     if (HIWORD(wParam) == 0){
    00216         wParamSave = wParam ;
    00217     }
    00218     else {
    00219         if (Message == WM_KEYDOWN   +CONIME_KEYDATA || Message == WM_KEYUP   +CONIME_KEYDATA ||
    00220             Message == WM_SYSKEYDOWN+CONIME_KEYDATA || Message == WM_SYSKEYUP+CONIME_KEYDATA){
    00221             wParamSave = 0 ;
    00222         }
    00223         else if(HIWORD(wParam) > 0x00ff){
    00224             WCHAR WideChar ;
    00225             UCHAR MultiChar ;
    00226             WideChar = HIWORD(wParam) ;
    00227             WideCharToMultiByte(CP_OEMCP, 0, &WideChar, 1, &MultiChar, 1, NULL, NULL) ;
    00228             wParamSave = MultiChar ;
    00229         }
    00230         else {
    00231             wParamSave = HIWORD(wParam) ;
    00232         }
    00233     }
    00234
    00235     if (HIWORD(lParam) & KF_UP) // KEY_TRANSITION_UP
    00236         TmpMessage = WM_KEYUP ;
    00237     else
    00238         TmpMessage = WM_KEYDOWN ;
    00239
    00240
    00241     // Return Value of ClientImmProcessKeyConsoleIME
    00242     // IPHK_HOTKEY          1   - the vkey is IME hotkey
    00243     // IPHK_PROCESSBYIME    2   - the vkey is the one that the IME is waiting for
    00244     // IPHK_CHECKCTRL       4   - not used by NT IME
    00245     dwImmRet = ImmCallImeConsoleIME(hWnd, TmpMessage, wParam, lParam, &uVKey) ;
    00246
    00247     if ( dwImmRet & IPHK_HOTKEY ) {
    00248     //
    00249     // if this vkey is the IME hotkey, we won't pass
    00250     // it to application or hook procedure.
    00251     // This is what Win95 does. [takaok]
    00252     //
    00253        return ;
    00254     }
    00255     else if (dwImmRet & IPHK_PROCESSBYIME) {
    00256         BOOL Status ;
    00257
    00258 //3.51
    00259 //      uVKey = (wParamSave<<8) | uVKey ;
    00260 //      Status = ClientImmTranslateMessageMain( hWnd,uVKey,lParam);
    00261
    00262         Status = ImmTranslateMessage(hWnd, TmpMessage, wParam, lParam);
    00263
    00264
    00265     }
    00266     else if (dwImmRet & IPHK_CHECKCTRL) {
    00267         CharHandlerToConsole( hWnd, Message-CONIME_KEYDATA, wParamSave, lParam);
    00268     }
    00269     else
    00270     {
    00271         if ((Message == WM_CHAR   +CONIME_KEYDATA)||
    00272             (Message == WM_SYSCHAR+CONIME_KEYDATA)) {
    00273             CharHandlerToConsole( hWnd, Message-CONIME_KEYDATA, wParamSave, lParam);
    00274         }
    00275         else
    00276             CharHandlerToConsole( hWnd, Message-CONIME_KEYDATA, wParam, lParam);
    00277     }
    00278
    00279 }
    00280
    00281 VOID CharHandlerToConsole( HWND hWnd, UINT Message, ULONG wParam, ULONG lParam)
    00282 {
    00283     PCONSOLE_TABLE ConTbl;
    00284     WORD  ch ;
    00285     int   NumByte = 0 ;
    00286
    00287     ConTbl = SearchConsole(LastConsole);
    00288     if (ConTbl == NULL) {
    00289         DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
    00290         return;
    00291     }
    00292
    00293     if (HIWORD(lParam) & KF_UP ) {
    00294         PostMessage( ConTbl->hWndCon,
    00295                      Message+CONIME_KEYDATA,
    00296                      wParam,
    00297                      lParam) ;
    00298         return ;
    00299     }
    00300
    00301     ch = LOWORD(wParam) ;
    00302     if ((ch < UNICODE_SPACE) ||
    00303         ((ch >= UNICODE_SPACE) &&
    00304         ((Message == WM_KEYDOWN) || (Message == WM_SYSKEYDOWN) ))) {
    00305 #ifdef DEBUG_MODE
    00306         VirtualKeyHandler( hWnd, wParam ,lParam) ;
    00307 #endif
    00308         PostMessage( ConTbl->hWndCon,
    00309                      Message+CONIME_KEYDATA,
    00310                      wParam,
    00311                      lParam) ;
    00312         return ;
    00313     }
    00314
    00315 #ifdef DEBUG_MODE
    00316     StoreChar( hWnd, ch, 0);
    00317 #endif
    00318
    00319     PostMessage( ConTbl->hWndCon,
    00320                  Message+CONIME_KEYDATA,
    00321                  wParam,          //*Dest,
    00322                  lParam) ;
    00323 }
    00324
    00325 #ifdef DEBUG_MODE
    00326 //**********************************************************************
    00327 //
    00328 // void ImeUIMove()
    00329 //
    00330 // Handler routine of WM_MOVE message.
    00331 //
    00332 //*********************************************************************
    00333
    00334 VOID ImeUIMoveCandWin( HWND hwnd )
    00335 {
    00336     PCONSOLE_TABLE ConTbl;
    00337
    00338     ConTbl = SearchConsole(LastConsole);
    00339     if (ConTbl == NULL) {
    00340         DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
    00341         return;
    00342     }
    00343
    00344     if ( ConTbl->fInCandidate )
    00345     {
    00346         POINT           point;          // Storage for caret position.
    00347         int             i;              // loop counter.
    00348         int             NumCandWin;     // Storage for num of cand win.
    00349         RECT            rect;           // Storage for client rect.
    00350
    00351         //
    00352         // If current IME state is in chosing candidate, here we
    00353         // move all candidate windows, if any, to the appropriate
    00354         // position based on the parent window's position.
    00355         //
    00356
    00357         NumCandWin = 0;
    00358
    00359         GetCaretPos( (LPPOINT)&point );
    00360         ClientToScreen( hwnd, (LPPOINT)&point );
    00361
    00362         for ( i = 0; i < MAX_LISTCAND ; i++ )
    00363         {
    00364             if ( ConTbl->hListCand[ i ] )
    00365             {
    00366                 GetClientRect( ConTbl->hListCand[ i ], &rect );
    00367
    00368                 MoveWindow( ConTbl->hListCand[ i ],
    00369                             point.x + X_INDENT * NumCandWin,
    00370                             point.y + Y_INDENT * NumCandWin + cyMetrics,
    00371                             ( rect.right - rect.left + 1 ),
    00372                             ( rect.bottom - rect.top + 1 ), TRUE );
    00373
    00374                 NumCandWin++;
    00375             }
    00376         }
    00377     }
    00378 }
    00379 #endif
    00380
    00381 #ifdef DEBUG_MODE
    00382 /************************************************************************
    00383 *
    00384 *   ResetCaret - Reset caret shape to match input mode (overtype/insert)
    00385 *
    00386 ************************************************************************/
    00387
    00388 VOID ResetCaret( HWND hWnd )
    00389 {
    00390
    00391     HideCaret( hWnd );
    00392     DestroyCaret();
    00393     CreateCaret( hWnd,
    00394          NULL,
    00395          IsUnicodeFullWidth( ConvertLine[xPos] ) ?
    00396            CaretWidth*2 : CaretWidth,
    00397          cyMetrics );
    00398     SetCaretPos( xPos * cxMetrics, 0 );
    00399     ShowCaret( hWnd );
    00400
    00401 }
    00402
    00403 //**********************************************************************
    00404 //
    00405 // BOOL MoveCaret()
    00406 //
    00407 //**********************************************************************
    00408
    00409 BOOL MoveCaret( HWND hwnd )
    00410 {
    00411     HIMC        hIMC;
    00412     BOOL        retVal = TRUE;
    00413
    00414     if ( !( hIMC = ImmGetContext( hwnd ) ) )
    00415     return retVal;
    00416
    00417     if ( ImmGetCompositionString( hIMC, GCS_CURSORPOS,
    00418                   (void FAR *)NULL, 0 ) )
    00419     retVal = FALSE;
    00420
    00421     ImmReleaseContext( hwnd, hIMC );
    00422
    00423     return retVal;
    00424 }
    00425 #endif
    00426
    00427 #ifdef DEBUG_MODE
    00428 /************************************************************************
    00429 *
    00430 *   StoreChar - Stores one character into text buffer and advances
    00431 *               cursor
    00432 *
    00433 ************************************************************************/
    00434
    00435 VOID StoreChar( HWND hWnd, WORD ch, UCHAR atr )
    00436 {
    00437     HDC hdc;
    00438
    00439     if ( xPos >= CVMAX-3 )
    00440         return;
    00441
    00442     //
    00443     // Store input character at current caret position
    00444     //
    00445     ConvertLine[xPos] = ch;
    00446     ConvertLineAtr[xPos] = atr;
    00447     xPos++ ;
    00448     xPosLast = max(xPosLast,xPos) ;
    00449
    00450     //
    00451     // Repaint the entire line
    00452     //
    00453     hdc = GetDC( hWnd );
    00454     HideCaret( hWnd );
    00455     DisplayConvInformation( hWnd ) ;
    00456     ResetCaret( hWnd );
    00457     ReleaseDC( hWnd, hdc );
    00458
    00459 }
    00460 #endif