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/winuser16.h"
35 #include "wine/server.h"
37 #include "user_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
58 #define PLACE_MIN 0x0001
59 #define PLACE_MAX 0x0002
60 #define PLACE_RECT 0x0004
63 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
81 } INTERNALPOS, *LPINTERNALPOS;
83 /* ----- internal functions ----- */
85 static const WCHAR SysIP_W[] = { 'S','y','s','I','P',0 };
87 static inline INTERNALPOS *get_internal_pos( HWND hwnd )
89 return GetPropW( hwnd, SysIP_W );
92 static inline void set_internal_pos( HWND hwnd, INTERNALPOS *pos )
94 SetPropW( hwnd, SysIP_W, pos );
97 /***********************************************************************
98 * WINPOS_CheckInternalPos
100 * Called when a window is destroyed.
102 void WINPOS_CheckInternalPos( HWND hwnd )
104 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
108 if( IsWindow(lpPos->hwndIconTitle) )
109 DestroyWindow( lpPos->hwndIconTitle );
110 HeapFree( GetProcessHeap(), 0, lpPos );
114 /***********************************************************************
115 * ArrangeIconicWindows (USER32.@)
117 UINT WINAPI ArrangeIconicWindows( HWND parent )
121 INT x, y, xspacing, yspacing;
123 GetClientRect( parent, &rectParent );
125 y = rectParent.bottom;
126 xspacing = GetSystemMetrics(SM_CXICONSPACING);
127 yspacing = GetSystemMetrics(SM_CYICONSPACING);
129 hwndChild = GetWindow( parent, GW_CHILD );
132 if( IsIconic( hwndChild ) )
134 WINPOS_ShowIconTitle( hwndChild, FALSE );
136 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
137 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
138 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
139 if( IsWindow(hwndChild) )
140 WINPOS_ShowIconTitle(hwndChild , TRUE );
142 if (x <= rectParent.right - xspacing) x += xspacing;
149 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
155 /***********************************************************************
156 * SwitchToThisWindow (USER32.@)
158 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
160 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
164 /***********************************************************************
165 * GetWindowRect (USER32.@)
167 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
169 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
172 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
173 TRACE( "hwnd %p (%d,%d)-(%d,%d)\n",
174 hwnd, rect->left, rect->top, rect->right, rect->bottom);
180 /***********************************************************************
181 * GetWindowRgn (USER32.@)
183 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
193 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
195 SetLastError( ERROR_OUTOFMEMORY );
198 SERVER_START_REQ( get_window_region )
201 wine_server_set_reply( req, data->Buffer, size );
202 if (!(status = wine_server_call( req )))
204 size_t reply_size = wine_server_reply_size( reply );
207 data->rdh.dwSize = sizeof(data->rdh);
208 data->rdh.iType = RDH_RECTANGLES;
209 data->rdh.nCount = reply_size / sizeof(RECT);
210 data->rdh.nRgnSize = reply_size;
211 win_rgn = ExtCreateRegion( NULL, size, data );
214 else size = reply->total_size;
217 HeapFree( GetProcessHeap(), 0, data );
218 } while (status == STATUS_BUFFER_OVERFLOW);
220 if (status) SetLastError( RtlNtStatusToDosError(status) );
223 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
224 DeleteObject( win_rgn );
230 /***********************************************************************
231 * SetWindowRgn (USER32.@)
233 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
235 static const RECT empty_rect;
243 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
244 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
245 if (!GetRegionData( hrgn, size, data ))
247 HeapFree( GetProcessHeap(), 0, data );
250 SERVER_START_REQ( set_window_region )
253 req->redraw = (bRedraw != 0);
254 if (data->rdh.nCount)
255 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
257 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
258 ret = !wine_server_call_err( req );
262 else /* clear existing region */
264 SERVER_START_REQ( set_window_region )
267 req->redraw = (bRedraw != 0);
268 ret = !wine_server_call_err( req );
273 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
277 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED;
278 if (hrgn) swp_flags |= SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
279 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
280 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
286 /***********************************************************************
287 * GetClientRect (USER32.@)
289 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
293 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
295 rect->right -= rect->left;
296 rect->bottom -= rect->top;
297 rect->left = rect->top = 0;
303 /*******************************************************************
304 * ClientToScreen (USER32.@)
306 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
308 MapWindowPoints( hwnd, 0, lppnt, 1 );
313 /*******************************************************************
314 * ScreenToClient (USER32.@)
316 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
318 MapWindowPoints( 0, hwnd, lppnt, 1 );
323 /***********************************************************************
324 * list_children_from_point
326 * Get the list of children that can contain point from the server.
327 * Point is in screen coordinates.
328 * Returned list must be freed by caller.
330 static HWND *list_children_from_point( HWND hwnd, POINT pt )
339 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
341 SERVER_START_REQ( get_window_children_from_point )
346 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
347 if (!wine_server_call( req )) count = reply->count;
350 if (count && count < size)
355 HeapFree( GetProcessHeap(), 0, list );
357 size = count + 1; /* restart with a large enough buffer */
363 /***********************************************************************
364 * WINPOS_WindowFromPoint
366 * Find the window and hittest for a given point.
368 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
373 if (!hwndScope) hwndScope = GetDesktopWindow();
375 *hittest = HTNOWHERE;
377 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
379 /* now determine the hittest */
381 for (i = 0; list[i]; i++)
383 LONG style = GetWindowLongW( list[i], GWL_STYLE );
385 /* If window is minimized or disabled, return at once */
386 if (style & WS_MINIMIZE)
388 *hittest = HTCAPTION;
391 if (style & WS_DISABLED)
396 /* Send WM_NCCHITTEST (if same thread) */
397 if (!WIN_IsCurrentThread( list[i] ))
402 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
403 if (res != HTTRANSPARENT)
405 *hittest = res; /* Found the window */
408 /* continue search with next window in z-order */
411 HeapFree( GetProcessHeap(), 0, list );
412 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
417 /*******************************************************************
418 * WindowFromPoint (USER32.@)
420 HWND WINAPI WindowFromPoint( POINT pt )
423 return WINPOS_WindowFromPoint( 0, pt, &hittest );
427 /*******************************************************************
428 * ChildWindowFromPoint (USER32.@)
430 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
432 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
435 /*******************************************************************
436 * ChildWindowFromPointEx (USER32.@)
438 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
440 /* pt is in the client coordinates */
446 GetClientRect( hwndParent, &rect );
447 if (!PtInRect( &rect, pt )) return 0;
448 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
450 for (i = 0; list[i]; i++)
452 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
453 if (!PtInRect( &rect, pt )) continue;
454 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
456 LONG style = GetWindowLongW( list[i], GWL_STYLE );
457 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
458 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
460 if (uFlags & CWP_SKIPTRANSPARENT)
462 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
467 HeapFree( GetProcessHeap(), 0, list );
468 if (!retvalue) retvalue = hwndParent;
473 /*******************************************************************
474 * WINPOS_GetWinOffset
476 * Calculate the offset between the origin of the two windows. Used
477 * to implement MapWindowPoints.
479 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
483 offset->x = offset->y = 0;
485 /* Translate source window origin to screen coords */
488 HWND hwnd = hwndFrom;
492 if (hwnd == hwndTo) return;
493 if (!(wndPtr = WIN_GetPtr( hwnd )))
495 ERR( "bad hwndFrom = %p\n", hwnd );
498 if (wndPtr == WND_DESKTOP) break;
499 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
500 offset->x += wndPtr->rectClient.left;
501 offset->y += wndPtr->rectClient.top;
502 hwnd = wndPtr->parent;
503 WIN_ReleasePtr( wndPtr );
507 /* Translate origin to destination window coords */
514 if (!(wndPtr = WIN_GetPtr( hwnd )))
516 ERR( "bad hwndTo = %p\n", hwnd );
519 if (wndPtr == WND_DESKTOP) break;
520 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
521 offset->x -= wndPtr->rectClient.left;
522 offset->y -= wndPtr->rectClient.top;
523 hwnd = wndPtr->parent;
524 WIN_ReleasePtr( wndPtr );
529 other_process: /* one of the parents may belong to another process, do it the hard way */
530 offset->x = offset->y = 0;
531 SERVER_START_REQ( get_windows_offset )
533 req->from = hwndFrom;
535 if (!wine_server_call( req ))
537 offset->x = reply->x;
538 offset->y = reply->y;
545 /*******************************************************************
546 * MapWindowPoints (USER.258)
548 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
549 LPPOINT16 lppt, UINT16 count )
553 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
563 /*******************************************************************
564 * MapWindowPoints (USER32.@)
566 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
570 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
577 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
581 /***********************************************************************
582 * IsIconic (USER32.@)
584 BOOL WINAPI IsIconic(HWND hWnd)
586 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
590 /***********************************************************************
591 * IsZoomed (USER32.@)
593 BOOL WINAPI IsZoomed(HWND hWnd)
595 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
599 /*******************************************************************
600 * AllowSetForegroundWindow (USER32.@)
602 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
604 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
605 * implemented, then fix this function. */
610 /*******************************************************************
611 * LockSetForegroundWindow (USER32.@)
613 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
615 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
616 * implemented, then fix this function. */
621 /***********************************************************************
622 * BringWindowToTop (USER32.@)
624 BOOL WINAPI BringWindowToTop( HWND hwnd )
626 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
630 /***********************************************************************
631 * MoveWindow (USER32.@)
633 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
636 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
637 if (!repaint) flags |= SWP_NOREDRAW;
638 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
639 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
642 /***********************************************************************
643 * WINPOS_InitInternalPos
645 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
647 LPINTERNALPOS lpPos = get_internal_pos( wnd->hwndSelf );
650 /* this happens when the window is minimized/maximized
651 * for the first time (rectWindow is not adjusted yet) */
653 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
654 if( !lpPos ) return NULL;
656 set_internal_pos( wnd->hwndSelf, lpPos );
657 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
658 lpPos->rectNormal.left = wnd->rectWindow.left;
659 lpPos->rectNormal.top = wnd->rectWindow.top;
660 lpPos->rectNormal.right = wnd->rectWindow.right;
661 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
662 lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
663 lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
666 if( wnd->dwStyle & WS_MINIMIZE )
668 lpPos->ptIconPos.x = wnd->rectWindow.left;
669 lpPos->ptIconPos.y = wnd->rectWindow.top;
671 else if( wnd->dwStyle & WS_MAXIMIZE )
673 lpPos->ptMaxPos.x = wnd->rectWindow.left;
674 lpPos->ptMaxPos.y = wnd->rectWindow.top;
678 lpPos->rectNormal.left = wnd->rectWindow.left;
679 lpPos->rectNormal.top = wnd->rectWindow.top;
680 lpPos->rectNormal.right = wnd->rectWindow.right;
681 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
686 /***********************************************************************
687 * WINPOS_RedrawIconTitle
689 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
691 LPINTERNALPOS lpPos = get_internal_pos( hWnd );
694 if( lpPos->hwndIconTitle )
696 SendMessageW( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
697 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
704 /***********************************************************************
705 * WINPOS_ShowIconTitle
707 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
709 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
711 if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
713 HWND title = lpPos->hwndIconTitle;
715 TRACE("%p %i\n", hwnd, (bShow != 0) );
718 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
721 if (!IsWindowVisible(title))
723 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
724 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
725 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
728 else ShowWindow( title, SW_HIDE );
733 /*******************************************************************
734 * WINPOS_GetMinMaxInfo
736 * Get the minimized and maximized information for a window.
738 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
739 POINT *minTrack, POINT *maxTrack )
745 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
746 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
749 /* Compute default values */
751 GetWindowRect(hwnd, &rc);
752 MinMax.ptReserved.x = rc.left;
753 MinMax.ptReserved.y = rc.top;
755 if (style & WS_CHILD)
757 if ((style & WS_CAPTION) == WS_CAPTION)
758 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
760 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
761 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
763 /* avoid calculating this twice */
764 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
766 MinMax.ptMaxSize.x = rc.right - rc.left;
767 MinMax.ptMaxSize.y = rc.bottom - rc.top;
771 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
772 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
774 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
775 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
776 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
777 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
779 if (HAS_DLGFRAME( style, exstyle ))
781 xinc = GetSystemMetrics(SM_CXDLGFRAME);
782 yinc = GetSystemMetrics(SM_CYDLGFRAME);
787 if (HAS_THICKFRAME(style))
789 xinc += GetSystemMetrics(SM_CXFRAME);
790 yinc += GetSystemMetrics(SM_CYFRAME);
792 if (style & WS_BORDER)
794 xinc += GetSystemMetrics(SM_CXBORDER);
795 yinc += GetSystemMetrics(SM_CYBORDER);
798 MinMax.ptMaxSize.x += 2 * xinc;
799 MinMax.ptMaxSize.y += 2 * yinc;
801 lpPos = get_internal_pos( hwnd );
802 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
804 MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
805 MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
809 MinMax.ptMaxPosition.x = -xinc;
810 MinMax.ptMaxPosition.y = -yinc;
813 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
815 /* if the app didn't change the values, adapt them for the current monitor */
817 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
819 MONITORINFO mon_info;
821 mon_info.cbSize = sizeof(mon_info);
822 GetMonitorInfoW( monitor, &mon_info );
824 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
825 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
827 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
828 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
830 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
832 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
833 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
837 /* Some sanity checks */
839 TRACE("%d %d / %d %d / %d %d / %d %d\n",
840 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
841 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
842 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
843 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
844 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
845 MinMax.ptMinTrackSize.x );
846 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
847 MinMax.ptMinTrackSize.y );
849 if (maxSize) *maxSize = MinMax.ptMaxSize;
850 if (maxPos) *maxPos = MinMax.ptMaxPosition;
851 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
852 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
855 /***********************************************************************
856 * ShowWindowAsync (USER32.@)
858 * doesn't wait; returns immediately.
859 * used by threads to toggle windows in other (possibly hanging) threads
861 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
865 if (is_broadcast(hwnd))
867 SetLastError( ERROR_INVALID_PARAMETER );
871 if ((full_handle = WIN_IsCurrentThread( hwnd )))
872 return USER_Driver->pShowWindow( full_handle, cmd );
874 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
878 /***********************************************************************
879 * ShowWindow (USER32.@)
881 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
885 if (is_broadcast(hwnd))
887 SetLastError( ERROR_INVALID_PARAMETER );
890 if ((full_handle = WIN_IsCurrentThread( hwnd )))
891 return USER_Driver->pShowWindow( full_handle, cmd );
893 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
897 /***********************************************************************
898 * GetInternalWindowPos (USER32.@)
900 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
903 WINDOWPLACEMENT wndpl;
904 if (GetWindowPlacement( hwnd, &wndpl ))
906 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
907 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
908 return wndpl.showCmd;
914 /***********************************************************************
915 * GetWindowPlacement (USER32.@)
918 * Fails if wndpl->length of Win95 (!) apps is invalid.
920 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
922 WND *pWnd = WIN_GetPtr( hwnd );
925 if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
926 if (pWnd == WND_OTHER_PROCESS)
928 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
932 lpPos = WINPOS_InitInternalPos( pWnd );
933 wndpl->length = sizeof(*wndpl);
934 if( pWnd->dwStyle & WS_MINIMIZE )
935 wndpl->showCmd = SW_SHOWMINIMIZED;
937 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
938 if( pWnd->flags & WIN_RESTORE_MAX )
939 wndpl->flags = WPF_RESTORETOMAXIMIZED;
942 wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
943 wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
944 wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
945 wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
946 wndpl->rcNormalPosition.left = lpPos->rectNormal.left;
947 wndpl->rcNormalPosition.top = lpPos->rectNormal.top;
948 wndpl->rcNormalPosition.right = lpPos->rectNormal.right;
949 wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
950 WIN_ReleasePtr( pWnd );
955 /***********************************************************************
956 * WINPOS_SetPlacement
958 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
962 WND *pWnd = WIN_GetPtr( hwnd );
964 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
965 lpPos = WINPOS_InitInternalPos( pWnd );
967 if( flags & PLACE_MIN )
969 lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
970 lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
972 if( flags & PLACE_MAX )
974 lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
975 lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
977 if( flags & PLACE_RECT)
979 lpPos->rectNormal.left = wndpl->rcNormalPosition.left;
980 lpPos->rectNormal.top = wndpl->rcNormalPosition.top;
981 lpPos->rectNormal.right = wndpl->rcNormalPosition.right;
982 lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
985 style = pWnd->dwStyle;
986 WIN_ReleasePtr( pWnd );
988 if( style & WS_MINIMIZE )
990 WINPOS_ShowIconTitle( hwnd, FALSE );
991 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
992 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
993 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
995 else if( style & WS_MAXIMIZE )
997 if( !EMPTYPOINT(lpPos->ptMaxPos) )
998 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
999 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1001 else if( flags & PLACE_RECT )
1002 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1003 lpPos->rectNormal.right - lpPos->rectNormal.left,
1004 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1005 SWP_NOZORDER | SWP_NOACTIVATE );
1007 ShowWindow( hwnd, wndpl->showCmd );
1009 if (IsIconic( hwnd ))
1011 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1013 /* SDK: ...valid only the next time... */
1014 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1016 pWnd = WIN_GetPtr( hwnd );
1017 if (pWnd && pWnd != WND_OTHER_PROCESS)
1019 pWnd->flags |= WIN_RESTORE_MAX;
1020 WIN_ReleasePtr( pWnd );
1028 /***********************************************************************
1029 * SetWindowPlacement (USER32.@)
1032 * Fails if wndpl->length of Win95 (!) apps is invalid.
1034 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1036 if (!wpl) return FALSE;
1037 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1041 /***********************************************************************
1042 * AnimateWindow (USER32.@)
1043 * Shows/Hides a window with an animation
1046 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1048 FIXME("partial stub\n");
1050 /* If trying to show/hide and it's already *
1051 * shown/hidden or invalid window, fail with *
1052 * invalid parameter */
1053 if(!IsWindow(hwnd) ||
1054 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1055 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1057 SetLastError(ERROR_INVALID_PARAMETER);
1061 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1066 /***********************************************************************
1067 * SetInternalWindowPos (USER32.@)
1069 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1070 LPRECT rect, LPPOINT pt )
1072 if( IsWindow(hwnd) )
1074 WINDOWPLACEMENT wndpl;
1077 wndpl.length = sizeof(wndpl);
1078 wndpl.showCmd = showCmd;
1079 wndpl.flags = flags = 0;
1084 wndpl.flags |= WPF_SETMINPOSITION;
1085 wndpl.ptMinPosition = *pt;
1089 flags |= PLACE_RECT;
1090 wndpl.rcNormalPosition = *rect;
1092 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1097 /*******************************************************************
1098 * can_activate_window
1100 * Check if we can activate the specified window.
1102 static BOOL can_activate_window( HWND hwnd )
1106 if (!hwnd) return FALSE;
1107 style = GetWindowLongW( hwnd, GWL_STYLE );
1108 if (!(style & WS_VISIBLE)) return FALSE;
1109 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1110 return !(style & WS_DISABLED);
1114 /*******************************************************************
1115 * WINPOS_ActivateOtherWindow
1117 * Activates window other than pWnd.
1119 void WINPOS_ActivateOtherWindow(HWND hwnd)
1123 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1125 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1126 if (can_activate_window( hwndTo )) goto done;
1132 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1133 if (can_activate_window( hwndTo )) break;
1137 fg = GetForegroundWindow();
1138 TRACE("win = %p fg = %p\n", hwndTo, fg);
1139 if (!fg || (hwnd == fg))
1141 if (SetForegroundWindow( hwndTo )) return;
1143 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1147 /***********************************************************************
1148 * WINPOS_HandleWindowPosChanging
1150 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1152 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1154 POINT minTrack, maxTrack;
1155 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1157 if (winpos->flags & SWP_NOSIZE) return 0;
1158 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1160 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1161 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1162 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1163 if (!(style & WS_MINIMIZE))
1165 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1166 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1173 /***********************************************************************
1176 static void dump_winpos_flags(UINT flags)
1179 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1180 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1181 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1182 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1183 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1184 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1185 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1186 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1187 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1188 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1189 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1190 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1191 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1193 #define DUMPED_FLAGS \
1199 SWP_FRAMECHANGED | \
1203 SWP_NOOWNERZORDER | \
1204 SWP_NOSENDCHANGING | \
1208 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1213 /***********************************************************************
1214 * SWP_DoWinPosChanging
1216 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1220 /* Send WM_WINDOWPOSCHANGING message */
1222 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1223 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1225 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1226 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1228 /* Calculate new position and size */
1230 *pNewWindowRect = wndPtr->rectWindow;
1231 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1232 : wndPtr->rectClient;
1234 if (!(pWinpos->flags & SWP_NOSIZE))
1236 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1237 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1239 if (!(pWinpos->flags & SWP_NOMOVE))
1241 pNewWindowRect->left = pWinpos->x;
1242 pNewWindowRect->top = pWinpos->y;
1243 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1244 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1246 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1247 pWinpos->y - wndPtr->rectWindow.top );
1249 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1251 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1252 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1253 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1254 TRACE( "current %s style %08x new %s\n",
1255 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1256 wine_dbgstr_rect( pNewWindowRect ));
1258 WIN_ReleasePtr( wndPtr );
1262 /***********************************************************************
1265 * Compute the valid rects from the old and new client rect and WVR_* flags.
1266 * Helper for WM_NCCALCSIZE handling.
1268 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1273 if (flags & WVR_REDRAW)
1275 SetRectEmpty( &valid[0] );
1276 SetRectEmpty( &valid[1] );
1280 if (flags & WVR_VALIDRECTS)
1282 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1283 !IntersectRect( &valid[1], &valid[1], old_client ))
1285 SetRectEmpty( &valid[0] );
1286 SetRectEmpty( &valid[1] );
1289 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1293 valid[0] = *new_client;
1294 valid[1] = *old_client;
1297 /* make sure the rectangles have the same size */
1298 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1299 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1301 if (flags & WVR_ALIGNBOTTOM)
1303 valid[0].top = valid[0].bottom - cy;
1304 valid[1].top = valid[1].bottom - cy;
1308 valid[0].bottom = valid[0].top + cy;
1309 valid[1].bottom = valid[1].top + cy;
1311 if (flags & WVR_ALIGNRIGHT)
1313 valid[0].left = valid[0].right - cx;
1314 valid[1].left = valid[1].right - cx;
1318 valid[0].right = valid[0].left + cx;
1319 valid[1].right = valid[1].left + cx;
1323 struct move_owned_info
1329 static BOOL CALLBACK move_owned_popups( HWND hwnd, LPARAM lparam )
1331 struct move_owned_info *info = (struct move_owned_info *)lparam;
1333 if (hwnd == info->owner) return FALSE;
1334 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) &&
1335 GetWindow( hwnd, GW_OWNER ) == info->owner)
1337 SetWindowPos( hwnd, info->insert_after, 0, 0, 0, 0,
1338 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
1339 SWP_NOSENDCHANGING | SWP_DEFERERASE );
1340 info->insert_after = hwnd;
1345 /***********************************************************************
1348 * fix Z order taking into account owned popups -
1349 * basically we need to maintain them above the window that owns them
1351 * FIXME: hide/show owned popups when owner visibility changes.
1353 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1355 HWND owner = GetWindow( hwnd, GW_OWNER );
1356 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1357 struct move_owned_info info;
1359 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1361 if ((style & WS_POPUP) && owner)
1363 /* make sure this popup stays above the owner */
1365 if( hwndInsertAfter != HWND_TOP )
1367 HWND hwndLocalPrev = HWND_TOP;
1368 HWND prev = GetWindow( owner, GW_HWNDPREV );
1370 while (prev && prev != hwndInsertAfter)
1372 if (hwndLocalPrev == HWND_TOP && GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)
1373 hwndLocalPrev = prev;
1374 prev = GetWindow( prev, GW_HWNDPREV );
1376 if (!prev) hwndInsertAfter = hwndLocalPrev;
1379 else if (style & WS_CHILD) return hwndInsertAfter;
1382 info.insert_after = hwndInsertAfter;
1383 EnumWindows( move_owned_popups, (LPARAM)&info );
1384 return info.insert_after;
1387 /***********************************************************************
1390 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1396 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1398 /* Send WM_NCCALCSIZE message to get new client area */
1399 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1401 NCCALCSIZE_PARAMS params;
1402 WINDOWPOS winposCopy;
1404 params.rgrc[0] = *pNewWindowRect;
1405 params.rgrc[1] = wndPtr->rectWindow;
1406 params.rgrc[2] = wndPtr->rectClient;
1407 params.lppos = &winposCopy;
1408 winposCopy = *pWinpos;
1409 WIN_ReleasePtr( wndPtr );
1411 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
1413 *pNewClientRect = params.rgrc[0];
1415 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1417 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1418 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1419 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1421 if( pNewClientRect->left != wndPtr->rectClient.left ||
1422 pNewClientRect->top != wndPtr->rectClient.top )
1423 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1425 if( (pNewClientRect->right - pNewClientRect->left !=
1426 wndPtr->rectClient.right - wndPtr->rectClient.left))
1427 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1429 wvrFlags &= ~WVR_HREDRAW;
1431 if (pNewClientRect->bottom - pNewClientRect->top !=
1432 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1433 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1435 wvrFlags &= ~WVR_VREDRAW;
1437 validRects[0] = params.rgrc[1];
1438 validRects[1] = params.rgrc[2];
1442 if (!(pWinpos->flags & SWP_NOMOVE) &&
1443 (pNewClientRect->left != wndPtr->rectClient.left ||
1444 pNewClientRect->top != wndPtr->rectClient.top))
1445 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1448 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1450 SetRectEmpty( &validRects[0] );
1451 SetRectEmpty( &validRects[1] );
1453 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1455 WIN_ReleasePtr( wndPtr );
1459 /* fix redundant flags and values in the WINDOWPOS structure */
1460 static BOOL fixup_flags( WINDOWPOS *winpos )
1463 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1466 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1468 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1471 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1473 /* Finally make sure that all coordinates are valid */
1474 if (winpos->x < -32768) winpos->x = -32768;
1475 else if (winpos->x > 32767) winpos->x = 32767;
1476 if (winpos->y < -32768) winpos->y = -32768;
1477 else if (winpos->y > 32767) winpos->y = 32767;
1479 if (winpos->cx < 0) winpos->cx = 0;
1480 else if (winpos->cx > 32767) winpos->cx = 32767;
1481 if (winpos->cy < 0) winpos->cy = 0;
1482 else if (winpos->cy > 32767) winpos->cy = 32767;
1484 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1485 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1487 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1490 winpos->flags &= ~SWP_HIDEWINDOW;
1491 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1494 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1495 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1496 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1498 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1499 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1501 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1503 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
1505 winpos->flags &= ~SWP_NOZORDER;
1506 winpos->hwndInsertAfter = HWND_TOP;
1510 /* Check hwndInsertAfter */
1511 if (winpos->flags & SWP_NOZORDER) goto done;
1513 /* fix sign extension */
1514 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1515 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1517 /* FIXME: TOPMOST not supported yet */
1518 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
1519 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
1521 /* hwndInsertAfter must be a sibling of the window */
1522 if (winpos->hwndInsertAfter == HWND_TOP)
1524 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1525 winpos->flags |= SWP_NOZORDER;
1527 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1529 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1530 winpos->flags |= SWP_NOZORDER;
1534 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1537 /* don't need to change the Zorder of hwnd if it's already inserted
1538 * after hwndInsertAfter or when inserting hwnd after itself.
1540 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1541 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1542 winpos->flags |= SWP_NOZORDER;
1546 WIN_ReleasePtr( wndPtr );
1550 /***********************************************************************
1553 * User32 internal function
1555 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1557 RECT newWindowRect, newClientRect, valid_rects[2];
1560 orig_flags = winpos->flags;
1562 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1563 if (!(winpos->flags & SWP_NOMOVE))
1565 if (winpos->x < -32768) winpos->x = -32768;
1566 else if (winpos->x > 32767) winpos->x = 32767;
1567 if (winpos->y < -32768) winpos->y = -32768;
1568 else if (winpos->y > 32767) winpos->y = 32767;
1570 if (!(winpos->flags & SWP_NOSIZE))
1572 if (winpos->cx < 0) winpos->cx = 0;
1573 else if (winpos->cx > 32767) winpos->cx = 32767;
1574 if (winpos->cy < 0) winpos->cy = 0;
1575 else if (winpos->cy > 32767) winpos->cy = 32767;
1578 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1580 /* Fix redundant flags */
1581 if (!fixup_flags( winpos )) return FALSE;
1583 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1585 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1586 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1589 /* Common operations */
1591 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1593 if(!USER_Driver->pSetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1594 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
1597 if (!(orig_flags & SWP_SHOWWINDOW))
1599 UINT rdw_flags = RDW_FRAME | RDW_ERASE;
1600 if ( !(orig_flags & SWP_DEFERERASE) ) rdw_flags |= RDW_ERASENOW;
1601 RedrawWindow( winpos->hwnd, NULL, NULL, rdw_flags );
1604 if( winpos->flags & SWP_HIDEWINDOW )
1605 HideCaret(winpos->hwnd);
1606 else if (winpos->flags & SWP_SHOWWINDOW)
1607 ShowCaret(winpos->hwnd);
1609 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1611 /* child windows get WM_CHILDACTIVATE message */
1612 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1613 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1615 SetForegroundWindow( winpos->hwnd );
1618 /* And last, send the WM_WINDOWPOSCHANGED message */
1620 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1622 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1624 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1625 and always contains final window position.
1627 winpos->x = newWindowRect.left;
1628 winpos->y = newWindowRect.top;
1629 winpos->cx = newWindowRect.right - newWindowRect.left;
1630 winpos->cy = newWindowRect.bottom - newWindowRect.top;
1631 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1636 /***********************************************************************
1637 * SetWindowPos (USER32.@)
1639 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1640 INT x, INT y, INT cx, INT cy, UINT flags )
1644 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1645 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1646 if(TRACE_ON(win)) dump_winpos_flags(flags);
1648 if (is_broadcast(hwnd))
1650 SetLastError( ERROR_INVALID_PARAMETER );
1654 winpos.hwnd = WIN_GetFullHandle(hwnd);
1655 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1660 winpos.flags = flags;
1662 if (WIN_IsCurrentThread( hwnd ))
1663 return USER_SetWindowPos(&winpos);
1665 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1669 /***********************************************************************
1670 * BeginDeferWindowPos (USER32.@)
1672 HDWP WINAPI BeginDeferWindowPos( INT count )
1677 TRACE("%d\n", count);
1681 SetLastError(ERROR_INVALID_PARAMETER);
1684 /* Windows allows zero count, in which case it allocates context for 8 moves */
1685 if (count == 0) count = 8;
1687 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1688 if (!handle) return 0;
1689 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1690 pDWP->actualCount = 0;
1691 pDWP->suggestedCount = count;
1693 pDWP->wMagic = DWP_MAGIC;
1694 pDWP->hwndParent = 0;
1696 TRACE("returning hdwp %p\n", handle);
1701 /***********************************************************************
1702 * DeferWindowPos (USER32.@)
1704 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1705 INT x, INT y, INT cx, INT cy,
1710 HDWP newhdwp = hdwp,retvalue;
1712 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1713 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1715 hwnd = WIN_GetFullHandle( hwnd );
1716 if (hwnd == GetDesktopWindow()) return 0;
1718 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1722 for (i = 0; i < pDWP->actualCount; i++)
1724 if (pDWP->winPos[i].hwnd == hwnd)
1726 /* Merge with the other changes */
1727 if (!(flags & SWP_NOZORDER))
1729 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1731 if (!(flags & SWP_NOMOVE))
1733 pDWP->winPos[i].x = x;
1734 pDWP->winPos[i].y = y;
1736 if (!(flags & SWP_NOSIZE))
1738 pDWP->winPos[i].cx = cx;
1739 pDWP->winPos[i].cy = cy;
1741 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1742 SWP_NOZORDER | SWP_NOREDRAW |
1743 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1745 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1751 if (pDWP->actualCount >= pDWP->suggestedCount)
1753 newhdwp = USER_HEAP_REALLOC( hdwp,
1754 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1760 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1761 pDWP->suggestedCount++;
1763 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1764 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1765 pDWP->winPos[pDWP->actualCount].x = x;
1766 pDWP->winPos[pDWP->actualCount].y = y;
1767 pDWP->winPos[pDWP->actualCount].cx = cx;
1768 pDWP->winPos[pDWP->actualCount].cy = cy;
1769 pDWP->winPos[pDWP->actualCount].flags = flags;
1770 pDWP->actualCount++;
1778 /***********************************************************************
1779 * EndDeferWindowPos (USER32.@)
1781 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1788 TRACE("%p\n", hdwp);
1790 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1791 if (!pDWP) return FALSE;
1792 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1794 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1795 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
1796 winpos->cx, winpos->cy, winpos->flags);
1798 if (!(res = USER_SetWindowPos( winpos ))) break;
1800 USER_HEAP_FREE( hdwp );
1805 /***********************************************************************
1806 * TileChildWindows (USER.199)
1808 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1810 FIXME("(%04x, %d): stub\n", parent, action);
1813 /***********************************************************************
1814 * CascadeChildWindows (USER.198)
1816 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1818 FIXME("(%04x, %d): stub\n", parent, action);