Ignore:
Timestamp:
Feb 13, 2003, 11:12:27 AM (23 years ago)
Author:
sandervl
Message:

Handle SetFocus(0) correctly: keystrokes are converted into WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/window.cpp

    r9590 r9791  
    1 /* $Id: window.cpp,v 1.130 2003-01-02 17:02:06 sandervl Exp $ */
     1/* $Id: window.cpp,v 1.131 2003-02-13 10:12:27 sandervl Exp $ */
    22/*
    33 * Win32 window apis for OS/2
     
    748748}
    749749//******************************************************************************
     750BOOL fIgnoreKeystrokes = FALSE;
     751//******************************************************************************
     752void SetFocusChanged()
     753{
     754    //Focus has changed; invalidate SetFocus(0) state
     755    fIgnoreKeystrokes = FALSE;
     756}
     757//******************************************************************************
    750758//******************************************************************************
    751759HWND WIN32API SetFocus(HWND hwnd)
     
    762770        DebugInt3();
    763771        return 0;
     772    }
     773    //Special case; SetFocus(0) tells Windows to ignore keystrokes. Pressing
     774    //a key now generates WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP instead
     775    //of WM_KEYDOWN/(WM_CHAR)/WM_KEYUP
     776    //WM_KILLFOCUS is sent to the window that currently has focus
     777    if(hwnd == 0) {
     778        lastFocus_W = GetFocus();
     779        if(lastFocus_W == 0) return 0;  //nothing to do
     780
     781        if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)lastFocus_W)) {
     782            dprintf(("hook cancelled SetFocus call!"));
     783            return 0;
     784        }
     785        SendMessageA(lastFocus_W, WM_KILLFOCUS, 0, 0);
     786
     787        fIgnoreKeystrokes = TRUE;
     788
     789        return lastFocus_W;
    764790    }
    765791
     
    820846        dprintf(("USER32: Delay SetFocus call!"));
    821847        teb->o.odin.hwndFocus = hwnd;
    822         //mp1 = win32 window handle
    823         //mp2 = top parent if activation required
    824         OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
     848
     849        //If keystrokes were ignored and focus is set to the old focus window, then
     850        //PM won't send us a WM_SETFOCUS message. (as we don't inform PM for SetFocus(0))
     851        if(fIgnoreKeystrokes && lastFocus_W == hwnd) {
     852            dprintf(("Manually send WM_SETFOCUS; real focus window hasn't changed"));
     853            SendMessageA(lastFocus_W, WM_SETFOCUS, 0, 0);
     854        }
     855        else {
     856            //mp1 = win32 window handle
     857            //mp2 = top parent if activation required
     858            OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
     859        }
    825860        RELEASE_WNDOBJ(window);
    826861        return lastFocus_W;
     
    832867    ret = (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
    833868    RELEASE_WNDOBJ(window);
     869
     870    //If keystrokes were ignored and focus is set to the old focus window, then
     871    //PM won't send us a WM_SETFOCUS message. (as we don't inform PM for SetFocus(0))
     872    if(fIgnoreKeystrokes && lastFocus_W == hwnd) {
     873        dprintf(("Manually send WM_SETFOCUS; real focus window hasn't changed"));
     874        SendMessageA(lastFocus_W, WM_SETFOCUS, 0, 0);
     875    }
     876
     877    fIgnoreKeystrokes = FALSE;
    834878    return ret;
    835879}
     
    844888    if(teb == NULL) {
    845889        DebugInt3();
     890        return 0;
     891    }
     892    //If keystrokes are ignored (SetFocus(0)), then return 0
     893    if(fIgnoreKeystrokes) {
     894        dprintf(("GetFocus; returning 0 after SetFocus(0) call"));
    846895        return 0;
    847896    }
Note: See TracChangeset for help on using the changeset viewer.