4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
16 static HWND hwndFocus
= 0;
18 /*****************************************************************
22 * Explicit colormap management seems to work only with OLVWM.
24 static void FOCUS_SetXFocus( HWND hwnd
)
26 XWindowAttributes win_attr
;
29 /* Only mess with the X focus if there's */
30 /* no desktop window and no window manager. */
31 if ((rootWindow
!= DefaultRootWindow(display
)) || Options
.managed
) return;
33 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
35 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE
)
36 XUninstallColormap( display
, COLOR_GetColormap() );
40 /* Set X focus and install colormap */
42 if (!(win
= WIN_GetXWindow( hwnd
))) return;
43 if (!XGetWindowAttributes( display
, win
, &win_attr
) ||
44 (win_attr
.map_state
!= IsViewable
))
45 return; /* If window is not viewable, don't change anything */
47 XSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
48 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE
)
49 XInstallColormap( display
, COLOR_GetColormap() );
52 /*****************************************************************
55 void FOCUS_SwitchFocus(HWND hFocusFrom
, HWND hFocusTo
)
59 if (hFocusFrom
) SendMessage16( hFocusFrom
, WM_KILLFOCUS
, (WPARAM
)hFocusTo
, 0L);
60 if( !hFocusTo
|| hFocusTo
!= hwndFocus
)
63 SendMessage16( hFocusTo
, WM_SETFOCUS
, (WPARAM
)hFocusFrom
, 0L);
64 FOCUS_SetXFocus( hFocusTo
);
68 /*****************************************************************
71 HWND
SetFocus(HWND hwnd
)
73 HWND hWndPrevFocus
, hwndTop
= hwnd
;
74 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
78 /* Check if we can set the focus to this window */
80 while ( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
82 if ( wndPtr
->dwStyle
& ( WS_MINIMIZE
| WS_DISABLED
) )
84 if (!(wndPtr
= wndPtr
->parent
)) return 0;
85 hwndTop
= wndPtr
->hwndSelf
;
88 if( hwnd
== hwndFocus
) return hwnd
;
91 if( HOOK_CallHooks( WH_CBT
, HCBT_SETFOCUS
, (WPARAM
)hwnd
, (LPARAM
)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, (LPARAM
)hwndFocus
) )
105 /* Change focus and send messages */
106 hWndPrevFocus
= hwndFocus
;
108 FOCUS_SwitchFocus( hwndFocus
, hwnd
);
110 return hWndPrevFocus
;
114 /*****************************************************************