Fixes crash when running without external shell32.dll.
[wine/multimedia.git] / windows / focus.c
blob4ff9faff24934eb93a06a5815a5762d16325d4a2
1 /*
2 * Focus functions
4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
6 * 1995 Alex Korobka
8 */
10 #include "win.h"
11 #include "winpos.h"
12 #include "hook.h"
13 #include "message.h"
15 static HWND32 hwndFocus = 0;
17 /*****************************************************************
18 * FOCUS_SwitchFocus
20 void FOCUS_SwitchFocus( HWND32 hFocusFrom, HWND32 hFocusTo )
22 WND *pFocusTo = WIN_FindWndPtr( hFocusTo );
23 hwndFocus = hFocusTo;
25 #if 0
26 if (hFocusFrom) SendMessage32A( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 );
27 #else
28 /* FIXME: must be SendMessage16() because 32A doesn't do
29 * intertask at this time */
30 if (hFocusFrom) SendMessage16( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 );
31 #endif
32 if( !pFocusTo || hFocusTo != hwndFocus )
33 return;
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);
40 #if 0
41 SendMessage32A( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
42 #else
43 SendMessage16( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
44 #endif
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 );
65 if (wndPtr)
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) )
72 return 0;
73 if (!(wndPtr = wndPtr->parent)) return 0;
74 hwndTop = wndPtr->hwndSelf;
77 if( hwnd == hwndFocus ) return hwnd;
79 /* call hooks */
80 if( HOOK_CallHooks16( WH_CBT, HCBT_SETFOCUS, (WPARAM16)hwnd,
81 (LPARAM)hwndFocus) )
82 return 0;
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 ) )
93 return 0;
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)
118 return hwndFocus;