4 * Copyright 1993 David Metcalfe
5 * 1994 Alexandre Julliard
10 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
18 static HWND32 hwndFocus = 0;
20 /*****************************************************************
24 * Explicit colormap management seems to work only with OLVWM.
26 void FOCUS_SetXFocus( HWND32 hwnd )
28 XWindowAttributes win_attr;
31 /* Only mess with the X focus if there's */
32 /* no desktop window and no window manager. */
33 if ((rootWindow != DefaultRootWindow(display)) || Options.managed) return;
35 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
37 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE)
38 XUninstallColormap( display, COLOR_GetColormap() );
42 /* Set X focus and install colormap */
44 if (!(win = WIN_GetXWindow( hwnd ))) return;
45 if (!XGetWindowAttributes( display, win, &win_attr ) ||
46 (win_attr.map_state != IsViewable))
47 return; /* If window is not viewable, don't change anything */
49 XSetInputFocus( display, win, RevertToParent, CurrentTime );
50 if (COLOR_GetSystemPaletteFlags() & COLOR_PRIVATE)
51 XInstallColormap( display, COLOR_GetColormap() );
56 /*****************************************************************
59 void FOCUS_SwitchFocus( HWND32 hFocusFrom, HWND32 hFocusTo )
63 if (hFocusFrom) SendMessage32A( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 );
64 if( !hFocusTo || hFocusTo != hwndFocus )
67 SendMessage32A( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
68 FOCUS_SetXFocus( hFocusTo );
72 /*****************************************************************
73 * SetFocus16 (USER.22)
75 HWND16 SetFocus16( HWND16 hwnd )
77 return (HWND16)SetFocus32( hwnd );
81 /*****************************************************************
82 * SetFocus32 (USER32.480)
84 HWND32 SetFocus32( HWND32 hwnd )
86 HWND32 hWndPrevFocus, hwndTop = hwnd;
87 WND *wndPtr = WIN_FindWndPtr( hwnd );
91 /* Check if we can set the focus to this window */
93 while ( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
95 if ( wndPtr->dwStyle & ( WS_MINIMIZE | WS_DISABLED) )
97 if (!(wndPtr = wndPtr->parent)) return 0;
98 hwndTop = wndPtr->hwndSelf;
101 if( hwnd == hwndFocus ) return hwnd;
104 if( HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM16)hwnd,
108 /* activate hwndTop if needed. */
109 if (hwndTop != GetActiveWindow())
111 if (!WINPOS_SetActiveWindow(hwndTop, 0, 0)) return 0;
113 if (!IsWindow( hwnd )) return 0; /* Abort if window destroyed */
116 else if( HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)hwndFocus ) )
119 /* Change focus and send messages */
120 hWndPrevFocus = hwndFocus;
122 FOCUS_SwitchFocus( hwndFocus , hwnd );
124 return hWndPrevFocus;
128 /*****************************************************************
129 * GetFocus16 (USER.23)
131 HWND16 GetFocus16(void)
133 return (HWND16)hwndFocus;
137 /*****************************************************************
138 * GetFocus32 (USER32.239)
140 HWND32 GetFocus32(void)