4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
17 static HWND32 hwndFocus
= 0;
19 /*****************************************************************
23 * Explicit colormap management seems to work only with OLVWM.
25 void FOCUS_SetXFocus( HWND32 hwnd
)
27 XWindowAttributes win_attr
;
30 /* Only mess with the X focus if there's */
31 /* no desktop window and no window manager. */
32 if ((rootWindow
!= DefaultRootWindow(display
)) || Options
.managed
) return;
34 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
36 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE
)
37 XUninstallColormap( display
, COLOR_GetColormap() );
41 /* Set X focus and install colormap */
43 if (!(win
= WIN_GetXWindow( hwnd
))) return;
44 if (!XGetWindowAttributes( display
, win
, &win_attr
) ||
45 (win_attr
.map_state
!= IsViewable
))
46 return; /* If window is not viewable, don't change anything */
48 XSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
49 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE
)
50 XInstallColormap( display
, COLOR_GetColormap() );
55 /*****************************************************************
58 void FOCUS_SwitchFocus( HWND32 hFocusFrom
, HWND32 hFocusTo
)
63 if (hFocusFrom
) SendMessage32A( hFocusFrom
, WM_KILLFOCUS
, hFocusTo
, 0 );
65 /* FIXME: must be SendMessage16() because 32A doesn't do
66 * intertask at this time */
67 if (hFocusFrom
) SendMessage16( hFocusFrom
, WM_KILLFOCUS
, hFocusTo
, 0 );
69 if( !hFocusTo
|| hFocusTo
!= hwndFocus
)
73 SendMessage32A( hFocusTo
, WM_SETFOCUS
, hFocusFrom
, 0 );
75 SendMessage16( hFocusTo
, WM_SETFOCUS
, hFocusFrom
, 0 );
77 FOCUS_SetXFocus( hFocusTo
);
81 /*****************************************************************
82 * SetFocus16 (USER.22)
84 HWND16
SetFocus16( HWND16 hwnd
)
86 return (HWND16
)SetFocus32( hwnd
);
90 /*****************************************************************
91 * SetFocus32 (USER32.480)
93 HWND32
SetFocus32( HWND32 hwnd
)
95 HWND32 hWndPrevFocus
, hwndTop
= hwnd
;
96 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
100 /* Check if we can set the focus to this window */
102 while ( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
104 if ( wndPtr
->dwStyle
& ( WS_MINIMIZE
| WS_DISABLED
) )
106 if (!(wndPtr
= wndPtr
->parent
)) return 0;
107 hwndTop
= wndPtr
->hwndSelf
;
110 if( hwnd
== hwndFocus
) return hwnd
;
113 if( HOOK_CallHooks16( WH_CBT
, HCBT_SETFOCUS
, (WPARAM16
)hwnd
,
117 /* activate hwndTop if needed. */
118 if (hwndTop
!= GetActiveWindow32())
120 if (!WINPOS_SetActiveWindow(hwndTop
, 0, 0)) return 0;
122 if (!IsWindow32( hwnd
)) return 0; /* Abort if window destroyed */
125 else if( HOOK_CallHooks16( WH_CBT
, HCBT_SETFOCUS
, 0, (LPARAM
)hwndFocus
) )
128 /* Change focus and send messages */
129 hWndPrevFocus
= hwndFocus
;
131 FOCUS_SwitchFocus( hwndFocus
, hwnd
);
133 return hWndPrevFocus
;
137 /*****************************************************************
138 * GetFocus16 (USER.23)
140 HWND16
GetFocus16(void)
142 return (HWND16
)hwndFocus
;
146 /*****************************************************************
147 * GetFocus32 (USER32.239)
149 HWND32
GetFocus32(void)