4 * Copyright 1993 David Metcalfe
5 * Copyright 1994 Alexandre Julliard
8 static char Copyright
[] = "Copyright David Metcalfe, 1993";
9 static char Copyright2
[] = "Copyright Alexandre Julliard, 1994";
13 extern Colormap COLOR_WinColormap
;
15 static HWND hWndFocus
= 0;
18 /*****************************************************************
23 static void FOCUS_SetXFocus( HWND hwnd
)
26 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 on the top-level ancestor. */
41 wndPtr
= WIN_FindWndPtr( hWndFocus
);
42 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
))
43 wndPtr
= WIN_FindWndPtr( wndPtr
->hwndParent
);
46 /* Make sure window is viewable */
47 if (!XGetWindowAttributes( display
, wndPtr
->window
, &win_attr
) ||
48 (win_attr
.map_state
!= IsViewable
)) return;
50 /* Set X focus and install colormap */
51 XSetInputFocus( display
, wndPtr
->window
, RevertToParent
, CurrentTime
);
52 if (COLOR_WinColormap
!= DefaultColormapOfScreen(screen
))
53 XInstallColormap( display
, COLOR_WinColormap
);
57 /*****************************************************************
61 HWND
SetFocus(HWND hwnd
)
63 HWND hWndPrevFocus
, hwndParent
;
66 if (hwnd
== hWndFocus
) return hWndFocus
; /* Nothing to do! */
70 /* Check if we can set the focus to this window */
73 while ((wndPtr
= WIN_FindWndPtr( hwndParent
)) != NULL
)
75 if ((wndPtr
->dwStyle
& WS_MINIMIZE
) ||
76 (wndPtr
->dwStyle
& WS_DISABLED
)) return 0;
77 if (!(wndPtr
->dwStyle
& WS_CHILD
)) break;
78 hwndParent
= wndPtr
->hwndParent
;
81 /* Now hwndParent is the top-level ancestor. Activate it. */
83 if (hwndParent
!= GetActiveWindow())
85 SetWindowPos( hwndParent
, HWND_TOP
, 0, 0, 0, 0,
86 SWP_NOSIZE
| SWP_NOMOVE
);
87 if (!IsWindow( hwnd
)) return 0; /* Abort if window destroyed */
91 /* Change focus and send messages */
93 hWndPrevFocus
= hWndFocus
;
95 if (hWndPrevFocus
) SendMessage( hWndPrevFocus
, WM_KILLFOCUS
, hwnd
, 0 );
96 if (hwnd
== hWndFocus
) /* Maybe already changed during WM_KILLFOCUS */
98 if (hwnd
) SendMessage( hWndFocus
, WM_SETFOCUS
, hWndPrevFocus
, 0 );
99 FOCUS_SetXFocus( hwnd
);
101 return hWndPrevFocus
;
105 /*****************************************************************