Changeset 9791 for trunk/src


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

Location:
trunk/src/user32
Files:
6 edited

Legend:

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

    r9598 r9791  
    1 /* $Id: oslibmsg.cpp,v 1.64 2003-01-03 16:35:54 sandervl Exp $ */
     1/* $Id: oslibmsg.cpp,v 1.65 2003-02-13 10:12:24 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    4848#include <winscan.h>
    4949#include <winkeyboard.h>
     50#include "user32api.h"
    5051
    5152#define DBG_LOCALLOG    DBG_oslibmsg
     
    265266        teb->o.odin.fTranslated = FALSE;
    266267        memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
     268
     269        //After SetFocus(0), all keystrokes are converted in WM_SYS*
     270        if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
     271            pMsg->message = WINWM_SYSCHAR;
     272        }
     273
    267274        teb->o.odin.os2msg.msg  = 0;
    268275        teb->o.odin.os2msg.hwnd = 0;
     
    423430        }
    424431        memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
     432        //After SetFocus(0), all keystrokes are converted in WM_SYS*
     433        if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
     434            pMsg->message = WINWM_SYSCHAR;
     435        }
     436
    425437
    426438        if(!IsWindow(pMsg->hwnd)) {
  • trunk/src/user32/oslibmsgtranslate.cpp

    r9765 r9791  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.99 2003-02-06 20:28:38 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.100 2003-02-13 10:12:25 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    3838#include <winkeyboard.h>
    3939#include "hook.h"
     40#include "user32api.h"
    4041
    4142#define DBG_LOCALLOG    DBG_oslibmsgtranslate
     
    662663            // adjust our WM_CHAR code
    663664            extramsg.lParam = 0x01460001;
    664             extramsg.message = WINWM_CHAR;
     665
     666            //After SetFocus(0), all keystrokes are converted in WM_SYS*
     667            extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     668
    665669            setThreadQueueExtraCharMessage(teb, &extramsg);
    666670            // and finally adjust our WM_KEYDOWN code
     
    712716                    memcpy(&extramsg, winMsg, sizeof(MSG));
    713717   
    714                     extramsg.message = WINWM_CHAR;
     718                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
     719                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
    715720
    716721                    // insert message into the queue
     
    729734                    memcpy(&extramsg, winMsg, sizeof(MSG));
    730735   
    731                     extramsg.message = WINWM_CHAR;
     736                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
     737                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
    732738
    733739                    // insert message into the queue
     
    766772            winMsg->lParam |= WIN_KEY_ALTHELD;
    767773          }
     774        }
     775        //After SetFocus(0), all keystrokes are converted in WM_SYS*
     776        if(fIgnoreKeystrokes) {
     777            if(winMsg->message == WINWM_KEYDOWN) {
     778                winMsg->message = WINWM_SYSKEYDOWN;
     779            }
     780            else
     781            if(winMsg->message == WINWM_KEYUP) {
     782                winMsg->message = WINWM_SYSKEYUP;
     783            }
    768784        }
    769785        break;
     
    9921008
    9931009
    994       if(msg->message >= WINWM_SYSKEYDOWN)
     1010      //After SetFocus(0), all keystrokes are converted in WM_SYS*
     1011      if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes)
    9951012        extramsg.message = WINWM_SYSCHAR;
    9961013      else   
  • trunk/src/user32/user32api.h

    r9005 r9791  
    1 /* $Id: user32api.h,v 1.1 2002-08-15 10:14:30 sandervl Exp $ */
     1/* $Id: user32api.h,v 1.2 2003-02-13 10:12:25 sandervl Exp $ */
    22//Internal user32 functions
    33
     
    77HWND WINAPI GetAncestor( HWND hwnd, UINT type );
    88
     9//Notify that focus has changed (necessary for SetFocus(0) handling)
     10void SetFocusChanged();
     11
     12extern BOOL fIgnoreKeystrokes;
     13
    914#endif
  • trunk/src/user32/win32wbase.cpp

    r9785 r9791  
    1 /* $Id: win32wbase.cpp,v 1.357 2003-02-11 14:20:01 sandervl Exp $ */
     1/* $Id: win32wbase.cpp,v 1.358 2003-02-13 10:12:25 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    10971097ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
    10981098{
     1099    //Notify that focus has changed (necessary for SetFocus(0) handling)
     1100    SetFocusChanged();
     1101
    10991102    //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
    11001103    if(fDestroyWindowCalled) {
     
    11131116ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
    11141117{
     1118    //Notify that focus has changed (necessary for SetFocus(0) handling)
     1119    SetFocusChanged();
     1120
    11151121    //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
    11161122    if(fDestroyWindowCalled) {
     
    11831189                    if (win32top) {
    11841190                        //Must use client window handle (not frame!!)
    1185                         OSLibWinSetFocus(win32top->getOS2WindowHandle());
     1191                        SetFocus(win32top->getWindowHandle());
    11861192                        RELEASE_WNDOBJ(win32top);
    11871193                    }
  • trunk/src/user32/win32wbasenonclient.cpp

    r9598 r9791  
    1 /* $Id: win32wbasenonclient.cpp,v 1.47 2003-01-03 16:35:57 sandervl Exp $ */
     1/* $Id: win32wbasenonclient.cpp,v 1.48 2003-02-13 10:12:27 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2 (non-client methods)
     
    270270                //SvL: Calling topparent->SetActiveWindow() causes focus problems
    271271                ::SetActiveWindow(hwndTopParent);
    272 ////            OSLibWinSetFocus(topparent->getOS2WindowHandle());
     272////            SetFocus(topparent->getWindowHandle());
    273273            }
    274274            if (GetActiveWindow() == hwndTopParent)
     
    10711071    dprintf(("DoNCPaint %x %x %d", getWindowHandle(), clip, suppress_menupaint));
    10721072
    1073     if ( getStyle() & WS_MINIMIZE ||
     1073    if ( (getStyle() & WS_MINIMIZE) ||
    10741074         !IsWindowVisible( getWindowHandle() )) {
    10751075        return; /* Nothing to do */
    1076     }
     1076   }
    10771077
    10781078    rect.top    = rect.left = 0;
  • 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.