4 * Copyright 1993 David Metcalfe
5 * Copyright 1994 Alexandre Julliard
7 static char Copyright[] = "Copyright David Metcalfe, 1993";
8 static char Copyright2[] = "Copyright Alexandre Julliard, 1994";
14 static HWND hWndFocus
= 0;
16 /*****************************************************************
21 static void FOCUS_SetXFocus( HWND hwnd
)
23 XWindowAttributes win_attr
;
26 /* Only mess with the X focus if there's no desktop window */
27 if (rootWindow
!= DefaultRootWindow(display
)) return;
29 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
31 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
32 XUninstallColormap( display
, COLOR_WinColormap
);
36 /* Set X focus and install colormap */
38 if (!(win
= WIN_GetXWindow( hwnd
))) return;
39 if (!XGetWindowAttributes( display
, win
, &win_attr
) ||
40 (win_attr
.map_state
!= IsViewable
))
41 return; /* If window is not viewable, don't change anything */
42 XSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
43 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
44 XInstallColormap( display
, COLOR_WinColormap
);
48 /*****************************************************************
52 HWND
SetFocus(HWND hwnd
)
54 HWND hWndPrevFocus
, hwndParent
;
57 if (hwnd
== hWndFocus
) return hWndFocus
; /* Nothing to do! */
61 /* Check if we can set the focus to this window */
64 while ((wndPtr
= WIN_FindWndPtr( hwndParent
)) != NULL
)
66 if ((wndPtr
->dwStyle
& WS_MINIMIZE
) ||
67 (wndPtr
->dwStyle
& WS_DISABLED
)) return 0;
68 if (!(wndPtr
->dwStyle
& WS_CHILD
)) break;
69 hwndParent
= wndPtr
->hwndParent
;
72 /* Now hwndParent is the top-level ancestor. Activate it. */
74 if (hwndParent
!= GetActiveWindow())
76 SetWindowPos( hwndParent
, HWND_TOP
, 0, 0, 0, 0,
77 SWP_NOSIZE
| SWP_NOMOVE
);
78 if (!IsWindow( hwnd
)) return 0; /* Abort if window destroyed */
82 /* Change focus and send messages */
84 hWndPrevFocus
= hWndFocus
;
86 if (hWndPrevFocus
) SendMessage( hWndPrevFocus
, WM_KILLFOCUS
, hwnd
, 0 );
87 if (hwnd
== hWndFocus
) /* Maybe already changed during WM_KILLFOCUS */
89 if (hwnd
) SendMessage( hWndFocus
, WM_SETFOCUS
, hWndPrevFocus
, 0 );
90 FOCUS_SetXFocus( hwnd
);
96 /*****************************************************************