Release 941210
[wine/multimedia.git] / windows / focus.c
blob7dc8897af809ec6fde8a8d497f3541935d80a3e0
1 /*
2 * Focus functions
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";
9 */
11 #include "win.h"
12 #include "color.h"
14 static HWND hWndFocus = 0;
16 /*****************************************************************
17 * FOCUS_SetXFocus
19 * Set the X focus.
21 static void FOCUS_SetXFocus( HWND hwnd )
23 XWindowAttributes win_attr;
24 Window win;
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 );
33 return;
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 /*****************************************************************
49 * SetFocus (USER.22)
52 HWND SetFocus(HWND hwnd)
54 HWND hWndPrevFocus, hwndParent;
55 WND *wndPtr;
57 if (hwnd == hWndFocus) return hWndFocus; /* Nothing to do! */
59 if (hwnd)
61 /* Check if we can set the focus to this window */
63 hwndParent = hwnd;
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;
85 hWndFocus = hwnd;
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 );
92 return hWndPrevFocus;
96 /*****************************************************************
97 * GetFocus (USER.23)
100 HWND GetFocus(void)
102 return hWndFocus;