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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
28 #define WIN32_NO_STATUS
34 #include "wine/server.h"
36 #include "user_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win);
42 #define SWP_AGG_NOGEOMETRYCHANGE \
43 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
44 #define SWP_AGG_NOPOSCHANGE \
45 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
46 #define SWP_AGG_STATUSFLAGS \
47 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
49 #define HAS_DLGFRAME(style,exStyle) \
50 (((exStyle) & WS_EX_DLGMODALFRAME) || \
51 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
53 #define HAS_THICKFRAME(style) \
54 (((style) & WS_THICKFRAME) && \
55 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
59 #define PLACE_MIN 0x0001
60 #define PLACE_MAX 0x0002
61 #define PLACE_RECT 0x0004
64 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
82 } INTERNALPOS, *LPINTERNALPOS;
84 /* ----- internal functions ----- */
86 static const WCHAR SysIP_W[] = { 'S','y','s','I','P',0 };
88 static inline INTERNALPOS *get_internal_pos( HWND hwnd )
90 return GetPropW( hwnd, SysIP_W );
93 static inline void set_internal_pos( HWND hwnd, INTERNALPOS *pos )
95 SetPropW( hwnd, SysIP_W, pos );
98 /***********************************************************************
99 * WINPOS_CheckInternalPos
101 * Called when a window is destroyed.
103 void WINPOS_CheckInternalPos( HWND hwnd )
105 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
109 if( IsWindow(lpPos->hwndIconTitle) )
110 DestroyWindow( lpPos->hwndIconTitle );
111 HeapFree( GetProcessHeap(), 0, lpPos );
115 /***********************************************************************
116 * ArrangeIconicWindows (USER32.@)
118 UINT WINAPI ArrangeIconicWindows( HWND parent )
122 INT x, y, xspacing, yspacing;
124 GetClientRect( parent, &rectParent );
126 y = rectParent.bottom;
127 xspacing = GetSystemMetrics(SM_CXICONSPACING);
128 yspacing = GetSystemMetrics(SM_CYICONSPACING);
130 hwndChild = GetWindow( parent, GW_CHILD );
133 if( IsIconic( hwndChild ) )
135 WINPOS_ShowIconTitle( hwndChild, FALSE );
137 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
138 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
139 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
140 if( IsWindow(hwndChild) )
141 WINPOS_ShowIconTitle(hwndChild , TRUE );
143 if (x <= rectParent.right - xspacing) x += xspacing;
150 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
156 /***********************************************************************
157 * SwitchToThisWindow (USER32.@)
159 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
161 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
165 /***********************************************************************
166 * GetWindowRect (USER32.@)
168 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
170 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
173 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
174 TRACE( "hwnd %p (%d,%d)-(%d,%d)\n",
175 hwnd, rect->left, rect->top, rect->right, rect->bottom);
181 /***********************************************************************
182 * GetWindowRgn (USER32.@)
184 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
194 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
196 SetLastError( ERROR_OUTOFMEMORY );
199 SERVER_START_REQ( get_window_region )
202 wine_server_set_reply( req, data->Buffer, size );
203 if (!(status = wine_server_call( req )))
205 size_t reply_size = wine_server_reply_size( reply );
208 data->rdh.dwSize = sizeof(data->rdh);
209 data->rdh.iType = RDH_RECTANGLES;
210 data->rdh.nCount = reply_size / sizeof(RECT);
211 data->rdh.nRgnSize = reply_size;
212 win_rgn = ExtCreateRegion( NULL, size, data );
215 else size = reply->total_size;
218 HeapFree( GetProcessHeap(), 0, data );
219 } while (status == STATUS_BUFFER_OVERFLOW);
221 if (status) SetLastError( RtlNtStatusToDosError(status) );
224 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
225 DeleteObject( win_rgn );
231 /***********************************************************************
232 * SetWindowRgn (USER32.@)
234 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
236 static const RECT empty_rect;
244 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
245 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
246 if (!GetRegionData( hrgn, size, data ))
248 HeapFree( GetProcessHeap(), 0, data );
251 SERVER_START_REQ( set_window_region )
254 req->redraw = (bRedraw != 0);
255 if (data->rdh.nCount)
256 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
258 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
259 ret = !wine_server_call_err( req );
263 else /* clear existing region */
265 SERVER_START_REQ( set_window_region )
268 req->redraw = (bRedraw != 0);
269 ret = !wine_server_call_err( req );
274 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
278 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED;
279 if (hrgn) swp_flags |= SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
280 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
281 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
287 /***********************************************************************
288 * GetClientRect (USER32.@)
290 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
294 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
296 rect->right -= rect->left;
297 rect->bottom -= rect->top;
298 rect->left = rect->top = 0;
304 /*******************************************************************
305 * ClientToScreen (USER32.@)
307 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
309 MapWindowPoints( hwnd, 0, lppnt, 1 );
314 /*******************************************************************
315 * ScreenToClient (USER32.@)
317 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
319 MapWindowPoints( 0, hwnd, lppnt, 1 );
324 /***********************************************************************
325 * list_children_from_point
327 * Get the list of children that can contain point from the server.
328 * Point is in screen coordinates.
329 * Returned list must be freed by caller.
331 static HWND *list_children_from_point( HWND hwnd, POINT pt )
340 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
342 SERVER_START_REQ( get_window_children_from_point )
347 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
348 if (!wine_server_call( req )) count = reply->count;
351 if (count && count < size)
356 HeapFree( GetProcessHeap(), 0, list );
358 size = count + 1; /* restart with a large enough buffer */
364 /***********************************************************************
365 * WINPOS_WindowFromPoint
367 * Find the window and hittest for a given point.
369 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
374 if (!hwndScope) hwndScope = GetDesktopWindow();
376 *hittest = HTNOWHERE;
378 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
380 /* now determine the hittest */
382 for (i = 0; list[i]; i++)
384 LONG style = GetWindowLongW( list[i], GWL_STYLE );
386 /* If window is minimized or disabled, return at once */
387 if (style & WS_MINIMIZE)
389 *hittest = HTCAPTION;
392 if (style & WS_DISABLED)
397 /* Send WM_NCCHITTEST (if same thread) */
398 if (!WIN_IsCurrentThread( list[i] ))
403 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
404 if (res != HTTRANSPARENT)
406 *hittest = res; /* Found the window */
409 /* continue search with next window in z-order */
412 HeapFree( GetProcessHeap(), 0, list );
413 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
418 /*******************************************************************
419 * WindowFromPoint (USER32.@)
421 HWND WINAPI WindowFromPoint( POINT pt )
424 return WINPOS_WindowFromPoint( 0, pt, &hittest );
428 /*******************************************************************
429 * ChildWindowFromPoint (USER32.@)
431 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
433 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
436 /*******************************************************************
437 * RealChildWindowFromPoint (USER32.@)
439 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
441 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
444 /*******************************************************************
445 * ChildWindowFromPointEx (USER32.@)
447 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
449 /* pt is in the client coordinates */
455 GetClientRect( hwndParent, &rect );
456 if (!PtInRect( &rect, pt )) return 0;
457 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
459 for (i = 0; list[i]; i++)
461 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
462 if (!PtInRect( &rect, pt )) continue;
463 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
465 LONG style = GetWindowLongW( list[i], GWL_STYLE );
466 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
467 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
469 if (uFlags & CWP_SKIPTRANSPARENT)
471 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
476 HeapFree( GetProcessHeap(), 0, list );
477 if (!retvalue) retvalue = hwndParent;
482 /*******************************************************************
483 * WINPOS_GetWinOffset
485 * Calculate the offset between the origin of the two windows. Used
486 * to implement MapWindowPoints.
488 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
492 offset->x = offset->y = 0;
494 /* Translate source window origin to screen coords */
497 HWND hwnd = hwndFrom;
501 if (hwnd == hwndTo) return;
502 if (!(wndPtr = WIN_GetPtr( hwnd )))
504 ERR( "bad hwndFrom = %p\n", hwnd );
507 if (wndPtr == WND_DESKTOP) break;
508 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
509 offset->x += wndPtr->rectClient.left;
510 offset->y += wndPtr->rectClient.top;
511 hwnd = wndPtr->parent;
512 WIN_ReleasePtr( wndPtr );
516 /* Translate origin to destination window coords */
523 if (!(wndPtr = WIN_GetPtr( hwnd )))
525 ERR( "bad hwndTo = %p\n", hwnd );
528 if (wndPtr == WND_DESKTOP) break;
529 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
530 offset->x -= wndPtr->rectClient.left;
531 offset->y -= wndPtr->rectClient.top;
532 hwnd = wndPtr->parent;
533 WIN_ReleasePtr( wndPtr );
538 other_process: /* one of the parents may belong to another process, do it the hard way */
539 offset->x = offset->y = 0;
540 SERVER_START_REQ( get_windows_offset )
542 req->from = hwndFrom;
544 if (!wine_server_call( req ))
546 offset->x = reply->x;
547 offset->y = reply->y;
554 /*******************************************************************
555 * MapWindowPoints (USER.258)
557 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
558 LPPOINT16 lppt, UINT16 count )
562 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
572 /*******************************************************************
573 * MapWindowPoints (USER32.@)
575 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
579 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
586 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
590 /***********************************************************************
591 * IsIconic (USER32.@)
593 BOOL WINAPI IsIconic(HWND hWnd)
595 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
599 /***********************************************************************
600 * IsZoomed (USER32.@)
602 BOOL WINAPI IsZoomed(HWND hWnd)
604 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
608 /*******************************************************************
609 * AllowSetForegroundWindow (USER32.@)
611 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
613 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
614 * implemented, then fix this function. */
619 /*******************************************************************
620 * LockSetForegroundWindow (USER32.@)
622 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
624 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
625 * implemented, then fix this function. */
630 /***********************************************************************
631 * BringWindowToTop (USER32.@)
633 BOOL WINAPI BringWindowToTop( HWND hwnd )
635 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
639 /***********************************************************************
640 * MoveWindow (USER32.@)
642 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
645 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
646 if (!repaint) flags |= SWP_NOREDRAW;
647 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
648 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
651 /***********************************************************************
652 * WINPOS_InitInternalPos
654 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
656 LPINTERNALPOS lpPos = get_internal_pos( wnd->hwndSelf );
659 /* this happens when the window is minimized/maximized
660 * for the first time (rectWindow is not adjusted yet) */
662 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
663 if( !lpPos ) return NULL;
665 set_internal_pos( wnd->hwndSelf, lpPos );
666 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
667 lpPos->rectNormal.left = wnd->rectWindow.left;
668 lpPos->rectNormal.top = wnd->rectWindow.top;
669 lpPos->rectNormal.right = wnd->rectWindow.right;
670 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
671 lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
672 lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
675 if( wnd->dwStyle & WS_MINIMIZE )
677 lpPos->ptIconPos.x = wnd->rectWindow.left;
678 lpPos->ptIconPos.y = wnd->rectWindow.top;
680 else if( wnd->dwStyle & WS_MAXIMIZE )
682 lpPos->ptMaxPos.x = wnd->rectWindow.left;
683 lpPos->ptMaxPos.y = wnd->rectWindow.top;
687 lpPos->rectNormal.left = wnd->rectWindow.left;
688 lpPos->rectNormal.top = wnd->rectWindow.top;
689 lpPos->rectNormal.right = wnd->rectWindow.right;
690 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
695 /***********************************************************************
696 * WINPOS_RedrawIconTitle
698 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
700 LPINTERNALPOS lpPos = get_internal_pos( hWnd );
703 if( lpPos->hwndIconTitle )
705 SendMessageW( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
706 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
713 /***********************************************************************
714 * WINPOS_ShowIconTitle
716 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
718 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
720 if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
722 HWND title = lpPos->hwndIconTitle;
724 TRACE("%p %i\n", hwnd, (bShow != 0) );
727 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
730 if (!IsWindowVisible(title))
732 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
733 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
734 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
737 else ShowWindow( title, SW_HIDE );
742 /*******************************************************************
743 * WINPOS_GetMinMaxInfo
745 * Get the minimized and maximized information for a window.
747 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
748 POINT *minTrack, POINT *maxTrack )
754 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
755 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
758 /* Compute default values */
760 GetWindowRect(hwnd, &rc);
761 MinMax.ptReserved.x = rc.left;
762 MinMax.ptReserved.y = rc.top;
764 if (style & WS_CHILD)
766 if ((style & WS_CAPTION) == WS_CAPTION)
767 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
769 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
770 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
772 /* avoid calculating this twice */
773 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
775 MinMax.ptMaxSize.x = rc.right - rc.left;
776 MinMax.ptMaxSize.y = rc.bottom - rc.top;
780 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
781 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
783 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
784 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
785 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
786 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
788 if (HAS_DLGFRAME( style, exstyle ))
790 xinc = GetSystemMetrics(SM_CXDLGFRAME);
791 yinc = GetSystemMetrics(SM_CYDLGFRAME);
796 if (HAS_THICKFRAME(style))
798 xinc += GetSystemMetrics(SM_CXFRAME);
799 yinc += GetSystemMetrics(SM_CYFRAME);
801 if (style & WS_BORDER)
803 xinc += GetSystemMetrics(SM_CXBORDER);
804 yinc += GetSystemMetrics(SM_CYBORDER);
807 MinMax.ptMaxSize.x += 2 * xinc;
808 MinMax.ptMaxSize.y += 2 * yinc;
810 lpPos = get_internal_pos( hwnd );
811 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
813 MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
814 MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
818 MinMax.ptMaxPosition.x = -xinc;
819 MinMax.ptMaxPosition.y = -yinc;
822 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
824 /* if the app didn't change the values, adapt them for the current monitor */
826 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
828 MONITORINFO mon_info;
830 mon_info.cbSize = sizeof(mon_info);
831 GetMonitorInfoW( monitor, &mon_info );
833 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
834 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
836 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
837 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
839 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
841 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
842 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
846 /* Some sanity checks */
848 TRACE("%d %d / %d %d / %d %d / %d %d\n",
849 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
850 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
851 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
852 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
853 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
854 MinMax.ptMinTrackSize.x );
855 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
856 MinMax.ptMinTrackSize.y );
858 if (maxSize) *maxSize = MinMax.ptMaxSize;
859 if (maxPos) *maxPos = MinMax.ptMaxPosition;
860 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
861 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
864 /***********************************************************************
865 * ShowWindowAsync (USER32.@)
867 * doesn't wait; returns immediately.
868 * used by threads to toggle windows in other (possibly hanging) threads
870 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
874 if (is_broadcast(hwnd))
876 SetLastError( ERROR_INVALID_PARAMETER );
880 if ((full_handle = WIN_IsCurrentThread( hwnd )))
881 return USER_Driver->pShowWindow( full_handle, cmd );
883 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
887 /***********************************************************************
888 * ShowWindow (USER32.@)
890 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
894 if (is_broadcast(hwnd))
896 SetLastError( ERROR_INVALID_PARAMETER );
899 if ((full_handle = WIN_IsCurrentThread( hwnd )))
900 return USER_Driver->pShowWindow( full_handle, cmd );
902 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
906 /***********************************************************************
907 * GetInternalWindowPos (USER32.@)
909 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
912 WINDOWPLACEMENT wndpl;
913 if (GetWindowPlacement( hwnd, &wndpl ))
915 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
916 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
917 return wndpl.showCmd;
923 /***********************************************************************
924 * GetWindowPlacement (USER32.@)
927 * Fails if wndpl->length of Win95 (!) apps is invalid.
929 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
931 WND *pWnd = WIN_GetPtr( hwnd );
934 if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
935 if (pWnd == WND_OTHER_PROCESS)
937 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
941 lpPos = WINPOS_InitInternalPos( pWnd );
942 wndpl->length = sizeof(*wndpl);
943 if( pWnd->dwStyle & WS_MINIMIZE )
944 wndpl->showCmd = SW_SHOWMINIMIZED;
946 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
947 if( pWnd->flags & WIN_RESTORE_MAX )
948 wndpl->flags = WPF_RESTORETOMAXIMIZED;
951 wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
952 wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
953 wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
954 wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
955 wndpl->rcNormalPosition.left = lpPos->rectNormal.left;
956 wndpl->rcNormalPosition.top = lpPos->rectNormal.top;
957 wndpl->rcNormalPosition.right = lpPos->rectNormal.right;
958 wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
959 WIN_ReleasePtr( pWnd );
964 /***********************************************************************
965 * WINPOS_SetPlacement
967 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
971 WND *pWnd = WIN_GetPtr( hwnd );
973 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
974 lpPos = WINPOS_InitInternalPos( pWnd );
976 if( flags & PLACE_MIN )
978 lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
979 lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
981 if( flags & PLACE_MAX )
983 lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
984 lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
986 if( flags & PLACE_RECT)
988 lpPos->rectNormal.left = wndpl->rcNormalPosition.left;
989 lpPos->rectNormal.top = wndpl->rcNormalPosition.top;
990 lpPos->rectNormal.right = wndpl->rcNormalPosition.right;
991 lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
994 style = pWnd->dwStyle;
995 WIN_ReleasePtr( pWnd );
997 if( style & WS_MINIMIZE )
999 WINPOS_ShowIconTitle( hwnd, FALSE );
1000 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
1001 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
1002 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1004 else if( style & WS_MAXIMIZE )
1006 if( !EMPTYPOINT(lpPos->ptMaxPos) )
1007 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
1008 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1010 else if( flags & PLACE_RECT )
1011 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1012 lpPos->rectNormal.right - lpPos->rectNormal.left,
1013 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1014 SWP_NOZORDER | SWP_NOACTIVATE );
1016 ShowWindow( hwnd, wndpl->showCmd );
1018 if (IsIconic( hwnd ))
1020 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1022 /* SDK: ...valid only the next time... */
1023 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1025 pWnd = WIN_GetPtr( hwnd );
1026 if (pWnd && pWnd != WND_OTHER_PROCESS)
1028 pWnd->flags |= WIN_RESTORE_MAX;
1029 WIN_ReleasePtr( pWnd );
1037 /***********************************************************************
1038 * SetWindowPlacement (USER32.@)
1041 * Fails if wndpl->length of Win95 (!) apps is invalid.
1043 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1045 if (!wpl) return FALSE;
1046 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1050 /***********************************************************************
1051 * AnimateWindow (USER32.@)
1052 * Shows/Hides a window with an animation
1055 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1057 FIXME("partial stub\n");
1059 /* If trying to show/hide and it's already *
1060 * shown/hidden or invalid window, fail with *
1061 * invalid parameter */
1062 if(!IsWindow(hwnd) ||
1063 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1064 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1066 SetLastError(ERROR_INVALID_PARAMETER);
1070 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1075 /***********************************************************************
1076 * SetInternalWindowPos (USER32.@)
1078 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1079 LPRECT rect, LPPOINT pt )
1081 if( IsWindow(hwnd) )
1083 WINDOWPLACEMENT wndpl;
1086 wndpl.length = sizeof(wndpl);
1087 wndpl.showCmd = showCmd;
1088 wndpl.flags = flags = 0;
1093 wndpl.flags |= WPF_SETMINPOSITION;
1094 wndpl.ptMinPosition = *pt;
1098 flags |= PLACE_RECT;
1099 wndpl.rcNormalPosition = *rect;
1101 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1106 /*******************************************************************
1107 * can_activate_window
1109 * Check if we can activate the specified window.
1111 static BOOL can_activate_window( HWND hwnd )
1115 if (!hwnd) return FALSE;
1116 style = GetWindowLongW( hwnd, GWL_STYLE );
1117 if (!(style & WS_VISIBLE)) return FALSE;
1118 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1119 return !(style & WS_DISABLED);
1123 /*******************************************************************
1124 * WINPOS_ActivateOtherWindow
1126 * Activates window other than pWnd.
1128 void WINPOS_ActivateOtherWindow(HWND hwnd)
1132 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1134 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1135 if (can_activate_window( hwndTo )) goto done;
1141 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1142 if (can_activate_window( hwndTo )) break;
1146 fg = GetForegroundWindow();
1147 TRACE("win = %p fg = %p\n", hwndTo, fg);
1148 if (!fg || (hwnd == fg))
1150 if (SetForegroundWindow( hwndTo )) return;
1152 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1156 /***********************************************************************
1157 * WINPOS_HandleWindowPosChanging
1159 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1161 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1163 POINT minTrack, maxTrack;
1164 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1166 if (winpos->flags & SWP_NOSIZE) return 0;
1167 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1169 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1170 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1171 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1172 if (!(style & WS_MINIMIZE))
1174 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1175 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1182 /***********************************************************************
1185 static void dump_winpos_flags(UINT flags)
1188 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1189 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1190 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1191 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1192 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1193 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1194 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1195 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1196 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1197 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1198 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1199 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1200 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1202 #define DUMPED_FLAGS \
1208 SWP_FRAMECHANGED | \
1212 SWP_NOOWNERZORDER | \
1213 SWP_NOSENDCHANGING | \
1217 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1222 /***********************************************************************
1223 * SWP_DoWinPosChanging
1225 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1229 /* Send WM_WINDOWPOSCHANGING message */
1231 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1232 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1234 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1235 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1237 /* Calculate new position and size */
1239 *pNewWindowRect = wndPtr->rectWindow;
1240 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1241 : wndPtr->rectClient;
1243 if (!(pWinpos->flags & SWP_NOSIZE))
1245 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1246 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1248 if (!(pWinpos->flags & SWP_NOMOVE))
1250 pNewWindowRect->left = pWinpos->x;
1251 pNewWindowRect->top = pWinpos->y;
1252 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1253 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1255 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1256 pWinpos->y - wndPtr->rectWindow.top );
1258 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1260 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1261 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1262 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1263 TRACE( "current %s style %08x new %s\n",
1264 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1265 wine_dbgstr_rect( pNewWindowRect ));
1267 WIN_ReleasePtr( wndPtr );
1271 /***********************************************************************
1274 * Compute the valid rects from the old and new client rect and WVR_* flags.
1275 * Helper for WM_NCCALCSIZE handling.
1277 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1282 if (flags & WVR_REDRAW)
1284 SetRectEmpty( &valid[0] );
1285 SetRectEmpty( &valid[1] );
1289 if (flags & WVR_VALIDRECTS)
1291 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1292 !IntersectRect( &valid[1], &valid[1], old_client ))
1294 SetRectEmpty( &valid[0] );
1295 SetRectEmpty( &valid[1] );
1298 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1302 valid[0] = *new_client;
1303 valid[1] = *old_client;
1306 /* make sure the rectangles have the same size */
1307 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1308 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1310 if (flags & WVR_ALIGNBOTTOM)
1312 valid[0].top = valid[0].bottom - cy;
1313 valid[1].top = valid[1].bottom - cy;
1317 valid[0].bottom = valid[0].top + cy;
1318 valid[1].bottom = valid[1].top + cy;
1320 if (flags & WVR_ALIGNRIGHT)
1322 valid[0].left = valid[0].right - cx;
1323 valid[1].left = valid[1].right - cx;
1327 valid[0].right = valid[0].left + cx;
1328 valid[1].right = valid[1].left + cx;
1332 struct move_owned_info
1338 static BOOL CALLBACK move_owned_popups( HWND hwnd, LPARAM lparam )
1340 struct move_owned_info *info = (struct move_owned_info *)lparam;
1342 if (hwnd == info->owner) return FALSE;
1343 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) &&
1344 GetWindow( hwnd, GW_OWNER ) == info->owner)
1346 SetWindowPos( hwnd, info->insert_after, 0, 0, 0, 0,
1347 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
1348 SWP_NOSENDCHANGING | SWP_DEFERERASE );
1349 info->insert_after = hwnd;
1354 /***********************************************************************
1357 * fix Z order taking into account owned popups -
1358 * basically we need to maintain them above the window that owns them
1360 * FIXME: hide/show owned popups when owner visibility changes.
1362 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1364 HWND owner = GetWindow( hwnd, GW_OWNER );
1365 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1366 struct move_owned_info info;
1368 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1370 if ((style & WS_POPUP) && owner)
1372 /* make sure this popup stays above the owner */
1374 if( hwndInsertAfter != HWND_TOP )
1376 HWND hwndLocalPrev = HWND_TOP;
1377 HWND prev = GetWindow( owner, GW_HWNDPREV );
1379 while (prev && prev != hwndInsertAfter)
1381 if (hwndLocalPrev == HWND_TOP && GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)
1382 hwndLocalPrev = prev;
1383 prev = GetWindow( prev, GW_HWNDPREV );
1385 if (!prev) hwndInsertAfter = hwndLocalPrev;
1388 else if (style & WS_CHILD) return hwndInsertAfter;
1391 info.insert_after = hwndInsertAfter;
1392 EnumWindows( move_owned_popups, (LPARAM)&info );
1393 return info.insert_after;
1396 /***********************************************************************
1399 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1405 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1407 /* Send WM_NCCALCSIZE message to get new client area */
1408 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1410 NCCALCSIZE_PARAMS params;
1411 WINDOWPOS winposCopy;
1413 params.rgrc[0] = *pNewWindowRect;
1414 params.rgrc[1] = wndPtr->rectWindow;
1415 params.rgrc[2] = wndPtr->rectClient;
1416 params.lppos = &winposCopy;
1417 winposCopy = *pWinpos;
1418 WIN_ReleasePtr( wndPtr );
1420 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
1422 *pNewClientRect = params.rgrc[0];
1424 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1426 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1427 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1428 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1430 if( pNewClientRect->left != wndPtr->rectClient.left ||
1431 pNewClientRect->top != wndPtr->rectClient.top )
1432 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1434 if( (pNewClientRect->right - pNewClientRect->left !=
1435 wndPtr->rectClient.right - wndPtr->rectClient.left))
1436 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1438 wvrFlags &= ~WVR_HREDRAW;
1440 if (pNewClientRect->bottom - pNewClientRect->top !=
1441 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1442 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1444 wvrFlags &= ~WVR_VREDRAW;
1446 validRects[0] = params.rgrc[1];
1447 validRects[1] = params.rgrc[2];
1451 if (!(pWinpos->flags & SWP_NOMOVE) &&
1452 (pNewClientRect->left != wndPtr->rectClient.left ||
1453 pNewClientRect->top != wndPtr->rectClient.top))
1454 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1457 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1459 SetRectEmpty( &validRects[0] );
1460 SetRectEmpty( &validRects[1] );
1462 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1464 WIN_ReleasePtr( wndPtr );
1468 /* fix redundant flags and values in the WINDOWPOS structure */
1469 static BOOL fixup_flags( WINDOWPOS *winpos )
1472 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1475 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1477 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1480 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1482 /* Finally make sure that all coordinates are valid */
1483 if (winpos->x < -32768) winpos->x = -32768;
1484 else if (winpos->x > 32767) winpos->x = 32767;
1485 if (winpos->y < -32768) winpos->y = -32768;
1486 else if (winpos->y > 32767) winpos->y = 32767;
1488 if (winpos->cx < 0) winpos->cx = 0;
1489 else if (winpos->cx > 32767) winpos->cx = 32767;
1490 if (winpos->cy < 0) winpos->cy = 0;
1491 else if (winpos->cy > 32767) winpos->cy = 32767;
1493 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1494 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1496 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1499 winpos->flags &= ~SWP_HIDEWINDOW;
1500 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1503 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1504 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1505 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1507 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1508 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1510 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1512 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
1514 winpos->flags &= ~SWP_NOZORDER;
1515 winpos->hwndInsertAfter = HWND_TOP;
1519 /* Check hwndInsertAfter */
1520 if (winpos->flags & SWP_NOZORDER) goto done;
1522 /* fix sign extension */
1523 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1524 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1526 /* FIXME: TOPMOST not supported yet */
1527 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
1528 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
1530 /* hwndInsertAfter must be a sibling of the window */
1531 if (winpos->hwndInsertAfter == HWND_TOP)
1533 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1534 winpos->flags |= SWP_NOZORDER;
1536 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1538 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1539 winpos->flags |= SWP_NOZORDER;
1543 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1546 /* don't need to change the Zorder of hwnd if it's already inserted
1547 * after hwndInsertAfter or when inserting hwnd after itself.
1549 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1550 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1551 winpos->flags |= SWP_NOZORDER;
1555 WIN_ReleasePtr( wndPtr );
1559 /***********************************************************************
1562 * User32 internal function
1564 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1566 RECT newWindowRect, newClientRect, valid_rects[2];
1569 orig_flags = winpos->flags;
1571 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1572 if (!(winpos->flags & SWP_NOMOVE))
1574 if (winpos->x < -32768) winpos->x = -32768;
1575 else if (winpos->x > 32767) winpos->x = 32767;
1576 if (winpos->y < -32768) winpos->y = -32768;
1577 else if (winpos->y > 32767) winpos->y = 32767;
1579 if (!(winpos->flags & SWP_NOSIZE))
1581 if (winpos->cx < 0) winpos->cx = 0;
1582 else if (winpos->cx > 32767) winpos->cx = 32767;
1583 if (winpos->cy < 0) winpos->cy = 0;
1584 else if (winpos->cy > 32767) winpos->cy = 32767;
1587 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1589 /* Fix redundant flags */
1590 if (!fixup_flags( winpos )) return FALSE;
1592 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1594 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1595 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1598 /* Common operations */
1600 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1602 if(!USER_Driver->pSetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1603 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
1606 /* erase parent when hiding or resizing child */
1607 if (!(orig_flags & SWP_DEFERERASE) &&
1608 ((orig_flags & SWP_HIDEWINDOW) ||
1609 (!(orig_flags & SWP_SHOWWINDOW) &&
1610 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1612 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1613 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1614 erase_now( parent, 0 );
1617 if( winpos->flags & SWP_HIDEWINDOW )
1618 HideCaret(winpos->hwnd);
1619 else if (winpos->flags & SWP_SHOWWINDOW)
1620 ShowCaret(winpos->hwnd);
1622 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1624 /* child windows get WM_CHILDACTIVATE message */
1625 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1626 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1628 SetForegroundWindow( winpos->hwnd );
1631 /* And last, send the WM_WINDOWPOSCHANGED message */
1633 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1635 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1637 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1638 and always contains final window position.
1640 winpos->x = newWindowRect.left;
1641 winpos->y = newWindowRect.top;
1642 winpos->cx = newWindowRect.right - newWindowRect.left;
1643 winpos->cy = newWindowRect.bottom - newWindowRect.top;
1644 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1649 /***********************************************************************
1650 * SetWindowPos (USER32.@)
1652 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1653 INT x, INT y, INT cx, INT cy, UINT flags )
1657 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1658 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1659 if(TRACE_ON(win)) dump_winpos_flags(flags);
1661 if (is_broadcast(hwnd))
1663 SetLastError( ERROR_INVALID_PARAMETER );
1667 winpos.hwnd = WIN_GetFullHandle(hwnd);
1668 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1673 winpos.flags = flags;
1675 if (WIN_IsCurrentThread( hwnd ))
1676 return USER_SetWindowPos(&winpos);
1678 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1682 /***********************************************************************
1683 * BeginDeferWindowPos (USER32.@)
1685 HDWP WINAPI BeginDeferWindowPos( INT count )
1690 TRACE("%d\n", count);
1694 SetLastError(ERROR_INVALID_PARAMETER);
1697 /* Windows allows zero count, in which case it allocates context for 8 moves */
1698 if (count == 0) count = 8;
1700 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1701 if (!handle) return 0;
1702 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1703 pDWP->actualCount = 0;
1704 pDWP->suggestedCount = count;
1706 pDWP->wMagic = DWP_MAGIC;
1707 pDWP->hwndParent = 0;
1709 TRACE("returning hdwp %p\n", handle);
1714 /***********************************************************************
1715 * DeferWindowPos (USER32.@)
1717 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1718 INT x, INT y, INT cx, INT cy,
1723 HDWP newhdwp = hdwp,retvalue;
1725 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1726 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1728 hwnd = WIN_GetFullHandle( hwnd );
1729 if (hwnd == GetDesktopWindow()) return 0;
1731 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1735 for (i = 0; i < pDWP->actualCount; i++)
1737 if (pDWP->winPos[i].hwnd == hwnd)
1739 /* Merge with the other changes */
1740 if (!(flags & SWP_NOZORDER))
1742 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1744 if (!(flags & SWP_NOMOVE))
1746 pDWP->winPos[i].x = x;
1747 pDWP->winPos[i].y = y;
1749 if (!(flags & SWP_NOSIZE))
1751 pDWP->winPos[i].cx = cx;
1752 pDWP->winPos[i].cy = cy;
1754 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1755 SWP_NOZORDER | SWP_NOREDRAW |
1756 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1758 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1764 if (pDWP->actualCount >= pDWP->suggestedCount)
1766 newhdwp = USER_HEAP_REALLOC( hdwp,
1767 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1773 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1774 pDWP->suggestedCount++;
1776 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1777 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1778 pDWP->winPos[pDWP->actualCount].x = x;
1779 pDWP->winPos[pDWP->actualCount].y = y;
1780 pDWP->winPos[pDWP->actualCount].cx = cx;
1781 pDWP->winPos[pDWP->actualCount].cy = cy;
1782 pDWP->winPos[pDWP->actualCount].flags = flags;
1783 pDWP->actualCount++;
1791 /***********************************************************************
1792 * EndDeferWindowPos (USER32.@)
1794 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1801 TRACE("%p\n", hdwp);
1803 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1804 if (!pDWP) return FALSE;
1805 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1807 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1808 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
1809 winpos->cx, winpos->cy, winpos->flags);
1811 if (!(res = USER_SetWindowPos( winpos ))) break;
1813 USER_HEAP_FREE( hdwp );
1818 /***********************************************************************
1819 * TileChildWindows (USER.199)
1821 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1823 FIXME("(%04x, %d): stub\n", parent, action);
1826 /***********************************************************************
1827 * CascadeChildWindows (USER.198)
1829 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1831 FIXME("(%04x, %d): stub\n", parent, action);