French translation of the README file.
[wine.git] / windows / winpos.c
blob98b8bd37ae88788e5f46fa7a6b13bac2ffbe3559
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <string.h>
23 #include "winerror.h"
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "winerror.h"
27 #include "wine/winuser16.h"
28 #include "wine/server.h"
29 #include "controls.h"
30 #include "user.h"
31 #include "win.h"
32 #include "hook.h"
33 #include "message.h"
34 #include "queue.h"
35 #include "winpos.h"
36 #include "dce.h"
37 #include "nonclient.h"
38 #include "wine/debug.h"
39 #include "input.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
43 #define HAS_DLGFRAME(style,exStyle) \
44 (((exStyle) & WS_EX_DLGMODALFRAME) || \
45 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
47 #define HAS_THICKFRAME(style) \
48 (((style) & WS_THICKFRAME) && \
49 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
51 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
53 #define PLACE_MIN 0x0001
54 #define PLACE_MAX 0x0002
55 #define PLACE_RECT 0x0004
58 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
60 typedef struct
62 INT actualCount;
63 INT suggestedCount;
64 BOOL valid;
65 INT wMagic;
66 HWND hwndParent;
67 WINDOWPOS winPos[1];
68 } DWP;
70 /* ----- internal variables ----- */
72 static HWND hwndPrevActive = 0; /* Previously active window */
73 static HWND hGlobalShellWindow=0; /*the shell*/
74 static HWND hGlobalTaskmanWindow=0;
75 static HWND hGlobalProgmanWindow=0;
77 static LPCSTR atomInternalPos;
79 extern HQUEUE16 hActiveQueue;
81 /***********************************************************************
82 * WINPOS_CreateInternalPosAtom
84 BOOL WINPOS_CreateInternalPosAtom()
86 LPSTR str = "SysIP";
87 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
88 return (atomInternalPos) ? TRUE : FALSE;
91 /***********************************************************************
92 * WINPOS_CheckInternalPos
94 * Called when a window is destroyed.
96 void WINPOS_CheckInternalPos( HWND hwnd )
98 LPINTERNALPOS lpPos;
99 MESSAGEQUEUE *pMsgQ = 0;
100 WND *wndPtr = WIN_GetPtr( hwnd );
102 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
104 lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
106 /* Retrieve the message queue associated with this window */
107 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
108 if ( !pMsgQ )
110 WARN("\tMessage queue not found. Exiting!\n" );
111 WIN_ReleasePtr( wndPtr );
112 return;
115 if( hwnd == hwndPrevActive ) hwndPrevActive = 0;
117 if( hwnd == PERQDATA_GetActiveWnd( pMsgQ->pQData ) )
119 PERQDATA_SetActiveWnd( pMsgQ->pQData, 0 );
120 WARN("\tattempt to activate destroyed window!\n");
123 if( lpPos )
125 if( IsWindow(lpPos->hwndIconTitle) )
126 DestroyWindow( lpPos->hwndIconTitle );
127 HeapFree( GetProcessHeap(), 0, lpPos );
130 QUEUE_Unlock( pMsgQ );
131 WIN_ReleasePtr( wndPtr );
134 /***********************************************************************
135 * ArrangeIconicWindows (USER32.@)
137 UINT WINAPI ArrangeIconicWindows( HWND parent )
139 RECT rectParent;
140 HWND hwndChild;
141 INT x, y, xspacing, yspacing;
143 GetClientRect( parent, &rectParent );
144 x = rectParent.left;
145 y = rectParent.bottom;
146 xspacing = GetSystemMetrics(SM_CXICONSPACING);
147 yspacing = GetSystemMetrics(SM_CYICONSPACING);
149 hwndChild = GetWindow( parent, GW_CHILD );
150 while (hwndChild)
152 if( IsIconic( hwndChild ) )
154 WINPOS_ShowIconTitle( hwndChild, FALSE );
156 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
157 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
158 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
159 if( IsWindow(hwndChild) )
160 WINPOS_ShowIconTitle(hwndChild , TRUE );
162 if (x <= rectParent.right - xspacing) x += xspacing;
163 else
165 x = rectParent.left;
166 y -= yspacing;
169 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
171 return yspacing;
175 /***********************************************************************
176 * SwitchToThisWindow (USER32.@)
178 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
180 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
184 /***********************************************************************
185 * GetWindowRect (USER32.@)
187 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
189 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
190 if (ret)
192 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
193 TRACE( "hwnd %04x (%d,%d)-(%d,%d)\n",
194 hwnd, rect->left, rect->top, rect->right, rect->bottom);
196 return ret;
200 /***********************************************************************
201 * GetWindowRgn (USER32.@)
203 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
205 int nRet = ERROR;
206 WND *wndPtr = WIN_GetPtr( hwnd );
208 if (wndPtr == WND_OTHER_PROCESS)
210 if (IsWindow( hwnd ))
211 FIXME( "not supported on other process window %x\n", hwnd );
212 wndPtr = NULL;
214 if (!wndPtr)
216 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
217 return ERROR;
219 if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
220 WIN_ReleasePtr( wndPtr );
221 return nRet;
225 /***********************************************************************
226 * SetWindowRgn (USER32.@)
228 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
230 RECT rect;
231 WND *wndPtr;
233 if (hrgn) /* verify that region really exists */
235 if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
238 if (USER_Driver.pSetWindowRgn)
239 return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
241 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
243 if (IsWindow( hwnd ))
244 FIXME( "not supported on other process window %x\n", hwnd );
245 wndPtr = NULL;
247 if (!wndPtr)
249 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
250 return FALSE;
253 if (wndPtr->hrgnWnd == hrgn)
255 WIN_ReleasePtr( wndPtr );
256 return TRUE;
259 if (wndPtr->hrgnWnd)
261 /* delete previous region */
262 DeleteObject(wndPtr->hrgnWnd);
263 wndPtr->hrgnWnd = 0;
265 wndPtr->hrgnWnd = hrgn;
266 WIN_ReleasePtr( wndPtr );
268 /* Size the window to the rectangle of the new region (if it isn't NULL) */
269 if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
270 rect.right - rect.left, rect.bottom - rect.top,
271 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
272 SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
273 return TRUE;
277 /***********************************************************************
278 * GetClientRect (USER32.@)
280 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
282 BOOL ret;
284 rect->right = rect->bottom = 0;
285 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
287 rect->right -= rect->left;
288 rect->bottom -= rect->top;
290 rect->left = rect->top = 0;
291 return ret;
295 /*******************************************************************
296 * ClientToScreen (USER32.@)
298 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
300 MapWindowPoints( hwnd, 0, lppnt, 1 );
301 return TRUE;
305 /*******************************************************************
306 * ScreenToClient (USER32.@)
308 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
310 MapWindowPoints( 0, hwnd, lppnt, 1 );
311 return TRUE;
315 /***********************************************************************
316 * find_child_from_point
318 * Find the child that contains pt. Helper for WindowFromPoint.
319 * pt is in parent client coordinates.
320 * lparam is the param to pass in the WM_NCHITTEST message.
322 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
324 int i, res;
325 LONG style, exstyle;
326 RECT rectWindow, rectClient;
327 WND *wndPtr;
328 HWND *list = WIN_ListChildren( parent );
329 HWND retvalue = 0;
331 if (!list) return 0;
332 for (i = 0; list[i]; i++)
334 /* If point is in window, and window is visible, and it */
335 /* is enabled (or it's a top-level window), then explore */
336 /* its children. Otherwise, go to the next window. */
338 style = GetWindowLongW( list[i], GWL_STYLE );
339 if (!(style & WS_VISIBLE)) continue; /* not visible -> skip */
340 if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
341 continue; /* disabled child -> skip */
342 exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
343 if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
344 continue; /* transparent -> skip */
346 if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
347 if (!PtInRect( &rectWindow, pt )) continue; /* not in window -> skip */
349 /* FIXME: check window region for other processes too */
350 if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
352 if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
353 pt.x - rectWindow.left, pt.y - rectWindow.top ))
355 WIN_ReleasePtr( wndPtr );
356 continue; /* point outside window region -> skip */
358 WIN_ReleasePtr( wndPtr );
361 /* If window is minimized or disabled, return at once */
362 if (style & WS_MINIMIZE)
364 *hittest = HTCAPTION;
365 retvalue = list[i];
366 break;
368 if (style & WS_DISABLED)
370 *hittest = HTERROR;
371 retvalue = list[i];
372 break;
375 /* If point is in client area, explore children */
376 if (PtInRect( &rectClient, pt ))
378 POINT new_pt;
380 new_pt.x = pt.x - rectClient.left;
381 new_pt.y = pt.y - rectClient.top;
382 if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
385 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
386 if (!WIN_IsCurrentThread( list[i] ))
388 *hittest = HTCLIENT;
389 retvalue = list[i];
390 break;
392 if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
394 *hittest = res; /* Found the window */
395 retvalue = list[i];
396 break;
398 /* continue search with next sibling */
400 HeapFree( GetProcessHeap(), 0, list );
401 return retvalue;
405 /***********************************************************************
406 * WINPOS_WindowFromPoint
408 * Find the window and hittest for a given point.
410 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
412 POINT xy = pt;
413 int res;
414 LONG style;
416 TRACE("scope %04x %ld,%ld\n", hwndScope, pt.x, pt.y);
418 if (!hwndScope) hwndScope = GetDesktopWindow();
419 style = GetWindowLongW( hwndScope, GWL_STYLE );
421 *hittest = HTERROR;
422 if (style & WS_DISABLED) return 0;
424 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
426 if (!(style & WS_MINIMIZE))
428 RECT rectClient;
429 if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
431 HWND ret;
433 xy.x -= rectClient.left;
434 xy.y -= rectClient.top;
435 if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
437 TRACE( "found child %x\n", ret );
438 return ret;
443 /* If nothing found, try the scope window */
444 if (!WIN_IsCurrentThread( hwndScope ))
446 *hittest = HTCLIENT;
447 TRACE( "returning %x\n", hwndScope );
448 return hwndScope;
450 res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
451 if (res != HTTRANSPARENT)
453 *hittest = res; /* Found the window */
454 TRACE( "returning %x\n", hwndScope );
455 return hwndScope;
457 *hittest = HTNOWHERE;
458 TRACE( "nothing found\n" );
459 return 0;
463 /*******************************************************************
464 * WindowFromPoint (USER32.@)
466 HWND WINAPI WindowFromPoint( POINT pt )
468 INT hittest;
469 return WINPOS_WindowFromPoint( 0, pt, &hittest );
473 /*******************************************************************
474 * ChildWindowFromPoint (USER32.@)
476 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
478 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
481 /*******************************************************************
482 * ChildWindowFromPointEx (USER32.@)
484 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
486 /* pt is in the client coordinates */
487 HWND *list;
488 int i;
489 RECT rect;
490 HWND retvalue;
492 GetClientRect( hwndParent, &rect );
493 if (!PtInRect( &rect, pt )) return 0;
494 if (!(list = WIN_ListChildren( hwndParent ))) return 0;
496 for (i = 0; list[i]; i++)
498 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
499 if (!PtInRect( &rect, pt )) continue;
500 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
502 LONG style = GetWindowLongW( list[i], GWL_STYLE );
503 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
504 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
506 if (uFlags & CWP_SKIPTRANSPARENT)
508 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
510 break;
512 retvalue = list[i];
513 HeapFree( GetProcessHeap(), 0, list );
514 if (!retvalue) retvalue = hwndParent;
515 return retvalue;
519 /*******************************************************************
520 * WINPOS_GetWinOffset
522 * Calculate the offset between the origin of the two windows. Used
523 * to implement MapWindowPoints.
525 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
527 WND * wndPtr;
529 offset->x = offset->y = 0;
531 /* Translate source window origin to screen coords */
532 if (hwndFrom)
534 HWND hwnd = hwndFrom;
536 while (hwnd)
538 if (hwnd == hwndTo) return;
539 if (!(wndPtr = WIN_GetPtr( hwnd )))
541 ERR( "bad hwndFrom = %04x\n", hwnd );
542 return;
544 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
545 offset->x += wndPtr->rectClient.left;
546 offset->y += wndPtr->rectClient.top;
547 hwnd = wndPtr->parent;
548 WIN_ReleasePtr( wndPtr );
552 /* Translate origin to destination window coords */
553 if (hwndTo)
555 HWND hwnd = hwndTo;
557 while (hwnd)
559 if (!(wndPtr = WIN_GetPtr( hwnd )))
561 ERR( "bad hwndTo = %04x\n", hwnd );
562 return;
564 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
565 offset->x -= wndPtr->rectClient.left;
566 offset->y -= wndPtr->rectClient.top;
567 hwnd = wndPtr->parent;
568 WIN_ReleasePtr( wndPtr );
571 return;
573 other_process: /* one of the parents may belong to another process, do it the hard way */
574 offset->x = offset->y = 0;
575 SERVER_START_REQ( get_windows_offset )
577 req->from = hwndFrom;
578 req->to = hwndTo;
579 if (!wine_server_call( req ))
581 offset->x = reply->x;
582 offset->y = reply->y;
585 SERVER_END_REQ;
589 /*******************************************************************
590 * MapWindowPoints (USER.258)
592 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
593 LPPOINT16 lppt, UINT16 count )
595 POINT offset;
597 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
598 while (count--)
600 lppt->x += offset.x;
601 lppt->y += offset.y;
602 lppt++;
607 /*******************************************************************
608 * MapWindowPoints (USER32.@)
610 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
612 POINT offset;
614 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
615 while (count--)
617 lppt->x += offset.x;
618 lppt->y += offset.y;
619 lppt++;
621 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
625 /***********************************************************************
626 * IsIconic (USER32.@)
628 BOOL WINAPI IsIconic(HWND hWnd)
630 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
634 /***********************************************************************
635 * IsZoomed (USER32.@)
637 BOOL WINAPI IsZoomed(HWND hWnd)
639 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
643 /*******************************************************************
644 * GetActiveWindow (USER32.@)
646 HWND WINAPI GetActiveWindow(void)
648 MESSAGEQUEUE *pCurMsgQ = 0;
650 /* Get the messageQ for the current thread */
651 if (!(pCurMsgQ = QUEUE_Current()))
653 WARN("\tCurrent message queue not found. Exiting!\n" );
654 return 0;
657 /* Return the current active window from the perQ data of the current message Q */
658 return PERQDATA_GetActiveWnd( pCurMsgQ->pQData );
662 /*******************************************************************
663 * WINPOS_CanActivate
665 static BOOL WINPOS_CanActivate(HWND hwnd)
667 if (!hwnd) return FALSE;
668 return ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_DISABLED|WS_CHILD)) == 0);
671 /*******************************************************************
672 * WINPOS_IsVisible
674 static BOOL WINPOS_IsVisible(HWND hwnd)
676 if (!hwnd) return FALSE;
677 return ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) == WS_VISIBLE);
681 /*******************************************************************
682 * SetActiveWindow (USER32.@)
684 HWND WINAPI SetActiveWindow( HWND hwnd )
686 HWND prev = 0;
687 WND *wndPtr = WIN_FindWndPtr( hwnd );
688 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
690 if (!wndPtr) return 0;
692 if (wndPtr->dwStyle & (WS_DISABLED | WS_CHILD)) goto error;
694 /* Get the messageQ for the current thread */
695 if (!(pCurMsgQ = QUEUE_Current()))
697 WARN("\tCurrent message queue not found. Exiting!\n" );
698 goto error;
701 /* Retrieve the message queue associated with this window */
702 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
703 if ( !pMsgQ )
705 WARN("\tWindow message queue not found. Exiting!\n" );
706 goto error;
709 /* Make sure that the window is associated with the calling threads
710 * message queue. It must share the same perQ data.
712 if ( pCurMsgQ->pQData != pMsgQ->pQData )
714 QUEUE_Unlock( pMsgQ );
715 goto error;
718 /* Save current active window */
719 prev = PERQDATA_GetActiveWnd( pMsgQ->pQData );
720 QUEUE_Unlock( pMsgQ );
721 WIN_ReleaseWndPtr(wndPtr);
722 WINPOS_SetActiveWindow( hwnd, FALSE, TRUE );
723 return prev;
725 error:
726 WIN_ReleaseWndPtr(wndPtr);
727 return 0;
731 /*******************************************************************
732 * GetForegroundWindow (USER32.@)
734 HWND WINAPI GetForegroundWindow(void)
736 HWND hwndActive = 0;
738 /* Get the foreground window (active window of hActiveQueue) */
739 if ( hActiveQueue )
741 MESSAGEQUEUE *pActiveQueue = QUEUE_Lock( hActiveQueue );
742 if ( pActiveQueue )
743 hwndActive = PERQDATA_GetActiveWnd( pActiveQueue->pQData );
745 QUEUE_Unlock( pActiveQueue );
748 return hwndActive;
751 /*******************************************************************
752 * SetForegroundWindow (USER32.@)
754 BOOL WINAPI SetForegroundWindow( HWND hwnd )
756 if (!hwnd) return WINPOS_SetActiveWindow( 0, FALSE, TRUE );
758 /* child windows get WM_CHILDACTIVATE message */
759 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
760 return SendMessageA( hwnd, WM_CHILDACTIVATE, 0, 0 );
762 hwnd = WIN_GetFullHandle( hwnd );
763 if( hwnd == GetForegroundWindow() ) return FALSE;
765 return WINPOS_SetActiveWindow( hwnd, FALSE, TRUE );
769 /*******************************************************************
770 * AllowSetForegroundWindow (USER32.@)
772 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
774 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
775 * implemented, then fix this function. */
776 return TRUE;
780 /*******************************************************************
781 * LockSetForegroundWindow (USER32.@)
783 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
785 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
786 * implemented, then fix this function. */
787 return TRUE;
791 /*******************************************************************
792 * SetShellWindow (USER32.@)
794 HWND WINAPI SetShellWindow(HWND hwndshell)
795 { WARN("(hWnd=%08x) semi stub\n",hwndshell );
797 hGlobalShellWindow = WIN_GetFullHandle( hwndshell );
798 return hGlobalShellWindow;
802 /*******************************************************************
803 * GetShellWindow (USER32.@)
805 HWND WINAPI GetShellWindow(void)
806 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow );
808 return hGlobalShellWindow;
812 /***********************************************************************
813 * BringWindowToTop (USER32.@)
815 BOOL WINAPI BringWindowToTop( HWND hwnd )
817 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
821 /***********************************************************************
822 * MoveWindow (USER32.@)
824 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
825 BOOL repaint )
827 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
828 if (!repaint) flags |= SWP_NOREDRAW;
829 TRACE("%04x %d,%d %dx%d %d\n",
830 hwnd, x, y, cx, cy, repaint );
831 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
834 /***********************************************************************
835 * WINPOS_InitInternalPos
837 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
839 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
840 atomInternalPos );
841 if( !lpPos )
843 /* this happens when the window is minimized/maximized
844 * for the first time (rectWindow is not adjusted yet) */
846 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
847 if( !lpPos ) return NULL;
849 SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
850 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
851 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
852 *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
855 if( wnd->dwStyle & WS_MINIMIZE )
856 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
857 else if( wnd->dwStyle & WS_MAXIMIZE )
858 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
859 else if( restoreRect )
860 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
862 return lpPos;
865 /***********************************************************************
866 * WINPOS_RedrawIconTitle
868 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
870 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
871 if( lpPos )
873 if( lpPos->hwndIconTitle )
875 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
876 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
877 return TRUE;
880 return FALSE;
883 /***********************************************************************
884 * WINPOS_ShowIconTitle
886 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
888 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
890 if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
892 HWND title = lpPos->hwndIconTitle;
894 TRACE("0x%04x %i\n", hwnd, (bShow != 0) );
896 if( !title )
897 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
898 if( bShow )
900 if (!IsWindowVisible(title))
902 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
903 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
904 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
907 else ShowWindow( title, SW_HIDE );
909 return FALSE;
912 /*******************************************************************
913 * WINPOS_GetMinMaxInfo
915 * Get the minimized and maximized information for a window.
917 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
918 POINT *minTrack, POINT *maxTrack )
920 LPINTERNALPOS lpPos;
921 MINMAXINFO MinMax;
922 INT xinc, yinc;
923 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
924 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
926 /* Compute default values */
928 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
929 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
930 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
931 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
932 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
933 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
935 if (HAS_DLGFRAME( style, exstyle ))
937 xinc = GetSystemMetrics(SM_CXDLGFRAME);
938 yinc = GetSystemMetrics(SM_CYDLGFRAME);
940 else
942 xinc = yinc = 0;
943 if (HAS_THICKFRAME(style))
945 xinc += GetSystemMetrics(SM_CXFRAME);
946 yinc += GetSystemMetrics(SM_CYFRAME);
948 if (style & WS_BORDER)
950 xinc += GetSystemMetrics(SM_CXBORDER);
951 yinc += GetSystemMetrics(SM_CYBORDER);
954 MinMax.ptMaxSize.x += 2 * xinc;
955 MinMax.ptMaxSize.y += 2 * yinc;
957 lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
958 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
959 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
960 else
962 MinMax.ptMaxPosition.x = -xinc;
963 MinMax.ptMaxPosition.y = -yinc;
966 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
968 /* Some sanity checks */
970 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
971 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
972 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
973 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
974 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
975 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
976 MinMax.ptMinTrackSize.x );
977 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
978 MinMax.ptMinTrackSize.y );
980 if (maxSize) *maxSize = MinMax.ptMaxSize;
981 if (maxPos) *maxPos = MinMax.ptMaxPosition;
982 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
983 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
986 /***********************************************************************
987 * ShowWindowAsync (USER32.@)
989 * doesn't wait; returns immediately.
990 * used by threads to toggle windows in other (possibly hanging) threads
992 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
994 /* FIXME: does ShowWindow() return immediately ? */
995 return ShowWindow(hwnd, cmd);
999 /***********************************************************************
1000 * ShowWindow (USER32.@)
1002 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1004 HWND full_handle;
1006 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1007 return USER_Driver.pShowWindow( full_handle, cmd );
1008 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1012 /***********************************************************************
1013 * GetInternalWindowPos (USER.460)
1015 UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd,
1016 LPPOINT16 ptIcon )
1018 WINDOWPLACEMENT16 wndpl;
1019 if (GetWindowPlacement16( hwnd, &wndpl ))
1021 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1022 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1023 return wndpl.showCmd;
1025 return 0;
1029 /***********************************************************************
1030 * GetInternalWindowPos (USER32.@)
1032 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1033 LPPOINT ptIcon )
1035 WINDOWPLACEMENT wndpl;
1036 if (GetWindowPlacement( hwnd, &wndpl ))
1038 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1039 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1040 return wndpl.showCmd;
1042 return 0;
1046 /***********************************************************************
1047 * GetWindowPlacement (USER32.@)
1049 * Win95:
1050 * Fails if wndpl->length of Win95 (!) apps is invalid.
1052 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1054 WND *pWnd = WIN_FindWndPtr( hwnd );
1055 LPINTERNALPOS lpPos;
1057 if(!pWnd ) return FALSE;
1059 lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
1060 wndpl->length = sizeof(*wndpl);
1061 if( pWnd->dwStyle & WS_MINIMIZE )
1062 wndpl->showCmd = SW_SHOWMINIMIZED;
1063 else
1064 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1065 if( pWnd->flags & WIN_RESTORE_MAX )
1066 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1067 else
1068 wndpl->flags = 0;
1069 CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
1070 CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
1071 CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
1072 WIN_ReleaseWndPtr(pWnd);
1073 return TRUE;
1077 /***********************************************************************
1078 * WINPOS_SetPlacement
1080 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1082 WND *pWnd = WIN_FindWndPtr( hwnd );
1083 if( pWnd )
1085 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
1086 *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
1088 if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
1089 if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
1090 if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
1092 if( pWnd->dwStyle & WS_MINIMIZE )
1094 WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
1095 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
1096 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
1097 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1099 else if( pWnd->dwStyle & WS_MAXIMIZE )
1101 if( !EMPTYPOINT(lpPos->ptMaxPos) )
1102 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
1103 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1105 else if( flags & PLACE_RECT )
1106 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1107 lpPos->rectNormal.right - lpPos->rectNormal.left,
1108 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1109 SWP_NOZORDER | SWP_NOACTIVATE );
1111 ShowWindow( hwnd, wndpl->showCmd );
1112 if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
1114 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
1116 /* SDK: ...valid only the next time... */
1117 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
1119 WIN_ReleaseWndPtr(pWnd);
1120 return TRUE;
1122 return FALSE;
1126 /***********************************************************************
1127 * SetWindowPlacement (USER32.@)
1129 * Win95:
1130 * Fails if wndpl->length of Win95 (!) apps is invalid.
1132 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1134 if (!wpl) return FALSE;
1135 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1139 /***********************************************************************
1140 * AnimateWindow (USER32.@)
1141 * Shows/Hides a window with an animation
1142 * NO ANIMATION YET
1144 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1146 FIXME("partial stub\n");
1148 /* If trying to show/hide and it's already *
1149 * shown/hidden or invalid window, fail with *
1150 * invalid parameter */
1151 if(!IsWindow(hwnd) ||
1152 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1153 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1155 SetLastError(ERROR_INVALID_PARAMETER);
1156 return FALSE;
1159 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1161 return TRUE;
1164 /***********************************************************************
1165 * SetInternalWindowPos (USER32.@)
1167 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1168 LPRECT rect, LPPOINT pt )
1170 if( IsWindow(hwnd) )
1172 WINDOWPLACEMENT wndpl;
1173 UINT flags;
1175 wndpl.length = sizeof(wndpl);
1176 wndpl.showCmd = showCmd;
1177 wndpl.flags = flags = 0;
1179 if( pt )
1181 flags |= PLACE_MIN;
1182 wndpl.flags |= WPF_SETMINPOSITION;
1183 wndpl.ptMinPosition = *pt;
1185 if( rect )
1187 flags |= PLACE_RECT;
1188 wndpl.rcNormalPosition = *rect;
1190 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1194 /*******************************************************************
1195 * WINPOS_SetActiveWindow
1197 * SetActiveWindow() back-end. This is the only function that
1198 * can assign active status to a window. It must be called only
1199 * for the top level windows.
1201 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus)
1203 WND* wndPtr=0, *wndTemp;
1204 HQUEUE16 hOldActiveQueue, hNewActiveQueue;
1205 MESSAGEQUEUE *pOldActiveQueue = 0, *pNewActiveQueue = 0;
1206 WORD wIconized = 0;
1207 HWND hwndActive = 0;
1208 BOOL bRet = 0;
1210 TRACE("(%04x, %d, %d)\n", hWnd, fMouse, fChangeFocus );
1212 /* Get current active window from the active queue */
1213 if ( hActiveQueue )
1215 pOldActiveQueue = QUEUE_Lock( hActiveQueue );
1216 if ( pOldActiveQueue )
1217 hwndActive = PERQDATA_GetActiveWnd( pOldActiveQueue->pQData );
1220 if ((wndPtr = WIN_FindWndPtr(hWnd)))
1221 hWnd = wndPtr->hwndSelf; /* make it a full handle */
1223 /* paranoid checks */
1224 if( hWnd == GetDesktopWindow() || (bRet = (hWnd == hwndActive)) )
1225 goto CLEANUP_END;
1227 /* if (wndPtr && (GetFastQueue16() != wndPtr->hmemTaskQ))
1228 * return 0;
1230 hOldActiveQueue = hActiveQueue;
1232 if( (wndTemp = WIN_FindWndPtr(hwndActive)) )
1234 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1235 WIN_ReleaseWndPtr(wndTemp);
1237 else
1238 TRACE("no current active window.\n");
1240 /* call CBT hook chain */
1241 if (HOOK_IsHooked( WH_CBT ))
1243 CBTACTIVATESTRUCT cbt;
1244 cbt.fMouse = fMouse;
1245 cbt.hWndActive = hwndActive;
1246 if (HOOK_CallHooksA( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd, (LPARAM)&cbt )) goto CLEANUP_END;
1249 /* set prev active wnd to current active wnd and send notification */
1250 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
1252 MESSAGEQUEUE *pTempActiveQueue = 0;
1254 SendNotifyMessageA( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 );
1255 SendNotifyMessageA( hwndPrevActive, WM_ACTIVATE,
1256 MAKEWPARAM( WA_INACTIVE, wIconized ),
1257 (LPARAM)hWnd );
1259 /* check if something happened during message processing
1260 * (global active queue may have changed)
1262 pTempActiveQueue = QUEUE_Lock( hActiveQueue );
1263 if(!pTempActiveQueue)
1264 goto CLEANUP_END;
1266 hwndActive = PERQDATA_GetActiveWnd( pTempActiveQueue->pQData );
1267 QUEUE_Unlock( pTempActiveQueue );
1268 if( hwndPrevActive != hwndActive )
1269 goto CLEANUP_END;
1272 /* Set new active window in the message queue */
1273 hwndActive = hWnd;
1274 if ( wndPtr )
1276 pNewActiveQueue = QUEUE_Lock( wndPtr->hmemTaskQ );
1277 if ( pNewActiveQueue )
1278 PERQDATA_SetActiveWnd( pNewActiveQueue->pQData, hwndActive );
1280 else /* have to do this or MDI frame activation goes to hell */
1281 if( pOldActiveQueue )
1282 PERQDATA_SetActiveWnd( pOldActiveQueue->pQData, 0 );
1284 /* send palette messages */
1285 if (hWnd && SendMessageW( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
1286 SendMessageW( HWND_BROADCAST, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0 );
1288 /* if prev wnd is minimized redraw icon title */
1289 if( IsIconic( hwndPrevActive ) ) WINPOS_RedrawIconTitle(hwndPrevActive);
1291 /* managed windows will get ConfigureNotify event */
1292 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->dwExStyle & WS_EX_MANAGED))
1294 /* check Z-order and bring hWnd to the top */
1295 HWND tmp = GetTopWindow(0);
1296 while (tmp && !(GetWindowLongA( tmp, GWL_STYLE ) & WS_VISIBLE))
1297 tmp = GetWindow( tmp, GW_HWNDNEXT );
1299 if( tmp != hWnd )
1300 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
1301 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1302 if (!IsWindow(hWnd))
1303 goto CLEANUP;
1306 /* Get a handle to the new active queue */
1307 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
1309 /* send WM_ACTIVATEAPP if necessary */
1310 if (hOldActiveQueue != hNewActiveQueue)
1312 HWND *list, *phwnd;
1313 DWORD old_thread = GetWindowThreadProcessId( hwndPrevActive, NULL );
1314 DWORD new_thread = GetWindowThreadProcessId( hwndActive, NULL );
1316 if ((list = WIN_ListChildren( GetDesktopWindow() )))
1318 for (phwnd = list; *phwnd; phwnd++)
1320 if (!IsWindow( *phwnd )) continue;
1321 if (GetWindowThreadProcessId( *phwnd, NULL ) == old_thread)
1322 SendNotifyMessageW( *phwnd, WM_ACTIVATEAPP, 0, new_thread );
1324 HeapFree( GetProcessHeap(), 0, list );
1327 hActiveQueue = hNewActiveQueue;
1329 if ((list = WIN_ListChildren( GetDesktopWindow() )))
1331 for (phwnd = list; *phwnd; phwnd++)
1333 if (!IsWindow( *phwnd )) continue;
1334 if (GetWindowThreadProcessId( *phwnd, NULL ) == new_thread)
1335 SendMessageW( *phwnd, WM_ACTIVATEAPP, 1, old_thread );
1337 HeapFree( GetProcessHeap(), 0, list );
1340 if (hWnd && !IsWindow(hWnd)) goto CLEANUP;
1343 if (hWnd)
1345 /* walk up to the first unowned window */
1346 HWND tmp = GetAncestor( hWnd, GA_ROOTOWNER );
1347 if ((wndTemp = WIN_FindWndPtr( tmp )))
1349 /* and set last active owned popup */
1350 wndTemp->hwndLastActive = hWnd;
1352 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1353 WIN_ReleaseWndPtr(wndTemp);
1355 SendMessageA( hWnd, WM_NCACTIVATE, TRUE, 0 );
1356 SendMessageA( hWnd, WM_ACTIVATE,
1357 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1358 (LPARAM)hwndPrevActive );
1359 if( !IsWindow(hWnd) ) goto CLEANUP;
1362 /* change focus if possible */
1363 if ( fChangeFocus )
1365 if ( pNewActiveQueue )
1367 HWND hOldFocus = PERQDATA_GetFocusWnd( pNewActiveQueue->pQData );
1369 if ( !hOldFocus || GetAncestor( hOldFocus, GA_ROOT ) != hwndActive )
1370 FOCUS_SwitchFocus( pNewActiveQueue, hOldFocus,
1371 (wndPtr && (wndPtr->dwStyle & WS_MINIMIZE))?
1372 0 : hwndActive );
1375 if ( pOldActiveQueue &&
1376 ( !pNewActiveQueue ||
1377 pNewActiveQueue->pQData != pOldActiveQueue->pQData ) )
1379 HWND hOldFocus = PERQDATA_GetFocusWnd( pOldActiveQueue->pQData );
1380 if ( hOldFocus )
1381 FOCUS_SwitchFocus( pOldActiveQueue, hOldFocus, 0 );
1385 if( !hwndPrevActive && wndPtr )
1387 if (USER_Driver.pForceWindowRaise) USER_Driver.pForceWindowRaise( wndPtr->hwndSelf );
1390 /* if active wnd is minimized redraw icon title */
1391 if( IsIconic(hwndActive) ) WINPOS_RedrawIconTitle(hwndActive);
1393 bRet = (hWnd == hwndActive); /* Success? */
1395 CLEANUP: /* Unlock the message queues before returning */
1397 if ( pNewActiveQueue )
1398 QUEUE_Unlock( pNewActiveQueue );
1400 CLEANUP_END:
1402 if ( pOldActiveQueue )
1403 QUEUE_Unlock( pOldActiveQueue );
1405 WIN_ReleaseWndPtr(wndPtr);
1406 return bRet;
1409 /*******************************************************************
1410 * WINPOS_ActivateOtherWindow
1412 * Activates window other than pWnd.
1414 void WINPOS_ActivateOtherWindow(HWND hwnd)
1416 HWND hwndActive = 0;
1417 HWND hwndTo = 0;
1418 HWND hwndDefaultTo = 0;
1419 HWND owner;
1421 /* Get current active window from the active queue */
1422 if ( hActiveQueue )
1424 MESSAGEQUEUE *pActiveQueue = QUEUE_Lock( hActiveQueue );
1425 if ( pActiveQueue )
1427 hwndActive = PERQDATA_GetActiveWnd( pActiveQueue->pQData );
1428 QUEUE_Unlock( pActiveQueue );
1432 if (!(hwnd = WIN_IsCurrentThread( hwnd ))) return;
1434 if( hwnd == hwndPrevActive )
1435 hwndPrevActive = 0;
1437 if( hwndActive != hwnd && (hwndActive || USER_IsExitingThread( GetCurrentThreadId() )))
1438 return;
1440 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) ||
1441 !(owner = GetWindow( hwnd, GW_OWNER )) ||
1442 !WINPOS_CanActivate((hwndTo = GetAncestor( owner, GA_ROOT ))) ||
1443 !WINPOS_IsVisible(hwndTo))
1445 HWND tmp = GetAncestor( hwnd, GA_ROOT );
1446 hwndTo = hwndPrevActive;
1448 while( !WINPOS_CanActivate(hwndTo) || !WINPOS_IsVisible(hwndTo))
1450 /* by now owned windows should've been taken care of */
1451 if(!hwndDefaultTo && WINPOS_CanActivate(hwndTo))
1452 hwndDefaultTo = hwndTo;
1453 tmp = hwndTo = GetWindow( tmp, GW_HWNDNEXT );
1454 if( !hwndTo )
1456 hwndTo = hwndDefaultTo;
1457 break;
1462 SetActiveWindow( hwndTo );
1463 hwndPrevActive = 0;
1467 /***********************************************************************
1468 * WINPOS_HandleWindowPosChanging16
1470 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1472 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1474 POINT maxSize, minTrack;
1475 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1477 if (winpos->flags & SWP_NOSIZE) return 0;
1478 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1480 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1481 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1482 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1483 if (!(style & WS_MINIMIZE))
1485 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1486 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1489 return 0;
1493 /***********************************************************************
1494 * WINPOS_HandleWindowPosChanging
1496 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1498 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1500 POINT maxSize, minTrack;
1501 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1503 if (winpos->flags & SWP_NOSIZE) return 0;
1504 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1506 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1507 winpos->cx = min( winpos->cx, maxSize.x );
1508 winpos->cy = min( winpos->cy, maxSize.y );
1509 if (!(style & WS_MINIMIZE))
1511 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1512 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1515 return 0;
1519 /***********************************************************************
1520 * SetWindowPos (USER32.@)
1522 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1523 INT x, INT y, INT cx, INT cy, UINT flags )
1525 WINDOWPOS winpos;
1527 winpos.hwnd = hwnd;
1528 winpos.hwndInsertAfter = hwndInsertAfter;
1529 winpos.x = x;
1530 winpos.y = y;
1531 winpos.cx = cx;
1532 winpos.cy = cy;
1533 winpos.flags = flags;
1534 if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1535 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1539 /***********************************************************************
1540 * BeginDeferWindowPos (USER32.@)
1542 HDWP WINAPI BeginDeferWindowPos( INT count )
1544 HDWP handle;
1545 DWP *pDWP;
1547 if (count < 0)
1549 SetLastError(ERROR_INVALID_PARAMETER);
1550 return 0;
1552 /* Windows allows zero count, in which case it allocates context for 8 moves */
1553 if (count == 0) count = 8;
1555 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1556 if (!handle) return 0;
1557 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1558 pDWP->actualCount = 0;
1559 pDWP->suggestedCount = count;
1560 pDWP->valid = TRUE;
1561 pDWP->wMagic = DWP_MAGIC;
1562 pDWP->hwndParent = 0;
1563 return handle;
1567 /***********************************************************************
1568 * DeferWindowPos (USER32.@)
1570 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1571 INT x, INT y, INT cx, INT cy,
1572 UINT flags )
1574 DWP *pDWP;
1575 int i;
1576 HDWP newhdwp = hdwp,retvalue;
1578 hwnd = WIN_GetFullHandle( hwnd );
1579 if (hwnd == GetDesktopWindow()) return 0;
1581 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1583 USER_Lock();
1585 for (i = 0; i < pDWP->actualCount; i++)
1587 if (pDWP->winPos[i].hwnd == hwnd)
1589 /* Merge with the other changes */
1590 if (!(flags & SWP_NOZORDER))
1592 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1594 if (!(flags & SWP_NOMOVE))
1596 pDWP->winPos[i].x = x;
1597 pDWP->winPos[i].y = y;
1599 if (!(flags & SWP_NOSIZE))
1601 pDWP->winPos[i].cx = cx;
1602 pDWP->winPos[i].cy = cy;
1604 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1605 SWP_NOZORDER | SWP_NOREDRAW |
1606 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1607 SWP_NOOWNERZORDER);
1608 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1609 SWP_FRAMECHANGED);
1610 retvalue = hdwp;
1611 goto END;
1614 if (pDWP->actualCount >= pDWP->suggestedCount)
1616 newhdwp = USER_HEAP_REALLOC( hdwp,
1617 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1618 if (!newhdwp)
1620 retvalue = 0;
1621 goto END;
1623 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1624 pDWP->suggestedCount++;
1626 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1627 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1628 pDWP->winPos[pDWP->actualCount].x = x;
1629 pDWP->winPos[pDWP->actualCount].y = y;
1630 pDWP->winPos[pDWP->actualCount].cx = cx;
1631 pDWP->winPos[pDWP->actualCount].cy = cy;
1632 pDWP->winPos[pDWP->actualCount].flags = flags;
1633 pDWP->actualCount++;
1634 retvalue = newhdwp;
1635 END:
1636 USER_Unlock();
1637 return retvalue;
1641 /***********************************************************************
1642 * EndDeferWindowPos (USER32.@)
1644 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1646 DWP *pDWP;
1647 WINDOWPOS *winpos;
1648 BOOL res = TRUE;
1649 int i;
1651 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1652 if (!pDWP) return FALSE;
1653 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1655 if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1657 USER_HEAP_FREE( hdwp );
1658 return res;
1662 /***********************************************************************
1663 * TileChildWindows (USER.199)
1665 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1667 FIXME("(%04x, %d): stub\n", parent, action);
1670 /***********************************************************************
1671 * CascadeChildWindows (USER.198)
1673 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1675 FIXME("(%04x, %d): stub\n", parent, action);
1678 /***********************************************************************
1679 * SetProgmanWindow (USER32.@)
1681 HWND WINAPI SetProgmanWindow ( HWND hwnd )
1683 hGlobalProgmanWindow = hwnd;
1684 return hGlobalProgmanWindow;
1687 /***********************************************************************
1688 * GetProgmanWindow (USER32.@)
1690 HWND WINAPI GetProgmanWindow(void)
1692 return hGlobalProgmanWindow;
1695 /***********************************************************************
1696 * SetShellWindowEx (USER32.@)
1697 * hwndProgman = Progman[Program Manager]
1698 * |-> SHELLDLL_DefView
1699 * hwndListView = | |-> SysListView32
1700 * | | |-> tooltips_class32
1701 * | |
1702 * | |-> SysHeader32
1704 * |-> ProxyTarget
1706 HWND WINAPI SetShellWindowEx ( HWND hwndProgman, HWND hwndListView )
1708 FIXME("0x%08x 0x%08x stub\n",hwndProgman ,hwndListView );
1709 hGlobalShellWindow = hwndProgman;
1710 return hGlobalShellWindow;
1714 /***********************************************************************
1715 * SetTaskmanWindow (USER32.@)
1716 * NOTES
1717 * hwnd = MSTaskSwWClass
1718 * |-> SysTabControl32
1720 HWND WINAPI SetTaskmanWindow ( HWND hwnd )
1722 hGlobalTaskmanWindow = hwnd;
1723 return hGlobalTaskmanWindow;
1726 /***********************************************************************
1727 * GetTaskmanWindow (USER32.@)
1729 HWND WINAPI GetTaskmanWindow(void)
1731 return hGlobalTaskmanWindow;