Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Focus functions |
| 3 | * |
| 4 | * Copyright 1993 David Metcalfe |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 5 | * 1994 Alexandre Julliard |
| 6 | * 1995 Alex Korobka |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 7 | * |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 8 | */ |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 9 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 10 | #include "windef.h" |
| 11 | #include "wingdi.h" |
Michael Veksler | 9d14a00 | 1999-05-08 12:40:24 +0000 | [diff] [blame] | 12 | #include "wine/winuser16.h" |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 13 | #include "win.h" |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 14 | #include "winpos.h" |
| 15 | #include "hook.h" |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 16 | #include "message.h" |
Patrik Stridvall | 6cc47d4 | 2000-03-08 18:26:56 +0000 | [diff] [blame] | 17 | #include "queue.h" |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 18 | #include "task.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 19 | #include "debugtools.h" |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 20 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 21 | DEFAULT_DEBUG_CHANNEL(win) |
| 22 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 24 | /***************************************************************** |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 25 | * FOCUS_SwitchFocus |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 26 | * pMsgQ is the queue whose perQData focus is to be modified |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 27 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 28 | void FOCUS_SwitchFocus( MESSAGEQUEUE *pMsgQ, HWND hFocusFrom, HWND hFocusTo ) |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 29 | { |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 30 | WND *pFocusTo = WIN_FindWndPtr( hFocusTo ); |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 31 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 32 | PERQDATA_SetFocusWnd( pMsgQ->pQData, hFocusTo ); |
| 33 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 34 | #if 0 |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 35 | if (hFocusFrom) SendMessageA( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 36 | #else |
| 37 | /* FIXME: must be SendMessage16() because 32A doesn't do |
| 38 | * intertask at this time */ |
| 39 | if (hFocusFrom) SendMessage16( hFocusFrom, WM_KILLFOCUS, hFocusTo, 0 ); |
| 40 | #endif |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 41 | |
| 42 | if( !pFocusTo || hFocusTo != PERQDATA_GetFocusWnd( pMsgQ->pQData ) ) |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 43 | { |
| 44 | WIN_ReleaseWndPtr(pFocusTo); |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 45 | return; |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 46 | } |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 48 | /* According to API docs, the WM_SETFOCUS message is sent AFTER the window |
| 49 | has received the keyboard focus. */ |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 50 | |
| 51 | pFocusTo->pDriver->pSetFocus(pFocusTo); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 52 | |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 53 | WIN_ReleaseWndPtr(pFocusTo); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 54 | #if 0 |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 55 | SendMessageA( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 56 | #else |
| 57 | SendMessage16( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 ); |
| 58 | #endif |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 61 | |
| 62 | /***************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 63 | * SetFocus16 (USER.22) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 64 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 65 | HWND16 WINAPI SetFocus16( HWND16 hwnd ) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 66 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 67 | return (HWND16)SetFocus( hwnd ); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
| 71 | /***************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 72 | * SetFocus (USER32.481) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 73 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 74 | HWND WINAPI SetFocus( HWND hwnd ) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 75 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 76 | HWND hWndFocus = 0, hwndTop = hwnd; |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 77 | WND *wndPtr = WIN_FindWndPtr( hwnd ); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 78 | MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0; |
| 79 | BOOL16 bRet = 0; |
| 80 | |
| 81 | /* Get the messageQ for the current thread */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 82 | if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 83 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 84 | WARN("\tCurrent message queue not found. Exiting!\n" ); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 85 | goto CLEANUP; |
| 86 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 87 | |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 88 | if (wndPtr) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 89 | { |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 90 | /* Check if we can set the focus to this window */ |
| 91 | |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 92 | while ( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD ) |
Alexandre Julliard | cdd0923 | 1994-01-12 11:12:51 +0000 | [diff] [blame] | 93 | { |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 94 | if ( wndPtr->dwStyle & ( WS_MINIMIZE | WS_DISABLED) ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 95 | goto CLEANUP; |
Francois Boisvert | 3a3cd9f | 1999-03-28 12:42:52 +0000 | [diff] [blame] | 96 | WIN_UpdateWndPtr(&wndPtr,wndPtr->parent); |
| 97 | if (!wndPtr) goto CLEANUP; |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 98 | hwndTop = wndPtr->hwndSelf; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Adrian Thurston | 73a26fa | 1999-10-24 17:23:52 +0000 | [diff] [blame] | 101 | /* definitely at the top window now */ |
| 102 | if ( wndPtr->dwStyle & ( WS_MINIMIZE | WS_DISABLED) ) goto CLEANUP; |
| 103 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 104 | /* Retrieve the message queue associated with this window */ |
| 105 | pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ ); |
| 106 | if ( !pMsgQ ) |
| 107 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 108 | WARN("\tMessage queue not found. Exiting!\n" ); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 109 | goto CLEANUP; |
| 110 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 111 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 112 | /* Make sure that message queue for the window we are setting focus to |
| 113 | * shares the same perQ data as the current threads message queue. |
| 114 | * In other words you can't set focus to a window owned by a different |
| 115 | * thread unless AttachThreadInput has been called previously. |
| 116 | * (see AttachThreadInput and SetFocus docs) |
| 117 | */ |
| 118 | if ( pCurMsgQ->pQData != pMsgQ->pQData ) |
| 119 | goto CLEANUP; |
| 120 | |
| 121 | /* Get the current focus window from the perQ data */ |
| 122 | hWndFocus = PERQDATA_GetFocusWnd( pMsgQ->pQData ); |
| 123 | |
| 124 | if( hwnd == hWndFocus ) |
| 125 | { |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 126 | bRet = 1; /* Success */ |
| 127 | goto CLEANUP; /* Nothing to do */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 130 | /* call hooks */ |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 131 | if( HOOK_CallHooks16( WH_CBT, HCBT_SETFOCUS, (WPARAM16)hwnd, |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 132 | (LPARAM)hWndFocus) ) |
| 133 | goto CLEANUP; |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 134 | |
| 135 | /* activate hwndTop if needed. */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 136 | if (hwndTop != GetActiveWindow()) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 137 | { |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 138 | if (!WINPOS_SetActiveWindow(hwndTop, 0, 0)) goto CLEANUP; |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 139 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 140 | if (!IsWindow( hwnd )) goto CLEANUP; /* Abort if window destroyed */ |
Alexandre Julliard | cdd0923 | 1994-01-12 11:12:51 +0000 | [diff] [blame] | 141 | } |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 142 | |
| 143 | /* Get the current focus window from the perQ data */ |
| 144 | hWndFocus = PERQDATA_GetFocusWnd( pMsgQ->pQData ); |
| 145 | |
| 146 | /* Change focus and send messages */ |
| 147 | FOCUS_SwitchFocus( pMsgQ, hWndFocus, hwnd ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 148 | } |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 149 | else /* NULL hwnd passed in */ |
| 150 | { |
| 151 | if( HOOK_CallHooks16( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)hWndFocus ) ) |
| 152 | goto CLEANUP; |
| 153 | |
| 154 | /* Get the current focus from the perQ data of the current message Q */ |
| 155 | hWndFocus = PERQDATA_GetFocusWnd( pCurMsgQ->pQData ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 156 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 157 | /* Change focus and send messages */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 158 | FOCUS_SwitchFocus( pCurMsgQ, hWndFocus, hwnd ); |
| 159 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 160 | |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 161 | bRet = 1; /* Success */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 162 | |
| 163 | CLEANUP: |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 164 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 165 | /* Unlock the queues before returning */ |
| 166 | if ( pMsgQ ) |
| 167 | QUEUE_Unlock( pMsgQ ); |
| 168 | if ( pCurMsgQ ) |
| 169 | QUEUE_Unlock( pCurMsgQ ); |
| 170 | |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 171 | WIN_ReleaseWndPtr(wndPtr); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 172 | return bRet ? hWndFocus : 0; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | /***************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 177 | * GetFocus16 (USER.23) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 178 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 179 | HWND16 WINAPI GetFocus16(void) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 180 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 181 | return (HWND16)GetFocus(); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 185 | /***************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 186 | * GetFocus (USER32.240) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 187 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 188 | HWND WINAPI GetFocus(void) |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 189 | { |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 190 | MESSAGEQUEUE *pCurMsgQ = 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 191 | HWND hwndFocus = 0; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 192 | |
| 193 | /* Get the messageQ for the current thread */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 194 | if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 195 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 196 | WARN("\tCurrent message queue not found. Exiting!\n" ); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* Get the current focus from the perQ data of the current message Q */ |
| 201 | hwndFocus = PERQDATA_GetFocusWnd( pCurMsgQ->pQData ); |
| 202 | |
| 203 | QUEUE_Unlock( pCurMsgQ ); |
| 204 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 205 | return hwndFocus; |
| 206 | } |