4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
16 static HWND hwndFocus
= 0;
18 /*****************************************************************
23 static void FOCUS_SetXFocus( HWND hwnd
)
25 XWindowAttributes win_attr
;
28 /* Only mess with the X focus if there's */
29 /* no desktop window and no window manager. */
30 if ((rootWindow
!= DefaultRootWindow(display
)) || Options
.managed
) return;
32 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
34 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
35 XUninstallColormap( display
, COLOR_WinColormap
);
39 /* Set X focus and install colormap */
41 if (!(win
= WIN_GetXWindow( hwnd
))) return;
42 if (!XGetWindowAttributes( display
, win
, &win_attr
) ||
43 (win_attr
.map_state
!= IsViewable
))
44 return; /* If window is not viewable, don't change anything */
45 XSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
46 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
47 XInstallColormap( display
, COLOR_WinColormap
);
50 /*****************************************************************
53 void FOCUS_SwitchFocus(HWND hFocusFrom
, HWND hFocusTo
)
57 if (hFocusFrom
) SendMessage( hFocusFrom
, WM_KILLFOCUS
, (WPARAM
)hFocusTo
, 0L);
58 if( !hFocusTo
|| hFocusTo
!= hwndFocus
)
61 SendMessage( hFocusTo
, WM_SETFOCUS
, (WPARAM
)hFocusFrom
, 0L);
62 FOCUS_SetXFocus( hFocusTo
);
66 /*****************************************************************
69 HWND
SetFocus(HWND hwnd
)
71 HWND hWndPrevFocus
, hwndTop
;
72 WND
*wndPtr
= WIN_FindWndPtr( hwndTop
= hwnd
);
76 /* Check if we can set the focus to this window */
78 while ( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
80 if ( wndPtr
->dwStyle
& ( WS_MINIMIZE
| WS_DISABLED
) )
83 hwndTop
= wndPtr
->hwndParent
;
84 wndPtr
= WIN_FindWndPtr( hwndTop
);
89 if( hwnd
== hwndFocus
) return hwnd
;
92 if( HOOK_CallHooks( WH_CBT
, HCBT_SETFOCUS
, (WPARAM
)hwnd
, (LPARAM
)hwndFocus
) )
95 /* activate hwndTop if needed. */
96 if (hwndTop
!= GetActiveWindow())
98 if (!WINPOS_SetActiveWindow(hwndTop
, 0, 0)) return 0;
100 if (!IsWindow( hwnd
)) return 0; /* Abort if window destroyed */
103 else if( HOOK_CallHooks( WH_CBT
, HCBT_SETFOCUS
, 0, (LPARAM
)hwndFocus
) )
106 /* Change focus and send messages */
107 hWndPrevFocus
= hwndFocus
;
109 FOCUS_SwitchFocus( hwndFocus
, hwnd
);
111 return hWndPrevFocus
;
115 /*****************************************************************