Example #1
0
File: imm32.c Project: bilboed/wine
static void test_ImmNotifyIME(void) {
    static const char string[] = "wine";
    char resstr[16] = "";
    HIMC imc;
    BOOL ret;

    imc = ImmGetContext(hwnd);
    msg_spy_flush_msgs();

    ret = ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    todo_wine
    {
        ok(!ret ||
           broken(ret), /* Vista and W2K8 */
           "Canceling an empty composition string should fail.\n");
    }
    ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
       "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
       "the composition string being canceled is empty.\n");

    ImmSetCompositionString(imc, SCS_SETSTR, string, sizeof(string), NULL, 0);
    msg_spy_flush_msgs();

    ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
       "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
       "the composition string being canceled is non empty.\n");

    /* behavior differs between win9x and NT */
    ret = ImmGetCompositionString(imc, GCS_COMPSTR, resstr, sizeof(resstr));
    ok(!ret, "After being cancelled the composition string is empty.\n");

    msg_spy_flush_msgs();

    ret = ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    todo_wine
    {
        ok(!ret ||
           broken(ret), /* Vista and W2K8 */
           "Canceling an empty composition string should fail.\n");
    }
    ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
       "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
       "the composition string being canceled is empty.\n");

    msg_spy_flush_msgs();
    ImmReleaseContext(hwnd, imc);
}
Example #2
0
// &SetImeString
static void funcSetImeString(HWND i_hwnd, int i_size)
{
    _TCHAR *buf = new _TCHAR(i_size);
    DWORD len = 0;
    _TCHAR ImeDesc[GANA_MAX_ATOM_LENGTH];
    UINT ImeDescLen;
    DWORD error;
    DWORD denom = 1;
    HANDLE hPipe
        = CreateFile(addSessionId(HOOK_PIPE_NAME).c_str(), GENERIC_READ,
                     FILE_SHARE_READ, (SECURITY_ATTRIBUTES *)NULL,
                     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
    error = ReadFile(hPipe, buf, i_size, &len, NULL);
    CloseHandle(hPipe);

    ImeDescLen = ImmGetDescription(GetKeyboardLayout(0),
                                   ImeDesc, sizeof(ImeDesc));
    if (_tcsncmp(ImeDesc, _T("SKKIME"), ImeDescLen) > 0)
        denom = sizeof(_TCHAR);

    HIMC hIMC = ImmGetContext(i_hwnd);
    if (hIMC == INVALID_HANDLE_VALUE)
        return;

    int status = ImmGetOpenStatus(hIMC);
    ImmSetCompositionString(hIMC, SCS_SETSTR, buf, len / denom, NULL, 0);
    delete buf;
    ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
    if (!status)
        ImmSetOpenStatus(hIMC, status);
    ImmReleaseContext(i_hwnd, hIMC);
}
Example #3
0
void Mint::EnableIME(bool bEnable)
{
	_ASSERT(GetHWND());
	if ( (bEnable == true) && MEvent::GetIMESupport()) {
		if (m_hImc) {
			ImmAssociateContext(GetHWND(), m_hImc);
			m_hImc = NULL;	// EnableIME(false) ÇÒ¶§ ´Ù½Ã ¼ÂÆõȴÙ
			::SetFocus(GetHWND());
		}
		m_bEnableIME = true;
	} else {
		// HIMC¸¦ m_hImc¿¡ Àӽà º¸°üÇØ µ×´Ù°¡, Enable¶§ º¹±¸ÇÑ´Ù.
		m_hImc = ImmGetContext(GetHWND());
		if (m_hImc) {
			ImmAssociateContext(GetHWND(), NULL);
			ImmReleaseContext(GetHWND(), m_hImc);
			::SetFocus(GetHWND());
		}
		//ImmDisableIME(0);
		m_bEnableIME = false;
	}

	// CompositionÁßÀÎ ¹®ÀÚ¿­ Á¦°Å
	HIMC hImc = ImmGetContext(GetInstance()->GetHWND());
	if(hImc!=NULL){
		ImmNotifyIME(hImc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
		ImmReleaseContext(GetInstance()->GetHWND(), hImc);
	}
}
Example #4
0
BOOL NotifyIMEProc(
    HIMC hImc,
    LONG lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    ImmNotifyIME(hImc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    return TRUE;
}
Example #5
0
// Cancel current IME composition.
static inline void imeNotifyCancelComposition(HWND hwnd)
{
    if (!hwnd) {
        qWarning() << __FUNCTION__ << "called with" << hwnd;
        return;
    }
    const HIMC himc = ImmGetContext(hwnd);
    ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    ImmReleaseContext(hwnd, himc);
}
void CTextEditor::FlushCompositionString()
{
    // We flush the composition string at selection change.
    HIMC himc = ImmGetContext(_hwnd);
    if (himc)
    {
        ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
        ImmReleaseContext(_hwnd, himc);
    }
}
Example #7
0
static HRESULT WINAPI ActiveIMMApp_NotifyIME(IActiveIMMApp* This,
        HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
{
    BOOL rc;

    rc = ImmNotifyIME(hIMC,dwAction,dwIndex,dwValue);

    if (rc)
        return S_OK;
    else
        return E_FAIL;
}
Example #8
0
void CandNotifyIME(HWND hCandWnd, WORD wCode)
{
    LPCUIPRIV lpUIPriv;
    HIMC      hIMC;

    lpUIPriv = (LPCUIPRIV)GetWindowLong(hCandWnd, IMMGWL_PRIVATE);
    if (!lpUIPriv) {
        return;
    }
    if (!lpUIPriv->lpCandList) {
        return;
    }
    
    hIMC = (HIMC)GetWindowLong(hCandWnd, IMMGWL_IMC);
    if (!hIMC) {
        return;
    }

    switch(wCode) {
    case CLN_SELECTION:
        ImmNotifyIME(hIMC, NI_SELECTCANDIDATESTR, 0L,
                     lpUIPriv->lpCandList->dwSelection);
        break;
    case CLN_DETERMINE:
        ImmNotifyIME(hIMC, NI_SELECTCANDIDATESTR, 0L,
                     lpUIPriv->lpCandList->dwSelection);
        ImmEscape((HKL)NULL, hIMC, IME_ESC_PRIVATE_FIRST, NULL);
        break;
    case CLN_PAGESTART:
        ImmNotifyIME(hIMC, NI_SETCANDIDATE_PAGESTART, 0L,
                     lpUIPriv->lpCandList->dwPageStart);
        break;
    default:
        break;
    }

    return;
}
Example #9
0
static __inline
LRESULT OnCandSetCursor(HWND hCandWnd, UINT uMsg, LPARAM lParam)
{
    LPUIPRIV        lpUIPriv;
    LPCANDIDATELIST lpCandList;
    POINT            ptCursor;
    DWORD           dwSelection;
    HDC             hDC;

    lpUIPriv = (LPUIPRIV)GetWindowLong(hCandWnd, IMMGWL_PRIVATE);
    if (!lpUIPriv) {
        return -1L;
    }
    
    lpCandList = lpUIPriv->lpCandList;
    if (!lpCandList) {
        return -1L;
    }
    
    ptCursor.x = LOWORD(lParam);
    ptCursor.y = HIWORD(lParam);


    dwSelection = lpCandList->dwPageStart + 
        (ptCursor.y - lpUIPriv->rcCandText.top) / g_sImeUIG.nCandLineHi;
    dwSelection = dwSelection >= (lpCandList->dwPageStart + lpCandList->dwPageSize) ?
        lpCandList->dwPageStart + lpCandList->dwPageSize - 1 : dwSelection;

    if (dwSelection > lpCandList->dwCount -1)
        dwSelection = lpCandList->dwCount -1;

    hDC = GetDC(hCandWnd);

    switch (uMsg) {
    case WM_MOUSEMOVE:
        if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
        }

        if (dwSelection != lpCandList->dwSelection) {
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, FALSE);
            lpCandList->dwSelection = dwSelection;
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, TRUE);
            if (lpUIPriv->fdwUIFlags & UI_CAND_FRACTION) {
                DrawFraction(hDC, lpUIPriv);
            }
        }
        break;
    case WM_LBUTTONDOWN:
        if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
        }

        SetCapture(hCandWnd);
        if (dwSelection != lpCandList->dwSelection) {
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, FALSE);
            lpCandList->dwSelection = dwSelection;
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, TRUE);
            if (lpUIPriv->fdwUIFlags & UI_CAND_FRACTION) {
                DrawFraction(hDC, lpUIPriv);
            }
        }
        break;
    case WM_LBUTTONUP:
        if (hCandWnd == GetCapture()) {
            ReleaseCapture();
        }

        if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
        } else if (dwSelection != lpCandList->dwSelection) {
            break;
        } else {
            HIMC hIMC;

            hIMC = (HIMC)GetWindowLong(hCandWnd, IMMGWL_IMC);
            ImmNotifyIME(hIMC, NI_SELECTCANDIDATESTR, 0L, lpCandList->dwSelection);
			ImmNotifyIME(hIMC, 0x12, 0L, lpCandList->dwSelection);
			ImmNotifyIME(hIMC, 2, 0L, lpCandList->dwSelection);
        }
        break;
    default:
        break;
    }

    ReleaseDC(hCandWnd, hDC);

    return 0L;
}
Example #10
0
LRESULT CALLBACK EditCtlProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
    LPCTSTR lpTable, lpTable1;
    TCHAR   c;
#ifdef FAREAST
    TCHAR ch, chHW;
#endif // FAREAST
    HKL     hkl = GetKeyboardLayout(0);

    ASSERT(oldEditCtlProc);

    switch (message) {
    case WM_PASTE :
    {
        BOOL bPassThrough = TRUE;

        if (IsNumericOnlyEdit(hwnd))
        {
            // only going to accept pastes that have pure numeric data in them

            HANDLE hMem;

            if(OpenClipboard(hwnd))
            {
                hMem = GetClipboardData(CF_UNICODETEXT);
                if(hMem)
                {
                    TCHAR *pText = (TCHAR *)LocalLock(hMem); // can't fail on CE
                    int iLen = _tcslen(pText);
                    int iPos = 0;

                    for (iPos = 0; (iPos < iLen) && bPassThrough; iPos++)
                    {
                        if (!_istdigit(pText[iPos]))
                        {
                            // bad char
                            bPassThrough = FALSE;

                        }
                    }

                    LocalUnlock(hMem);
                }
                CloseClipboard();
            }
        }

        if (bPassThrough)
        {
            return CallWindowProc(oldEditCtlProc,hwnd, message, wParam, lParam);
        } else {
            MessageBeep(MB_OK);
            return FALSE;
        }
    }
    break;


    case WM_IME_COMPOSITION:
        if( ImmIsIME(hkl ) &&
                LOWORD(hkl ) == MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT))
        {
            HIMC himc = ImmGetContext(hwnd);
            if (himc)
            {
                TCHAR szTempStr[4];
                if (0<ImmGetCompositionString(himc,GCS_COMPSTR, szTempStr, 4))
                {
                    DWORD fdwConversion;
                    DWORD fdwSentence;

                    ImmNotifyIME(himc,NI_COMPOSITIONSTR,CPS_CANCEL,0);
                    ImmGetConversionStatus(himc, &fdwConversion, &fdwSentence);
                    fdwConversion&=(~IME_CMODE_NATIVE);
                    ImmSetConversionStatus(himc,fdwConversion, fdwSentence);
                }
                ImmReleaseContext(hwnd,himc);
                return CallWindowProc(oldEditCtlProc,hwnd, message, wParam, lParam);
            }
        }
        break;

    case WM_CHAR:
#ifdef FAREAST // Convert full-width numbers to half width
        ch = (TCHAR)wParam;
        LCMapString(LOCALE_USER_DEFAULT, LCMAP_HALFWIDTH,
                    &ch, 1, &chHW, 1);
        wParam = (WPARAM)chHW;
#endif // FAREAST
        // This character is not ASCII. If your country/region needs specific characters. You
        // have to change this. Otherwise, we abandon this character.
        if (wParam >= 0x80 )  {  // service on ilegal chars
            MessageBeep(MB_OK);
            return TRUE;
        }
        if (wParam < VK_SPACE || wParam > 0x7e )  {  // service on legal chars
            //DPF("None ascii char. ignore \r\n ");
            break;
        }

        if ((lpTable = GetTable(hwnd)) == NULL) {
            //				DPF("Can not find table, trying parent \r\n");
            if ((lpTable = GetTable(GetParent(hwnd))) == NULL) {
                //DPF("Can not find table,  \r\n");
                break;
            }
        }
        lpTable1 = lpTable;
        if (wParam >= '0' && wParam <= '9')
            goto found;
        while ((c = *lpTable++) > 0) {
            if ((TCHAR)wParam == c)
                goto found;
        }
        // now try w/ upper case
        if (iswlower((TCHAR)wParam)) {
            wParam = (LPARAM)towupper((TCHAR)wParam);
            while ((c = *lpTable1++) > 0) {
                if ((TCHAR)wParam == c)
                    goto found;
            }
        }
        //DPF1("Char '%c' not in table\r\n", wParam);
        MessageBeep(MB_OK);
        return TRUE;
found:
        //DPF1("Found char '%c' in table\r\n", wParam);
        break;
    default:
        break;
    }                                                                                   // of switch
    return CallWindowProc(oldEditCtlProc, hwnd, message, wParam, lParam);
}
// Cancel current IME composition.
static inline void imeNotifyCancelComposition(HWND hwnd)
{
    const HIMC himc = ImmGetContext(hwnd);
    ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
    ImmReleaseContext(hwnd, himc);
}
Example #12
0
LRESULT CALLBACK CMessageLoopHook::ProcessMessage ( HWND hwnd, 
                                                    UINT uMsg, 
                                                    WPARAM wParam, 
                                                    LPARAM lParam )
{
    CMessageLoopHook *  pThis;

    // Get a pointer to ourself.
    pThis = CMessageLoopHook::GetSingletonPtr ( );

    if ( pThis )
        pThis->m_ProcessMessageTimer.Reset();

    // Alternate alt-tab system
    if ( pThis && hwnd == pThis->GetHookedWindowHandle () )
    {
        if ( uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_ACTIVE )
        {
            GetVideoModeManager()->OnGainFocus();
        }
        if ( uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE )
        {
            GetVideoModeManager()->OnLoseFocus();
        }
        if ( uMsg == WM_PAINT )
        {
            GetVideoModeManager()->OnPaint();
        }
    }

    // Log our state
    if ( uMsg == WM_KILLFOCUS || (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE) )
    {
        CSetCursorPosHook::GetSingleton ().DisableSetCursorPos ();
    }
    else if ( uMsg == WM_SETFOCUS || (uMsg == WM_ACTIVATE && LOWORD(wParam) != WA_INACTIVE) )
    {
        if ( !g_pCore->GetLocalGUI ()->InputGoesToGUI () )
            CSetCursorPosHook::GetSingleton ().EnableSetCursorPos ();
    }

    // Prevent GTA from knowing about kill focuses. Prevents pausing.
    if ( uMsg == WM_KILLFOCUS || (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE) )
    {
        return true;
    }

    // Disable the system context menu by clicking in the process icon or pressing ALT+SPACE.
    if ( uMsg == WM_SYSCOMMAND )
    {
        if ( wParam == 0xF093 || wParam == SC_KEYMENU || wParam == SC_MOUSEMENU )
            return 0;
    }

    // Quit message?
    if ( uMsg == WM_CLOSE )
    {
        g_pCore->Quit ();
    }

    if ( uMsg == WM_COPYDATA )
    {
        PCOPYDATASTRUCT pCDS = (PCOPYDATASTRUCT) lParam;

        if ( pCDS->dwData == URI_CONNECT )
        {
            LPSTR szConnectInfo      = (LPSTR) pCDS->lpData;
            CCommandFuncs::Connect ( szConnectInfo );
        }
    }

    // Make sure our pointers are valid.
    if ( pThis != NULL && hwnd == pThis->GetHookedWindowHandle () && g_pCore->AreModulesLoaded() )
    {
        g_pCore->UpdateIsWindowMinimized ();  // Force update of stuff

        if ( uMsg == WM_TIMER && wParam == IDT_TIMER1 )
            g_pCore->WindowsTimerHandler();     // Used for 'minimized before first game' pulses

        // Handle IME if input is not for the GUI
        if ( !g_pCore->GetLocalGUI ()->InputGoesToGUI () )
        {
            if ( uMsg == WM_KEYDOWN )
            {
                // Recover virtual key
                if ( wParam == VK_PROCESSKEY )
                    wParam = MapVirtualKey ( lParam >> 16, MAPVK_VSC_TO_VK_EX );
            }

            if ( uMsg == WM_IME_STARTCOMPOSITION || uMsg == WM_IME_ENDCOMPOSITION || uMsg == WM_IME_COMPOSITION )
            {
                // Cancel, stop, block and ignore
                HIMC himc = ImmGetContext ( hwnd );
                ImmNotifyIME ( himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0 );
                ImmReleaseContext ( hwnd, himc );
                return true;
            }
        }

        // Pass escape keyup to onClientKey
        if ( uMsg == WM_KEYUP && wParam == VK_ESCAPE )
        {
            g_pCore->GetKeyBinds()->TriggerKeyStrokeHandler ( "escape", uMsg == WM_KEYDOWN, true );
            return true;
        }

        // Suppress auto repeat of escape and console toggle keys
        if ( ( uMsg == WM_KEYDOWN || uMsg == WM_CHAR ) && ( wParam == VK_ESCAPE || wParam == VK_F8 || wParam == '`' ) )
        {
            bool bFirstHit = ( lParam & 0x40000000 ) ? false:true;
            if ( !bFirstHit )
                return true;
        }

        // Slightly hacky way of suppressing escape character when console is closed with escape key
        if ( uMsg == WM_CHAR && wParam == VK_ESCAPE )
        {
            bool bTemp = ms_bIgnoreNextEscapeCharacter;
            ms_bIgnoreNextEscapeCharacter = false;
            if ( bTemp )
                return true;
        }

        if ( CKeyBinds::IsFakeCtrl_L ( uMsg, wParam, lParam ) )
            return true;

        // See if this is message was caused by our asynchronous sockets
        if ( uMsg >= WM_ASYNCTRAP && uMsg <= ( WM_ASYNCTRAP + 511 ))
        {
            /* ACHTUNG: uMsg - 10? Windows seems to add 10 or there's a bug in the message code. Hack! */
            // Let the CTCPManager handle it
            CTCPManager::GetSingletonPtr ()->HandleEvent ( ( uMsg - WM_ASYNCTRAP ), wParam, lParam );
        }

        bool bWasCaptureKey = false;
        CMainMenu* pMainMenu = g_pCore->GetLocalGUI ()->GetMainMenu ();
        if ( pMainMenu )
        {
            CSettings* pSettings = pMainMenu->GetSettingsWindow ();
            if ( pSettings )
            {
                if ( uMsg == WM_KEYDOWN && wParam == VK_ESCAPE && GetJoystickManager ()->IsCapturingAxis () )
                {
                    GetJoystickManager ()->CancelCaptureAxis ( true );
                    return true;
                }
                bWasCaptureKey = ( pSettings->IsCapturingKey () && pSettings->ProcessMessage ( uMsg, wParam, lParam ) );
                if ( !bWasCaptureKey )
                {
                    // If Escape is pressed and we're playing ingame, we show/hide the menu
                    if ( uMsg == WM_KEYDOWN && wParam == VK_ESCAPE && g_pCore->IsConnected () )
                    {
                        // Hide the console
                        CConsoleInterface* pConsole = g_pCore->GetConsole ();
                        if ( pConsole->IsVisible () )
                        {
                            ms_bIgnoreNextEscapeCharacter = true;
                            pConsole->SetVisible ( false );
                            return true;
                        }

                        // The mainmenu makes sure it isn't hidden if UseIngameButtons == false
                        if ( !CCore::GetSingleton().IsOfflineMod () )
                        {
                            if ( g_pCore->GetKeyBinds()->TriggerKeyStrokeHandler ( "escape", uMsg == WM_KEYDOWN, true ) )
                            {
                                // Stop chat input
                                if ( CLocalGUI::GetSingleton ().IsChatBoxInputEnabled () )
                                {
                                    CLocalGUI::GetSingleton ().SetChatBoxInputEnabled ( false );
                                    return true;
                                }

                                CLocalGUI::GetSingleton ().SetMainMenuVisible ( !CLocalGUI::GetSingleton ().IsMainMenuVisible () );
                            }
                            return true;
                        }
                    }
                    else
                    if ( uMsg == WM_KEYDOWN && wParam == VK_ESCAPE && !g_pCore->IsConnected () )
                    {
                        // If Escape is pressed and we're not playing ingame, hide certain windows
                        CLocalGUI::GetSingleton ().GetMainMenu ()->OnEscapePressedOffLine ();
                    }

                    // If CTRL and Tab are pressed, Trigger a skip
                    if ( ( uMsg == WM_KEYDOWN && wParam == VK_TAB ) )
                    {
                        eSystemState systemState = g_pCore->GetGame ()->GetSystemState ();
                        if ( systemState == 7 || systemState == 8 || systemState == 9 )
                        {
                            short sCtrlState = GetKeyState ( VK_CONTROL );
                            short sShiftState = GetKeyState ( VK_SHIFT );
                            if ( sCtrlState & 0x8000 )
                            {
                                CSettings * pSettings = CLocalGUI::GetSingleton ().GetMainMenu ()->GetSettingsWindow ();
                                CServerBrowser * pServerBrowser = CLocalGUI::GetSingleton ().GetMainMenu ()->GetServerBrowser ();

                                if ( pSettings && pSettings->IsVisible ( ) && pSettings->IsActive ( ) )
                                {
                                    pSettings->TabSkip ( ( sShiftState & 0x8000 ) ? true : false );
                                }
                                else if ( pServerBrowser && pServerBrowser->IsVisible ( ) && pServerBrowser->IsActive ( ) )
                                {
                                    pServerBrowser->TabSkip ( ( sShiftState & 0x8000 ) ? true : false );
                                }
                            }
                        }
                    }
                    if ( ( uMsg == WM_KEYDOWN && ( wParam >= VK_1 && wParam <= VK_9 ) ) )
                    {
                        eSystemState systemState = g_pCore->GetGame ()->GetSystemState ();
                        if ( systemState == 7 || systemState == 8 || systemState == 9 )
                        {
                            short sCtrlState = GetKeyState ( VK_CONTROL );
                            if ( sCtrlState & 0x8000 )
                            {
                                CSettings * pSettings = CLocalGUI::GetSingleton ().GetMainMenu ()->GetSettingsWindow ();
                                CServerBrowser * pServerBrowser = CLocalGUI::GetSingleton ().GetMainMenu ()->GetServerBrowser ();

                                if ( pSettings && pSettings->IsVisible ( ) && pSettings->IsActive ( ) )
                                {
                                    pSettings->SetSelectedIndex ( ( wParam - VK_1 ) - 1 );
                                }
                                else if ( pServerBrowser && pServerBrowser->IsVisible ( ) && pServerBrowser->IsActive ( ) )
                                {
                                    pServerBrowser->SetSelectedIndex ( ( wParam - VK_1 ) - 1 );
                                }
                            }
                        }
                    }

                    // If F8 is pressed, we show/hide the console
                    if ( ( uMsg == WM_KEYDOWN && wParam == VK_F8 ) || ( uMsg == WM_CHAR && wParam == '`' ) )
                    {
                        eSystemState systemState = g_pCore->GetGame ()->GetSystemState ();
                        if ( CLocalGUI::GetSingleton ().IsConsoleVisible () || systemState == 7 || systemState == 8 || systemState == 9 ) /* GS_FRONTEND, GS_INIT_PLAYING_GAME, GS_PLAYING_GAME */
                        {
                            CLocalGUI::GetSingleton ().SetConsoleVisible ( !CLocalGUI::GetSingleton ().IsConsoleVisible () );           
                        }
                        return true;
                    }

                    // If the console is accepting input, and we pressed down/up, scroll the console history
                    //                          or if we pressed tab, step through possible autocomplete matches
                    if ( CLocalGUI::GetSingleton ().GetConsole()->IsInputActive() )
                    {
                        if ( uMsg == WM_KEYDOWN )
                        {
                            if ( wParam == VK_DOWN )
                            {
                                CLocalGUI::GetSingleton ().GetConsole ()->SetPreviousHistoryText ();
                            }

                            if ( wParam == VK_UP )
                            {
                                CLocalGUI::GetSingleton ().GetConsole ()->SetNextHistoryText ();
                            }

                            if ( wParam == VK_TAB )
                            {
                                CLocalGUI::GetSingleton ().GetConsole ()->SetNextAutoCompleteMatch ();
                            }
                            else
                            {
                                CLocalGUI::GetSingleton ().GetConsole ()->ResetAutoCompleteMatch ();
                            }
                        }
                    }
                    else if ( uMsg == WM_KEYDOWN && CLocalGUI::GetSingleton().GetMainMenu()->GetServerBrowser()->IsAddressBarAwaitingInput() )
                    {
                        if ( wParam == VK_DOWN )
                        {
                            CLocalGUI::GetSingleton().GetMainMenu()->GetServerBrowser()->SetNextHistoryText ( true );
                        }

                        if ( wParam == VK_UP )
                        {
                            CLocalGUI::GetSingleton().GetMainMenu()->GetServerBrowser()->SetNextHistoryText ( false );
                        }

                    }
                }
            }
        }

        if ( !bWasCaptureKey )
        {
            // Store our keydown for backup unicode translation
            if ( uMsg == WM_KEYDOWN )
            {
                m_LastVirtualKeyCode = wParam;
                m_LastScanCode = (BYTE)((lParam >> 16) & 0x000F);
                GetKeyboardState( m_LastKeyboardState );
            }
            // If it was a question mark character, we may have an unprocessed unicode character
            if ( uMsg == WM_CHAR && wParam == 0x3F )
            {
                wchar_t* wcsUnicode = new wchar_t[1];
                ToUnicodeEx ( m_LastVirtualKeyCode, m_LastScanCode, m_LastKeyboardState, wcsUnicode, 1, 0, GetKeyboardLayout(0) );
                wParam = (WPARAM)wcsUnicode[0];
                delete wcsUnicode;
            }

            // Lead the message through the keybinds message processor
            g_pCore->GetKeyBinds ()->ProcessMessage ( hwnd, uMsg, wParam, lParam );

            bool bProcessed = false, bClientProcessed = false;          

            // Check and see if the GUI should process this message
            bProcessed = CLocalGUI::GetSingleton ().ProcessMessage ( hwnd, uMsg, wParam, lParam );
            
            // Check and see if the Core/mod should process this message
            if ( !CCore::GetSingleton ().GetGame ()->IsAtMenu() )
            {            
                pfnProcessMessage pfnClientMessageProcessor = CCore::GetSingleton ().GetClientMessageProcessor();
                if ( pfnClientMessageProcessor )
                {
                    bClientProcessed = pfnClientMessageProcessor ( hwnd, uMsg, wParam, lParam );
                }
            }

            // If GTA can process this key
            if ( !bProcessed && !bClientProcessed )
            {
                // ALWAYS return true on escape to stop us getting to GTA's menu
                if ( uMsg == WM_KEYDOWN && wParam == VK_ESCAPE )
                {
                    return true; 
                }

                // Prevent game window auto-minimizing if full screen and:
                //     1. More than one monitor present
                // and 2. Minimizing option disabled
                // or
                //     1. Starting up (Main menu has not been displayed yet)
                if ( uMsg == WM_ACTIVATE ||
                    uMsg == WM_ACTIVATEAPP ||
                    uMsg == WM_NCACTIVATE ||
                    uMsg == WM_SETFOCUS ||
                    uMsg == WM_KILLFOCUS )
                {
                    if ( !GetVideoModeManager ()->IsWindowed () )
                    {
                        if ( !CLocalGUI::GetSingleton ().GetMainMenu () || !CLocalGUI::GetSingleton ().GetMainMenu ()->HasStarted () )
                            return true;    // No auto-minimize

                        if ( GetVideoModeManager ()->IsMultiMonitor ()
                            && !GetVideoModeManager ()->IsMinimizeEnabled () )
                            return true;    // No auto-minimize
                    }
                }
                /*
                // Should not really ever get here, just in case. 
                else if ( uMsg == WM_SIZE )
                {
                    if ( wParam == SIZE_MINIMIZED )
                    {
                        ShowWindow ( pThis->GetHookedWindowHandle(), SW_RESTORE );
                        return true;
                    }
                }
                */

                if ( uMsg == WM_SYSCOMMAND && wParam == 0xF012 ) // SC_DRAGMOVE
                {
                    CMessageLoopHook::GetSingleton().StartWindowMovement ();
                    return true;
                }


                // If we handled mouse steering, don't let GTA.
                //if ( !CCore::GetSingleton ().GetMouseControl()->ProcessMouseMove ( uMsg, wParam, lParam ) )
                    // Call GTA's window procedure.
                    return CallWindowProcW ( pThis->m_HookedWindowProc, hwnd, uMsg, wParam, lParam );
            }

            // Don't allow DefWindowProc if processed here. (Important for IME)
            return true; 
        }
static __inline LRESULT OnCandSetCursor(HWND hCandWnd, UINT uMsg, LPARAM lParam)
{
    LPUIPRIV        lpUIPriv;
    LPCANDIDATELIST lpCandList;
    POINT            ptCursor;
    DWORD           dwSelection;
    HDC             hDC;
	int				i;

    lpUIPriv = (LPUIPRIV)GetWindowLong(hCandWnd, IMMGWL_PRIVATE);
    if (!lpUIPriv) {
        return -1L;
    }
    
    lpCandList = lpUIPriv->lpCandList;
    if (!lpCandList) {
        return -1L;
    }
    
    ptCursor.x = LOWORD(lParam);
    ptCursor.y = HIWORD(lParam);

	//Determine selected item acoording to mouse cursor  coordinate
 
	if(ptCursor.x < g_sImeUIG.nCandDx[0]){
		// page-up
		lpCandList->dwStyle = 4;
	}
	else if(ptCursor.x > lpUIPriv->rcCandText.right ) {
		// page-down
		lpCandList->dwStyle = 3;
	}
	else{
		for(i=0; i< 32; i++){
			if(ptCursor.x > g_sImeUIG.nCandDx[i] && ptCursor.x < g_sImeUIG.nCandDx[i+1])
				break;
		}
	}
	dwSelection = lpCandList->dwPageStart + i;

    if (dwSelection > lpCandList->dwCount -1)
        dwSelection = lpCandList->dwCount -1;

    hDC = GetDC(hCandWnd);

    switch (uMsg) {
    case WM_MOUSEMOVE:
        if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
        }

        if (dwSelection != lpCandList->dwSelection) {
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, FALSE);
            lpCandList->dwSelection = dwSelection;
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, TRUE);

        }
        break;
    case WM_LBUTTONDOWN:
        if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
        }

        SetCapture(hCandWnd);
        if (dwSelection != lpCandList->dwSelection) {
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, FALSE);
            lpCandList->dwSelection = dwSelection;
            DrawCandLine(hDC, lpUIPriv, lpCandList->dwSelection, TRUE);
//            if (lpUIPriv->fdwUIFlags & UI_CAND_FRACTION) {
//                DrawFraction(hDC, lpUIPriv);
//            }
        }
        break;
    case WM_LBUTTONUP:
        if (hCandWnd == GetCapture()) {
            ReleaseCapture();
        }
	
        
		if(lpCandList->dwStyle !=0){
			ReleaseDC(hCandWnd, hDC);
			ChangeCand(hCandWnd);
			return 0L;
		} else if (!PtInRect(&lpUIPriv->rcCandText, ptCursor)) {
            break;
		} else if (dwSelection != lpCandList->dwSelection) {
            break;
        } else {
            HIMC hIMC;

            hIMC = (HIMC)GetWindowLong(hCandWnd, IMMGWL_IMC);
            ImmNotifyIME(hIMC, NI_SELECTCANDIDATESTR, 0L, lpCandList->dwSelection);
			//ImmNotifyIME(hIMC, 0x12, 0L, lpCandList->dwSelection);
			//ImmNotifyIME(hIMC, 2, 0L, lpCandList->dwSelection);
        }
        break;
    default:
        break;
    }

    ReleaseDC(hCandWnd, hDC);

    return 0L;
}
LRESULT HandleConvertCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    HIMC hIMC = ImmGetContext(hWndCompStr);
    DWORD dwSel;
    DWORD dwSize;
    LPCANDIDATELIST lpCL = NULL;

    switch(wParam)
    {
        case IDM_CONVERT:
            ImmNotifyIME(hIMC,NI_COMPOSITIONSTR,CPS_CONVERT,0);
            break;

        case IDM_CANCEL:
            ImmNotifyIME(hIMC,NI_COMPOSITIONSTR,CPS_CANCEL,0);
            break;

        case IDM_REVERT:
            ImmNotifyIME(hIMC,NI_COMPOSITIONSTR,CPS_REVERT,0);
            break;

        case IDM_COMPLETE:
            ImmNotifyIME(hIMC,NI_COMPOSITIONSTR,CPS_COMPLETE,0);
            break;

        case IDM_OPENCAND:
            ImmNotifyIME(hIMC,NI_OPENCANDIDATE,0,0);
            break;

        case IDM_CLOSECAND:
            ImmNotifyIME(hIMC,NI_CLOSECANDIDATE,0,0);
            break;

        case IDM_NEXTCAND: /* fall-through */
        case IDM_PREVCAND:
            if (dwSize = ImmGetCandidateList(hIMC,0x0,NULL,0))
            {
                lpCL = (LPCANDIDATELIST)GlobalAlloc(GPTR,dwSize);
        
                ImmGetCandidateList(hIMC,0x0,lpCL,dwSize);
 
                dwSel = lpCL->dwSelection;

                if (wParam == IDM_NEXTCAND)
                {
                   if (++dwSel >= lpCL->dwCount)
                   {
                      dwSel = 0;
                   }
                }
                else
                {
                   if (dwSel)
                   {
                      dwSel--;
                   }
                   else
                   {
                      dwSel = lpCL->dwCount - 1;
                   }
                }
                GlobalFree((HANDLE)lpCL);

                ImmNotifyIME(hIMC,NI_SELECTCANDIDATESTR,0,dwSel);
            }
            break;

    }

    ImmReleaseContext(hWndCompStr,hIMC);

    return 1;
}
Example #15
0
LRESULT CALLBACK CompStrWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HIMC hIMC    = NULL;
    HIMC hOldIMC = NULL;

    switch (message) 
    {
        case WM_CREATE:
            hIMC = ImmCreateContext();
            hOldIMC = ImmAssociateContext(hWnd,hIMC);
            SetWindowLongPtr(hWnd, 0, (LONG_PTR)hOldIMC);
            fdwProperty = ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY);
            break;

        case WM_CHAR:
            HandleChar(hWnd,wParam,lParam);
            break;

        case WM_LBUTTONUP:  /* fall-through */
        case WM_RBUTTONUP:
            if (hIMC = ImmGetContext(hWnd))
            {
                HMENU hMenu = NULL;

                InitMenuItemIDTable();
                hMenu = CreateImeMenu(hWnd, hIMC, NULL,(message == WM_RBUTTONUP));

                if (hMenu)
                {
                    DWORD dwItemData;
                    DWORD dwPos = (DWORD)GetMessagePos();
                    int nCmd;
                  
                    nCmd = TrackPopupMenuEx(hMenu,
                                            TPM_RETURNCMD | TPM_NONOTIFY | 
                                            TPM_LEFTBUTTON | TPM_LEFTALIGN | TPM_TOPALIGN, 
                                            LOWORD(dwPos), HIWORD(dwPos), 
                                            hWnd, NULL);

                    if (nCmd)
                    {
                        nCmd -= IDM_STARTIMEMENU;
                        dwItemData = FindItemData(nCmd);
                        ImmNotifyIME(hIMC, NI_IMEMENUSELECTED, nCmd, dwItemData);
                    }
                }
                EndMenuItemIDTable();

                DestroyMenu(hMenu);
            }
            break;

        case WM_IME_SETCONTEXT:
            if (fShowCand)
            {
                lParam &= ~ISC_SHOWUICANDIDATEWINDOW;
            }

            if (fdwProperty & IME_PROP_SPECIAL_UI)
            {
                // EMPTY
            }
            else if (fdwProperty & IME_PROP_AT_CARET)
            {
                lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
            }
            else
            {
                // EMPTY
            }

            return (DefWindowProc(hWnd, message, wParam, lParam));

        case WM_IME_STARTCOMPOSITION:
            // Normally, we should not call into HandleStartComposition
            // for IME_PROP_SPECIAL_UI and not IME_PROP_AT_CARET IMEs
            // we should pass this message to DefWindowProc directly for
            // this kind of IMEs

            HandleStartComposition(hWnd,wParam,lParam);

            // pass this message to DefWindowProc for IME_PROP_SPECIAL_UI
            // and not IME_PROP_AT_CARET IMEs

            if (fdwProperty & IME_PROP_SPECIAL_UI)
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            else if (fdwProperty & IME_PROP_AT_CARET)
            {
                // EMPTY
            }
            else
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }

            break;

        case WM_IME_ENDCOMPOSITION:
            // Normally, we should not call into HandleEndComposition
            // for IME_PROP_SPECIAL_UI and not IME_PROP_AT_CARET IMEs
            // we should pass this message to DefWindowProc directly for
            // this kind of IMEs

            HandleEndComposition(hWnd,wParam,lParam);

            // pass this message to DefWindowProc for IME_PROP_SPECIAL_UI
            // and not IME_PROP_AT_CARET IMEs

            if (fdwProperty & IME_PROP_SPECIAL_UI)
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            else if (fdwProperty & IME_PROP_AT_CARET)
            {
                // EMPTY
            }
            else
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            break;

        case WM_IME_COMPOSITION:
            // Normally, we should not call into HandleComposition
            // for IME_PROP_SPECIAL_UI and not IME_PROP_AT_CARET IMEs
            // we should pass this message to DefWindowProc directly for
            // this kind of IMEs

            HandleComposition(hWnd,wParam,lParam);

            // pass this message to DefWindowProc for IME_PROP_SPECIAL_UI
            // and not IME_PROP_AT_CARET IMEs

            if (fdwProperty & IME_PROP_SPECIAL_UI)
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            else if (fdwProperty & IME_PROP_AT_CARET)
            {
                // EMPTY
            }
            else
            {
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            break;

        case WM_PAINT:
            HandlePaint(hWnd,wParam,lParam);
            break;

        case WM_IME_NOTIFY:
            {
                LRESULT lRet;

                // Normally, we should not call into HandleNotify
                // for IME_PROP_SPECIAL_UI and not IME_PROP_AT_CARET IMEs
                // we should pass this message to DefWindowProc directly for
                // this kind of IMEs

                lRet = HandleNotify(hWnd, message, wParam, lParam);
 
                // pass this message to DefWindowProc for IME_PROP_SPECIAL_UI
                // and not IME_PROP_AT_CARET IMEs

                if (fdwProperty & IME_PROP_SPECIAL_UI)
                {
                    return (DefWindowProc(hWnd, message, wParam, lParam));
                }
                else if (fdwProperty & IME_PROP_AT_CARET)
                {
                    // EMPTY
                }
                else
                {
                    return (DefWindowProc(hWnd, message, wParam, lParam));
                }

                return lRet;
            }

        case WM_DESTROY:
            hOldIMC = (HIMC)GetWindowLongPtr(hWnd, 0);
            hIMC = ImmAssociateContext(hWnd, hOldIMC);
            ImmDestroyContext(hIMC);
            break;

        case WM_INPUTLANGCHANGE:
            fdwProperty = ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY);

            if (hIMC = ImmGetContext(hWnd))
            {
                CANDIDATEFORM cdf = {0};

                if (fdwProperty & IME_PROP_AT_CARET)
                {
                    cdf.dwIndex = 0;
                    cdf.dwStyle = CFS_CANDIDATEPOS;
                    cdf.ptCurrentPos.x = ptImeUIPos.x;
                    cdf.ptCurrentPos.y = ptImeUIPos.y;
                    ImmSetCandidateWindow(hIMC, &cdf);
                }
                else
                {
                    UINT i;

                    // The candidate position should be decided by a near caret
                    // IME. There are 4 candidate form in the input context

                    for (i = 0; i < 4; i++)
                    {
                        if (!ImmGetCandidateWindow(hIMC, i, &cdf))
                        {
                            continue;
                        }

                        if (cdf.dwStyle == CFS_DEFAULT)
                        {
                            continue;
                        }

                        cdf.dwStyle = CFS_DEFAULT;

                        ImmSetCandidateWindow(hIMC, &cdf);
                    }

                }

                ImmReleaseContext(hWnd, hIMC);
            }

            return (DefWindowProc(hWnd, message, wParam, lParam));

        default:
	        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return 0L;
}