4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
17 static HWND32 hwndFocus
= 0;
19 /*****************************************************************
22 void FOCUS_SwitchFocus( HWND32 hFocusFrom
, HWND32 hFocusTo
)
24 WND
*pFocusTo
= WIN_FindWndPtr( hFocusTo
);
28 if (hFocusFrom
) SendMessage32A( hFocusFrom
, WM_KILLFOCUS
, hFocusTo
, 0 );
30 /* FIXME: must be SendMessage16() because 32A doesn't do
31 * intertask at this time */
32 if (hFocusFrom
) SendMessage16( hFocusFrom
, WM_KILLFOCUS
, hFocusTo
, 0 );
34 if( !hFocusTo
|| hFocusTo
!= hwndFocus
)
37 /* According to API docs, the WM_SETFOCUS message is sent AFTER the window
38 has received the keyboard focus. */
40 pFocusTo
->pDriver
->pSetFocus(pFocusTo
);
43 SendMessage32A( hFocusTo
, WM_SETFOCUS
, hFocusFrom
, 0 );
45 SendMessage16( hFocusTo
, WM_SETFOCUS
, hFocusFrom
, 0 );
50 /*****************************************************************
51 * SetFocus16 (USER.22)
53 HWND16 WINAPI
SetFocus16( HWND16 hwnd
)
55 return (HWND16
)SetFocus32( hwnd
);
59 /*****************************************************************
60 * SetFocus32 (USER32.481)
62 HWND32 WINAPI
SetFocus32( HWND32 hwnd
)
64 HWND32 hWndPrevFocus
, hwndTop
= hwnd
;
65 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
69 /* Check if we can set the focus to this window */
71 while ( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
73 if ( wndPtr
->dwStyle
& ( WS_MINIMIZE
| WS_DISABLED
) )
75 if (!(wndPtr
= wndPtr
->parent
)) return 0;
76 hwndTop
= wndPtr
->hwndSelf
;
79 if( hwnd
== hwndFocus
) return hwnd
;
82 if( HOOK_CallHooks16( WH_CBT
, HCBT_SETFOCUS
, (WPARAM16
)hwnd
,
86 /* activate hwndTop if needed. */
87 if (hwndTop
!= GetActiveWindow32())
89 if (!WINPOS_SetActiveWindow(hwndTop
, 0, 0)) return 0;
91 if (!IsWindow32( hwnd
)) return 0; /* Abort if window destroyed */
94 else if( HOOK_CallHooks16( WH_CBT
, HCBT_SETFOCUS
, 0, (LPARAM
)hwndFocus
) )
97 /* Change focus and send messages */
98 hWndPrevFocus
= hwndFocus
;
100 FOCUS_SwitchFocus( hwndFocus
, hwnd
);
102 return hWndPrevFocus
;
106 /*****************************************************************
107 * GetFocus16 (USER.23)
109 HWND16 WINAPI
GetFocus16(void)
111 return (HWND16
)hwndFocus
;
115 /*****************************************************************
116 * GetFocus32 (USER32.240)
118 HWND32 WINAPI
GetFocus32(void)