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
23 #include "wine/port.h"
32 #include "wine/winuser16.h"
33 #include "wine/server.h"
39 #include "nonclient.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
44 #define HAS_DLGFRAME(style,exStyle) \
45 (((exStyle) & WS_EX_DLGMODALFRAME) || \
46 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
48 #define HAS_THICKFRAME(style) \
49 (((style) & WS_THICKFRAME) && \
50 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
52 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
54 #define PLACE_MIN 0x0001
55 #define PLACE_MAX 0x0002
56 #define PLACE_RECT 0x0004
59 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
71 /* ----- internal variables ----- */
73 static LPCSTR atomInternalPos;
76 /***********************************************************************
77 * WINPOS_CreateInternalPosAtom
79 BOOL WINPOS_CreateInternalPosAtom()
82 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
83 return (atomInternalPos) ? TRUE : FALSE;
86 /***********************************************************************
87 * WINPOS_CheckInternalPos
89 * Called when a window is destroyed.
91 void WINPOS_CheckInternalPos( HWND hwnd )
93 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
97 if( IsWindow(lpPos->hwndIconTitle) )
98 DestroyWindow( lpPos->hwndIconTitle );
99 HeapFree( GetProcessHeap(), 0, lpPos );
103 /***********************************************************************
104 * ArrangeIconicWindows (USER32.@)
106 UINT WINAPI ArrangeIconicWindows( HWND parent )
110 INT x, y, xspacing, yspacing;
112 GetClientRect( parent, &rectParent );
114 y = rectParent.bottom;
115 xspacing = GetSystemMetrics(SM_CXICONSPACING);
116 yspacing = GetSystemMetrics(SM_CYICONSPACING);
118 hwndChild = GetWindow( parent, GW_CHILD );
121 if( IsIconic( hwndChild ) )
123 WINPOS_ShowIconTitle( hwndChild, FALSE );
125 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
126 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
127 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
128 if( IsWindow(hwndChild) )
129 WINPOS_ShowIconTitle(hwndChild , TRUE );
131 if (x <= rectParent.right - xspacing) x += xspacing;
138 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
144 /***********************************************************************
145 * SwitchToThisWindow (USER32.@)
147 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
149 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
153 /***********************************************************************
154 * GetWindowRect (USER32.@)
156 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
158 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
161 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
162 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
163 hwnd, rect->left, rect->top, rect->right, rect->bottom);
169 /***********************************************************************
170 * GetWindowRgn (USER32.@)
172 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
175 WND *wndPtr = WIN_GetPtr( hwnd );
177 if (wndPtr == WND_OTHER_PROCESS)
179 if (IsWindow( hwnd ))
180 FIXME( "not supported on other process window %p\n", hwnd );
185 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
188 if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
189 WIN_ReleasePtr( wndPtr );
194 /***********************************************************************
195 * SetWindowRgn (USER32.@)
197 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
202 if (hrgn) /* verify that region really exists */
204 if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
207 if (USER_Driver.pSetWindowRgn)
208 return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
210 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
212 if (IsWindow( hwnd ))
213 FIXME( "not supported on other process window %p\n", hwnd );
218 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
222 if (wndPtr->hrgnWnd == hrgn)
224 WIN_ReleasePtr( wndPtr );
230 /* delete previous region */
231 DeleteObject(wndPtr->hrgnWnd);
234 wndPtr->hrgnWnd = hrgn;
235 WIN_ReleasePtr( wndPtr );
237 /* Size the window to the rectangle of the new region (if it isn't NULL) */
238 if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
239 rect.right - rect.left, rect.bottom - rect.top,
240 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
241 SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
246 /***********************************************************************
247 * GetClientRect (USER32.@)
249 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
253 rect->right = rect->bottom = 0;
254 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
256 rect->right -= rect->left;
257 rect->bottom -= rect->top;
259 rect->left = rect->top = 0;
264 /*******************************************************************
265 * ClientToScreen (USER32.@)
267 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
269 MapWindowPoints( hwnd, 0, lppnt, 1 );
274 /*******************************************************************
275 * ScreenToClient (USER32.@)
277 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
279 MapWindowPoints( 0, hwnd, lppnt, 1 );
284 /***********************************************************************
285 * find_child_from_point
287 * Find the child that contains pt. Helper for WindowFromPoint.
288 * pt is in parent client coordinates.
289 * lparam is the param to pass in the WM_NCHITTEST message.
291 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
295 RECT rectWindow, rectClient;
297 HWND *list = WIN_ListChildren( parent );
301 for (i = 0; list[i]; i++)
303 /* If point is in window, and window is visible, and it */
304 /* is enabled (or it's a top-level window), then explore */
305 /* its children. Otherwise, go to the next window. */
307 style = GetWindowLongW( list[i], GWL_STYLE );
308 if (!(style & WS_VISIBLE)) continue; /* not visible -> skip */
309 if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
310 continue; /* disabled child -> skip */
311 exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
312 if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
313 continue; /* transparent -> skip */
315 if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
316 if (!PtInRect( &rectWindow, pt )) continue; /* not in window -> skip */
318 /* FIXME: check window region for other processes too */
319 if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
321 if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
322 pt.x - rectWindow.left, pt.y - rectWindow.top ))
324 WIN_ReleasePtr( wndPtr );
325 continue; /* point outside window region -> skip */
327 WIN_ReleasePtr( wndPtr );
330 /* If window is minimized or disabled, return at once */
331 if (style & WS_MINIMIZE)
333 *hittest = HTCAPTION;
337 if (style & WS_DISABLED)
344 /* If point is in client area, explore children */
345 if (PtInRect( &rectClient, pt ))
349 new_pt.x = pt.x - rectClient.left;
350 new_pt.y = pt.y - rectClient.top;
351 if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
354 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
355 if (!WIN_IsCurrentThread( list[i] ))
361 if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
363 *hittest = res; /* Found the window */
367 /* continue search with next sibling */
369 HeapFree( GetProcessHeap(), 0, list );
374 /***********************************************************************
375 * WINPOS_WindowFromPoint
377 * Find the window and hittest for a given point.
379 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
385 TRACE("scope %p %ld,%ld\n", hwndScope, pt.x, pt.y);
387 if (!hwndScope) hwndScope = GetDesktopWindow();
388 style = GetWindowLongW( hwndScope, GWL_STYLE );
391 if (style & WS_DISABLED) return 0;
393 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
395 if (!(style & WS_MINIMIZE))
398 if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
402 xy.x -= rectClient.left;
403 xy.y -= rectClient.top;
404 if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
406 TRACE( "found child %p\n", ret );
412 /* If nothing found, try the scope window */
413 if (!WIN_IsCurrentThread( hwndScope ))
416 TRACE( "returning %p\n", hwndScope );
419 res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
420 if (res != HTTRANSPARENT)
422 *hittest = res; /* Found the window */
423 TRACE( "returning %p\n", hwndScope );
426 *hittest = HTNOWHERE;
427 TRACE( "nothing found\n" );
432 /*******************************************************************
433 * WindowFromPoint (USER32.@)
435 HWND WINAPI WindowFromPoint( POINT pt )
438 return WINPOS_WindowFromPoint( 0, pt, &hittest );
442 /*******************************************************************
443 * ChildWindowFromPoint (USER32.@)
445 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
447 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
450 /*******************************************************************
451 * ChildWindowFromPointEx (USER32.@)
453 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
455 /* pt is in the client coordinates */
461 GetClientRect( hwndParent, &rect );
462 if (!PtInRect( &rect, pt )) return 0;
463 if (!(list = WIN_ListChildren( hwndParent ))) return 0;
465 for (i = 0; list[i]; i++)
467 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
468 if (!PtInRect( &rect, pt )) continue;
469 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
471 LONG style = GetWindowLongW( list[i], GWL_STYLE );
472 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
473 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
475 if (uFlags & CWP_SKIPTRANSPARENT)
477 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
482 HeapFree( GetProcessHeap(), 0, list );
483 if (!retvalue) retvalue = hwndParent;
488 /*******************************************************************
489 * WINPOS_GetWinOffset
491 * Calculate the offset between the origin of the two windows. Used
492 * to implement MapWindowPoints.
494 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
498 offset->x = offset->y = 0;
500 /* Translate source window origin to screen coords */
503 HWND hwnd = hwndFrom;
507 if (hwnd == hwndTo) return;
508 if (!(wndPtr = WIN_GetPtr( hwnd )))
510 ERR( "bad hwndFrom = %p\n", hwnd );
513 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
514 offset->x += wndPtr->rectClient.left;
515 offset->y += wndPtr->rectClient.top;
516 hwnd = wndPtr->parent;
517 WIN_ReleasePtr( wndPtr );
521 /* Translate origin to destination window coords */
528 if (!(wndPtr = WIN_GetPtr( hwnd )))
530 ERR( "bad hwndTo = %p\n", hwnd );
533 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
534 offset->x -= wndPtr->rectClient.left;
535 offset->y -= wndPtr->rectClient.top;
536 hwnd = wndPtr->parent;
537 WIN_ReleasePtr( wndPtr );
542 other_process: /* one of the parents may belong to another process, do it the hard way */
543 offset->x = offset->y = 0;
544 SERVER_START_REQ( get_windows_offset )
546 req->from = hwndFrom;
548 if (!wine_server_call( req ))
550 offset->x = reply->x;
551 offset->y = reply->y;
558 /*******************************************************************
559 * MapWindowPoints (USER.258)
561 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
562 LPPOINT16 lppt, UINT16 count )
566 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
576 /*******************************************************************
577 * MapWindowPoints (USER32.@)
579 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
583 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
590 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
594 /***********************************************************************
595 * IsIconic (USER32.@)
597 BOOL WINAPI IsIconic(HWND hWnd)
599 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
603 /***********************************************************************
604 * IsZoomed (USER32.@)
606 BOOL WINAPI IsZoomed(HWND hWnd)
608 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
612 /*******************************************************************
613 * AllowSetForegroundWindow (USER32.@)
615 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
617 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
618 * implemented, then fix this function. */
623 /*******************************************************************
624 * LockSetForegroundWindow (USER32.@)
626 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
628 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
629 * implemented, then fix this function. */
634 /***********************************************************************
635 * BringWindowToTop (USER32.@)
637 BOOL WINAPI BringWindowToTop( HWND hwnd )
639 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
643 /***********************************************************************
644 * MoveWindow (USER32.@)
646 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
649 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
650 if (!repaint) flags |= SWP_NOREDRAW;
651 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
652 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
655 /***********************************************************************
656 * WINPOS_InitInternalPos
658 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
660 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
664 /* this happens when the window is minimized/maximized
665 * for the first time (rectWindow is not adjusted yet) */
667 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
668 if( !lpPos ) return NULL;
670 SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
671 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
672 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
673 *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
676 if( wnd->dwStyle & WS_MINIMIZE )
677 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
678 else if( wnd->dwStyle & WS_MAXIMIZE )
679 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
680 else if( restoreRect )
681 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
686 /***********************************************************************
687 * WINPOS_RedrawIconTitle
689 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
691 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
694 if( lpPos->hwndIconTitle )
696 SendMessageA( 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 = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
711 if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_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 SendMessageA( 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 )
744 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
745 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
748 /* Compute default values */
750 GetWindowRect(hwnd, &rc);
751 MinMax.ptReserved.x = rc.left;
752 MinMax.ptReserved.y = rc.top;
754 if (style & WS_CHILD)
756 GetClientRect(GetParent(hwnd), &rc);
757 MinMax.ptMaxSize.x = rc.right;
758 MinMax.ptMaxSize.y = rc.bottom;
762 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
763 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
765 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
766 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
767 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
768 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
770 if (HAS_DLGFRAME( style, exstyle ))
772 xinc = GetSystemMetrics(SM_CXDLGFRAME);
773 yinc = GetSystemMetrics(SM_CYDLGFRAME);
778 if (HAS_THICKFRAME(style))
780 xinc += GetSystemMetrics(SM_CXFRAME);
781 yinc += GetSystemMetrics(SM_CYFRAME);
783 if (style & WS_BORDER)
785 xinc += GetSystemMetrics(SM_CXBORDER);
786 yinc += GetSystemMetrics(SM_CYBORDER);
789 MinMax.ptMaxSize.x += 2 * xinc;
790 MinMax.ptMaxSize.y += 2 * yinc;
792 lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
793 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
794 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
797 MinMax.ptMaxPosition.x = -xinc;
798 MinMax.ptMaxPosition.y = -yinc;
801 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
803 /* Some sanity checks */
805 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
806 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
807 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
808 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
809 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
810 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
811 MinMax.ptMinTrackSize.x );
812 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
813 MinMax.ptMinTrackSize.y );
815 if (maxSize) *maxSize = MinMax.ptMaxSize;
816 if (maxPos) *maxPos = MinMax.ptMaxPosition;
817 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
818 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
821 /***********************************************************************
822 * ShowWindowAsync (USER32.@)
824 * doesn't wait; returns immediately.
825 * used by threads to toggle windows in other (possibly hanging) threads
827 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
831 if (is_broadcast(hwnd))
833 SetLastError( ERROR_INVALID_PARAMETER );
837 if ((full_handle = WIN_IsCurrentThread( hwnd )))
838 return USER_Driver.pShowWindow( full_handle, cmd );
839 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
843 /***********************************************************************
844 * ShowWindow (USER32.@)
846 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
850 if (is_broadcast(hwnd))
852 SetLastError( ERROR_INVALID_PARAMETER );
855 if ((full_handle = WIN_IsCurrentThread( hwnd )))
857 if (USER_Driver.pShowWindow)
858 return USER_Driver.pShowWindow( full_handle, cmd );
861 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
865 /***********************************************************************
866 * GetInternalWindowPos (USER32.@)
868 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
871 WINDOWPLACEMENT wndpl;
872 if (GetWindowPlacement( hwnd, &wndpl ))
874 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
875 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
876 return wndpl.showCmd;
882 /***********************************************************************
883 * GetWindowPlacement (USER32.@)
886 * Fails if wndpl->length of Win95 (!) apps is invalid.
888 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
890 WND *pWnd = WIN_FindWndPtr( hwnd );
893 if(!pWnd ) return FALSE;
895 lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
896 wndpl->length = sizeof(*wndpl);
897 if( pWnd->dwStyle & WS_MINIMIZE )
898 wndpl->showCmd = SW_SHOWMINIMIZED;
900 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
901 if( pWnd->flags & WIN_RESTORE_MAX )
902 wndpl->flags = WPF_RESTORETOMAXIMIZED;
905 CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
906 CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
907 CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
908 WIN_ReleaseWndPtr(pWnd);
913 /***********************************************************************
914 * WINPOS_SetPlacement
916 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
918 WND *pWnd = WIN_FindWndPtr( hwnd );
921 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
922 *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
924 if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
925 if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
926 if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
928 if( pWnd->dwStyle & WS_MINIMIZE )
930 WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
931 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
932 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
933 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
935 else if( pWnd->dwStyle & WS_MAXIMIZE )
937 if( !EMPTYPOINT(lpPos->ptMaxPos) )
938 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
939 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
941 else if( flags & PLACE_RECT )
942 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
943 lpPos->rectNormal.right - lpPos->rectNormal.left,
944 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
945 SWP_NOZORDER | SWP_NOACTIVATE );
947 ShowWindow( hwnd, wndpl->showCmd );
948 if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
950 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
952 /* SDK: ...valid only the next time... */
953 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
955 WIN_ReleaseWndPtr(pWnd);
962 /***********************************************************************
963 * SetWindowPlacement (USER32.@)
966 * Fails if wndpl->length of Win95 (!) apps is invalid.
968 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
970 if (!wpl) return FALSE;
971 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
975 /***********************************************************************
976 * AnimateWindow (USER32.@)
977 * Shows/Hides a window with an animation
980 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
982 FIXME("partial stub\n");
984 /* If trying to show/hide and it's already *
985 * shown/hidden or invalid window, fail with *
986 * invalid parameter */
987 if(!IsWindow(hwnd) ||
988 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
989 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
991 SetLastError(ERROR_INVALID_PARAMETER);
995 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1000 /***********************************************************************
1001 * SetInternalWindowPos (USER32.@)
1003 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1004 LPRECT rect, LPPOINT pt )
1006 if( IsWindow(hwnd) )
1008 WINDOWPLACEMENT wndpl;
1011 wndpl.length = sizeof(wndpl);
1012 wndpl.showCmd = showCmd;
1013 wndpl.flags = flags = 0;
1018 wndpl.flags |= WPF_SETMINPOSITION;
1019 wndpl.ptMinPosition = *pt;
1023 flags |= PLACE_RECT;
1024 wndpl.rcNormalPosition = *rect;
1026 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1031 /*******************************************************************
1032 * can_activate_window
1034 * Check if we can activate the specified window.
1036 static BOOL can_activate_window( HWND hwnd )
1040 if (!hwnd) return FALSE;
1041 style = GetWindowLongW( hwnd, GWL_STYLE );
1042 if (!(style & WS_VISIBLE)) return FALSE;
1043 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1044 return !(style & WS_DISABLED);
1048 /*******************************************************************
1049 * WINPOS_ActivateOtherWindow
1051 * Activates window other than pWnd.
1053 void WINPOS_ActivateOtherWindow(HWND hwnd)
1057 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1059 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1060 if (can_activate_window( hwndTo )) goto done;
1066 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1067 if (can_activate_window( hwndTo )) break;
1071 fg = GetForegroundWindow();
1072 TRACE("win = %p fg = %p\n", hwndTo, fg);
1073 if (!fg || (hwnd == fg))
1075 if (SetForegroundWindow( hwndTo )) return;
1077 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1081 /***********************************************************************
1082 * WINPOS_HandleWindowPosChanging16
1084 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1086 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1088 POINT maxSize, minTrack;
1089 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1091 if (winpos->flags & SWP_NOSIZE) return 0;
1092 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1094 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1095 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1096 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1097 if (!(style & WS_MINIMIZE))
1099 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1100 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1107 /***********************************************************************
1108 * WINPOS_HandleWindowPosChanging
1110 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1112 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1114 POINT maxSize, minTrack;
1115 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1117 if (winpos->flags & SWP_NOSIZE) return 0;
1118 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1120 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1121 winpos->cx = min( winpos->cx, maxSize.x );
1122 winpos->cy = min( winpos->cy, maxSize.y );
1123 if (!(style & WS_MINIMIZE))
1125 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1126 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1133 /***********************************************************************
1136 static void dump_winpos_flags(UINT flags)
1139 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1140 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1141 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1142 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1143 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1144 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1145 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1146 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1147 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1148 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1149 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1150 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1151 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1153 #define DUMPED_FLAGS \
1159 SWP_FRAMECHANGED | \
1163 SWP_NOOWNERZORDER | \
1164 SWP_NOSENDCHANGING | \
1168 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1173 /***********************************************************************
1174 * SetWindowPos (USER32.@)
1176 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1177 INT x, INT y, INT cx, INT cy, UINT flags )
1181 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1182 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1183 if(TRACE_ON(win)) dump_winpos_flags(flags);
1185 if (is_broadcast(hwnd))
1187 SetLastError( ERROR_INVALID_PARAMETER );
1191 winpos.hwnd = WIN_GetFullHandle(hwnd);
1192 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1197 winpos.flags = flags;
1198 if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1199 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1203 /***********************************************************************
1204 * BeginDeferWindowPos (USER32.@)
1206 HDWP WINAPI BeginDeferWindowPos( INT count )
1211 TRACE("%d\n", count);
1215 SetLastError(ERROR_INVALID_PARAMETER);
1218 /* Windows allows zero count, in which case it allocates context for 8 moves */
1219 if (count == 0) count = 8;
1221 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1222 if (!handle) return 0;
1223 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1224 pDWP->actualCount = 0;
1225 pDWP->suggestedCount = count;
1227 pDWP->wMagic = DWP_MAGIC;
1228 pDWP->hwndParent = 0;
1230 TRACE("returning hdwp %p\n", handle);
1235 /***********************************************************************
1236 * DeferWindowPos (USER32.@)
1238 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1239 INT x, INT y, INT cx, INT cy,
1244 HDWP newhdwp = hdwp,retvalue;
1246 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1247 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1249 hwnd = WIN_GetFullHandle( hwnd );
1250 if (hwnd == GetDesktopWindow()) return 0;
1252 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1256 for (i = 0; i < pDWP->actualCount; i++)
1258 if (pDWP->winPos[i].hwnd == hwnd)
1260 /* Merge with the other changes */
1261 if (!(flags & SWP_NOZORDER))
1263 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1265 if (!(flags & SWP_NOMOVE))
1267 pDWP->winPos[i].x = x;
1268 pDWP->winPos[i].y = y;
1270 if (!(flags & SWP_NOSIZE))
1272 pDWP->winPos[i].cx = cx;
1273 pDWP->winPos[i].cy = cy;
1275 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1276 SWP_NOZORDER | SWP_NOREDRAW |
1277 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1279 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1285 if (pDWP->actualCount >= pDWP->suggestedCount)
1287 newhdwp = USER_HEAP_REALLOC( hdwp,
1288 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1294 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1295 pDWP->suggestedCount++;
1297 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1298 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1299 pDWP->winPos[pDWP->actualCount].x = x;
1300 pDWP->winPos[pDWP->actualCount].y = y;
1301 pDWP->winPos[pDWP->actualCount].cx = cx;
1302 pDWP->winPos[pDWP->actualCount].cy = cy;
1303 pDWP->winPos[pDWP->actualCount].flags = flags;
1304 pDWP->actualCount++;
1312 /***********************************************************************
1313 * EndDeferWindowPos (USER32.@)
1315 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1322 TRACE("%p\n", hdwp);
1324 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1325 if (!pDWP) return FALSE;
1326 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1328 if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1330 USER_HEAP_FREE( hdwp );
1335 /***********************************************************************
1336 * TileChildWindows (USER.199)
1338 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1340 FIXME("(%04x, %d): stub\n", parent, action);
1343 /***********************************************************************
1344 * CascadeChildWindows (USER.198)
1346 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1348 FIXME("(%04x, %d): stub\n", parent, action);