4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
15 static HWND32 hwndFocus = 0;
17 /*****************************************************************
20 void FOCUS_SwitchFocus( HWND32 hFocusFrom, HWND32 hFocusTo )
22 WND *pFocusTo = WIN_FindWndPtr( hFocusTo );
26 if (hFocusFrom) SendMessage32A( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 );
28 /* FIXME: must be SendMessage16() because 32A doesn't do
29 * intertask at this time */
30 if (hFocusFrom) SendMessage16( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 );
32 if( !hFocusTo || hFocusTo != hwndFocus )
35 /* According to API docs, the WM_SETFOCUS message is sent AFTER the window
36 has received the keyboard focus. */
38 pFocusTo->pDriver->pSetFocus(pFocusTo);
41 SendMessage32A( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
43 SendMessage16( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
48 /*****************************************************************
49 * SetFocus16 (USER.22)
51 HWND16 WINAPI SetFocus16( HWND16 hwnd )
53 return (HWND16)SetFocus32( hwnd );
57 /*****************************************************************
58 * SetFocus32 (USER32.481)
60 HWND32 WINAPI SetFocus32( HWND32 hwnd )
62 HWND32 hWndPrevFocus, hwndTop = hwnd;
63 WND *wndPtr = WIN_FindWndPtr( hwnd );
67 /* Check if we can set the focus to this window */
69 while ( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
71 if ( wndPtr->dwStyle & ( WS_MINIMIZE | WS_DISABLED) )
73 if (!(wndPtr = wndPtr->parent)) return 0;
74 hwndTop = wndPtr->hwndSelf;
77 if( hwnd == hwndFocus ) return hwnd;
80 if( HOOK_CallHooks16( WH_CBT, HCBT_SETFOCUS, (WPARAM16)hwnd,
84 /* activate hwndTop if needed. */
85 if (hwndTop != GetActiveWindow32())
87 if (!WINPOS_SetActiveWindow(hwndTop, 0, 0)) return 0;
89 if (!IsWindow32( hwnd )) return 0; /* Abort if window destroyed */
92 else if( HOOK_CallHooks16( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)hwndFocus ) )
95 /* Change focus and send messages */
96 hWndPrevFocus = hwndFocus;
98 FOCUS_SwitchFocus( hwndFocus , hwnd );
100 return hWndPrevFocus;
104 /*****************************************************************
105 * GetFocus16 (USER.23)
107 HWND16 WINAPI GetFocus16(void)
109 return (HWND16)hwndFocus;
113 /*****************************************************************
114 * GetFocus32 (USER32.240)
116 HWND32 WINAPI GetFocus32(void)