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 no desktop window */
29 if (rootWindow
!= DefaultRootWindow(display
)) return;
31 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
33 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
34 XUninstallColormap( display
, COLOR_WinColormap
);
38 /* Set X focus and install colormap */
40 if (!(win
= WIN_GetXWindow( hwnd
))) return;
41 if (!XGetWindowAttributes( display
, win
, &win_attr
) ||
42 (win_attr
.map_state
!= IsViewable
))
43 return; /* If window is not viewable, don't change anything */
44 XSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
45 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
46 XInstallColormap( display
, COLOR_WinColormap
);
49 /*****************************************************************
52 void FOCUS_SwitchFocus(HWND hFocusFrom
, HWND hFocusTo
)
56 if (hFocusFrom
) SendMessage( hFocusFrom
, WM_KILLFOCUS
, hFocusTo
, 0L);
57 if( !hFocusTo
|| hFocusTo
!= hwndFocus
)
60 SendMessage( hFocusTo
, WM_SETFOCUS
, hFocusFrom
, 0L);
61 FOCUS_SetXFocus( hFocusTo
);
65 /*****************************************************************
68 HWND
SetFocus(HWND hwnd
)
70 HWND hWndPrevFocus
, hwndTop
;
71 WND
*wndPtr
= WIN_FindWndPtr( hwndTop
= hwnd
);
75 /* Check if we can set the focus to this window */
77 while ( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
79 if ( wndPtr
->dwStyle
& ( WS_MINIMIZE
| WS_DISABLED
) )
82 hwndTop
= wndPtr
->hwndParent
;
83 wndPtr
= WIN_FindWndPtr( hwndTop
);
88 if( hwnd
== hwndFocus
) return hwnd
;
91 if( HOOK_CallHooks( WH_CBT
, HCBT_SETFOCUS
, hwnd
, hwndFocus
) )
94 /* activate hwndTop if needed. */
95 if (hwndTop
!= GetActiveWindow())
97 if (!WINPOS_SetActiveWindow(hwndTop
, 0, 0)) return 0;
99 if (!IsWindow( hwnd
)) return 0; /* Abort if window destroyed */
102 else if( HOOK_CallHooks( WH_CBT
, HCBT_SETFOCUS
, 0, hwndFocus
) )
105 /* Change focus and send messages */
106 hWndPrevFocus
= hwndFocus
;
108 FOCUS_SwitchFocus( hwndFocus
, hwnd
);
110 return hWndPrevFocus
;
114 /*****************************************************************